Merge branch 'master' of ssh://www.aleph1.co.uk/home/aleph1/git/yaffs2
[yaffs2.git] / direct / timothy_tests / threading / thread_function.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 "thread_function.h"
15
16
17
18 int number_of_tests=2;
19
20
21 void * init(int threadId, const char *baseDir, int bovver_type)
22 {
23         struct bovver_context *bc = malloc(sizeof(struct bovver_context));
24
25         if(bc){
26                 memset(bc,0,sizeof(*bc));
27                 bc->threadId = threadId;
28                 strncpy(bc->baseDir,baseDir,200);
29                 bc->bovverType = bovver_type;
30                 bc->opMax = 99;
31                 printf("bovver_init %d \"%s\"\n",threadId,baseDir);
32         }
33         return (void *)bc;
34 }
35
36
37 typedef struct test {
38         void (*p_function)(void *);     /*pointer to test function*/
39         /*char pass_message[50]; will not need a pass message*/
40         char *name_of_test;     /*pointer to fail message, needs to include name of test*/
41 }test_template;
42
43
44 test_template test_list[]={
45         //{dummy_test,dummy_test_clean,"dummy_test"},
46         {test_a, "test_a"},
47         {test_b, "test_b"}
48 };
49
50 int thread_function(void *thread_id_ptr)
51 {
52         int thread_id = (int) thread_id_ptr;
53         int test_id=0;
54         unsigned int y=0;
55         printf("Starting thread %d, id %d\n", pthread_self(),thread_id);
56         void *x=init(thread_id,"/yaffs2/",0);
57         while(1){
58                 y++;
59                 //set_counter(thread_id,y);
60                 test_id=(rand()%(number_of_tests-1));
61                 test_list[test_id].p_function(x);
62                 //printf("thread: %d. ran test: %d\n",thread_id,y);
63                 //printf("counter before %d\n",get_counter(thread_id));
64                 set_counter(thread_id,y);
65                 //printf("counter after setting %d\n",get_counter(thread_id));
66         }
67         //select random file name from a list.
68         //run a random function on the file.
69         return 1;
70 }