Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -22,7 +22,7 @@
bool testlib_endswith(size_t cw, const void *s, const void *suffix) {
if (s == suffix) return true;
if (!s || !suffix) return false;
return cw == sizeof(wchar_t) ? wcsendswith(s, suffix)
: cw == sizeof(char16_t) ? endswith16(s, suffix)
: endswith(s, suffix);
return cw == sizeof(wchar_t) ? _wcsendswith(s, suffix)
: cw == sizeof(char16_t) ? _endswith16(s, suffix)
: _endswith(s, suffix);
}

View file

@ -1,12 +1,9 @@
#ifndef COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_
#define COSMOPOLITAN_LIBC_TESTLIB_EZBENCH_H_
#include "libc/macros.internal.h"
#include "libc/nexgen32e/bench.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/sysv/consts/clock.h"
#include "libc/testlib/bench.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

View file

@ -18,7 +18,7 @@
*/
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
void testlib_formatbinaryasglyphs(const char16_t *want, const void *got,
size_t n, char **out_v1, char **out_v2) {

View file

@ -16,11 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/mem/mem.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "third_party/gdtoa/gdtoa.h"
#include "libc/x/xasprintf.h"
char *testlib_formatfloat(long double x) {
return xasprintf("%.15Lg", x);

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
dontdiscard char *testlib_formatrange(intptr_t beg, intptr_t end) {
return xasprintf("[%#ld,%#ld]", beg, end);

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/safemacros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
/**
* Turns string into code.

View file

@ -51,8 +51,7 @@ static relegated void DieBecauseOfQuota(int rc, const char *message) {
gethostname(hostname, sizeof(hostname));
kprintf("%s on %s pid %d\n", message, hostname, (long)getpid());
PrintBacktraceUsingSymbols(2, 0, GetSymbolTable());
__restorewintty();
_Exit(rc);
_Exitr(rc);
}
static relegated void OnXcpu(int sig) {
@ -76,7 +75,7 @@ relegated void __oom_hook(size_t request) {
if (IsRunningUnderMake()) {
newlim = toto + request;
newlim += newlim >> 1;
newlim = roundup2pow(newlim);
newlim = _roundup2pow(newlim);
kprintf("FIX CODE OR TUNE QUOTA += -M%dm\n", newlim / (1024 * 1024));
}
kprintf("\n");
@ -84,8 +83,7 @@ relegated void __oom_hook(size_t request) {
kprintf("\nTHE STRAW THAT BROKE THE CAMEL'S BACK\n");
PrintBacktraceUsingSymbols(2, 0, GetSymbolTable());
PrintSystemMappings(2);
__restorewintty();
_Exit(42);
_Exitr(42);
}
static textstartup void InstallQuotaHandlers(void) {

View file

@ -22,7 +22,7 @@
bool testlib_startswith(size_t cw, const void *s, const void *prefix) {
if (s == prefix) return true;
if (!s || !prefix) return false;
return cw == sizeof(wchar_t) ? wcsstartswith(s, prefix)
: cw == sizeof(char16_t) ? startswith16(s, prefix)
: startswith(s, prefix);
return cw == sizeof(wchar_t) ? _wcsstartswith(s, prefix)
: cw == sizeof(char16_t) ? _startswith16(s, prefix)
: _startswith(s, prefix);
}

View file

@ -5,7 +5,6 @@ COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
cosmopolitan § testing library
*/
#include "libc/macros.internal.h"
/**
* Declares test case function.
@ -82,13 +81,16 @@ COSMOPOLITAN_C_START_
#define __ROSTR(STR) __TEST_SECTION(".rodata.str1.1,\"aSM\",@progbits,1", STR)
#define __FIXTURE(KIND, GROUP, ENTRY) \
asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \
"\t.quad\t1f\n" \
"\t.quad\t2f\n" \
"\t.quad\t" STRINGIFY(GROUP##_##ENTRY)) \
__ROSTR("1:\t.asciz\t" STRINGIFY(#GROUP)) \
__ROSTR("2:\t.asciz\t" STRINGIFY(#ENTRY))); \
#define TESTLIB_STRINGIFY(A) _TESTLIB_STRINGIFY(A)
#define _TESTLIB_STRINGIFY(A) #A
#define __FIXTURE(KIND, GROUP, ENTRY) \
asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \
"\t.quad\t1f\n" \
"\t.quad\t2f\n" \
"\t.quad\t" TESTLIB_STRINGIFY(GROUP##_##ENTRY)) \
__ROSTR("1:\t.asciz\t" TESTLIB_STRINGIFY(#GROUP)) \
__ROSTR("2:\t.asciz\t" TESTLIB_STRINGIFY(#ENTRY))); \
void GROUP##_##ENTRY(void)
/**

View file

@ -17,7 +17,6 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.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"
@ -27,6 +26,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/log/check.h"
#include "libc/log/color.internal.h"
@ -65,7 +65,7 @@ Flags:\n\
\n"
STATIC_YOINK("__die");
STATIC_YOINK("__get_symbol_by_addr");
STATIC_YOINK("GetSymbolByAddr");
STATIC_YOINK("testlib_quota_handlers");
STATIC_YOINK("stack_usage_logging");
@ -182,8 +182,9 @@ noasan int main(int argc, char *argv[]) {
if (!IsWindows()) sys_getpid(); // make strace easier to read
testlib_clearxmmregisters();
testlib_runalltests();
if (!g_testlib_failed && runbenchmarks_ && weaken(testlib_runallbenchmarks)) {
weaken(testlib_runallbenchmarks)();
if (!g_testlib_failed && runbenchmarks_ &&
_weaken(testlib_runallbenchmarks)) {
_weaken(testlib_runallbenchmarks)();
if (IsAsan() && !g_testlib_failed) {
CheckForMemoryLeaks();
}

View file

@ -19,7 +19,6 @@
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/sigset.h"
#include "libc/calls/syscall-sysv.internal.h"
@ -28,7 +27,7 @@
#include "libc/fmt/fmt.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/atomic.h"
#include "libc/thread/thread.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/log/check.h"
#include "libc/log/internal.h"
@ -45,6 +44,7 @@
#include "libc/sysv/consts/sig.h"
#include "libc/sysv/consts/w.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
#include "libc/x/x.h"
static int x;
@ -81,8 +81,7 @@ void testlib_error_leave(void) {
wontreturn void testlib_abort(void) {
testlib_finish();
__restorewintty();
_Exit(MAX(1, MIN(255, g_testlib_failed)));
_Exitr(MAX(1, MIN(255, g_testlib_failed)));
}
static void SetupTmpDir(void) {
@ -155,7 +154,7 @@ static void CheckForFileDescriptors(void) {
// TODO: race condition on fd cleanup :'(
int i;
struct pollfd pfds[16];
if (!weaken(open) && !weaken(socket)) return;
if (!_weaken(open) && !_weaken(socket)) return;
for (i = 0; i < ARRAYLEN(pfds); ++i) {
pfds[i].fd = i + 3;
pfds[i].events = POLLIN;
@ -176,7 +175,7 @@ static void CheckForZombies(void) {
sigset_t ss, oldss;
struct sigaction oldsa;
struct sigaction ignore = {.sa_handler = DoNothing};
if (!weaken(fork)) return;
if (!_weaken(fork)) return;
for (;;) {
if ((pid = wait(0)) == -1) {
CHECK_EQ(ECHILD, errno);
@ -210,17 +209,17 @@ void testlib_runtestcases(testfn_t *start, testfn_t *end, testfn_t warmup) {
*/
const testfn_t *fn;
CopySignalHandlers();
if (weaken(testlib_enable_tmp_setup_teardown) ||
weaken(testlib_enable_tmp_setup_teardown_once)) {
if (_weaken(testlib_enable_tmp_setup_teardown) ||
_weaken(testlib_enable_tmp_setup_teardown_once)) {
CHECK_NOTNULL(getcwd(g_testlib_olddir, sizeof(g_testlib_olddir)));
}
if (weaken(testlib_enable_tmp_setup_teardown_once)) {
if (_weaken(testlib_enable_tmp_setup_teardown_once)) {
SetupTmpDir();
}
if (weaken(SetUpOnce)) weaken(SetUpOnce)();
if (_weaken(SetUpOnce)) _weaken(SetUpOnce)();
for (x = 0, fn = start; fn != end; ++fn) {
if (weaken(testlib_enable_tmp_setup_teardown)) SetupTmpDir();
if (weaken(SetUp)) weaken(SetUp)();
if (_weaken(testlib_enable_tmp_setup_teardown)) SetupTmpDir();
if (_weaken(SetUp)) _weaken(SetUp)();
errno = 0;
SetLastError(0);
if (!IsWindows()) sys_getpid();
@ -228,16 +227,16 @@ void testlib_runtestcases(testfn_t *start, testfn_t *end, testfn_t warmup) {
testlib_clearxmmregisters();
(*fn)();
if (!IsWindows()) sys_getpid();
if (weaken(TearDown)) weaken(TearDown)();
if (weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir();
if (_weaken(TearDown)) _weaken(TearDown)();
if (_weaken(testlib_enable_tmp_setup_teardown)) TearDownTmpDir();
CheckForFileDescriptors();
CheckForSignalHandlers();
CheckForZombies();
}
if (weaken(TearDownOnce)) {
weaken(TearDownOnce)();
if (_weaken(TearDownOnce)) {
_weaken(TearDownOnce)();
}
if (weaken(testlib_enable_tmp_setup_teardown_once)) {
if (_weaken(testlib_enable_tmp_setup_teardown_once)) {
TearDownTmpDir();
}
}