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