Fix unmatched temporary buffer allocations
[yaffs2.git] / direct / test-framework / stress_tests / threading / thread_function.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Timothy Manning <timothy@yaffs.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include "thread_function.h"
14
15
16
17 int number_of_tests=2;
18
19
20 void * init(int threadId, const char *baseDir, int bovver_type)
21 {
22         struct bovver_context *bc = malloc(sizeof(struct bovver_context));
23
24         if(bc){
25                 memset(bc,0,sizeof(*bc));
26                 bc->threadId = threadId;
27                 strncpy(bc->baseDir,baseDir,200);
28                 bc->bovverType = bovver_type;
29                 bc->opMax = 99;
30                 printf("bovver_init %d \"%s\"\n",threadId,baseDir);
31         }
32         return (void *)bc;
33 }
34
35
36 typedef struct test {
37         void (*p_function)(void *);     /*pointer to test function*/
38         /*char pass_message[50]; will not need a pass message*/
39         char *name_of_test;     /*pointer to fail message, needs to include name of test*/
40 }test_template;
41
42
43 test_template test_list[]={
44         //{dummy_test,dummy_test_clean,"dummy_test"},
45         {test_a, "test_a"},
46         {test_b, "test_b"}
47 };
48
49 int thread_function(void *thread_id_ptr)
50 {
51         int thread_id = (int) thread_id_ptr;
52         int test_id=0;
53         unsigned int y=0;
54         printf("Starting thread %d, id %d\n", pthread_self(),thread_id);
55         void *x=init(thread_id,"/yaffs2/",0);
56         while(1){
57                 y++;
58                 //set_counter(thread_id,y);
59                 test_id=(rand()%(number_of_tests-1));
60                 test_list[test_id].p_function(x);
61                 //printf("thread: %d. ran test: %d\n",thread_id,y);
62                 //printf("counter before %d\n",get_counter(thread_id));
63                 set_counter(thread_id,y);
64                 //printf("counter after setting %d\n",get_counter(thread_id));
65         }
66         //select random file name from a list.
67         //run a random function on the file.
68         return 1;
69 }