Make improvements

- Emulator can now test the αcτµαlly pδrταblε εxεcµταblε bootloader

- Whipped up a webserver named redbean. It services 150k requests per
  second on a single core. Bundling assets inside zip enables extremely
  fast serving for two reasons. The first is that zip central directory
  lookups go faster than stat() system calls. The second is that both
  zip and gzip content-encoding use DEFLATE, therefore, compressed
  responses can be served via the sendfile() system call which does an
  in-kernel copy directly from the zip executable structure. Also note
  that red bean zip executables can be deployed easily to all platforms,
  since these native executables work on Linux, Mac, BSD, and Windows.

- Address sanitizer now works very well
This commit is contained in:
Justine Tunney 2020-09-06 21:39:00 -07:00
parent 7327c345f9
commit 416fd86676
230 changed files with 9835 additions and 5682 deletions

View file

@ -24,6 +24,10 @@ TEST(itoa64radix16, test) {
char buf[21];
EXPECT_EQ(5, uint64toarray_radix16(0x31337, buf));
EXPECT_STREQ("31337", buf);
EXPECT_EQ(2, uint64toarray_radix16(0x13, buf));
EXPECT_STREQ("13", buf);
EXPECT_EQ(3, uint64toarray_radix16(0x113, buf));
EXPECT_STREQ("113", buf);
}
TEST(itoa64fixed16, test) {

View file

@ -416,12 +416,8 @@ TEST(sprintf, test_float) {
EXPECT_STREQ("42.90", Format("%.2f", 42.8952));
EXPECT_STREQ("42.895200000", Format("%.9f", 42.8952));
EXPECT_STREQ("42.8952230000", Format("%.10f", 42.895223));
/* this testcase checks, that the precision is truncated to 9 digits. */
/* a perfect working float should return the whole number */
EXPECT_STREQ("42.895223123000", Format("%.12f", 42.89522312345678));
/* this testcase checks, that the precision is truncated AND rounded to 9 */
/* digits. a perfect working float should return the whole number */
EXPECT_STREQ("42.895223877000", Format("%.12f", 42.89522387654321));
EXPECT_STREQ("42.89522312345678", Format("%.14f", 42.89522312345678));
EXPECT_STREQ("42.89522387654321", Format("%.14f", 42.89522387654321));
EXPECT_STREQ(" 42.90", Format("%6.2f", 42.8952));
EXPECT_STREQ("+42.90", Format("%+6.2f", 42.8952));
EXPECT_STREQ("+42.9", Format("%+5.1f", 42.9252));

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/progn.h"
#include "libc/intrin/mpsadbw.h"
#include "libc/intrin/pabsb.h"
#include "libc/intrin/pabsd.h"
#include "libc/intrin/pabsw.h"
@ -1422,7 +1423,8 @@ TEST(pabsb, fuzz) {
RngSet(x, sizeof(x));
pabsb(a, x);
(pabsb)(b, x);
ASSERT_EQ(0, memcmp(a, b, 16));
ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%`#.16s\n\t%`#.16s\n\t%`#.16s", i, x,
a, b);
}
}
@ -1975,6 +1977,21 @@ TEST(pmulhrsw, fuzz) {
}
}
TEST(mpsadbw, fuzz) {
int i, j;
uint16_t a[8], b[8];
uint8_t x[16], y[16];
for (i = 0; i < 100; ++i) {
RngSet(x, sizeof(x));
RngSet(y, sizeof(y));
for (j = 0; j < 8; ++j) {
mpsadbw(a, x, y, j);
(mpsadbw)(b, x, y, j);
ASSERT_EQ(0, memcmp(a, b, 16), "%d %d", i, j);
}
}
}
TEST(pmaddubsw, fuzz) {
int i, j;
int8_t y[16];

View file

@ -52,6 +52,10 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \
$(APE)
@$(APELINK)
$(TEST_LIBC_INTRIN_OBJS): \
OVERRIDE_CFLAGS += \
-fsanitize=address
.PHONY: o/$(MODE)/test/libc/intrin
o/$(MODE)/test/libc/intrin: \
$(TEST_LIBC_INTRIN_BINS) \

View file

@ -57,3 +57,37 @@ TEST(memmove, overlappingDirect) {
}
}
}
char *MoveMemory(char *dst, const char *src, size_t n) {
size_t i;
for (i = 0; i < n; ++i) {
dst[i] = src[i];
}
return dst;
}
TEST(memmove, overlappingBackwards_isGenerallySafe) {
char buf[32];
strcpy(buf, "abcdefghijklmnopqrstuvwxyz");
ASSERT_STREQ("cdefghijklmnopqrstuvwxyzyz", MoveMemory(buf, buf + 2, 24));
strcpy(buf, "abcdefghijklmnopqrstuvwxyz");
ASSERT_STREQ("cdefghijklmnopqrstuvwxyzyz", memmove(buf, buf + 2, 24));
strcpy(buf, "abcdefghijklmnopqrstuvwxyz");
ASSERT_STREQ("cdefghijklmnopqrstuvwxyzyz", memcpy(buf, buf + 2, 24));
}
TEST(memmove, overlappingForwards_avoidsRunLengthDecodeBehavior) {
volatile char buf[32];
strcpy(buf, "abc");
MoveMemory(buf + 1, buf, 2);
ASSERT_STREQ("aaa", buf);
strcpy(buf, "abc");
(memmove)(buf + 1, buf, 2);
ASSERT_STREQ("aab", buf);
strcpy(buf, "abcdefghijklmnopqrstuvwxyz");
MoveMemory(buf + 2, buf, 24);
ASSERT_STREQ("ababababababababababababab", buf);
strcpy(buf, "abcdefghijklmnopqrstuvwxyz");
memmove(buf + 2, buf, 24);
ASSERT_STREQ("ababcdefghijklmnopqrstuvwx", buf);
}

View file

@ -81,3 +81,17 @@ TEST(memcpy, overlapping_isFineIfCopyingBackwards) {
tfree(b1);
}
}
TEST(stpcpy, test) {
volatile char *p;
volatile char b[16];
volatile const char *s1 = "hello";
volatile const char *s2 = "there";
p = b;
p = stpcpy(p, s1);
EXPECT_EQ((intptr_t)b + 5, (intptr_t)p);
EXPECT_STREQ("hello", b);
p = stpcpy(p, s2);
EXPECT_EQ((intptr_t)b + 10, (intptr_t)p);
EXPECT_STREQ("hellothere", b);
}

View file

@ -21,22 +21,26 @@
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(strlen16, testEmpty) { EXPECT_EQ(0, strlen(u"")); }
TEST(strlen16, testAscii) { EXPECT_EQ(5, strlen(u"hello")); }
TEST(strlen16, testEmpty) {
EXPECT_EQ(0, strlen16(u""));
}
TEST(strlen16, testAscii) {
EXPECT_EQ(5, strlen16(u"hello"));
}
TEST(strlen16, testUnicode) {
EXPECT_EQ(28, strlen(u"αcτµαlly pδrταblε εxεcµταblε"));
EXPECT_EQ(28, strlen16(u"αcτµαlly pδrταblε εxεcµταblε"));
}
TEST(strclen, testAegeanNumberSupplementaryPlane) {
EXPECT_EQ(36, strlen("𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(18, strlen(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strlen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(18, strlen16(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, wcslen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen("𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen(u"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
EXPECT_EQ(9, strclen(L"𐄷𐄸𐄹𐄺𐄻𐄼𐄽𐄾𐄿"));
}
TEST(strlen16, testCoolKidNulTerminator) {
EXPECT_EQ(2, strlen((const char16_t *)"\x00\xd8\x00\xdc\x00"));
EXPECT_EQ(2, strlen16((const char16_t *)"\x00\xd8\x00\xdc\x00"));
}

View file

@ -29,8 +29,8 @@ wchar_t u32[] = L"utf32 ☻";
TEST(strlen, usageExample_c11) {
EXPECT_EQ(6 + 3, strlen(u8));
EXPECT_EQ(7, strlen(u16));
EXPECT_EQ(7, strlen(u32));
EXPECT_EQ(7, strlen16(u16));
EXPECT_EQ(7, wcslen(u32));
}
TEST(strlen, usageExample_c99) {

View file

@ -39,3 +39,8 @@ TEST(ldexp, test) {
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalblnf(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalblnl(pi, twopow))));
}
TEST(exp10, test) {
ASSERT_EQ(100, (int)exp10(2));
ASSERT_STREQ("100.000000", gc(xasprintf("%Lf", exp10l(2))));
}

View file

@ -20,6 +20,7 @@
#include "libc/math.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "libc/tinymath/tinymath.h"
#include "libc/x/x.h"
@ -27,6 +28,10 @@
float tinymath_roundf$k8(float);
double tinymath_round$k8(double);
FIXTURE(intrin, disableHardwareExtensions) {
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
}
TEST(round, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_round(-0.0))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_round(NAN))));
@ -35,6 +40,14 @@ TEST(round, testCornerCases) {
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round(-INFINITY))));
}
TEST(roundl, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundl(-0.0))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundl(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundl(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundl(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundl(-INFINITY))));
}
TEST(round, test) {
EXPECT_STREQ("-3", gc(xdtoa(tinymath_round(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(tinymath_round(-1.5))));
@ -134,16 +147,6 @@ TEST(rintl, test) {
EXPECT_STREQ("2", gc(xdtoa(tinymath_rintl(2.5))));
}
TEST(lround, test) {
EXPECT_EQ(-3, tinymath_lround(-2.5));
EXPECT_EQ(-2, tinymath_lround(-1.5));
EXPECT_EQ(-1, tinymath_lround(-.5));
EXPECT_EQ(0, tinymath_lround(-.0));
EXPECT_EQ(1, tinymath_lround(.5));
EXPECT_EQ(2, tinymath_lround(1.5));
EXPECT_EQ(3, tinymath_lround(2.5));
}
TEST(roundf, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf(-0.0))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf(NAN))));
@ -162,40 +165,24 @@ TEST(lroundf, test) {
EXPECT_EQ(3, tinymath_lroundf(2.5));
}
#if !X86_NEED(SSE4_2)
TEST(round$k8, test) {
EXPECT_STREQ("-3", gc(xdtoa(tinymath_round$k8(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(tinymath_round$k8(-1.5))));
EXPECT_STREQ("-1", gc(xdtoa(tinymath_round$k8(-.5))));
EXPECT_STREQ("1", gc(xdtoa(tinymath_round$k8(.5))));
EXPECT_STREQ("2", gc(xdtoa(tinymath_round$k8(1.5))));
EXPECT_STREQ("3", gc(xdtoa(tinymath_round$k8(2.5))));
TEST(lround, test) {
EXPECT_EQ(-3, tinymath_lround(-2.5));
EXPECT_EQ(-2, tinymath_lround(-1.5));
EXPECT_EQ(-1, tinymath_lround(-.5));
EXPECT_EQ(-0, tinymath_lround(-.4));
EXPECT_EQ(0, tinymath_lround(.4));
EXPECT_EQ(1, tinymath_lround(.5));
EXPECT_EQ(2, tinymath_lround(1.5));
EXPECT_EQ(3, tinymath_lround(2.5));
}
TEST(roundf$k8, test) {
EXPECT_STREQ("-3", gc(xdtoa(tinymath_roundf$k8(-2.5))));
EXPECT_STREQ("-2", gc(xdtoa(tinymath_roundf$k8(-1.5))));
EXPECT_STREQ("-1", gc(xdtoa(tinymath_roundf$k8(-.5))));
EXPECT_STREQ("1", gc(xdtoa(tinymath_roundf$k8(.5))));
EXPECT_STREQ("2", gc(xdtoa(tinymath_roundf$k8(1.5))));
EXPECT_STREQ("3", gc(xdtoa(tinymath_roundf$k8(2.5))));
TEST(lroundl, test) {
EXPECT_EQ(-3, tinymath_lroundl(-2.5));
EXPECT_EQ(-2, tinymath_lroundl(-1.5));
EXPECT_EQ(-1, tinymath_lroundl(-.5));
EXPECT_EQ(-0, tinymath_lroundl(-.4));
EXPECT_EQ(0, tinymath_lroundl(.4));
EXPECT_EQ(1, tinymath_lroundl(.5));
EXPECT_EQ(2, tinymath_lroundl(1.5));
EXPECT_EQ(3, tinymath_lroundl(2.5));
}
TEST(round$k8, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_round$k8(-0.0))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_round$k8(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_round$k8(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_round$k8(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_round$k8(-INFINITY))));
}
TEST(roundf$k8, testCornerCases) {
EXPECT_STREQ("-0", gc(xdtoa(tinymath_roundf$k8(-0.0))));
EXPECT_STREQ("nan", gc(xdtoa(tinymath_roundf$k8(NAN))));
EXPECT_STREQ("-nan", gc(xdtoa(tinymath_roundf$k8(-NAN))));
EXPECT_STREQ("inf", gc(xdtoa(tinymath_roundf$k8(INFINITY))));
EXPECT_STREQ("-inf", gc(xdtoa(tinymath_roundf$k8(-INFINITY))));
}
#endif

View file

@ -29,6 +29,7 @@ TEST_LIBC_TINYMATH_DIRECTDEPS = \
LIBC_TINYMATH \
LIBC_MEM \
LIBC_RUNTIME \
LIBC_NEXGEN32E \
LIBC_STUBS \
LIBC_TESTLIB \
LIBC_X \

View file

@ -28,7 +28,7 @@
testonly nodiscard uint8_t *unbingx86op(const char16_t *codez) {
size_t len;
len = strlen(codez);
len = strlen16(codez);
return unbingbuf(xmalloc(ROUNDUP(len, 16)), len, codez, 0x90);
}