yaffs Fixed some tests in direct/timothy_tests/quick_tests
[yaffs2.git] / direct / timothy_tests / quick_tests / quick_tests.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2010 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Timothy Manning <timothy@yaffs.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include "quick_tests.h"
15
16
17 int random_seed;
18 int simulate_power_failure = 0;
19
20
21
22
23
24 static unsigned int num_of_tests_pass=0;
25 static unsigned int num_of_tests_failed=0;
26 static unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
27
28 int main(int argc, char *argv[]){
29         int output=0;
30         char message[30];
31         message[0]='\0';
32         unsigned int x=0;
33
34         init_quick_tests(argc, argv);
35         print_message("\n\nrunning quick tests for yaffs\n\n", 0);
36
37         for (x=0;x<total_number_of_tests;x++){
38         /*      output=yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
39                 printf("yaffs_open %d \n",output);
40                 printf("yaffs_close %d \n",yaffs_close(output));
41         */      yaffs_set_error(0);     /*reset the last error to 0 */
42                 //printf("foo exists %d\n",test_yaffs_open());
43                 sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test);
44                 print_message(message,3);
45                 output=test_list[x].p_function();       /*run test*/
46                 if (output>=0){
47                         /*test has passed*/
48                         sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test);
49                         print_message(message,3); 
50                         num_of_tests_pass++;
51                 } else {
52                         /*test is assumed to have failed*/
53                         //printf("test failed\n");
54                         sprintf(message,"test: %s failed\n",test_list[x].name_of_test);
55                         print_message(message,1);               
56                         num_of_tests_failed ++; 
57                 
58                         get_error();
59                         print_message("\n\n",1);
60                         if (get_exit_on_error()){       
61                                 quit_quick_tests(1);
62                         }
63
64                 }
65                 output=0;
66                 output=test_list[x].p_function_clean(); /*clean the test*/
67                 if (output <0){
68                         /* if the test failed to clean it's self then */
69                         sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test);
70                         print_message(message,1);               
71                         num_of_tests_failed ++; 
72                         num_of_tests_pass--;
73                         get_error();
74                         printf("\n\n");
75                         if (get_exit_on_error()){
76                                 quit_quick_tests(1);
77                         }
78                         
79                 } else {
80                         sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
81                         print_message(message,3);
82                 }
83         }
84         /*this is where the loop should break to*/
85         quit_quick_tests(0);
86 }
87
88 void quit_quick_tests(int exit_code)
89 {
90         char message[30];
91         message[0]='\0';        
92         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
93                 printf("\t OK --all tests passed\n");
94         }
95         printf("out of %d tests, %d ran: %d passed and %d failed\n\n\n", total_number_of_tests,(num_of_tests_pass+num_of_tests_failed) ,num_of_tests_pass,num_of_tests_failed);
96         yaffs_unmount(YAFFS_MOUNT_POINT);
97         exit(exit_code);
98 }
99
100 void get_error(void)
101 {
102         int error_code=0;
103         char message[30];
104         message[0]='\0';
105
106         error_code=yaffs_get_error();
107         sprintf(message,"yaffs_error code %d\n",error_code);
108         print_message(message,1);
109         sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
110         print_message(message,1);
111 }
112
113 void init_quick_tests(int argc, char *argv[])
114 {
115         int trace=0;
116         int x=0;        
117         for (x = 0; x < argc; x++){
118                 if (0==strcmp(argv[x],"-h")){
119                         printf("help\n");
120                         printf("-h will print the commands available\n");
121                         printf("-c will continue after a test failes else the program will exit\n");
122                         printf("-v will print all messages\n");
123                         printf("-q quiet mode only the number of tests passed and failed will be printed\n");
124                         printf("-t [number] set yaffs_trace to number\n");
125                         exit(0);
126                 } else if (0==strcmp(argv[x],"-c")) {
127                         set_exit_on_error(0);
128                 } else if (0==strcmp(argv[x],"-q")) {
129                         set_print_level(-3);
130                 } else if (0==strcmp(argv[x],"-t")) {
131                         trace = atoi(argv[x+1]);
132                 }  else if (0==strcmp(argv[x],"-v")) {
133                         set_print_level(5);
134                 }
135
136         }
137         yaffs_start_up();
138         yaffs_set_trace(trace);
139
140 }