Add MODE=optlinux build mode (#141)

This commit is contained in:
Justine Tunney 2021-10-14 19:36:49 -07:00
parent 226aaf3547
commit 67b5200a0b
111 changed files with 934 additions and 854 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/kntprioritycombos.internal.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/runtime.h"
@ -51,9 +52,12 @@ void testlib_benchwarmup(void) {
* @see BENCH()
*/
void testlib_runallbenchmarks(void) {
int e;
e = errno;
_peekall();
mlockall(MCL_CURRENT);
nice(-1);
errno = e;
__log_level = kLogWarn;
testlib_runtestcases(__bench_start, __bench_end, testlib_benchwarmup);
}

View file

@ -71,7 +71,7 @@ noasan void testlib_checkformemoryleaks(void) {
struct mallinfo mi;
if (!cmpxchg(&once, false, true)) {
__printf("testlib_checkformemoryleaks() may only be called once\n");
_Exit(1);
exit(1);
}
__cxa_finalize(0);
if (!IsAsan()) {

View file

@ -47,7 +47,7 @@ static relegated void DieBecauseOfQuota(int rc, const char *message) {
gethostname(hostname, sizeof(hostname));
__printf("%s on %s pid %d\n", message, hostname, (long)__getpid());
PrintBacktraceUsingSymbols(2, 0, GetSymbolTable());
_Exit(rc);
exit(rc);
}
static relegated void OnXcpu(int sig) {
@ -89,7 +89,7 @@ relegated void __oom_hook(size_t request) {
__printf("\nTHE STRAW THAT BROKE THE CAMEL'S BACK\n");
PrintBacktraceUsingSymbols(2, 0, GetSymbolTable());
PrintSystemMappings(2);
_Exit(42);
exit(42);
}
static textstartup void InstallQuotaHandlers(void) {

View file

@ -37,18 +37,15 @@ testonly void testlib_showerror(const char *file, int line, const char *func,
/* TODO(jart): Pay off tech debt re duplication */
__getpid(); /* make strace easier to read */
__getpid();
__printf("%serror%s:%s:%d%s: %s() in %s(%s)\n"
__printf("%serror%s%s:%s:%d%s: %s() in %s(%s)\n"
"\t%s\n"
"\t\tneed %s %s\n"
"\t\t got %s\n"
"\t%s%s\n"
"\t%s%s\n",
!g_isterminalinarticulate ? "\e[91;1m" : "",
!g_isterminalinarticulate ? "\e[22;94;49m" : "", file, (long)line,
!g_isterminalinarticulate ? "\e[0m" : "", method, func,
g_fixturename, code, v1, symbol, v2,
!g_isterminalinarticulate ? "\e[35m" : "", strerror(errno),
program_executable_name, !g_isterminalinarticulate ? "\e[0m" : "");
RED2, UNBOLD, BLUE1, file, (long)line, RESET, method, func,
g_fixturename, code, v1, symbol, v2, SUBTLE, strerror(errno),
program_executable_name, RESET);
free_s(&v1);
free_s(&v2);
}
@ -58,67 +55,36 @@ testonly void testlib_showerror_(int line, const char *wantcode,
const char *gotcode, char *FREED_want,
char *FREED_got, const char *fmt, ...) {
int e;
char *p;
va_list va;
char hostname[32];
__getpid();
__getpid();
p = __fatalbuf;
e = errno;
p = __stpcpy(p, RED2);
p = __stpcpy(p, "error");
p = __stpcpy(p, UNBOLD);
p = __stpcpy(p, ":");
p = __stpcpy(p, BLUE1);
p = __stpcpy(p, testlib_showerror_file);
p = __stpcpy(p, ":");
p = __intcpy(p, line);
p = __stpcpy(p, RESET);
p = __stpcpy(p, ": ");
p = __stpcpy(p, testlib_showerror_func);
p = __stpcpy(p, "(");
p = __stpcpy(p, g_fixturename);
p = __stpcpy(p, ")\n\t");
p = __stpcpy(p, testlib_showerror_macro);
p = __stpcpy(p, "(");
p = __stpcpy(p, wantcode);
p = __stpcpy(p, ", ");
p = __stpcpy(p, gotcode);
__getpid();
__getpid();
__printf("%serror%s:%s%s:%d%s: %s(%s)\n"
"\t%s(%s, %s)\n",
RED2, UNBOLD, BLUE1, testlib_showerror_file, line, RESET,
testlib_showerror_func, g_fixturename, testlib_showerror_macro,
wantcode, gotcode);
if (wantcode) {
p = __stpcpy(p, ")\n\t\tneed ");
p = __stpcpy(p, FREED_want);
p = __stpcpy(p, " ");
p = __stpcpy(p, testlib_showerror_symbol);
p = __stpcpy(p, "\n\t\t got ");
p = __stpcpy(p, FREED_got);
p = __stpcpy(p, "\n");
__printf("\t\tneed %s %s\n"
"\t\t got %s\n",
FREED_want, testlib_showerror_symbol, FREED_got);
} else {
p = __stpcpy(p, ")\n\t\t");
p = __stpcpy(p, testlib_showerror_symbol);
p = __stpcpy(p, FREED_want);
p = __stpcpy(p, "\n");
__printf("\t\t→ %s%s\n", testlib_showerror_symbol, FREED_want);
}
if (!isempty(fmt)) {
*p++ = '\t';
__printf("\t");
va_start(va, fmt);
p += vsprintf(p, fmt, va);
__vprintf(fmt, va);
va_end(va);
*p++ = '\n';
__printf("\n");
}
__stpcpy(hostname, "unknown");
gethostname(hostname, sizeof(hostname));
p = __stpcpy(p, "\t");
p = __stpcpy(p, SUBTLE);
p = __stpcpy(p, strerror(e));
p = __stpcpy(p, RESET);
p = __stpcpy(p, "\n\t");
p = __stpcpy(p, SUBTLE);
p = __stpcpy(p, program_invocation_name);
p = __stpcpy(p, " @ ");
p = __stpcpy(p, hostname);
p = __stpcpy(p, RESET);
p = __stpcpy(p, "\n");
__write(__fatalbuf, p - __fatalbuf);
__printf("\t%s%s%s\n"
"\t%s%s @ %s%s\n",
SUBTLE, strerror(e), RESET, SUBTLE, program_invocation_name,
hostname, RESET);
free_s(&FREED_want);
free_s(&FREED_got);
++g_testlib_failed;

View file

@ -103,5 +103,5 @@ noasan int main(int argc, char *argv[]) {
} else if (!g_testlib_failed) {
testlib_checkformemoryleaks();
}
_Exit(min(255, g_testlib_failed));
exit(min(255, g_testlib_failed));
}