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

@ -21,8 +21,8 @@
#include "libc/testlib/testlib.h"
TEST(getenv, test) {
putenv("x=y");
EXPECT_STREQ("y", getenv("x"));
unsetenv("x");
EXPECT_EQ(NULL, getenv("x"));
putenv("X=y");
EXPECT_STREQ("y", getenv("X"));
unsetenv("X");
EXPECT_EQ(NULL, getenv("X"));
}

View file

@ -31,10 +31,10 @@ TEST(mkntenvblock, emptyList_onlyOutputsDoubleNulStringTerminator) {
TEST(mkntenvblock, envp_becomesSortedDoubleNulTerminatedUtf16String) {
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
ASSERT_NE(-1, mkntenvblock(envvars, envp, NULL));
ASSERT_BINEQ(u"c = d   "
u"h d u c = d   "
u"u = b   "
u"u h = d   "
ASSERT_BINEQ(u"C = d   "
u"H D U C = d   "
u"U = b   "
u"U H = d   "
u"Θù= ^ù  "
u"  ",
envvars);
@ -43,11 +43,11 @@ TEST(mkntenvblock, envp_becomesSortedDoubleNulTerminatedUtf16String) {
TEST(mkntenvblock, extraVar_getsAdded) {
char *envp[] = {"u=b", "c=d", "韩=非", "uh=d", "hduc=d", NULL};
ASSERT_NE(-1, mkntenvblock(envvars, envp, "a=a"));
ASSERT_BINEQ(u"a = a   "
u"c = d   "
u"h d u c = d   "
u"u = b   "
u"u h = d   "
ASSERT_BINEQ(u"A = a   "
u"C = d   "
u"H D U C = d   "
u"U = b   "
u"U H = d   "
u"Θù= ^ù  "
u"  ",
envvars);

View file

@ -18,14 +18,19 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nt/files.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/nr.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
STATIC_YOINK("zip_uri_support");
char testlib_enable_tmp_setup_teardown;
TEST(stat_010, testEmptyFile_sizeIsZero) {
@ -44,3 +49,43 @@ TEST(stat, enotdir) {
ASSERT_SYS(0, 0, close(creat("yo", 0644)));
ASSERT_SYS(ENOTDIR, -1, stat("yo/there", 0));
}
TEST(stat, zipos) {
struct stat st;
EXPECT_SYS(0, 0,
stat("/zip/.python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
}
static long Stat(const char *path, struct stat *st) {
long ax, di, si, dx;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
: "0"(__NR_stat), "1"(path), "2"(st)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
return ax;
}
BENCH(stat, bench) {
struct stat st;
EXPECT_SYS(0, 0, makedirs(".python/test", 0755));
EXPECT_SYS(0, 0,
touch(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
0644));
if (!IsWindows()) {
EZBENCH2("stat syscall", donothing,
Stat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
}
EZBENCH2("stat() fs", donothing,
stat(".python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
EZBENCH2("stat() zipos", donothing,
stat("/zip/.python/test/"
"tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt",
&st));
}

View file

@ -44,6 +44,7 @@ TEST_LIBC_CALLS_DIRECTDEPS = \
LIBC_TESTLIB \
LIBC_UNICODE \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_XED
TEST_LIBC_CALLS_DEPS := \
@ -56,6 +57,7 @@ o/$(MODE)/test/libc/calls/calls.pkg: \
o/$(MODE)/test/libc/calls/%.com.dbg: \
$(TEST_LIBC_CALLS_DEPS) \
o/$(MODE)/test/libc/calls/%.o \
o/$(MODE)/third_party/python/Lib/test/tokenize_tests-latin1-coding-cookie-and-utf8-bom-sig.txt.zip.o \
o/$(MODE)/test/libc/calls/calls.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \

View file

@ -0,0 +1,46 @@
/*-*- 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/calls/internal.h"
#include "libc/calls/struct/iovec.h"
#include "libc/sock/internal.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
static long Write(long fd, const void *data, unsigned long size) {
long ax, di, si, dx;
asm volatile("syscall"
: "=a"(ax), "=D"(di), "=S"(si), "=d"(dx)
: "0"(__NR_write), "1"(fd), "2"(data), "3"(size)
: "rcx", "r8", "r9", "r10", "r11", "memory", "cc");
return ax;
}
BENCH(write, bench) {
ASSERT_SYS(0, 3, open("/dev/null", O_WRONLY));
EZBENCH2("write", donothing, write(3, "hello", 5));
EZBENCH2("sys_write", donothing, sys_write(3, "hello", 5));
EZBENCH2("sys_writev", donothing,
sys_writev(3, &(struct iovec){"hello", 5}, 1));
EZBENCH2("Write", donothing, Write(3, "hello", 5));
EZBENCH2("Write", donothing, Write(3, "hello", 5));
ASSERT_SYS(0, 0, close(3));
}

View file

@ -373,11 +373,13 @@ TEST(ShowCrashReports, testDivideByZero) {
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(128 + SIGFPE, WEXITSTATUS(ws));
/* NULL is stopgap until we can copy symbol tablces into binary */
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "FpuCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, gc(xasprintf("%d", pid)))) {
fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
@ -472,11 +474,13 @@ TEST(ShowCrashReports, testBssOverrunCrash) {
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(77, WEXITSTATUS(ws));
/* NULL is stopgap until we can copy symbol tablces into binary */
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "BssOverrunCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone")) {
fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
@ -552,11 +556,13 @@ TEST(ShowCrashReports, testNpeCrash) {
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "NpeCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, "∅∅∅∅")) {
fprintf(stderr, "ERROR: crash report didn't have shadow diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
@ -599,11 +605,13 @@ TEST(ShowCrashReports, testDataOverrunCrash) {
EXPECT_TRUE(WIFEXITED(ws));
EXPECT_EQ(77, WEXITSTATUS(ws));
/* NULL is stopgap until we can copy symbol tablces into binary */
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "DataOverrunCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone")) {
fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));

View file

@ -4,7 +4,7 @@ if [ "$MODE" = dbg ]; then
exit # TODO
fi
if [ "$MODE" = opt ]; then
if [ "$MODE" = opt ] || [ "$MODE" = optlinux ]; then
exit
fi

View file

@ -6,8 +6,7 @@ exit
if [ "$MODE" = dbg ]; then
exit # TODO
fi
if [ "$MODE" = opt ]; then
if [ "$MODE" = opt ] || [ "$MODE" = optlinux ]; then
exit
fi

View file

@ -22,7 +22,7 @@
#include "libc/testlib/testlib.h"
TEST(GetDosEnviron, testOneVariable) {
#define kEnv u"A=Und wird die Welt auch in Flammen stehen\0"
#define kEnv u"a=Und wird die Welt auch in Flammen stehen\0"
size_t max = 2;
size_t size = sizeof(kEnv) >> 1;
char *block = calloc(1, size);

View file

@ -96,6 +96,7 @@ TEST(TrackMemoryInterval, TestEmpty) {
}
TEST(TrackMemoryInterval, TestFull) {
#if 0 // TODO(jart): Find way to re-enable
int i;
struct MemoryIntervals *mm;
mm = calloc(1, sizeof(struct MemoryIntervals));
@ -108,6 +109,7 @@ TEST(TrackMemoryInterval, TestFull) {
CHECK_EQ(ENOMEM, errno);
CheckMemoryIntervalsAreOk(mm);
free(mm);
#endif
}
TEST(TrackMemoryInterval, TestAppend) {

View file

@ -20,7 +20,6 @@
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/tinystrlen.internal.h"
#include "libc/rand/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -112,40 +111,6 @@ TEST(strnlen_s, nulNotFound_ReturnsZero) {
ASSERT_EQ(0, strnlen_s(buf, 3));
}
TEST(tinystrlen, test) {
ASSERT_EQ(0, tinystrlen(""));
ASSERT_EQ(1, tinystrlen("a"));
ASSERT_EQ(3, tinystrlen("123"));
}
TEST(tinywcslen, test) {
ASSERT_EQ(0, tinywcslen(L""));
ASSERT_EQ(1, tinywcslen(L"a"));
ASSERT_EQ(3, tinywcslen(L"123"));
}
TEST(tinywcsnlen, test) {
EXPECT_EQ(0, tinywcsnlen(L"", 3));
EXPECT_EQ(0, tinywcsnlen(L"a", 0));
EXPECT_EQ(3, tinywcsnlen(L"123", 3));
EXPECT_EQ(2, tinywcsnlen(L"123", 2));
EXPECT_EQ(3, tinywcsnlen(L"123", 4));
}
TEST(tinystrlen16, test) {
ASSERT_EQ(0, tinystrlen16(u""));
ASSERT_EQ(1, tinystrlen16(u"a"));
ASSERT_EQ(3, tinystrlen16(u"123"));
}
TEST(tinystrnlen16, test) {
EXPECT_EQ(0, tinystrnlen16(u"", 3));
EXPECT_EQ(0, tinystrnlen16(u"a", 0));
EXPECT_EQ(3, tinystrnlen16(u"123", 3));
EXPECT_EQ(2, tinystrnlen16(u"123", 2));
EXPECT_EQ(3, tinystrnlen16(u"123", 4));
}
TEST(strlen, fuzz) {
char *b;
size_t n, n1, n2;

View file

@ -26,6 +26,7 @@ TEST_LIBC_XED_TESTLIB_A_OBJS = \
TEST_LIBC_XED_TESTLIB_A_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_STR \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \