71a11f89f6e6c28ce5387d1139ae14c2ca0a88e5
[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");
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                         num_of_tests_pass++;
45                 }
46                 else {
47                         /*test is assumed to have failed*/
48                         //printf("test failed\n");
49                         printf("test: %s failed\n",test_list[x].name_of_test);          
50                         num_of_tests_failed ++; 
51
52                         if (EXIT_ON_ERROR){
53                                 printf("\n\n");
54                                 quit_quick_tests(1);
55                         }
56                         else {
57                                 get_error();
58                                 printf("\n\n");
59                         }
60                 }
61                 output=test_list[x].p_function_clean(); /*clean the test*/
62                 if (output <0){
63                         /* if the test failed to clean it's self then */
64                         printf("test: %s failed to clean\n",test_list[x].name_of_test);         
65                         num_of_tests_failed ++; 
66                         num_of_tests_pass--;
67                         quit_quick_tests(1);
68                 }
69                         
70         }
71         /*this is where the loop should break to*/
72         quit_quick_tests(0);
73         /* the progame should never get here*/  
74         return 0;
75 }
76
77 void quit_quick_tests(int exit_code){
78         
79         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
80                 printf("\t OK \n");
81         }
82         else {
83                 get_error();
84         }
85         printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
86         yaffs_unmount(YAFFS_MOUNT_POINT);
87         exit(exit_code);
88 }
89
90 void get_error(void){
91         int error_code=0;
92         error_code=yaffs_get_error();
93         printf("yaffs_error code %d\n",error_code);
94         printf("error is : %s\n",yaffs_error_to_str(error_code));
95 }
96
97 void init_quick_tests(void){
98         yaffs_start_up();;
99         yaffs_set_trace(0);
100
101 }