mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-04-15 20:28:45 +00:00
Make getprogramexecutablename_test pass fleet
This commit is contained in:
parent
8b0e42a31b
commit
80fca1f7c3
2 changed files with 19 additions and 20 deletions
|
@ -86,7 +86,7 @@ IGNORE := $(shell $(MKDIR) $(TMPDIR))
|
||||||
|
|
||||||
ifneq ($(findstring aarch64,$(MODE)),)
|
ifneq ($(findstring aarch64,$(MODE)),)
|
||||||
ARCH = aarch64
|
ARCH = aarch64
|
||||||
HOSTS ?= pi silicon
|
HOSTS ?= pi studio
|
||||||
else
|
else
|
||||||
ARCH = x86_64
|
ARCH = x86_64
|
||||||
HOSTS ?= freebsd rhel7 xnu win10 openbsd netbsd
|
HOSTS ?= freebsd rhel7 xnu win10 openbsd netbsd
|
||||||
|
|
|
@ -35,35 +35,30 @@ void SetUpOnce(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
|
__attribute__((__constructor__)) static void Child(int argc, char *argv[]) {
|
||||||
static bool skiparg0tests;
|
|
||||||
if (!IsXnuSilicon()) {
|
|
||||||
/* 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." */
|
|
||||||
skiparg0tests = true;
|
|
||||||
if (argc < 2) {
|
|
||||||
fprintf(stderr, "warning: skipping argv[0] tests\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (argc >= 2 && !strcmp(argv[1], "Child")) {
|
if (argc >= 2 && !strcmp(argv[1], "Child")) {
|
||||||
ASSERT_EQ(argc, 4);
|
if (strcmp(argv[2], GetProgramExecutableName())) {
|
||||||
EXPECT_STREQ(argv[2], GetProgramExecutableName());
|
exit(123);
|
||||||
if (!skiparg0tests) {
|
|
||||||
EXPECT_STREQ(argv[3], argv[0]);
|
|
||||||
}
|
}
|
||||||
exit(g_testlib_failed);
|
if (strcmp(argv[3], argv[0])) {
|
||||||
|
exit(124);
|
||||||
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GetProgramExecutableName, ofThisFile) {
|
TEST(GetProgramExecutableName, ofThisFile) {
|
||||||
EXPECT_EQ('/', *self);
|
EXPECT_EQ('/', *self);
|
||||||
EXPECT_TRUE(
|
EXPECT_TRUE(!!strstr(self, "getprogramexecutablename_test"));
|
||||||
endswith(self, "test/libc/calls/getprogramexecutablename_test.com"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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();
|
||||||
|
@ -71,6 +66,7 @@ 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();
|
||||||
|
@ -78,6 +74,7 @@ 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);
|
||||||
|
@ -88,6 +85,7 @@ 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},
|
||||||
|
@ -97,6 +95,7 @@ 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));
|
||||||
|
|
Loading…
Add table
Reference in a new issue