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