thread8.c
1.87 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
#include <os.h>
#include <rmon.h>
#include "corefunc.h"
/*
* thread8
*
* Tests for:
* osDestroyThread (on stopped threads)
*
* Assumed working:
* osSetIntMask
* osGetIntMask
* osCreateThread
* osStartThread
* osYieldThread
* osStopThread
*
* Description:
* Check that osDestroyThread called on newly created thread has no
* unexpected results.
* Check that osDestroyThread called on thread that has stopped itself
* has no expected results.
* Check that osDestroyThread does not affect interrupt mask.
*/
static void slave1(void *);
static OSThread slaveThread;
static char slaveStack[STACKSIZE];
int
thread8(void)
{
OSIntMask savedMask, currentMask;
OSMesg actualMesg, expectedMesg;
int i, j;
int numFailures = 0;
savedMask = osSetIntMask(OS_IM_ALL);
/*
* Set thread priority to the same as slaves.
*/
osSetThreadPri(NULL, 10);
/*
* Try and destroy a newly created one just for fun.
*/
osCreateThread(&slaveThread, 101, slave1, (void *)0,
slaveStack+STACKSIZE, 10);
osDestroyThread(&slaveThread);
currentMask = osGetIntMask();
if (currentMask != OS_IM_ALL) {
osSyncPrintf("thread8: expected interrupt mask 0x%x, actual 0x%x\n",
OS_IM_ALL, currentMask);
numFailures++;
}
/*
* This time, create it, let it stop itself, and then destroy it.
*/
osCreateThread(&slaveThread, 101, slave1, (void *)0,
slaveStack+STACKSIZE, 10);
osStartThread(&slaveThread);
osYieldThread();
osDestroyThread(&slaveThread);
/*
* Restore original interrupt mask and check it once more.
*/
currentMask = osSetIntMask(savedMask);
if (currentMask != OS_IM_ALL) {
osSyncPrintf("thread8: expected interrupt mask 0x%x, actual 0x%x\n",
OS_IM_ALL, currentMask);
numFailures++;
}
return(numFailures);
}
static void
slave1(void *arg)
{
osStopThread(NULL);
}