thread5.c
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include <os.h>
#include <rmon.h>
#include "corefunc.h"
/*
* thread5
*
* Tests for:
* osStartThread
* osStopThread
*
* Assumed working:
*
* Description:
*/
static void t1(void *);
static void t2(void *);
static OSThread t1Thread;
static char t1ThreadStack[STACKSIZE];
static OSThread t2Thread;
static char t2ThreadStack[STACKSIZE];
static OSMesgQueue mesgQueue;
static OSMesg mesgBuf[100];
static OSMesg mesgSend, mesgRecv;
static int checkpoint;
static int numFailures;
int
thread5(void)
{
osSetThreadPri(NULL, 10);
osCreateMesgQueue(&mesgQueue, mesgBuf, 100);
checkpoint = 0;
numFailures = 0;
osCreateThread(&t1Thread, 101, t1, (void *)0, t1ThreadStack+STACKSIZE,
(OSPri)10);
osStartThread(&t1Thread);
osCreateThread(&t2Thread, 102, t2, (void *)0, t2ThreadStack+STACKSIZE,
(OSPri)10);
osStartThread(&t2Thread);
while (checkpoint != 18)
osYieldThread();
return(numFailures);
}
static void
t1(void *arg)
{
checkpoint = 1;
osYieldThread();
if (++checkpoint != 3)
numFailures++;
mesgSend = (OSMesg) 200;
osSendMesg(&mesgQueue, mesgSend, OS_MESG_BLOCK);
if (++checkpoint != 4)
numFailures++;
osYieldThread();
if (++checkpoint != 10)
numFailures++;
osRecvMesg(&mesgQueue, &mesgRecv, OS_MESG_BLOCK);
if (++checkpoint != 17)
numFailures++;
if (mesgSend != mesgRecv)
numFailures++;;
}
static void
t2(void *arg)
{
if (++checkpoint != 2)
numFailures++;
osYieldThread();
if (++checkpoint != 5)
numFailures++;
osRecvMesg(&mesgQueue, &mesgRecv, OS_MESG_BLOCK);
if (++checkpoint != 6)
numFailures++;
if (mesgSend != mesgRecv)
numFailures++;
osStopThread(&t1Thread);
if (++checkpoint != 7)
numFailures++;
osYieldThread();
if (++checkpoint != 8)
numFailures++;
osStartThread(&t1Thread);
if (++checkpoint != 9)
numFailures++;
osYieldThread();
if (++checkpoint != 11)
numFailures++;
osStopThread(&t1Thread);
if (++checkpoint != 12)
numFailures++;
osYieldThread();
if (++checkpoint != 13)
numFailures++;
osStartThread(&t1Thread);
if (++checkpoint != 14)
numFailures++;
osYieldThread();
if (++checkpoint != 15)
numFailures++;
mesgSend = (OSMesg) 300;
osSendMesg(&mesgQueue, mesgSend, OS_MESG_BLOCK);
if (++checkpoint != 16)
numFailures++;
osYieldThread();
if (++checkpoint != 18)
numFailures++;
}