diff --git a/test/libc/calls/getprogramexecutablename_test.c b/test/libc/calls/getprogramexecutablename_test.c index aa5d51a32b00..d6255960fce4 100644 --- a/test/libc/calls/getprogramexecutablename_test.c +++ b/test/libc/calls/getprogramexecutablename_test.c @@ -29,23 +29,37 @@ static char *self; -void SetUp(void) { - self = GetProgramExecutableName(); -} - void SetUpOnce(void) { + self = GetProgramExecutableName(); testlib_enable_tmp_setup_teardown(); } __attribute__((__constructor__)) static void Child(int argc, char *argv[]) { + static bool skiparg0tests; + if (!__program_executable_name && !IsFreebsd() && !IsNetbsd()) { + if (argc == 2 && !strcmp(argv[1], "ChildInit")) { + fprintf(stderr, "warning: old/no loader; skipping argv[0] tests\n"); + exit(0); + } + skiparg0tests = true; + } if (argc >= 2 && !strcmp(argv[1], "Child")) { ASSERT_EQ(argc, 4); EXPECT_STREQ(argv[2], GetProgramExecutableName()); - EXPECT_STREQ(argv[3], argv[0]); + if (!skiparg0tests) { + EXPECT_STREQ(argv[3], argv[0]); + } exit(g_testlib_failed); } } +TEST(GetProgramExecutableName, printWarning) { + SPAWN(fork); + execve(self, (char *[]){self, "ChildInit", 0}, (char *[]){0}); + abort(); + EXITS(0); +} + TEST(GetProgramExecutableName, ofThisFile) { EXPECT_EQ('/', *self); EXPECT_TRUE(