Make more improvements

This change includes many bug fixes, for the NT polyfills, strings,
memory, boot, and math libraries which were discovered by adding more
tools for recreational programming, such as PC emulation. Lemon has also
been vendored because it works so well at parsing languages.
This commit is contained in:
Justine Tunney 2020-09-28 01:13:56 -07:00
parent 416fd86676
commit 23d333c090
201 changed files with 14558 additions and 3082 deletions

View file

@ -18,13 +18,13 @@
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/calls.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
@ -56,7 +56,7 @@ TEST(fallocate_020, test) {
ASSERT_NE(-1, close(fd));
ASSERT_NE(-1, stat(path, &st));
ASSERT_EQ(31337, st.st_size);
ASSERT_BINEQ(u"helloworld", gc(slurp(path, NULL)));
ASSERT_BINEQ(u"helloworld", gc(xslurp(path, NULL)));
unlink(path);
}

View file

@ -17,13 +17,13 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/calls.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
@ -44,6 +44,6 @@ TEST(ftruncate, test) {
ASSERT_NE(-1, close(fd));
ASSERT_NE(-1, stat(path, &st));
ASSERT_EQ(31337, st.st_size);
ASSERT_BINEQ(u"helloworld", gc(slurp(path, NULL)));
ASSERT_BINEQ(u"helloworld", gc(xslurp(path, 0)));
unlink(path);
}

View file

@ -26,6 +26,10 @@ TEST(int64toarray_radix10, test) {
char buf[21];
EXPECT_EQ(1, int64toarray_radix10(0, buf));
EXPECT_STREQ("0", buf);
EXPECT_EQ(1, int64toarray_radix10(1, buf));
EXPECT_STREQ("1", buf);
EXPECT_EQ(2, int64toarray_radix10(-1, buf));
EXPECT_STREQ("-1", buf);
EXPECT_EQ(19, int64toarray_radix10(INT64_MAX, buf));
EXPECT_STREQ("9223372036854775807", buf);
EXPECT_EQ(20, int64toarray_radix10(INT64_MIN, buf));

View file

@ -29,6 +29,7 @@
#include "libc/bits/safemacros.h"
#include "libc/conv/itoa.h"
#include "libc/errno.h"
#include "libc/escape/escape.h"
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
#include "libc/math.h"
@ -671,6 +672,12 @@ TEST(snprintf, twosBaneWithTypePromotion) {
EXPECT_STREQ("-32768", Format("%hd", x));
}
TEST(snprintf, formatStringLiteral) {
EXPECT_EQ('\\' | 'n' << 8, cescapec('\n'));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec('\377'));
EXPECT_STREQ("\"hi\\n\"", Format("%`'s", "hi\n"));
}
BENCH(palandprintf, bench) {
EZBENCH2("snprintf %x", donothing, Format("%x", VEIL("r", INT_MIN)));
EZBENCH2("snprintf %d", donothing, Format("%d", VEIL("r", INT_MIN)));

View file

@ -0,0 +1,31 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/math/math.h"
#include "libc/runtime/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(atan2l, test) {
volatile double a = -.9816175436063843;
volatile double b = -.1908585813741899;
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2f(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2Lf", atan2l(b, a))));
}

View file

@ -21,9 +21,11 @@
#include "libc/bits/xchg.h"
#include "libc/calls/calls.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/memtrack.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -106,5 +108,6 @@ TEST(isheap, emptyMalloc) {
}
TEST(isheap, mallocOffset) {
ASSERT_TRUE(isheap((char *)gc(malloc(131072)) + 100000));
char *p = gc(malloc(131072));
ASSERT_TRUE(isheap(p + 100000));
}

View file

@ -0,0 +1,45 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/popcnt.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"
unsigned naive(unsigned beg, unsigned end, unsigned size) {
assert(end < size);
assert(beg < size);
assert(popcnt(size) == 1);
if (beg == end) return size;
if (end > beg) return end - beg;
return (size - beg) + end;
}
unsigned fancy(unsigned beg, unsigned end, unsigned size) {
return ((end - beg - 1) & (size - 1)) + 1;
}
TEST(favail, test) {
unsigned i, j, n = 4;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
ASSERT_EQ(naive(i, j, n), fancy(i, j, n), "%u %u %u", i, j, n);
}
}
}

View file

@ -24,6 +24,7 @@ TEST_LIBC_STDIO_CHECKS = \
$(TEST_LIBC_STDIO_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_STDIO_DIRECTDEPS = \
LIBC_BITS \
LIBC_CALLS \
LIBC_CALLS_HEFTY \
LIBC_FMT \

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
@ -95,3 +96,13 @@ TEST(stpcpy, test) {
EXPECT_EQ((intptr_t)b + 10, (intptr_t)p);
EXPECT_STREQ("hellothere", b);
}
TEST(memcpy, testBackwardsOverlap3) {
volatile char *c;
c = malloc(3);
memcpy(c, "\e[C", 3);
memcpy(c, c + 1, VEIL("r", 3) - 1);
EXPECT_EQ('[', c[0]);
EXPECT_EQ('C', c[1]);
free(c);
}

View file

@ -28,22 +28,26 @@
#undef S
#undef T
#define T(NAME) NAME##16
#define S(S) u##S
#define C(C) u##C
#define strchr(x, y) strchr16(x, y)
#define T(NAME) NAME##16
#define S(S) u##S
#define C(C) u##C
#define strrchr(x, y) strrchr16(x, y)
#define strchr(x, y) strchr16(x, y)
#include "test/libc/str/strrchr_test.inc"
#undef strchr
#undef strrchr
#undef C
#undef S
#undef T
#define T(NAME) NAME##32
#define S(S) L##S
#define C(C) L##C
#define strchr(x, y) wcschr(x, y)
#define T(NAME) NAME##32
#define S(S) L##S
#define C(C) L##C
#define strchr(x, y) wcschr(x, y)
#define strrchr(x, y) wcsrchr(x, y)
#include "test/libc/str/strrchr_test.inc"
#undef strchr
#undef strrchr
#undef C
#undef S
#undef T

View file

@ -0,0 +1,31 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/math.h"
#include "libc/runtime/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(atan2l, test) {
volatile double a = -.9816175436063843;
volatile double b = -.1908585813741899;
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2f(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2f", atan2(b, a))));
EXPECT_STREQ("-2.95", gc(xasprintf("%.2Lf", atan2l(b, a))));
}

View file

@ -24,10 +24,12 @@ TEST_LIBC_X_CHECKS = \
$(TEST_LIBC_X_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_X_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_MEM \
LIBC_STDIO \
LIBC_STR \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_X \
LIBC_STUBS \

46
test/libc/x/xslurp_test.c Normal file
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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/runtime/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(xslurp, testEmptyWithNulTerminatedStringBehavior) {
size_t got;
const char *data;
const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt"));
ASSERT_NE(-1, xbarf(path, "", -1));
ASSERT_NE(NULL, (data = gc(xslurp(path, &got))));
ASSERT_EQ(0, got);
ASSERT_STREQ("", data);
ASSERT_NE(-1, unlink(path));
}
TEST(xslurp, testHyperion) {
size_t got;
const char *data;
const char *path = gc(xjoinpaths(kTmpPath, "xslurp.txt"));
ASSERT_NE(-1, xbarf(path, kHyperion, kHyperionSize));
ASSERT_NE(NULL, (data = gc(xslurp(path, &got))));
ASSERT_EQ(kHyperionSize, got);
ASSERT_EQ(0, memcmp(data, kHyperion, kHyperionSize));
ASSERT_NE(-1, unlink(path));
}