-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestapp.c
63 lines (51 loc) · 1.19 KB
/
testapp.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _MSC_VER
#include <windows.h>
static void sleep(int sec)
{
Sleep(sec * 1000);
}
#else
#include <unistd.h>
#endif
void crash_me(int *invalid_ptr)
{
*invalid_ptr = 0x12345678;
}
int main(int argc, char *argv[])
{
int i;
int timeout = 0;
int crash = 0;
int *invalid_ptr = NULL;
setvbuf(stdout, NULL, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
if (argc<=1) {
puts("Usage:");
puts(" testapp [-c] -t SECS");
puts("");
puts("where:");
puts(" -t SECS Sleep SECS seconds before exit or crash");
puts(" -c Crash the application");
}
for (i=1; i<argc; ++i) {
if (!strcmp(argv[i], "-t")) {
timeout = atoi(argv[++i]);
} else if (!strcmp(argv[i], "-c")) {
crash = 1;
} else {
printf("Error: unknown option %s\n", argv[i]);
return 1;
}
}
printf("Waiting for %d seconds..\n", timeout);
sleep(timeout);
if (crash) {
puts("We're about to crash.."); fflush(stdout);
crash_me(invalid_ptr);
}
puts("Exiting normally..");
return 0;
}