Merge branch '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(){
29         int output=0;
30         char message[30];
31         message[0]='\0';
32
33         unsigned int x=0;       
34         init_quick_tests();
35         print_message("\n\nrunning quick tests for yaffs\n\n", 0);
36         //printf("testing yaffs\n");
37
38         //printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
39         for (x=0;x<total_number_of_tests;x++){
40                 //printf("x %d\n",x);
41                 yaffs_set_error(0);     /*reset the last error to 0 */
42                 sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test);
43                 print_message(message,2);
44                 output=test_list[x].p_function();       /*run test*/
45                 if (output>=0){
46                         /*test has passed*/
47                         sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test);
48                         print_message(message,2); 
49                         num_of_tests_pass++;
50                 } else {
51                         /*test is assumed to have failed*/
52                         //printf("test failed\n");
53                         sprintf(message,"test: %s failed\n",test_list[x].name_of_test);
54                         print_message(message,1);               
55                         num_of_tests_failed ++; 
56                 
57                         get_error();
58                         print_message("\n\n",1);
59                         if (EXIT_ON_ERROR){     
60                                 quit_quick_tests(1);
61                         }
62
63                 }
64                 output=0;
65                 output=test_list[x].p_function_clean(); /*clean the test*/
66                 if (output <0){
67                         /* if the test failed to clean it's self then */
68                         sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test);
69                         print_message(message,1);               
70                         num_of_tests_failed ++; 
71                         num_of_tests_pass--;
72                         get_error();
73                         printf("\n\n");
74                         if (EXIT_ON_ERROR){
75                                 quit_quick_tests(1);
76                         }
77                         
78                 } else {
79                         sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
80                         print_message(message,2);
81                 }
82         }
83         /*this is where the loop should break to*/
84         quit_quick_tests(0);
85 }
86
87 void quit_quick_tests(int exit_code)
88 {
89         char message[30];
90         message[0]='\0';        
91         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
92                 printf("\t OK \n");
93         }
94         printf("tests: %d passed %d failed out of %d tests\n\n\n",num_of_tests_pass,num_of_tests_failed,total_number_of_tests);
95         yaffs_unmount(YAFFS_MOUNT_POINT);
96         exit(exit_code);
97 }
98
99 void get_error(void)
100 {
101         int error_code=0;
102         char message[30];
103         message[0]='\0';
104
105         error_code=yaffs_get_error();
106         sprintf(message,"yaffs_error code %d\n",error_code);
107         print_message(message,1);
108         sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
109         print_message(message,1);
110 }
111
112 void init_quick_tests(void)
113 {
114         yaffs_start_up();
115         yaffs_set_trace(0);
116
117 }