mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15:28:30 +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
|
@ -18,23 +18,37 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/rlimit.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/runtime/sysconf.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/ex.h"
|
||||
#include "libc/sysv/consts/exit.h"
|
||||
#include "libc/sysv/consts/f.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
#include "libc/sysv/consts/rlimit.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/dlmalloc/dlmalloc.h"
|
||||
|
@ -81,16 +95,75 @@ void GetOpts(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
|
||||
static void EmptySignalMask(void) {
|
||||
sigset_t ss;
|
||||
sigemptyset(&ss);
|
||||
sigprocmask(SIG_SETMASK, &ss, 0);
|
||||
}
|
||||
|
||||
static void FixIrregularFds(void) {
|
||||
int i;
|
||||
struct pollfd pfds[64];
|
||||
for (i = 0; i < 3; ++i) {
|
||||
if (fcntl(0, F_GETFL) == -1) {
|
||||
CHECK_EQ(0, open("/dev/null", O_RDWR));
|
||||
}
|
||||
}
|
||||
for (i = 0; i < ARRAYLEN(pfds); ++i) {
|
||||
pfds[i].fd = i + 3;
|
||||
pfds[i].events = POLLIN;
|
||||
}
|
||||
if (poll(pfds, ARRAYLEN(pfds), 0) != -1) {
|
||||
for (i = 0; i < ARRAYLEN(pfds); ++i) {
|
||||
if (pfds[i].revents & POLLNVAL) continue;
|
||||
CHECK_EQ(0, close(pfds[i].fd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SetLimit(int resource, uint64_t soft, uint64_t hard) {
|
||||
struct rlimit old;
|
||||
struct rlimit lim = {soft, hard};
|
||||
if (resource == 127) return;
|
||||
if (setrlimit(resource, &lim) == -1) {
|
||||
if (!getrlimit(resource, &old)) {
|
||||
lim.rlim_max = MIN(hard, old.rlim_max);
|
||||
lim.rlim_cur = MIN(soft, lim.rlim_max);
|
||||
setrlimit(resource, &lim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic test program main function.
|
||||
*/
|
||||
noasan int main(int argc, char *argv[]) {
|
||||
unsigned cpus;
|
||||
const char *comdbg;
|
||||
__log_level = kLogInfo;
|
||||
GetOpts(argc, argv);
|
||||
|
||||
// normalize this process
|
||||
FixIrregularFds();
|
||||
EmptySignalMask();
|
||||
ShowCrashReports();
|
||||
|
||||
// so the test runner can terminate unknown children without
|
||||
// accidentally killing parent processes
|
||||
if (!IsWindows() && weaken(fork)) {
|
||||
setpgrp();
|
||||
}
|
||||
|
||||
// prevent runaway tests from bombing the computer
|
||||
cpus = GetCpuCount();
|
||||
cpus = MAX(4, cpus);
|
||||
SetLimit(RLIMIT_NOFILE, 32, 128);
|
||||
SetLimit(RLIMIT_SIGPENDING, 16, 16384);
|
||||
SetLimit(RLIMIT_NPROC, cpus * 8, 2048);
|
||||
|
||||
// now get down to business
|
||||
g_testlib_shoulddebugbreak = IsDebuggerPresent(false);
|
||||
if (!IsWindows()) sys_getpid(); /* make strace easier to read */
|
||||
if (!IsWindows()) sys_getpid(); // make strace easier to read
|
||||
testlib_clearxmmregisters();
|
||||
testlib_runalltests();
|
||||
if (!g_testlib_failed && runbenchmarks_ && weaken(testlib_runallbenchmarks)) {
|
||||
|
@ -99,10 +172,12 @@ noasan int main(int argc, char *argv[]) {
|
|||
CheckForMemoryLeaks();
|
||||
}
|
||||
if (!g_testlib_failed && IsRunningUnderMake()) {
|
||||
return 254; /* compile.com considers this 0 and propagates output */
|
||||
return 254; // compile.com considers this 0 and propagates output
|
||||
}
|
||||
} else if (!g_testlib_failed) {
|
||||
CheckForMemoryLeaks();
|
||||
}
|
||||
|
||||
// we're done!
|
||||
exit(min(255, g_testlib_failed));
|
||||
}
|
||||
|
|
|
@ -16,29 +16,39 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/sigbits.h"
|
||||
#include "libc/calls/strace.internal.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/sigset.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/runtime/symbols.internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
#include "libc/sysv/consts/sa.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/w.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
static int x;
|
||||
char g_testlib_olddir[PATH_MAX];
|
||||
char g_testlib_tmpdir[PATH_MAX];
|
||||
struct sigaction wanthandlers[31];
|
||||
|
||||
void testlib_finish(void) {
|
||||
if (g_testlib_failed) {
|
||||
|
@ -61,7 +71,6 @@ static void SetupTmpDir(void) {
|
|||
p = FormatInt64(p, x++);
|
||||
p[0] = '\0';
|
||||
CHECK_NE(-1, makedirs(g_testlib_tmpdir, 0755), "%s", g_testlib_tmpdir);
|
||||
CHECK_EQ(1, isdirectory(g_testlib_tmpdir), "%s", g_testlib_tmpdir);
|
||||
CHECK_NOTNULL(realpath(g_testlib_tmpdir, g_testlib_tmpdir), "%`'s",
|
||||
g_testlib_tmpdir);
|
||||
CHECK_NE(-1, chdir(g_testlib_tmpdir), "%s", g_testlib_tmpdir);
|
||||
|
@ -69,8 +78,93 @@ static void SetupTmpDir(void) {
|
|||
|
||||
static void TearDownTmpDir(void) {
|
||||
CHECK_NE(-1, chdir(g_testlib_olddir));
|
||||
CHECK_NE(-1, rmrf(g_testlib_tmpdir), "ugh %s", g_testlib_tmpdir);
|
||||
CHECK_EQ(0, isdirectory(g_testlib_tmpdir), "%s", g_testlib_tmpdir);
|
||||
CHECK_NE(-1, rmrf(g_testlib_tmpdir), "%s", g_testlib_tmpdir);
|
||||
}
|
||||
|
||||
static void DoNothing(int sig) {
|
||||
// function intentionally empty
|
||||
}
|
||||
|
||||
static void CopySignalHandlers(void) {
|
||||
#if 0
|
||||
int i;
|
||||
for (i = 0; i < ARRAYLEN(wanthandlers); ++i) {
|
||||
if (i + 1 == SIGKILL || i + 1 == SIGSTOP) continue;
|
||||
CHECK_EQ(0, sigaction(i + 1, 0, wanthandlers + i), "sig=%d", i + 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CheckSignalHandler(int sig) {
|
||||
#if 0
|
||||
int i;
|
||||
struct sigaction sa = {0};
|
||||
assert(0 <= sig - 1 && sig - 1 < ARRAYLEN(wanthandlers));
|
||||
CHECK_EQ(0, sigaction(sig, 0, &sa));
|
||||
CHECK_EQ(0, memcmp(wanthandlers + sig - 1, &sa, sizeof(sa)),
|
||||
"signal handler for %s was %p/%#x/%#x:%x "
|
||||
"but should have been restored to %p/%#x/%#x:%x",
|
||||
strsignal(sig), sa.sa_handler, sa.sa_flags, sa.sa_mask.__bits[0],
|
||||
sa.sa_mask.__bits[1], wanthandlers[sig - 1].sa_handler,
|
||||
wanthandlers[sig - 1].sa_flags,
|
||||
wanthandlers[sig - 1].sa_mask.__bits[0],
|
||||
wanthandlers[sig - 1].sa_mask.__bits[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CheckForSignalHandlers(void) {
|
||||
#if 0
|
||||
CheckSignalHandler(SIGINT);
|
||||
CheckSignalHandler(SIGQUIT);
|
||||
CheckSignalHandler(SIGCHLD);
|
||||
CheckSignalHandler(SIGFPE);
|
||||
CheckSignalHandler(SIGILL);
|
||||
CheckSignalHandler(SIGSEGV);
|
||||
CheckSignalHandler(SIGTRAP);
|
||||
CheckSignalHandler(SIGABRT);
|
||||
CheckSignalHandler(SIGBUS);
|
||||
CheckSignalHandler(SIGSYS);
|
||||
CheckSignalHandler(SIGWINCH);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CheckForFileDescriptors(void) {
|
||||
#if 0
|
||||
// TODO: race condition on fd cleanup :'(
|
||||
int i;
|
||||
struct pollfd pfds[16];
|
||||
if (!weaken(open) && !weaken(socket)) return;
|
||||
for (i = 0; i < ARRAYLEN(pfds); ++i) {
|
||||
pfds[i].fd = i + 3;
|
||||
pfds[i].events = POLLIN;
|
||||
}
|
||||
if (poll(pfds, ARRAYLEN(pfds), 0) > 0) {
|
||||
for (i = 0; i < ARRAYLEN(pfds); ++i) {
|
||||
if (pfds[i].revents & POLLNVAL) continue;
|
||||
++g_testlib_failed;
|
||||
fprintf(stderr, "error: test failed to close() fd %d%n", pfds[i].fd);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void CheckForZombies(void) {
|
||||
#if 0
|
||||
int e, pid;
|
||||
sigset_t ss, oldss;
|
||||
struct sigaction oldsa;
|
||||
struct sigaction ignore = {.sa_handler = DoNothing};
|
||||
if (!weaken(fork)) return;
|
||||
for (;;) {
|
||||
if ((pid = wait(0)) == -1) {
|
||||
CHECK_EQ(ECHILD, errno);
|
||||
break;
|
||||
} else {
|
||||
++g_testlib_failed;
|
||||
fprintf(stderr, "error: test failed to reap zombies %d%n", pid);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,6 +188,7 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end,
|
|||
* @see ape/ape.lds
|
||||
*/
|
||||
const testfn_t *fn;
|
||||
CopySignalHandlers();
|
||||
CHECK_NOTNULL(getcwd(g_testlib_olddir, sizeof(g_testlib_olddir)));
|
||||
if (weaken(testlib_enable_tmp_setup_teardown_once)) SetupTmpDir();
|
||||
if (weaken(SetUpOnce)) weaken(SetUpOnce)();
|
||||
|
@ -109,6 +204,9 @@ testonly void testlib_runtestcases(testfn_t *start, testfn_t *end,
|
|||
if (!IsWindows()) sys_getpid();
|
||||
if (weaken(TearDown)) weaken(TearDown)();
|
||||
if (weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir();
|
||||
CheckForFileDescriptors();
|
||||
CheckForSignalHandlers();
|
||||
CheckForZombies();
|
||||
}
|
||||
if (weaken(TearDownOnce)) weaken(TearDownOnce)();
|
||||
if (weaken(testlib_enable_tmp_setup_teardown_once)) TearDownTmpDir();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue