-
Notifications
You must be signed in to change notification settings - Fork 16
/
msg-test.c
95 lines (82 loc) · 1.37 KB
/
msg-test.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
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
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "msg.h"
#include "ct/ct.h"
void
cttestset()
{
const char *m;
set_message("foo");
m = get_message();
assert(strcmp("foo", m) == 0);
}
void
cttestdefault()
{
const char *m;
m = get_message();
assert(strcmp("default message", m) == 0);
}
void
cttestfailure()
{
return; /* remove this line to see a failure */
assert(1 == 2);
}
void
cttestfmt()
{
return; /* remove this line to see a failure with formatting */
int n = 1;
assertf(n == 2, "n is %d", n);
}
void
cttestsegfault()
{
return; /* remove this line to see a segfault error */
*(volatile int*)0 = 0;
}
void
cttesttmpdir()
{
assert(chdir(ctdir()) == 0);
assert(open("x", O_CREAT|O_RDWR, 0777));
}
void
cttestexit()
{
return; /* remove this line to see an exit error */
exit(2);
}
void
cttestfail()
{
return; /* remove this line to see multiple failures */
ctlog("first");
ctfail();
ctlog("second");
ctfail();
ctlog("third");
}
void
ctbenchprintf(int n)
{
int i;
const char *m = get_message();
for (i = 0; i < n; i++) {
printf("%s\n", m);
}
}
void
ctbenchprintsz(int n)
{
int i;
const char *m = get_message();
ctsetbytes(strlen(m)+1);
for (i = 0; i < n; i++) {
printf("%s\n", m);
}
}