Skip to content

Commit

Permalink
move execve test out of fexecve_test.c
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi committed Sep 2, 2023
1 parent b7ebcc2 commit a3d5a48
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
21 changes: 21 additions & 0 deletions test/libc/calls/execve_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "libc/runtime/runtime.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/s.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/subprocess.h"
Expand All @@ -37,6 +38,8 @@

#define N 16

int fds[2];
char buf[8];
bool HasProcFSAndMemfd = false;

char *GenBuf(char buf[8], int x) {
Expand Down Expand Up @@ -78,6 +81,24 @@ TEST(execve, testArgPassing) {
}
}

TEST(execve, elfIsUnreadable_mayBeExecuted) {
if (IsWindows() || IsXnu()) return;
testlib_extract("/zip/echo.elf", "echo", 0111);
ASSERT_SYS(0, 0, pipe2(fds, O_CLOEXEC));
SPAWN(vfork);
ASSERT_SYS(0, 1, dup2(4, 1));
ASSERT_SYS(
0, 0,
execve("echo", (char *const[]){"echo", "hi", 0}, (char *const[]){0}));
exit(1);
EXITS(0);
bzero(buf, 8);
ASSERT_SYS(0, 0, close(4));
ASSERT_SYS(0, 3, read(3, buf, 7));
ASSERT_SYS(0, 0, close(3));
ASSERT_STREQ("hi\n", buf);
}

TEST(execve, ziposELF) {
if (IsFreebsd()) return; // TODO: fixme on freebsd
if (!__is_linux_2_6_23()) return; // TODO: fixme on old linux
Expand Down
18 changes: 0 additions & 18 deletions test/libc/calls/fexecve_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,6 @@ void SetUp(void) {
}
}

TEST(execve, elfIsUnreadable_mayBeExecuted) {
if (IsWindows() || IsXnu()) return;
testlib_extract("/zip/echo.elf", "echo", 0111);
ASSERT_SYS(0, 0, pipe2(fds, O_CLOEXEC));
SPAWN(vfork);
ASSERT_SYS(0, 1, dup2(4, 1));
ASSERT_SYS(
0, 0,
execve("echo", (char *const[]){"echo", "hi", 0}, (char *const[]){0}));
exit(1);
EXITS(0);
bzero(buf, 8);
ASSERT_SYS(0, 0, close(4));
ASSERT_SYS(0, 3, read(3, buf, 7));
ASSERT_SYS(0, 0, close(3));
ASSERT_STREQ("hi\n", buf);
}

TEST(fexecve, elfIsUnreadable_mayBeExecuted) {
if (!IsLinux() && !IsFreebsd()) return;
testlib_extract("/zip/echo.elf", "echo", 0111);
Expand Down
1 change: 1 addition & 0 deletions test/libc/calls/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ o/$(MODE)/test/libc/calls/echo.elf: \
o/$(MODE)/test/libc/calls/execve_test.com.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/execve_test.o \
o/$(MODE)/test/libc/calls/echo.elf.zip.o \
o/$(MODE)/test/libc/calls/life-nomod.com.zip.o \
o/$(MODE)/test/libc/mem/prog/life.elf.zip.o \
o/$(MODE)/test/libc/mem/prog/sock.elf.zip.o \
Expand Down

0 comments on commit a3d5a48

Please sign in to comment.