From 4f032d82fa439a5968d7f90602f712555e54b78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Sun, 31 Dec 2023 10:45:28 -0500 Subject: [PATCH] Re-enable non-argv[0] exe name tests These should always pass no matter what and if they don't it's a bug somewhere. Cases where they fail: - assimilated binary on OpenBSD or x86_64 XNU (no `KERN_PROC_PATHNAME`) - bad loader that did not implement `RealPath` on Free/Net BSD --- test/libc/calls/getprogramexecutablename_test.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/test/libc/calls/getprogramexecutablename_test.c b/test/libc/calls/getprogramexecutablename_test.c index 13f475163..274a5bd97 100644 --- a/test/libc/calls/getprogramexecutablename_test.c +++ b/test/libc/calls/getprogramexecutablename_test.c @@ -39,6 +39,12 @@ __attribute__((__constructor__)) static void Child(int argc, char *argv[]) { if (strcmp(argv[2], GetProgramExecutableName())) { exit(123); } + if (!IsXnuSilicon()) exit(0); + /* TODO(mrdomino): argv[0] tests only pass on XnuSilicon right now because + __sys_execve fails there, so the ape loader is used. + the correct check is "we have been invoked either as an + assimilated binary or via the ape loader, and not via a + raw __sys_execve." */ if (strcmp(argv[3], argv[0])) { exit(124); } @@ -51,14 +57,7 @@ TEST(GetProgramExecutableName, ofThisFile) { EXPECT_TRUE(!!strstr(self, "getprogramexecutablename_test")); } -/* TODO(mrdomino): these tests only pass on XnuSilicon right now because - __sys_execve fails there, so the ape loader is used. - the correct check here is "we have been invoked either - as an assimilated binary or via the ape loader, and not - via a raw __sys_execve." */ - TEST(GetProgramExecutableName, nullEnv) { - if (!IsXnuSilicon()) return; SPAWN(fork); execve(self, (char *[]){self, "Child", self, self, 0}, (char *[]){0}); abort(); @@ -66,7 +65,6 @@ TEST(GetProgramExecutableName, nullEnv) { } TEST(GetProramExecutableName, weirdArgv0NullEnv) { - if (!IsXnuSilicon()) return; SPAWN(fork); execve(self, (char *[]){"hello", "Child", self, "hello", 0}, (char *[]){0}); abort(); @@ -74,7 +72,6 @@ TEST(GetProramExecutableName, weirdArgv0NullEnv) { } TEST(GetProgramExecutableName, weirdArgv0CosmoVar) { - if (!IsXnuSilicon()) return; char buf[32 + PATH_MAX]; stpcpy(stpcpy(buf, "COSMOPOLITAN_PROGRAM_EXECUTABLE="), self); SPAWN(fork); @@ -85,7 +82,6 @@ TEST(GetProgramExecutableName, weirdArgv0CosmoVar) { } TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) { - if (!IsXnuSilicon()) return; char *bad = "COSMOPOLITAN_PROGRAM_EXECUTABLE=hi"; SPAWN(fork); execve(self, (char *[]){"hello", "Child", self, "hello", 0}, @@ -95,7 +91,6 @@ TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) { } TEST(GetProgramExecutableName, movedSelf) { - if (!IsXnuSilicon()) return; char buf[BUFSIZ]; ASSERT_SYS(0, 3, open(GetProgramExecutableName(), O_RDONLY)); ASSERT_SYS(0, 4, creat("test", 0755));