yaffs Added a README file and some more 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");
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                 output=test_list[x].p_function();       /*run test*/
41                 if (output>=0){
42                         /*test has passed*/
43                         num_of_tests_pass++;
44                 }
45                 else {
46                         /*test is assumed to have failed*/
47                         //printf("test failed\n");
48                         printf("test: %s failed\n",test_list[x].fail_message);          
49                         num_of_tests_failed ++; 
50                         quit_quick_tests(1);
51                         
52                 }
53                 output=test_list[x].p_function_clean(); /*clean the test*/
54                 if (output <0){
55                         /* if the test failed to clean it's self then */
56                         printf("test: %s failed to clean\n",test_list[x].fail_message);         
57                         num_of_tests_failed ++; 
58                         num_of_tests_pass--;
59                         quit_quick_tests(1);
60                 }
61                         
62         }
63         /*this is where the loop should break to*/
64         quit_quick_tests(0);
65         /* the progame should never get here*/  
66         return 0;
67 }
68
69 void quit_quick_tests(int exit_code){
70         int error_code=0;
71         if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
72                 printf("\t OK \n");
73         }
74         else {
75                 error_code=yaffs_get_error();
76                 printf("yaffs_error code %d\n",error_code);
77                 printf("error is : %s\n",yaffs_error_to_str(error_code));
78         }
79         printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
80         yaffs_unmount(YAFFS_MOUNT_POINT);
81         exit(exit_code);
82 }
83
84 void init_quick_tests(void){
85         yaffs_start_up();;
86         yaffs_set_trace(0);
87
88 }