# yaffs_checkptrwtest.o\
-YAFFSTESTOBJS = $(COMMONTESTOBJS) quick_tests.o test_mount_yaffs.o
+YAFFSTESTOBJS = $(COMMONTESTOBJS) quick_tests.o lib.o test_mount_yaffs.o test_yaffs_unlinking.o test_open_file.o test_yaffs_ftruncate.o test_yaffs_truncate.o \
+ test_yaffs_write.o test_yaffs_read.o test_yaffs_lseek.o
+
ALLOBJS = $(sort $(YAFFSTESTOBJS))
--- /dev/null
+#include "lib.h"
+
+
+void join_paths(char *path1,char *path2,char *new_path ){
+
+ //strcat(new_path,path1); /*since all functions have this then pull it out*/
+ if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
+ /*paths are compatiable. concatanate them. note -2 is because of \0*/
+ strcat(new_path,path1);
+ strcat(new_path,path2);
+ //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
+ //strcpy(new_path,strcat(path1,path2));
+ //return new_path;
+ }
+ else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
+ /*paths are compatiable. concatanate them*/
+ strcat(new_path,path1);
+ strcat(new_path,path2);
+
+ }
+ else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
+ /*need to add a "/". */
+ strcat(new_path,path1);
+ strcat(new_path,"/");
+ strcat(new_path,path2);
+
+
+ }
+ else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
+ /*need to remove a "/". */
+ /*yaffs does not mind the extra slash. */
+ strcat(new_path,path1);
+ strcat(new_path,path2);
+
+ }
+ else{
+ //error
+ //return -1;
+ }
+}
+
--- /dev/null
+#ifndef _lib_h__
+#define _lib_h__
+
+
+#include <string.h>
+#define YAFFS_MOUNT_POINT "/yaffs2/"
+#define FILE_NAME "foo"
+#define FILE_SIZE 9
+
+#define FILE_SIZE_TRUNCATED 100
+#define FILE_TEXT "file foo"
+#define FILE_TEXT_NBYTES 9
+
+/* warning do not define anything as FILE because there seems to be a conflict with stdio.h */
+#define FILE_PATH "/yaffs2/foo"
+
+void join_paths(char *path1,char *path2,char *new_path );
+#endif
typedef struct test {
int (*p_function)(void); /*pointer to test function*/
- void (*p_function_clean)(void);
+ int (*p_function_clean)(void);
/*char pass_message[50]; will not need a pass message*/
char *fail_message; /*pointer to fail message, needs to include name of test*/
}test_template;
}
int dummy_test_fail(void){
//printf("running dummy_test_fail\n");
- return 0;
+ return -1;
}
void dummy_test_fail_clean(void){
}
test_template test_list[]={
- {dummy_test_pass,dummy_test_pass_clean,"dummy_test_pass"},
- {dummy_test_fail,dummy_test_fail_clean,"dummy_test_fail"},
- {mount_yaffs_test,mount_yaffs_test_clean,"mount_yaffs_test"}
+ //{dummy_test_pass,dummy_test_pass_clean,"dummy_test_pass"},
+ //{dummy_test_fail,dummy_test_fail_clean,"dummy_test_fail"},
+ {mount_yaffs_test,mount_yaffs_test_clean,"mount_yaffs_test"},
+
+ {test_open_file,test_open_file_clean,"test_open_file"},
+ {test_yaffs_unlinking, test_yaffs_unlinking_clean,"test_yaffs_unlinking"},
+
+ {test_yaffs_lseek,test_yaffs_lseek_clean,"test_yaffs_lseek"},
+ {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
+ {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
+
+ {test_yaffs_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
+ {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
+
};
+unsigned int num_of_tests_pass=0;
+unsigned int num_of_tests_failed=0;
+unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
int main(){
int output=0;
- unsigned int num_of_tests_pass=0;
- int num_of_tests_failed=0;
- unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
+
+
unsigned int x=0;
init_quick_tests();
- printf("quick tests for yaffs\n");
+ printf("\n\nrunning quick tests for yaffs\n");
//printf("testing yaffs\n");
//printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
for (x=0;x<total_number_of_tests;x++){
//printf("x %d\n",x);
output=test_list[x].p_function(); /*run test*/
- if (output>0){
+ if (output>=0){
/*test has passed*/
num_of_tests_pass++;
}
//printf("test failed\n");
printf("test: %s failed\n",test_list[x].fail_message);
num_of_tests_failed ++;
+ quit_quick_tests(1);
+
+ }
+ output=test_list[x].p_function_clean(); /*clean the test*/
+ if (output <0){
+ /* if the test failed to clean it's self then */
+ printf("test: %s failed to clean\n",test_list[x].fail_message);
+ num_of_tests_failed ++;
+ num_of_tests_pass--;
+ quit_quick_tests(1);
}
- test_list[x].p_function_clean(); /*run test*/
}
- if (num_of_tests_pass==total_number_of_tests){
+ /*this is where the loop should break to*/
+ quit_quick_tests(0);
+ /* the progame should never get here*/
+ return 0;
+}
+
+void quit_quick_tests(int exit_code){
+ if (num_of_tests_pass==total_number_of_tests && num_of_tests_failed==0){
printf("\t OK \n");
}
- printf("tests: %d passed %d failed\n",num_of_tests_pass,num_of_tests_failed);
- return 0;
+ printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
+ exit(exit_code);
}
void init_quick_tests(void){
yaffs_start_up();;
- //yaffs_set_trace(0);
+ yaffs_set_trace(0);
}
#ifndef __quick_tests_h__
#define __quick_tests_h__
#include <stdio.h>
-#include "test_mount_yaffs.h"
-
+#include "test_mount_yaffs.h"
+#include "test_open_file.h"
+#include "test_yaffs_unlinking.h"
+#include "test_yaffs_ftruncate.h"
+#include "test_yaffs_truncate.h"
+#include "test_yaffs_write.h"
+#include "test_yaffs_read.h"
+#include "test_yaffs_lseek.h"
#define YAFFS_MOUNT_POINT "/yaffs2/"
void init_quick_tests(void);
int dummy_test_pass(void);
-int dummy_test_pass(void);
+int dummy_test_fail(void);
+void quit_quick_tests(int exit_code);
#endif
#include "test_mount_yaffs.h"
#include "yaffsfs.h"
+#include "lib.h"
+
int mount_yaffs_test(void){
int output=0;
output=yaffs_mount(YAFFS_MOUNT_POINT);
+ /*printf("output %d",output);*/
return output;
}
-void mount_yaffs_test_clean(void){
- yaffs_unmount(YAFFS_MOUNT_POINT);
+int mount_yaffs_test_clean(void){
+ return 1;
+
}
#ifndef __mount_yaffs_test__
#define __mount_yaffs_test__
-#define YAFFS_MOUNT_POINT "/yaffs2/"
+
int mount_yaffs_test(void);
-void mount_yaffs_test_clean(void);
+int mount_yaffs_test_clean(void);
#endif
--- /dev/null
+#include "test_open_file.h"
+#include "lib.h"
+#include "yaffsfs.h"
+
+
+
+int test_open_file(void){
+
+ int output=0;
+
+ /*printf("path %s\n",path); */
+ output=yaffs_open(FILE_PATH,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
+
+ return output;
+}
+int test_open_file_clean(void){
+ return 1;
+}
+
--- /dev/null
+#ifndef __test_open_file_h__
+#define __test_open_file_h__
+
+int test_open_file(void);
+int test_open_file_clean(void);
+#endif
--- /dev/null
+#include "test_yaffs_ftruncate.h"
+
+int test_yaffs_ftruncate(void){
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_ftruncate(handle,FILE_SIZE_TRUNCATED );
+ }
+ else {
+ printf("error opening file");
+ return -1;
+ }
+}
+
+int test_yaffs_ftruncate_clean(void){
+ /* change file size back to orignal size */
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_ftruncate(handle,FILE_SIZE );
+ }
+ else {
+ printf("error opening file in clean function");
+ return -1;
+ }
+
+}
--- /dev/null
+#ifndef __test_yaffs_ftruncate_h__
+#define __test_yaffs_ftruncate_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+int test_yaffs_ftruncate(void);
+int test_yaffs_ftruncate_clean(void);
+#endif
--- /dev/null
+#include "test_yaffs_lseek.h"
+
+int test_yaffs_lseek(void){
+ int handle=test_open_file();
+ char text[20]="\0";
+ int output=0;
+ if (handle>0){
+ return yaffs_lseek(handle, 0, SEEK_SET);
+ /*
+ if (output>0){
+ if (text==FILE_TEXT){
+ return 1;
+ }
+ else {
+ printf("text does not match the the text that should be in the file\n");
+ }
+ }
+ else{
+ printf("error reading file");
+ } */
+ }
+ else {
+ printf("error opening file\n");
+ return -1;
+ }
+
+}
+
+int test_yaffs_lseek_clean(void){
+ /* need to reset the seek position*/
+ return test_yaffs_lseek_to_beginning();
+}
+int test_yaffs_lseek_to_beginning(void){
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_lseek(handle, 0, SEEK_SET);
+ }
+ else {
+ printf("error opening file\n");
+ return -1;
+ }
+}
--- /dev/null
+#ifndef __test_yaffs_lseek_h__
+#define __test_yaffs_lseek_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+int test_yaffs_lseek(void);
+int test_yaffs_lseek_clean(void);
+int test_yaffs_lseek_to_beginning(void);
+#endif
--- /dev/null
+#include "test_yaffs_write.h"
+
+int test_yaffs_read(void){
+ int handle=test_open_file();
+ char text[20]="\0";
+ int output=0;
+ if (handle>0){
+ output=yaffs_read(handle, text, FILE_TEXT_NBYTES);
+ if (output>0){
+ if (text==FILE_TEXT){
+ return 1;
+ }
+ else {
+ printf("text does not match the the text that should be in the file\n");
+ }
+ }
+ else{
+ printf("error reading file");
+ }
+ }
+ else {
+ printf("error opening file\n");
+ return -1;
+ }
+
+}
+
+int test_yaffs_read_clean(void){
+ /* need to reset the seek position*/
+
+ return test_yaffs_lseek_to_beginning();
+}
--- /dev/null
+#ifndef __test_yaffs_read_h__
+#define __test_yaffs_read_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_read(void);
+int test_yaffs_read_clean(void);
+#endif
--- /dev/null
+#include "test_yaffs_truncate.h"
+
+int test_yaffs_truncate(void){
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_truncate(FILE_PATH,FILE_SIZE_TRUNCATED );
+ }
+ else {
+ printf("error opening file");
+ return -1;
+ }
+}
+
+int test_yaffs_truncate_clean(void){
+ /* change file size back to orignal size */
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_truncate(FILE_PATH,FILE_SIZE );
+ }
+ else {
+ printf("error opening file in clean function");
+ return -1;
+ }
+
+}
--- /dev/null
+#ifndef __test_yaffs_truncate_h__
+#define __test_yaffs_truncate_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+int test_yaffs_truncate(void);
+int test_yaffs_truncate_clean(void);
+#endif
--- /dev/null
+#include "test_yaffs_unlinking.h"
+
+int test_yaffs_unlinking(void){
+ int output=yaffs_unlink(FILE_PATH);
+ return output;
+}
+
+int test_yaffs_unlinking_clean(void){
+ return test_open_file();
+}
--- /dev/null
+#ifndef __test_yaffs_unlinking_h__
+#define __test_yaffs_unlinking_h__
+
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+
+int test_yaffs_unlinking(void);
+int test_yaffs_unlinking_clean(void);
+#endif
--- /dev/null
+#include "test_yaffs_write.h"
+
+int test_yaffs_write(void){
+ int handle=test_open_file();
+ if (handle>0){
+ return yaffs_write(handle, FILE_TEXT, FILE_TEXT_NBYTES);
+ }
+ else {
+ printf("error opening file");
+ return -1;
+ }
+
+}
+
+int test_yaffs_write_clean(void){
+ return 1;
+}
--- /dev/null
+#ifndef __test_yaffs_write_h__
+#define __test_yaffs_write_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_write(void);
+int test_yaffs_write_clean(void);
+#endif