yaffs all timothy_tests makefiles are working. threading test is broken.
[yaffs2.git] / direct / test-framework / timothy_tests / threading / threading.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 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 int random_seed;
16 int simulate_power_failure = 0;
17
18 const struct option long_options[]={
19         {"help",        0,NULL,'h'},
20         {"threads",     1,NULL,'t'}
21 };
22
23 const char short_options[]="ht:";
24
25
26
27
28 void main_init(int argc, char *argv[])
29 {
30         int new_option;
31         int x=0;
32         int new_num_of_threads=5;       
33         x=(unsigned)time(NULL);
34         printf("seeding srand with: %d\n",x);
35         srand(x);
36         do{
37                 new_option=getopt_long(argc,argv,short_options,long_options,NULL);              
38                 if (new_option=='h'){
39                         printf("help\n");
40                         printf("-h will print the commands available\n");
41                         printf("-t [number] sets the number of threads\n");
42                         exit(0);
43                 } else if (new_option=='t') {
44                         new_num_of_threads=atoi(optarg);
45                 }
46         }while (new_option!=-1);
47         number_of_threads(new_num_of_threads);
48         init_counter(new_num_of_threads);
49
50 }
51
52 int main(int argc, char *argv[])
53 {
54         main_init(argc,argv);
55         pthread_t threads[get_num_of_threads()];
56         unsigned int x=0;
57         int output=0;
58         int y=0;
59
60         for (x=0;x<get_num_of_threads();x++)
61         {
62                 
63                 output = pthread_create(&threads[x], NULL,thread_function, (void *)x );
64                 if (output>0){
65                         printf("failed to create thread %d. Error is %d\n",x,output);
66                 }
67                 
68         }
69         while (1){
70                 y=0;
71                 printf("thread counter: %d ",get_counter(y));
72                 for (y=1;y<get_num_of_threads();y++){
73                         printf("| %d ",get_counter(y));
74                 }
75                 printf("\n");
76                 sleep(1);
77         }
78
79 }
80