X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=tools%2Fconfigurator%2Fconfigurator.c;h=33651ef4df3bc95c27ad12a25327439a40ce4213;hp=d99d4a003065557a79815dfeca4d292eb4b1e699;hb=HEAD;hpb=920ca95d6ef6cad6f33cddb235bc3cb9dea4d00c diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index d99d4a00..7d8f6b09 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -142,6 +142,9 @@ static const struct test base_tests[] = { { "HAVE_ATTRIBUTE_NONNULL", "__attribute__((nonnull)) support", "DEFINES_FUNC", NULL, NULL, "static char *__attribute__((nonnull)) func(char *p) { return p; }" }, + { "HAVE_ATTRIBUTE_RETURNS_NONNULL", "__attribute__((returns_nonnull)) support", + "DEFINES_FUNC", NULL, NULL, + "static const char *__attribute__((returns_nonnull)) func(void) { return \"hi\"; }" }, { "HAVE_ATTRIBUTE_SENTINEL", "__attribute__((sentinel)) support", "DEFINES_FUNC", NULL, NULL, "static int __attribute__((sentinel)) func(int i, ...) { return i; }" }, @@ -194,7 +197,7 @@ static const struct test base_tests[] = { "return __builtin_clzll(1) == (sizeof(long long)*8 - 1) ? 0 : 1;" }, { "HAVE_BUILTIN_CTZ", "__builtin_ctz support", "INSIDE_MAIN", NULL, NULL, - "return __builtin_ctz(1 << (sizeof(int)*8 - 1)) == (sizeof(int)*8 - 1) ? 0 : 1;" }, + "return __builtin_ctz(1U << (sizeof(int)*8 - 1)) == (sizeof(int)*8 - 1) ? 0 : 1;" }, { "HAVE_BUILTIN_CTZL", "__builtin_ctzl support", "INSIDE_MAIN", NULL, NULL, "return __builtin_ctzl(1UL << (sizeof(long)*8 - 1)) == (sizeof(long)*8 - 1) ? 0 : 1;" }, @@ -411,7 +414,7 @@ static const struct test base_tests[] = { "int main(int argc, char *argv[]) {\n" " (void)argc;\n" " char pad[sizeof(int *) * 1];\n" - " strncpy(pad, argv[0], sizeof(pad));\n" + " memcpy(pad, argv[0], sizeof(pad));\n" " int *x = (int *)pad, *y = (int *)(pad + 1);\n" " return *x == *y;\n" "}\n" }, @@ -468,7 +471,7 @@ static const struct test base_tests[] = { "#include \n" "#include \n" "static int worked = 0;\n" - "static char stack[1024];\n" + "static char stack[8192];\n" "static ucontext_t a, b;\n" "static void fn(void *p, void *q) {\n" " void *cp = &worked;\n" @@ -495,6 +498,43 @@ static const struct test base_tests[] = { " return __builtin_cpu_supports(\"mmx\");\n" "}" }, + { "HAVE_CLOSEFROM", "closefrom() offered by system", + "DEFINES_EVERYTHING", NULL, NULL, + "#include \n" + "#include \n" + "int main(void) {\n" + " closefrom(STDERR_FILENO + 1);\n" + " return 0;\n" + "}\n" + }, + { "HAVE_F_CLOSEM", "F_CLOSEM defined for fctnl.", + "DEFINES_EVERYTHING", NULL, NULL, + "#include \n" + "#include \n" + "int main(void) {\n" + " int res = fcntl(STDERR_FILENO + 1, F_CLOSEM, 0);\n" + " return res < 0;\n" + "}\n" + }, + { "HAVE_NR_CLOSE_RANGE", "close_range syscall available as __NR_close_range.", + "DEFINES_EVERYTHING", NULL, NULL, + "#include \n" + "#include \n" + "#include \n" + "int main(void) {\n" + " int res = syscall(__NR_close_range, STDERR_FILENO + 1, INT_MAX, 0);\n" + " return res < 0;\n" + "}\n" + }, + { "HAVE_F_MAXFD", "F_MAXFD defined for fcntl.", + "DEFINES_EVERYTHING", NULL, NULL, + "#include \n" + "#include \n" + "int main(void) {\n" + " int res = fcntl(0, F_MAXFD);\n" + " return res < 0;\n" + "}\n" + }, }; static void c12r_err(int eval, const char *fmt, ...) @@ -639,7 +679,7 @@ static struct test *find_test(const char *name) #define MAIN_BODY_BOILERPLATE "return 0;\n" #define MAIN_END_BOILERPLATE "}\n" -static bool run_test(const char *cmd, struct test *test) +static bool run_test(const char *cmd, const char *wrapper, struct test *test) { char *output, *newcmd; FILE *outf; @@ -667,7 +707,7 @@ static bool run_test(const char *cmd, struct test *test) dep++; positive = false; } - if (run_test(cmd, find_test(dep)) != positive) { + if (run_test(cmd, wrapper, find_test(dep)) != positive) { test->answer = false; test->done = true; return test->answer; @@ -757,7 +797,12 @@ static bool run_test(const char *cmd, struct test *test) /* We run INSIDE_MAIN tests for sanity checking. */ if (strstr(test->style, "EXECUTE") || strstr(test->style, "INSIDE_MAIN")) { - output = run("." DIR_SEP OUTPUT_FILE, &status); + char *runcmd = malloc(strlen(wrapper) + strlen(" ." DIR_SEP OUTPUT_FILE) + 1); + + strcpy(runcmd, wrapper); + strcat(runcmd, " ." DIR_SEP OUTPUT_FILE); + output = run(runcmd, &status); + free(runcmd); if (!strstr(test->style, "EXECUTE") && status != 0) c12r_errx(EXIT_BAD_TEST, "Test for %s failed with %i:\n%s", @@ -908,6 +953,7 @@ int main(int argc, const char *argv[]) = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL }; const char *outflag = DEFAULT_OUTPUT_EXE_FLAG; const char *configurator_cc = NULL; + const char *wrapper = ""; const char *orig_cc; const char *varfile = NULL; const char *headerfile = NULL; @@ -919,7 +965,7 @@ int main(int argc, const char *argv[]) while (argc > 1) { if (strcmp(argv[1], "--help") == 0) { - printf("Usage: configurator [-v] [--var-file=] [-O] [--configurator-cc=] [--autotools-style] [--extra-tests] [ ...]\n" + printf("Usage: configurator [-v] [--var-file=] [-O] [--configurator-cc=] [--wrapper=] [--autotools-style] [--extra-tests] [ ...]\n" " will have \" \" appended\n" "Default: %s %s %s\n", DEFAULT_COMPILER, DEFAULT_FLAGS, @@ -948,6 +994,10 @@ int main(int argc, const char *argv[]) configurator_cc = argv[1] + 18; argc--; argv++; + } else if (strncmp(argv[1], "--wrapper=", 10) == 0) { + wrapper = argv[1] + 10; + argc--; + argv++; } else if (strncmp(argv[1], "--var-file=", 11) == 0) { varfile = argv[1] + 11; argc--; @@ -995,7 +1045,7 @@ int main(int argc, const char *argv[]) end_test(1); } for (i = 0; tests[i].name; i++) - run_test(cmd, &tests[i]); + run_test(cmd, wrapper, &tests[i]); free(cmd); remove(OUTPUT_FILE);