add arg0 passing execve test

This commit is contained in:
Gavin Hayes 2023-01-03 10:32:52 -05:00
parent a6586cafb2
commit b045194d99

View file

@ -25,6 +25,7 @@
#include "libc/testlib/testlib.h" #include "libc/testlib/testlib.h"
#define N 16 #define N 16
static const char *testArg0PassingArg = "bothArgsShouldBeThis";
char *GenBuf(char buf[8], int x) { char *GenBuf(char buf[8], int x) {
int i; int i;
@ -41,6 +42,9 @@ __attribute__((__constructor__)) static void init(void) {
if (__argc == 4 && !strcmp(__argv[1], "-")) { if (__argc == 4 && !strcmp(__argv[1], "-")) {
ASSERT_STREQ(GenBuf(buf, atoi(__argv[2])), __argv[3]); ASSERT_STREQ(GenBuf(buf, atoi(__argv[2])), __argv[3]);
exit(0); exit(0);
} else if (__argc == 2 && !strcmp(__argv[1], testArg0PassingArg)) {
ASSERT_STREQ(__argv[0], __argv[1]);
exit(0);
} }
} }
@ -58,3 +62,12 @@ TEST(execve, testArgPassing) {
EXITS(0); EXITS(0);
} }
} }
TEST(execve, testArg0Passing) {
SPAWN(vfork);
execve(GetProgramExecutableName(),
(char *const[]){testArg0PassingArg, testArg0PassingArg, 0},
(char *const[]){0});
notpossible;
EXITS(0);
}