mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-15 07:19:18 +00:00
Fix bugs and make improvements
- Get clone() working on FreeBSD - Increase some Python build quotas - Add more atomic builtins to chibicc - Fix ASAN poisoning of alloca() memory - Make MODE= mandatory link path tinier - Improve the examples folder a little bit - Start working on some more resource limits - Make the linenoise auto-complete UI as good as GNU readline - Update compile.com, avoiding AVX codegen on non-AVX systems - Make sure empty path to syscalls like opendir raises ENOENT - Correctly polyfill ENOENT vs. ENOTDIR on the New Technology - Port bestline's paredit features to //third_party/linenoise - Remove workarounds for RHEL 5.0 bugs that were fixed in 5.1
This commit is contained in:
parent
c3fb624647
commit
ae638c0850
181 changed files with 2994 additions and 1367 deletions
|
@ -36,6 +36,7 @@ TEST(access, efault) {
|
|||
}
|
||||
|
||||
TEST(access, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, access("", F_OK));
|
||||
ASSERT_SYS(ENOENT, -1, access("doesnotexist", F_OK));
|
||||
ASSERT_SYS(ENOENT, -1, access("o/doesnotexist", F_OK));
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ TEST(chdir, efault) {
|
|||
}
|
||||
|
||||
TEST(chdir, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, chdir(""));
|
||||
ASSERT_SYS(ENOENT, -1, chdir("doesnotexist"));
|
||||
ASSERT_SYS(ENOENT, -1, chdir("o/doesnotexist"));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/msync.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(fork, testPipes) {
|
||||
|
@ -77,3 +78,16 @@ TEST(fork, testSharedMemory) {
|
|||
EXPECT_NE(-1, munmap(sharedvar, FRAMESIZE));
|
||||
EXPECT_NE(-1, munmap(privatevar, FRAMESIZE));
|
||||
}
|
||||
|
||||
void ForkInSerial(void) {
|
||||
int pid, ws;
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) _Exit(0);
|
||||
ASSERT_NE(-1, waitpid(pid, &ws, 0));
|
||||
ASSERT_TRUE(WIFEXITED(ws));
|
||||
ASSERT_EQ(0, WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
BENCH(fork, bench) {
|
||||
EZBENCH2("fork", donothing, ForkInSerial());
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ TEST(open, efault) {
|
|||
}
|
||||
|
||||
TEST(open, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, open("", O_RDONLY));
|
||||
ASSERT_SYS(ENOENT, -1, open("doesnotexist", O_RDONLY));
|
||||
ASSERT_SYS(ENOENT, -1, open("o/doesnotexist", O_RDONLY));
|
||||
}
|
||||
|
|
75
test/libc/calls/pipe_test.c
Normal file
75
test/libc/calls/pipe_test.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*-*- 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/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int ws, pid, f[2];
|
||||
char buf[6] = {0};
|
||||
struct rlimit rlim = {0, 10};
|
||||
|
||||
TEST(pipe, efault) {
|
||||
EXPECT_SYS(EFAULT, -1, pipe(0));
|
||||
}
|
||||
|
||||
TEST(pipe, einval) {
|
||||
EXPECT_SYS(EINVAL, -1, pipe2(f, -1));
|
||||
}
|
||||
|
||||
TEST(pipe, ebadf) {
|
||||
if (IsFreebsd()) return; // somehow succeeds
|
||||
if (IsOpenbsd()) return; // somehow succeeds
|
||||
EXPECT_SYS(0, 0, pipe(f));
|
||||
EXPECT_SYS(EBADF, -1, write(f[0], "h", 1));
|
||||
EXPECT_SYS(EBADF, -1, read(f[1], buf, 1));
|
||||
EXPECT_SYS(0, 0, close(f[0]));
|
||||
EXPECT_SYS(0, 0, close(f[1]));
|
||||
}
|
||||
|
||||
TEST(pipe, emfile) {
|
||||
if (IsWindows()) return; // TODO
|
||||
ASSERT_NE(-1, (pid = fork()));
|
||||
if (!pid) {
|
||||
ASSERT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlim));
|
||||
ASSERT_SYS(EMFILE, -1, pipe(f));
|
||||
_exit(0);
|
||||
}
|
||||
EXPECT_NE(-1, waitpid(pid, &ws, 0));
|
||||
EXPECT_TRUE(WIFEXITED(ws));
|
||||
EXPECT_EQ(0, WEXITSTATUS(ws));
|
||||
}
|
||||
|
||||
TEST(pipe, usesLowestFileNumbers) {
|
||||
EXPECT_SYS(0, 0, pipe(f));
|
||||
EXPECT_SYS(0, 3, f[0]);
|
||||
EXPECT_SYS(0, 4, f[1]);
|
||||
EXPECT_SYS(0, 0, close(f[0]));
|
||||
EXPECT_SYS(0, 0, close(f[1]));
|
||||
}
|
||||
|
||||
TEST(pipe, doesBuffering) {
|
||||
EXPECT_SYS(0, 0, pipe(f));
|
||||
EXPECT_SYS(0, 5, write(f[1], "hello", 5));
|
||||
EXPECT_SYS(0, 5, read(f[0], buf, 5));
|
||||
EXPECT_STREQ("hello", buf);
|
||||
EXPECT_SYS(0, 0, close(f[0]));
|
||||
EXPECT_SYS(0, 0, close(f[1]));
|
||||
}
|
|
@ -52,6 +52,7 @@ TEST(readansi, test) {
|
|||
EXPECT_STREQ("\xc2\x9bM", b);
|
||||
EXPECT_EQ(0, readansi(fds[0], b, sizeof(b)));
|
||||
EXPECT_STREQ("", b);
|
||||
close(fds[0]);
|
||||
ASSERT_NE(-1, wait(&ws));
|
||||
ASSERT_TRUE(WIFEXITED(ws));
|
||||
ASSERT_EQ(0, WEXITSTATUS(ws));
|
||||
|
@ -73,6 +74,7 @@ TEST(readansi, testOperatingSystemCommand) {
|
|||
EXPECT_STREQ(s, b);
|
||||
EXPECT_EQ(0, readansi(fds[0], b, sizeof(b)));
|
||||
EXPECT_STREQ("", b);
|
||||
close(fds[0]);
|
||||
ASSERT_NE(-1, wait(&ws));
|
||||
ASSERT_TRUE(WIFEXITED(ws));
|
||||
ASSERT_EQ(0, WEXITSTATUS(ws));
|
||||
|
|
|
@ -31,6 +31,18 @@
|
|||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
TEST(readlink, enoent) {
|
||||
char buf[32];
|
||||
ASSERT_SYS(ENOENT, -1, readlink("doesnotexist", buf, 32));
|
||||
ASSERT_SYS(ENOENT, -1, readlink("o/doesnotexist", buf, 32));
|
||||
}
|
||||
|
||||
TEST(readlink, enotdir) {
|
||||
char buf[32];
|
||||
ASSERT_SYS(0, 0, touch("o", 0644));
|
||||
ASSERT_SYS(ENOTDIR, -1, readlink("o/doesnotexist", buf, 32));
|
||||
}
|
||||
|
||||
TEST(readlinkat, test) {
|
||||
char buf[128], *p, *q;
|
||||
memset(buf, -1, sizeof(buf));
|
||||
|
|
|
@ -24,6 +24,20 @@
|
|||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
TEST(rename, enoent) {
|
||||
EXPECT_SYS(ENOENT, -1, rename("foo", ""));
|
||||
EXPECT_SYS(ENOENT, -1, rename("", "foo"));
|
||||
EXPECT_SYS(ENOENT, -1, rename("foo", "o/bar"));
|
||||
EXPECT_SYS(ENOENT, -1, rename("o/bar", "foo"));
|
||||
}
|
||||
|
||||
TEST(renameat, enotdir) {
|
||||
EXPECT_SYS(0, 0, close(creat("yo", 0644)));
|
||||
EXPECT_SYS(ENOTDIR, -1, rename("yo/there", "hrcue"));
|
||||
// this test makes platforms crazy
|
||||
// EXPECT_SYS(ENOTDIR, -1, rename("zoo", "yo/there"));
|
||||
}
|
||||
|
||||
TEST(renameat, testNull_returnsEfault) {
|
||||
ASSERT_SYS(0, 0, close(creat("hello", 0644)));
|
||||
EXPECT_SYS(EFAULT, -1, renameat(AT_FDCWD, 0, AT_FDCWD, 0));
|
||||
|
|
|
@ -43,6 +43,7 @@ TEST(stat_010, testEmptyFile_sizeIsZero) {
|
|||
|
||||
TEST(stat, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, stat("hi", 0));
|
||||
ASSERT_SYS(ENOENT, -1, stat("o/doesnotexist", 0));
|
||||
}
|
||||
|
||||
TEST(stat, enotdir) {
|
||||
|
|
|
@ -29,6 +29,16 @@ char testlib_enable_tmp_setup_teardown;
|
|||
char p[2][PATH_MAX];
|
||||
struct stat st;
|
||||
|
||||
TEST(symlink, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, symlink("o/foo", ""));
|
||||
ASSERT_SYS(ENOENT, -1, symlink("o/foo", "o/bar"));
|
||||
}
|
||||
|
||||
TEST(symlinkat, enotdir) {
|
||||
ASSERT_SYS(0, 0, close(creat("yo", 0644)));
|
||||
ASSERT_SYS(ENOTDIR, -1, symlink("hrcue", "yo/there"));
|
||||
}
|
||||
|
||||
TEST(symlinkat, test) {
|
||||
sprintf(p[0], "%s.%d", program_invocation_short_name, rand());
|
||||
sprintf(p[1], "%s.%d", program_invocation_short_name, rand());
|
||||
|
|
|
@ -17,11 +17,29 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/sysv/consts/at.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
char testlib_enable_tmp_setup_teardown;
|
||||
|
||||
TEST(unlink, efault) {
|
||||
ASSERT_SYS(EFAULT, -1, unlink(0));
|
||||
if (IsWindows() && !IsAsan()) return; // not possible
|
||||
ASSERT_SYS(EFAULT, -1, unlink((void *)77));
|
||||
}
|
||||
|
||||
TEST(unlink, enoent) {
|
||||
ASSERT_SYS(ENOENT, -1, unlink(""));
|
||||
ASSERT_SYS(ENOENT, -1, unlink("doesnotexist"));
|
||||
ASSERT_SYS(ENOENT, -1, unlink("o/doesnotexist"));
|
||||
}
|
||||
|
||||
TEST(unlink, enotdir) {
|
||||
ASSERT_SYS(0, 0, touch("o", 0644));
|
||||
ASSERT_SYS(ENOTDIR, -1, unlink("o/doesnotexist"));
|
||||
}
|
||||
|
||||
TEST(unlinkat, test) {
|
||||
int i, fd;
|
||||
EXPECT_EQ(0, touch("mytmp", 0644));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue