2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Timothy Manning <timothy@yaffs.net>
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.
14 #include "quick_tests.h"
18 int simulate_power_failure = 0;
23 static int number_of_random_tests=0;
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));
29 const struct option long_options[]={
31 {"quiet", 0,NULL,'q'},
32 {"number", 1,NULL,'n'},
33 {"trace", 1,NULL,'t'},
34 {"continue", 0,NULL,'c'},
35 {"verbose", 0,NULL,'v'}
38 const char short_options[]="hqn:t:cv";
42 int main(int argc, char *argv[])
46 init_quick_tests(argc, argv);
47 logical_run_of_tests();
48 for (x=0;x<number_of_random_tests;x ++){
49 run_random_test_loop();
51 /*this is where the loop should break to*/
57 void run_random_test_loop(void)
61 //int run_list[total_number_of_tests];
62 for (x=0;x<total_number_of_tests;x++){
63 id = (rand() % (total_number_of_tests-1));
68 void logical_run_of_tests(void)
71 print_message("\n\nrunning quick tests for yaffs\n\n", 0);
73 for (x=0;x<total_number_of_tests;x++){
84 printf ("making test dir %d\n",yaffs_mkdir(TEST_DIR,S_IWRITE | S_IREAD));
86 yaffs_set_error(0); /*reset the last error to 0 */
87 //printf("foo exists %d\n",test_yaffs_open());
88 sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test);
89 print_message(message,3);
90 output=test_list[x].p_function(); /*run test*/
93 sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test);
94 print_message(message,3);
97 /*test is assumed to have failed*/
98 //printf("test failed\n");
99 sprintf(message,"test: %s failed\n",test_list[x].name_of_test);
100 print_message(message,1);
101 num_of_tests_failed ++;
104 print_message("\n\n",1);
105 if (get_exit_on_error()){
110 output=test_list[x].p_function_clean(); /*clean the test*/
112 /* if the test failed to clean it's self then */
113 sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test);
114 print_message(message,1);
115 num_of_tests_failed ++;
119 if (get_exit_on_error()){
124 sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
125 print_message(message,3);
127 /* close all open handles */
128 for (y=0; y<100;y++){
131 delete_dir(TEST_DIR);
134 void quit_quick_tests(int exit_code)
139 if (num_of_tests_pass==total_number_of_tests && num_of_tests_failed==0){
140 printf("\t OK --all tests passed\n");
142 printf("out of %d tests, %d ran: %d passed and %d failed\n\n\n", total_number_of_tests,(num_of_tests_pass+num_of_tests_failed) ,num_of_tests_pass,num_of_tests_failed);
143 yaffs_unmount(YAFFS_MOUNT_POINT);
148 void init_quick_tests(int argc, char *argv[])
154 new_option=getopt_long(argc,argv,short_options,long_options,NULL);
155 if (new_option=='h'){
157 printf("-h will print the commands available\n");
158 printf("-c will continue after a test fails else the program will exit\n");
159 printf("-v will print all messages\n");
160 printf("-q quiet mode only the number of tests passed and failed will be printed\n");
161 printf("-t [number] set yaffs_trace to number\n");
162 printf("-n [number] sets the number of random loops to run after the the test has run\n");
164 } else if (new_option=='c') {
165 set_exit_on_error(0);
166 } else if (new_option=='q') {
168 } else if (new_option=='t') {
169 trace = atoi(optarg);
170 } else if (new_option=='v') {
172 } else if (new_option=='n') {
173 number_of_random_tests=atoi(optarg);
176 }while (new_option!=-1);
178 yaffs_set_trace(trace);