Skip to content

Commit

Permalink
Skip argv[0] tests with old/no loader
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdomino committed Dec 15, 2023
1 parent 580982e commit 7da74f5
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions test/libc/calls/getprogramexecutablename_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 7da74f5

Please sign in to comment.