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
This commit is contained in:
Jōshin 2023-12-31 10:45:28 -05:00
parent 14fe83facd
commit 4f032d82fa
No known key found for this signature in database

View file

@ -39,6 +39,12 @@ __attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
if (strcmp(argv[2], GetProgramExecutableName())) { if (strcmp(argv[2], GetProgramExecutableName())) {
exit(123); 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])) { if (strcmp(argv[3], argv[0])) {
exit(124); exit(124);
} }
@ -51,14 +57,7 @@ TEST(GetProgramExecutableName, ofThisFile) {
EXPECT_TRUE(!!strstr(self, "getprogramexecutablename_test")); 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) { TEST(GetProgramExecutableName, nullEnv) {
if (!IsXnuSilicon()) return;
SPAWN(fork); SPAWN(fork);
execve(self, (char *[]){self, "Child", self, self, 0}, (char *[]){0}); execve(self, (char *[]){self, "Child", self, self, 0}, (char *[]){0});
abort(); abort();
@ -66,7 +65,6 @@ TEST(GetProgramExecutableName, nullEnv) {
} }
TEST(GetProramExecutableName, weirdArgv0NullEnv) { TEST(GetProramExecutableName, weirdArgv0NullEnv) {
if (!IsXnuSilicon()) return;
SPAWN(fork); SPAWN(fork);
execve(self, (char *[]){"hello", "Child", self, "hello", 0}, (char *[]){0}); execve(self, (char *[]){"hello", "Child", self, "hello", 0}, (char *[]){0});
abort(); abort();
@ -74,7 +72,6 @@ TEST(GetProramExecutableName, weirdArgv0NullEnv) {
} }
TEST(GetProgramExecutableName, weirdArgv0CosmoVar) { TEST(GetProgramExecutableName, weirdArgv0CosmoVar) {
if (!IsXnuSilicon()) return;
char buf[32 + PATH_MAX]; char buf[32 + PATH_MAX];
stpcpy(stpcpy(buf, "COSMOPOLITAN_PROGRAM_EXECUTABLE="), self); stpcpy(stpcpy(buf, "COSMOPOLITAN_PROGRAM_EXECUTABLE="), self);
SPAWN(fork); SPAWN(fork);
@ -85,7 +82,6 @@ TEST(GetProgramExecutableName, weirdArgv0CosmoVar) {
} }
TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) { TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) {
if (!IsXnuSilicon()) return;
char *bad = "COSMOPOLITAN_PROGRAM_EXECUTABLE=hi"; char *bad = "COSMOPOLITAN_PROGRAM_EXECUTABLE=hi";
SPAWN(fork); SPAWN(fork);
execve(self, (char *[]){"hello", "Child", self, "hello", 0}, execve(self, (char *[]){"hello", "Child", self, "hello", 0},
@ -95,7 +91,6 @@ TEST(GetProgramExecutableName, weirdArgv0WrongCosmoVar) {
} }
TEST(GetProgramExecutableName, movedSelf) { TEST(GetProgramExecutableName, movedSelf) {
if (!IsXnuSilicon()) return;
char buf[BUFSIZ]; char buf[BUFSIZ];
ASSERT_SYS(0, 3, open(GetProgramExecutableName(), O_RDONLY)); ASSERT_SYS(0, 3, open(GetProgramExecutableName(), O_RDONLY));
ASSERT_SYS(0, 4, creat("test", 0755)); ASSERT_SYS(0, 4, creat("test", 0755));