yaffs Adding more error code test programs to quick tests. note the bugs are still...
[yaffs2.git] / direct / timothy_tests / quick_tests / quick_tests.c
1 #include "quick_tests.h"
2
3
4 int random_seed;
5 int simulate_power_failure = 0;
6
7
8
9 typedef struct test {
10         int (*p_function)(void);        /*pointer to test function*/
11         int (*p_function_clean)(void);
12         /*char pass_message[50]; will not need a pass message*/
13         char *fail_message;     /*pointer to fail message, needs to include name of test*/
14 }test_template;
15
16
17 int dummy_test_pass(void){
18         //printf("running dummy_test_pass\n");
19         return 1;
20 }
21 void dummy_test_pass_clean(void){
22         
23 }
24 int dummy_test_fail(void){
25         //printf("running dummy_test_fail\n");
26         return -1;
27 }
28 void dummy_test_fail_clean(void){
29 }
30 test_template test_list[]={
31         //{dummy_test_pass,dummy_test_pass_clean,"dummy_test_pass"},
32         //{dummy_test_fail,dummy_test_fail_clean,"dummy_test_fail"},
33         {mount_yaffs_test,mount_yaffs_test_clean,"mount_yaffs_test"},
34         {test_yaffs_open,test_yaffs_open_clean,"test_yaffs_open"},
35         {test_yaffs_open_EISDIR,test_yaffs_open_EISDIR_clean,"test_yaffs_open_EISDIR"},
36         {test_yaffs_open_EEXIST,test_yaffs_open_EEXIST_clean,"test_yaffs_open_EEXIST"},
37         {test_yaffs_open_ENOTDIR,test_yaffs_open_ENOTDIR_clean,"test_yaffs_open_ENOTDIR"},
38         {test_yaffs_open_ENOENT,test_yaffs_open_ENOENT_clean,"test_yaffs_open_ENOENT"},
39         
40         {test_yaffs_access,test_yaffs_access_clean,"test_yaffs_access"},
41         {test_yaffs_unlinking, test_yaffs_unlinking_clean,"test_yaffs_unlinking"},
42
43         {test_yaffs_lseek,test_yaffs_lseek_clean,"test_yaffs_lseek"},
44         {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
45         {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
46
47
48         {test_yaffs_stat,test_yaffs_stat_clean,"test_yaffs_stat"},
49         {test_yaffs_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
50         {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
51
52         };
53
54 unsigned int num_of_tests_pass=0;
55 unsigned int num_of_tests_failed=0;
56 unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
57
58 int main(){
59         int output=0;
60
61
62         unsigned int x=0;       
63         init_quick_tests();
64         printf("\n\nrunning quick tests for yaffs\n");
65         //printf("testing yaffs\n");
66
67         //printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
68         for (x=0;x<total_number_of_tests;x++){
69                 //printf("x %d\n",x);
70                 output=test_list[x].p_function();       /*run test*/
71                 if (output>=0){
72                         /*test has passed*/
73                         num_of_tests_pass++;
74                 }
75                 else {
76                         /*test is assumed to have failed*/
77                         //printf("test failed\n");
78                         printf("test: %s failed\n",test_list[x].fail_message);          
79                         num_of_tests_failed ++; 
80                         quit_quick_tests(1);
81                         
82                 }
83                 output=test_list[x].p_function_clean(); /*clean the test*/
84                 if (output <0){
85                         /* if the test failed to clean it's self then */
86                         printf("test: %s failed to clean\n",test_list[x].fail_message);         
87                         num_of_tests_failed ++; 
88                         num_of_tests_pass--;
89                         quit_quick_tests(1);
90                 }
91                         
92         }
93         /*this is where the loop should break to*/
94         quit_quick_tests(0);
95         /* the progame should never get here*/  
96         return 0;
97 }
98
99 void quit_quick_tests(int exit_code){
100         int error_code=0;
101         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
102                 printf("\t OK \n");
103         }
104         else {
105                 error_code=yaffs_get_error();
106                 printf("yaffs_error code %d\n",error_code);
107                 printf("error is : %s\n",yaffs_error_to_str(error_code));
108         }
109         printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
110         yaffs_unmount(YAFFS_MOUNT_POINT);
111         exit(exit_code);
112 }
113
114 void init_quick_tests(void){
115         yaffs_start_up();;
116         yaffs_set_trace(0);
117
118 }