Commit a7188fd6 authored by Rusty Russell's avatar Rusty Russell

tools/configurator: don't rely on size of tests_array.

Groundwork for adding tests dynamically.
Signed-off-by: default avatarRusty Russell <rusty@rustcorp.com.au>
parent e2ae8d42
...@@ -100,7 +100,10 @@ struct test { ...@@ -100,7 +100,10 @@ struct test {
bool answer; bool answer;
}; };
static struct test tests[] = { /* Terminated by a NULL name */
static struct test *tests;
static const struct test base_tests[] = {
{ "HAVE_32BIT_OFF_T", "off_t is 32 bits", { "HAVE_32BIT_OFF_T", "off_t is 32 bits",
"DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE", NULL, NULL, "DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE", NULL, NULL,
"#include <sys/types.h>\n" "#include <sys/types.h>\n"
...@@ -598,10 +601,11 @@ static struct test *find_test(const char *name) ...@@ -598,10 +601,11 @@ static struct test *find_test(const char *name)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) { for (i = 0; tests[i].name; i++) {
if (strcmp(tests[i].name, name) == 0) if (strcmp(tests[i].name, name) == 0)
return &tests[i]; return &tests[i];
} }
c12r_errx(2, "Unknown test %s", name);
abort(); abort();
} }
...@@ -823,6 +827,11 @@ int main(int argc, const char *argv[]) ...@@ -823,6 +827,11 @@ int main(int argc, const char *argv[])
if (argc == 1) if (argc == 1)
argv = default_args; argv = default_args;
/* Copy with NULL entry at end */
tests = calloc(sizeof(base_tests)/sizeof(base_tests[0]) + 1,
sizeof(base_tests[0]));
memcpy(tests, base_tests, sizeof(base_tests));
orig_cc = argv[1]; orig_cc = argv[1];
if (configurator_cc) if (configurator_cc)
argv[1] = configurator_cc; argv[1] = configurator_cc;
...@@ -833,7 +842,7 @@ int main(int argc, const char *argv[]) ...@@ -833,7 +842,7 @@ int main(int argc, const char *argv[])
sleep(1); sleep(1);
end_test(1); end_test(1);
} }
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) for (i = 0; tests[i].name; i++)
run_test(cmd, &tests[i]); run_test(cmd, &tests[i]);
free(cmd); free(cmd);
...@@ -851,7 +860,7 @@ int main(int argc, const char *argv[]) ...@@ -851,7 +860,7 @@ int main(int argc, const char *argv[])
if (!vars) if (!vars)
c12r_err(2, "Could not open %s", varfile); c12r_err(2, "Could not open %s", varfile);
} }
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) for (i = 0; tests[i].name; i++)
fprintf(vars, "%s=%u\n", tests[i].name, tests[i].answer); fprintf(vars, "%s=%u\n", tests[i].name, tests[i].answer);
if (vars != stdout) { if (vars != stdout) {
if (fclose(vars) != 0) if (fclose(vars) != 0)
...@@ -881,7 +890,7 @@ int main(int argc, const char *argv[]) ...@@ -881,7 +890,7 @@ int main(int argc, const char *argv[])
fprintf(outf, "#define CCAN_OUTPUT_EXE_CFLAG \"%s\"\n\n", outflag); fprintf(outf, "#define CCAN_OUTPUT_EXE_CFLAG \"%s\"\n\n", outflag);
/* This one implies "#include <ccan/..." works, eg. for tdb2.h */ /* This one implies "#include <ccan/..." works, eg. for tdb2.h */
fprintf(outf, "#define HAVE_CCAN 1\n"); fprintf(outf, "#define HAVE_CCAN 1\n");
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) for (i = 0; tests[i].name; i++)
fprintf(outf, "#define %s %u\n", tests[i].name, tests[i].answer); fprintf(outf, "#define %s %u\n", tests[i].name, tests[i].answer);
fprintf(outf, "#endif /* CCAN_CONFIG_H */\n"); fprintf(outf, "#endif /* CCAN_CONFIG_H */\n");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment