yaffs Added another test to direct/timothy_tests/threading
[yaffs2.git] / direct / timothy_tests / threading / threading.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 "threading.h"
15
16 int random_seed;
17 int simulate_power_failure = 0;
18
19 const struct option long_options[]={
20         {"help",        0,NULL,'h'},
21         {"threads",     1,NULL,'t'}
22 };
23
24 const char short_options[]="hqn:t:cv";
25
26
27
28
29 void main_init(int argc, char *argv[])
30 {
31         int new_option;
32         int x=0;
33         int new_num_of_threads=5;       
34         do{
35                 new_option=getopt_long(argc,argv,short_options,long_options,NULL);              
36                 if (0==strcmp(argv[x],"-h")){
37                         printf("help\n");
38                         printf("-h will print the commands available\n");
39                         printf("-c will continue after a test failes else the program will exit\n");
40                         printf("-v will print all messages\n");
41                         printf("-q quiet mode only the number of tests passed and failed will be printed\n");
42                         printf("-t [number] set yaffs_trace to number\n");
43                         printf("-n [number] sets the number of random loops to run after the the test has run\n");
44                         exit(0);
45                 } else if (new_option=='t') {
46                         new_num_of_threads=atoi(optarg);
47                 }
48         }while (new_option!=-1);
49         number_of_threads(new_num_of_threads);
50         init_counter(new_num_of_threads);
51
52 }
53
54 int main(int argc, char *argv[])
55 {
56         main_init(argc,argv);
57         pthread_t threads[get_num_of_threads()];
58         unsigned int x=0;
59         int output=0;
60         int y=0;
61
62         for (x=0;x<get_num_of_threads();x++)
63         {
64                 
65                 output=pthread_create(&threads[x], NULL,thread_function, (void *)x );
66                 if (output>0){
67                         printf("failed to create thread %d. Error is %d\n",x,output);
68                 }
69                 
70         }
71         while (1){
72                 y=0;
73                 printf("thread counter: %d ",get_counter(y));
74                 for (y=1;y<get_num_of_threads();y++){
75                         printf("| %d ",get_counter(y));
76                 }
77                 printf("\n");
78         }
79
80 }
81