Remove plenty of makefile misconfigurations

This commit is contained in:
Justine Tunney 2022-07-21 09:16:38 -07:00
parent 9172fd42a0
commit 8b469389f6
186 changed files with 1408 additions and 901 deletions

View file

@ -1,363 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/io.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
STATIC_YOINK("zip_uri_support");
int ws, pid;
char testlib_enable_tmp_setup_teardown;
__attribute__((__constructor__)) static void init(void) {
pledge("stdio rpath wpath cpath fattr proc exec", 0);
errno = 0;
}
bool UsingBinfmtMisc(void) {
return fileexists("/proc/sys/fs/binfmt_misc/APE");
}
// see: #431
// todo(jart): figure out what is wrong with github actions
// thetanil: same issue reproducible on my debian 5.10
// bool HasMzHeader(const char *path) {
// char buf[2] = {0};
// open(path, O_RDONLY);
// read(3, buf, 2);
// close(3);
// return buf[0] == 'M' && buf[1] == 'Z';
// }
void Extract(const char *from, const char *to, int mode) {
ASSERT_SYS(0, 3, open(from, O_RDONLY), "%s %s", from, to);
ASSERT_SYS(0, 4, creat(to, mode));
ASSERT_NE(-1, _copyfd(3, 4, -1));
EXPECT_SYS(0, 0, close(4));
EXPECT_SYS(0, 0, close(3));
}
void SetUp(void) {
ASSERT_SYS(0, 0, mkdir("tmp", 0755));
ASSERT_SYS(0, 0, mkdir("bin", 0755));
Extract("/zip/tiny64.elf", "bin/tiny64.elf", 0755);
// Extract("/zip/pylife.com", "bin/pylife.com", 0755);
Extract("/zip/life-nomod.com", "bin/life-nomod.com", 0755);
Extract("/zip/life-classic.com", "bin/life-classic.com", 0755);
setenv("TMPDIR", "tmp", true);
if (IsOpenbsd()) {
// printf is in /usr/bin/printf on openbsd...
setenv("PATH", "/bin:/usr/bin", true);
} else if (!IsWindows()) {
setenv("PATH", "/bin", true);
}
}
////////////////////////////////////////////////////////////////////////////////
TEST(execve, system_elf) {
if (!IsLinux()) return;
ws = system("bin/tiny64.elf");
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
system("cp bin/tiny64.elf /tmp/tiny64.elf");
}
TEST(execve, fork_elf) {
if (!IsLinux()) return;
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
execl("bin/tiny64.elf", "bin/tiny64.elf", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
}
TEST(execve, vfork_elf) {
if (!IsLinux()) return;
ASSERT_NE(-1, (pid = vfork()));
if (!pid) {
execl("bin/tiny64.elf", "bin/tiny64.elf", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
}
////////////////////////////////////////////////////////////////////////////////
TEST(execve, system_apeNoModifySelf) {
if (IsWindows()) return; // todo(jart): wut
for (int i = 0; i < 2; ++i) {
ws = system("bin/life-nomod.com");
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// EXPECT_TRUE(HasMzHeader("bin/life-nomod.com"));
system("cp bin/life-nomod.com /tmp/life-nomod.com");
}
}
TEST(execve, fork_apeNoModifySelf) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// EXPECT_TRUE(HasMzHeader("bin/life-nomod.com"));
}
}
TEST(execve, vfork_apeNoModifySelf) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = vfork()));
if (!pid) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// EXPECT_TRUE(HasMzHeader("bin/life-nomod.com"));
}
}
////////////////////////////////////////////////////////////////////////////////
TEST(execve, system_apeClassic) {
if (IsWindows()) return; // todo(jart): wut
for (int i = 0; i < 2; ++i) {
system("bin/life-classic.com");
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// if (UsingBinfmtMisc()) {
// EXPECT_TRUE(HasMzHeader("bin/life-classic.com"));
// }
}
}
TEST(execve, fork_apeClassic) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
execl("bin/life-classic.com", "bin/life-classic.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// if (UsingBinfmtMisc()) {
// EXPECT_TRUE(HasMzHeader("bin/life-classic.com"));
// }
}
}
TEST(execve, vfork_apeClassic) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = vfork()));
if (!pid) {
execl("bin/life-classic.com", "bin/life-classic.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
// see: HasMzHeader()
// if (UsingBinfmtMisc()) {
// EXPECT_TRUE(HasMzHeader("bin/life-classic.com"));
// }
}
}
////////////////////////////////////////////////////////////////////////////////
#if 0 // not worth depending on THIRD_PARTY_PYTHON for this test
TEST(execve, system_apeNoMod3mb) {
if (IsWindows()) return; // todo(jart): wut
for (int i = 0; i < 2; ++i) {
system("bin/pylife.com");
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
EXPECT_TRUE(HasMzHeader("bin/pylife.com"));
}
}
TEST(execve, fork_apeNoMod3mb) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = fork()));
if (!pid) {
execl("bin/pylife.com", "bin/pylife.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
EXPECT_TRUE(HasMzHeader("bin/pylife.com"));
}
}
TEST(execve, vfork_apeNoMod3mb) {
for (int i = 0; i < 2; ++i) {
ASSERT_NE(-1, (pid = vfork()));
if (!pid) {
execl("bin/pylife.com", "bin/pylife.com", 0);
_Exit(127);
}
ASSERT_EQ(pid, wait(&ws));
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(42, WEXITSTATUS(ws));
EXPECT_TRUE(HasMzHeader("bin/pylife.com"));
}
}
#endif
////////////////////////////////////////////////////////////////////////////////
void SystemElf(void) {
system("bin/tiny64.elf");
}
void ForkElf(void) {
if (!(pid = fork())) {
execl("bin/tiny64.elf", "bin/tiny64.elf", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
void VforkElf(void) {
if (!(pid = vfork())) {
execl("bin/tiny64.elf", "bin/tiny64.elf", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
void SystemNoMod(void) {
system("bin/life-nomod.com");
}
void ForkNoMod(void) {
if (!(pid = fork())) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
void VforkNoMod(void) {
if (!(pid = vfork())) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
void SystemClassic(void) {
system("bin/life-classic.com");
}
void ForkClassic(void) {
if (!(pid = fork())) {
execl("bin/life-classic.com", "bin/life-classic.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
void VforkClassic(void) {
if (!(pid = vfork())) {
execl("bin/life-classic.com", "bin/life-classic.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
////////////////////////////////////////////////////////////////////////////////
void SystemNoMod3mb(void) {
system("bin/life-nomod.com");
}
void ForkNoMod3mb(void) {
if (!(pid = fork())) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
void VforkNoMod3mb(void) {
if (!(pid = vfork())) {
execl("bin/life-nomod.com", "bin/life-nomod.com", 0);
_Exit(127);
}
waitpid(pid, 0, 0);
}
BENCH(execve, bench1) {
if (IsLinux()) {
EZBENCH2("ForkElf", donothing, ForkElf());
EZBENCH2("VforkElf", donothing, VforkElf());
EZBENCH2("SystemElf", donothing, SystemElf());
kprintf("\n");
}
EZBENCH2("ForkApeClassic", donothing, ForkClassic());
EZBENCH2("VforkApeClassic", donothing, VforkClassic());
if (!IsWindows()) {
EZBENCH2("SystemApeClassic", donothing, SystemClassic());
}
kprintf("\n");
EZBENCH2("ForkApeNoMod", donothing, ForkNoMod());
EZBENCH2("VforkApeNoMod", donothing, VforkNoMod());
if (!IsWindows()) {
EZBENCH2("SystemApeNoMod", donothing, SystemNoMod());
}
kprintf("\n");
EZBENCH2("ForkNoMod3mb", donothing, ForkNoMod3mb());
EZBENCH2("VforkNoMod3mb", donothing, VforkNoMod3mb());
if (!IsWindows()) {
EZBENCH2("SystemNoMod3mb", donothing, SystemNoMod3mb());
}
}

View file

@ -23,13 +23,12 @@
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"
#define PATH "o/vfork_test"
char testlib_enable_tmp_setup_teardown;
TEST(vfork, test) {
int fd;
char buf[8] = {0};
mkdir("o", 0755);
ASSERT_NE(-1, (fd = open(PATH, O_RDWR | O_CREAT, 0644)));
ASSERT_NE(-1, (fd = open("vfork_test", O_RDWR | O_CREAT, 0644)));
ASSERT_EQ(5, write(fd, "hello", 5));
ASSERT_NE(-1, lseek(fd, 0, SEEK_SET));
if (!vfork()) {
@ -44,5 +43,4 @@ TEST(vfork, test) {
EXPECT_EQ(5, read(fd, buf, 5));
EXPECT_STREQ("hello", buf);
EXPECT_NE(-1, close(fd));
unlink(PATH);
}

View file

@ -44,10 +44,10 @@ STATIC_YOINK("zip_uri_support");
#define EACCES_OR_ENOENT (IsOpenbsd() ? ENOENT : EACCES)
#define SPAWN() \
{ \
int ws, pid; \
ASSERT_NE(-1, (pid = fork())); \
#define SPAWN(METHOD) \
{ \
int ws, pid; \
ASSERT_NE(-1, (pid = METHOD())); \
if (!pid) {
#define EXITS(rc) \
@ -94,7 +94,7 @@ int extract(const char *from, const char *to, int mode) {
}
TEST(unveil, api_differences) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, stat("/", &st));
ASSERT_SYS(0, 0, unveil(".", "rw"));
if (IsOpenbsd()) {
@ -117,12 +117,12 @@ TEST(unveil, api_differences) {
}
TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("folder", 0755));
ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755));
ASSERT_SYS(0, 0, unveil("folder", "rx"));
ASSERT_SYS(0, 0, unveil(0, 0));
SPAWN();
SPAWN(fork);
execl("folder/life.elf", "folder/life.elf", 0);
kprintf("execve failed! %s\n", strerror(errno));
_Exit(127);
@ -131,24 +131,41 @@ TEST(unveil, rx_readOnlyPreexistingExecutable_worksFine) {
}
TEST(unveil, r_noExecutePreexistingExecutable_raisesEacces) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("folder", 0755));
ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755));
ASSERT_SYS(0, 0, unveil("folder", "r"));
ASSERT_SYS(0, 0, unveil(0, 0));
SPAWN();
SPAWN(fork);
ASSERT_SYS(EACCES, -1, execl("folder/life.elf", "folder/life.elf", 0));
EXITS(0);
EXITS(0);
}
TEST(unveil, canBeUsedAgainAfterVfork) {
ASSERT_SYS(0, 0, touch("bad", 0644));
ASSERT_SYS(0, 0, touch("good", 0644));
SPAWN(fork);
SPAWN(vfork);
ASSERT_SYS(0, 0, unveil("bad", "r"));
ASSERT_SYS(0, 0, unveil("good", "r"));
ASSERT_SYS(0, 0, unveil(0, 0));
ASSERT_SYS(0, 3, open("bad", 0));
EXITS(0);
ASSERT_SYS(0, 0, unveil("good", "r"));
ASSERT_SYS(0, 0, unveil(0, 0));
ASSERT_SYS(0, 3, open("good", 0));
ASSERT_SYS(EACCES_OR_ENOENT, -1, open("bad", 0));
EXITS(0);
}
TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("folder", 0755));
ASSERT_SYS(0, 0, unveil("folder", "rwc"));
ASSERT_SYS(0, 0, unveil(0, 0));
ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755));
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, stat("folder/life.elf", &st));
ASSERT_SYS(EACCES, -1, execl("folder/life.elf", "folder/life.elf", 0));
EXITS(0);
@ -156,12 +173,12 @@ TEST(unveil, rwc_createExecutableFile_isAllowedButCantBeRun) {
}
TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("folder", 0755));
ASSERT_SYS(0, 0, unveil("folder", "rwcx"));
ASSERT_SYS(0, 0, unveil(0, 0));
ASSERT_SYS(0, 0, extract("/zip/life.elf", "folder/life.elf", 0755));
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, stat("folder/life.elf", &st));
execl("folder/life.elf", "folder/life.elf", 0);
kprintf("execve failed! %s\n", strerror(errno));
@ -171,7 +188,7 @@ TEST(unveil, rwcx_createExecutableFile_canAlsoBeRun) {
}
TEST(unveil, dirfdHacking_doesntWork) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("jail", 0755));
ASSERT_SYS(0, 0, mkdir("garden", 0755));
ASSERT_SYS(0, 0, touch("garden/secret.txt", 0644));
@ -184,7 +201,7 @@ TEST(unveil, dirfdHacking_doesntWork) {
TEST(unveil, mostRestrictivePolicy) {
if (IsOpenbsd()) return; // openbsd behaves oddly; see docs
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("jail", 0755));
ASSERT_SYS(0, 0, mkdir("garden", 0755));
ASSERT_SYS(0, 0, touch("garden/secret.txt", 0644));
@ -195,7 +212,7 @@ TEST(unveil, mostRestrictivePolicy) {
}
TEST(unveil, overlappingDirectories_inconsistentBehavior) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, makedirs("f1/f2", 0755));
ASSERT_SYS(0, 0, extract("/zip/life.elf", "f1/f2/life.elf", 0755));
ASSERT_SYS(0, 0, unveil("f1", "x"));
@ -203,7 +220,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) {
ASSERT_SYS(0, 0, unveil(0, 0));
if (IsOpenbsd()) {
// OpenBSD favors the most restrictive policy
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, stat("f1/f2/life.elf", &st));
ASSERT_SYS(EACCES, -1, execl("f1/f2/life.elf", "f1/f2/life.elf", 0));
EXITS(0);
@ -214,7 +231,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) {
// exit code of 0! find out why this is happening...
// so far it's happened to MODE=rel and MODE=tiny...
//
// SPAWN();
// SPAWN(fork);
// ASSERT_SYS(0, 0, stat("f1/f2/life.elf", &st));
// execl("f1/f2/life.elf", "f1/f2/life.elf", 0);
// kprintf("execve failed! %s\n", strerror(errno));
@ -225,7 +242,7 @@ TEST(unveil, overlappingDirectories_inconsistentBehavior) {
}
TEST(unveil, usedTwice_forbidden) {
SPAWN();
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("jail", 0755));
ASSERT_SYS(0, 0, mkdir("garden", 0755));
ASSERT_SYS(0, 0, xbarf("garden/secret.txt", "hello", 5));
@ -288,7 +305,7 @@ TEST(unveil, usedTwice_forbidden_worksWithPledge) {
TEST(unveil, lotsOfPaths) {
int i, n;
SPAWN();
SPAWN(fork);
n = 100;
for (i = 0; i < n; ++i) {
ASSERT_SYS(0, 0, touch(xasprintf("%d", i), 0644));
@ -305,3 +322,15 @@ TEST(unveil, lotsOfPaths) {
}
EXITS(0);
}
TEST(unveil, reparent) {
return; // need abi 2 :'(
SPAWN(fork);
ASSERT_SYS(0, 0, mkdir("x", 0755));
ASSERT_SYS(0, 0, unveil("x", "rwc"));
ASSERT_SYS(0, 0, unveil(0, 0));
ASSERT_SYS(0, 0, mkdir("x/y", 0755));
ASSERT_SYS(0, 0, touch("x/y/z", 0644));
ASSERT_SYS(0, 0, rename("x/y/z", "x/z"));
EXITS(0);
}

View file

@ -9,10 +9,6 @@ int main(int argc, char *argv[]) {
fputs(_gc(xiso8601ts(NULL)), f);
fputs(_gc(xasprintf("hello world %d %s\n", argc, s)), f);
fclose(f);
rc = system("exit 42");
CHECK_NE(-1, rc);
CHECK(WIFEXITED(rc));
CHECK_EQ(42, WEXITSTATUS(rc));
free(s);
return 0;
}

View file

@ -1,11 +1,9 @@
int main() {
int rc;
FILE *f;
f = fopen("/dev/null", "w");
fprintf(f, "hello world\n");
fclose(f);
rc = system("exit 42");
CHECK_NE(-1, rc);
CHECK_EQ(42, WEXITSTATUS(rc));
return 0;
int *x = new int[32];
x[0] = 2;
x[1] = 2;
x[2] = x[0] + x[1];
return x[2] - 4;
}

View file

@ -18,6 +18,7 @@
*/
#include "libc/bits/atomic.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/xchg.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/ucontext.h"
@ -46,6 +47,8 @@
#include "libc/x/x.h"
#include "third_party/xed/x86.h"
#define TMP firstnonnull(getenv("TMPDIR"), kTmpPath)
char testlib_enable_tmp_setup_teardown;
__attribute__((__constructor__)) static void init(void) {
@ -93,7 +96,7 @@ TEST(mmap, testMapFile) {
int fd;
char *p;
char path[PATH_MAX];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(5, write(fd, "hello", 5));
EXPECT_NE(-1, fdatasync(fd));
@ -107,7 +110,7 @@ TEST(mmap, testMapFile) {
TEST(mmap, testMapFile_fdGetsClosed_makesNoDifference) {
int fd;
char *p, buf[16], path[PATH_MAX];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(5, write(fd, "hello", 5));
EXPECT_NE(-1, fdatasync(fd));
@ -227,8 +230,9 @@ TEST(mmap, cow) {
int fd;
char *p;
char path[PATH_MAX];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)), "%s",
path);
EXPECT_EQ(5, write(fd, "hello", 5));
EXPECT_NE(-1, fdatasync(fd));
EXPECT_NE(MAP_FAILED,
@ -246,7 +250,7 @@ TEST(mmap, cowFileMapReadonlyFork) {
char *p;
int fd, pid, ws;
char path[PATH_MAX], lol[6];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(6, write(fd, "hello", 6));
EXPECT_NE(-1, close(fd));
@ -271,7 +275,7 @@ TEST(mmap, cowFileMapFork) {
char *p;
int fd, pid, ws;
char path[PATH_MAX], lol[6];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(6, write(fd, "parnt", 6));
EXPECT_NE(-1, fdatasync(fd));
@ -321,7 +325,7 @@ TEST(mmap, sharedFileMapFork) {
char *p;
int fd, pid, ws;
char path[PATH_MAX], lol[6];
sprintf(path, "%s%s.%ld", kTmpPath, program_invocation_short_name, lemur64());
sprintf(path, "%s.%ld", program_invocation_short_name, lemur64());
ASSERT_NE(-1, (fd = open(path, O_CREAT | O_TRUNC | O_RDWR, 0644)));
EXPECT_EQ(6, write(fd, "parnt", 6));
EXPECT_NE(-1, fdatasync(fd));

View file

@ -1,35 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"
TEST(popen, test) {
int ws;
FILE *f;
f = popen("echo hi", "r");
ASSERT_NE(NULL, f);
EXPECT_EQ('h', fgetc(f));
EXPECT_EQ('i', fgetc(f));
ws = pclose(f);
EXPECT_NE(-1, ws);
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(0, WEXITSTATUS(ws));
}

View file

@ -1,32 +0,0 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"
TEST(system, nullParam_testsIfSystemHasShell) {
ASSERT_EQ(true, system(NULL));
}
TEST(system, test) {
int rc;
rc = system("exit 42");
ASSERT_NE(-1, rc);
ASSERT_EQ(42, WEXITSTATUS(rc));
}

View file

@ -58,6 +58,7 @@ o/$(MODE)/test/libc/stdio/%.com.dbg: \
$(TEST_LIBC_STDIO_DEPS) \
o/$(MODE)/test/libc/stdio/%.o \
o/$(MODE)/test/libc/stdio/stdio.pkg \
o/$(MODE)/tool/build/echo.zip.o \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE_NO_MODIFY_SELF)

View file

@ -22,24 +22,22 @@
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
char testlib_enable_tmp_setup_teardown;
TEST(xslurp, testEmptyWithNulTerminatedStringBehavior) {
size_t got;
const char *data;
const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt"));
ASSERT_NE(-1, xbarf(path, "", -1));
ASSERT_NE(NULL, (data = gc(xslurp(path, &got))));
ASSERT_NE(-1, xbarf("xslurp.txt", "", -1));
ASSERT_NE(NULL, (data = gc(xslurp("xslurp.txt", &got))));
ASSERT_EQ(0, got);
ASSERT_STREQ("", data);
ASSERT_NE(-1, unlink(path));
}
TEST(xslurp, testHyperion) {
size_t got;
const char *data;
const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt"));
ASSERT_NE(-1, xbarf(path, kHyperion, kHyperionSize));
ASSERT_NE(NULL, (data = gc(xslurp(path, &got))));
ASSERT_NE(-1, xbarf("xslurp.txt", kHyperion, kHyperionSize));
ASSERT_NE(NULL, (data = gc(xslurp("xslurp.txt", &got))));
ASSERT_EQ(kHyperionSize, got);
ASSERT_EQ(0, memcmp(data, kHyperion, kHyperionSize));
ASSERT_NE(-1, unlink(path));
}