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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
#include <tools/ccanlint/ccanlint.h>
#include <tools/tools.h>
#include <ccan/str/str.h>
#include <ccan/foreach/foreach.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <limits.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <err.h>
#include <string.h>
#include <ctype.h>
#include "reduce_features.h"
#include "tests_compile.h"
static const char *can_build(struct manifest *m)
{
if (safe_mode)
return "Safe mode enabled";
return NULL;
}
char *test_obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype, enum compile_type own_ctype)
{
char *list = tal_strdup(m, "");
struct ccan_file *i;
struct manifest *subm;
/* Objects from any other C files. */
list_for_each(&m->other_test_c_files, i, list)
tal_append_fmt(&list, " %s", i->compiled[ctype]);
/* Our own object files. */
if (link_with_module)
list_for_each(&m->c_files, i, list)
tal_append_fmt(&list, " %s", i->compiled[own_ctype]);
/* Other ccan modules (normal depends). */
list_for_each(&m->deps, subm, list) {
if (subm->compiled[ctype])
tal_append_fmt(&list, " %s", subm->compiled[ctype]);
}
/* Other ccan modules (test depends). */
list_for_each(&m->test_deps, subm, list) {
if (subm->compiled[ctype])
tal_append_fmt(&list, " %s", subm->compiled[ctype]);
}
return list;
}
char *test_lib_list(const struct manifest *m, enum compile_type ctype)
{
unsigned int i;
char **libs;
char *ret = tal_strdup(m, "");
libs = get_libs(m, m->dir, "testdepends", get_or_compile_info);
for (i = 0; libs[i]; i++)
tal_append_fmt(&ret, "-l%s ", libs[i]);
return ret;
}
static char *cflags_list(const struct manifest *m, const char *iflags)
{
unsigned int i;
char *ret = tal_strdup(m, iflags);
char **flags = get_cflags(m, m->dir, get_or_compile_info);
for (i = 0; flags[i]; i++)
tal_append_fmt(&ret, " %s", flags[i]);
return ret;
}
static bool compile(const void *ctx,
struct manifest *m,
struct ccan_file *file,
bool fail,
bool link_with_module,
enum compile_type ctype,
char **output)
{
char *fname, *flags;
flags = tal_fmt(ctx, "%s%s%s",
fail ? "-DFAIL " : "",
cflags,
ctype == COMPILE_NOFEAT
? " "REDUCE_FEATURES_FLAGS : "");
flags = cflags_list(m, flags);
fname = temp_file(ctx, "", file->fullname);
if (!compile_and_link(ctx, file->fullname, ccan_dir,
test_obj_list(m, link_with_module,
ctype, ctype),
compiler, flags, test_lib_list(m, ctype), fname,
output)) {
tal_free(fname);
return false;
}
file->compiled[ctype] = fname;
return true;
}
static void compile_async(const void *ctx,
struct manifest *m,
struct ccan_file *file,
bool link_with_module,
enum compile_type ctype,
unsigned int time_ms)
{
char *flags;
file->compiled[ctype] = temp_file(ctx, "", file->fullname);
flags = tal_fmt(ctx, "%s%s",
cflags,
ctype == COMPILE_NOFEAT
? " "REDUCE_FEATURES_FLAGS : "");
flags = cflags_list(m, flags);
compile_and_link_async(file, time_ms, file->fullname, ccan_dir,
test_obj_list(m, link_with_module, ctype, ctype),
compiler, flags, test_lib_list(m, ctype),
file->compiled[ctype]);
}
static void compile_tests(struct manifest *m,
struct score *score,
enum compile_type ctype,
unsigned int time_ms)
{
char *cmdout;
struct ccan_file *i;
struct list_head *list;
bool errors = false, warnings = false, ok;
foreach_ptr(list, &m->compile_ok_tests, &m->run_tests, &m->api_tests) {
list_for_each(list, i, list) {
compile_async(score, m, i,
list == &m->api_tests,
ctype, time_ms);
}
}
while ((i = collect_command(&ok, &cmdout)) != NULL) {
if (!ok) {
score_file_error(score, i, 0,
"Compile failed:\n%s",
cmdout);
errors = true;
} else if (!streq(cmdout, "")) {
score_file_error(score, i, 0,
"Compile gave warnings:\n%s",
cmdout);
warnings = true;
}
}
/* The compile fail tests are a bit weird, handle them separately */
if (errors)
return;
/* For historical reasons, "fail" often means "gives warnings" */
list_for_each(&m->compile_fail_tests, i, list) {
if (!compile(score, m, i, false, false, ctype, &cmdout)) {
score_file_error(score, i, 0,
"Compile without -DFAIL failed:\n%s",
cmdout);
return;
}
if (!streq(cmdout, "")) {
score_file_error(score, i, 0,
"Compile gave warnings"
" without -DFAIL:\n%s",
cmdout);
return;
}
if (compile(score, m, i, true, false, ctype, &cmdout)
&& streq(cmdout, "")) {
score_file_error(score, i, 0,
"Compiled successfully with -DFAIL?");
return;
}
score->total++;
}
score->pass = true;
score->score = score->total - warnings;
}
/* FIXME: If we time out, set *timeleft to 0 */
static void do_compile_tests(struct manifest *m,
unsigned int *timeleft, struct score *score)
{
compile_tests(m, score, COMPILE_NORMAL, *timeleft);
}
struct ccanlint tests_compile = {
.key = "tests_compile",
.name = "Module tests compile",
.check = do_compile_tests,
.can_run = can_build,
.needs = "tests_helpers_compile objects_build"
};
REGISTER_TEST(tests_compile);
static const char *features_reduced(struct manifest *m)
{
if (features_were_reduced)
return NULL;
return "No features to turn off";
}
static void do_compile_tests_without_features(struct manifest *m,
unsigned int *timeleft,
struct score *score)
{
compile_tests(m, score, COMPILE_NOFEAT, *timeleft);
}
struct ccanlint tests_compile_without_features = {
.key = "tests_compile_without_features",
.name = "Module tests compile (without features)",
.check = do_compile_tests_without_features,
.can_run = features_reduced,
.needs = "module_builds tests_helpers_compile_without_features objects_build_without_features"
};
REGISTER_TEST(tests_compile_without_features);
|