6c548fbbc3803e1c2e8c25f908ffdc3e857bf076
[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_file,test_yaffs_open_file_clean,"test_yaffs_open_file"},
35         {test_yaffs_open_file_ENOENT,test_yaffs_open_file_ENOENT_clean,"test_yaffs_open_file_ENOENT"},
36         
37         {test_yaffs_access,test_yaffs_access_clean,"test_yaffs_access"},
38         {test_yaffs_unlinking, test_yaffs_unlinking_clean,"test_yaffs_unlinking"},
39
40         {test_yaffs_lseek,test_yaffs_lseek_clean,"test_yaffs_lseek"},
41         {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
42         {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
43
44
45         {test_yaffs_stat,test_yaffs_stat_clean,"test_yaffs_stat"},
46         {test_yaffs_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
47         {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
48
49         };
50
51 unsigned int num_of_tests_pass=0;
52 unsigned int num_of_tests_failed=0;
53 unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
54
55 int main(){
56         int output=0;
57
58
59         unsigned int x=0;       
60         init_quick_tests();
61         printf("\n\nrunning quick tests for yaffs\n");
62         //printf("testing yaffs\n");
63
64         //printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
65         for (x=0;x<total_number_of_tests;x++){
66                 //printf("x %d\n",x);
67                 output=test_list[x].p_function();       /*run test*/
68                 if (output>=0){
69                         /*test has passed*/
70                         num_of_tests_pass++;
71                 }
72                 else {
73                         /*test is assumed to have failed*/
74                         //printf("test failed\n");
75                         printf("test: %s failed\n",test_list[x].fail_message);          
76                         num_of_tests_failed ++; 
77                         quit_quick_tests(1);
78                         
79                 }
80                 output=test_list[x].p_function_clean(); /*clean the test*/
81                 if (output <0){
82                         /* if the test failed to clean it's self then */
83                         printf("test: %s failed to clean\n",test_list[x].fail_message);         
84                         num_of_tests_failed ++; 
85                         num_of_tests_pass--;
86                         quit_quick_tests(1);
87                 }
88                         
89         }
90         /*this is where the loop should break to*/
91         quit_quick_tests(0);
92         /* the progame should never get here*/  
93         return 0;
94 }
95
96 void quit_quick_tests(int exit_code){
97         int error_code=0;
98         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
99                 printf("\t OK \n");
100         }
101         else {
102                 error_code=yaffs_get_error();
103                 printf("yaffs_error code %d\n",error_code);
104                 printf("error is : %s\n",yaffs_error_to_str(error_code));
105         }
106         printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
107         yaffs_unmount(YAFFS_MOUNT_POINT);
108         exit(exit_code);
109 }
110
111 void init_quick_tests(void){
112         yaffs_start_up();;
113         yaffs_set_trace(0);
114
115 }