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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/** @file 410user/progs/slaughter.c
* @author mtelgars
* @author nwf
* @brief Runs a lot of copies of a given test.
* @public yes
* @for p3
* @covers fork exec wait set_status vanish
* @status done
*/
#include <syscall.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include "410_tests.h"
#include <report.h>
DEF_TEST_NAME("slaughter:");
unsigned int width;
int initial_tid;
int exit_status;
void __attribute__((noreturn)) slaughter(char **argv, unsigned int depth)
{
int curtid = gettid();
report_start(START_CMPLT);
if ( ! depth )
{
if (exec(argv[0], argv))
{
lprintf("=====> exec failed from %d!", curtid);
exit(-373);
}
}
else
{
unsigned int i, j, matched;
int threads[2*width]; /* not doing anything smart here yet.. */
int status, tid;
for (i = 0; i != 2*width; ++i)
{
if ( ! (threads[i] = fork()) )
{
/* alternate immediate exec and slaughter */
slaughter(argv, (i % 2) * (depth - 1));
}
else if (threads[i] < 0) {
lprintf("=====> XXX tid %d could not fork (err=%d)!!",
curtid,threads[i]);
report_end(END_FAIL);
exit(exit_status+1);
}
else
{
lprintf("=====> Slaugher created TID %d from TID %d",
threads[i], curtid);
}
}
for (i = 0; i != 2*width; ++i)
{
tid = wait(&status);
if ( tid < 0 )
{
lprintf("=====> XXX Wait failed in TID %d with %d; bombing out",
curtid, tid );
report_end(END_FAIL);
exit(exit_status+3);
}
else
{
matched = 0;
for ( j = 0; j != 2*width; ++j )
{
if ( threads[j] == tid )
{
matched = 1;
threads[j] = -1;
break;
}
}
if ( matched == 0 )
{
lprintf("=====> XXX Wait returned bad TID %d to TID %d; bombing out",
tid, curtid );
report_end(END_FAIL);
exit(exit_status+5);
}
lprintf("=====> %stid %d gave %svalid status code of %d to tid %d",
(status == exit_status) ? "" : "XXX ",
tid, (status == exit_status) ? "" : "IN", status, curtid);
if ( status != exit_status )
{
report_end(END_FAIL);
exit(exit_status+7);
}
}
}
}
lprintf("=====> Slaughterer %d completed", curtid);
report_end(END_SUCCESS);
exit(exit_status);
}
int main(int argc, char *argv[])
{
unsigned int initial_depth;
char *default_vec[] = { "print_basic", NULL };
char **command_vec;
if (argc < 5)
{
printf("slaughter <recursive depth> "
"<recursive width> <exit status> <command line>\n");
initial_depth = 2;
width = 2;
exit_status = 0;
command_vec = default_vec;
printf(" DEFAULTING TO: %d %d %d %s\n", initial_depth, width, exit_status, command_vec[0]);
}
else if ( ! (width = strtoul(argv[1], NULL, 10)) )
{
printf(" bad recursive width\n");
return -2;
}
else if ( ! (initial_depth = strtoul(argv[2], NULL, 10)) )
{
printf(" bad recursive depth\n");
return -3;
}
else
{
exit_status = strtol(argv[3], NULL, 10);
command_vec = &argv[4];
}
slaughter(command_vec, initial_depth);
return 0;
}
|