Initial import

This commit is contained in:
Justine Tunney 2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

View file

@ -0,0 +1,42 @@
/*-*- 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/macros.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
uint32_t crc32(uint32_t, const void *, int);
uint32_t crc32$pclmul(uint32_t, const void *, size_t);
uint32_t crc32$pclmul2(uint32_t, const void *, size_t);
TEST(crc32, testBigText) {
size_t size;
size = kHyperionSize;
EXPECT_EQ(0xe9ded8e6, crc32(0, kHyperion, size));
EXPECT_EQ(0xe9ded8e6, crc32_z(0, kHyperion, size));
if (X86_HAVE(PCLMUL)) {
size = ROUNDDOWN(size, 64);
EXPECT_EQ(0xc7adc04f, crc32(0, kHyperion, size));
EXPECT_EQ(0xc7adc04f, crc32_z(0, kHyperion, size));
EXPECT_EQ(0xc7adc04f,
0xffffffffu ^ crc32$pclmul(0 ^ 0xffffffffu, kHyperion, size));
}
}

View file

@ -0,0 +1,96 @@
/*-*- 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/bits/safemacros.h"
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/nexgen32e/kompressor.h"
#include "libc/nexgen32e/lz4.h"
#include "libc/runtime/ezmap.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(lz4, decompress_emptyStringWithoutChecksum) {
/* lz4 -9 --content-size --no-frame-crc /tmp/empty - | hexdump -C */
static char kLz4Data[] = {0x04, 0x22, 0x4d, 0x18, 0x60, 0x40,
0x82, 0x00, 0x00, 0x00, 0x00};
char *src = memcpy(tmalloc(sizeof(kLz4Data)), kLz4Data, sizeof(kLz4Data));
char *dst = tmalloc(1);
*dst = 'z';
ASSERT_EQ(dst, lz4decode(dst, src));
ASSERT_EQ('z', *dst);
tfree(dst);
tfree(src);
}
TEST(lz4, decompress_oneLetterWithoutChecksum) {
/* printf a >oneletter */
/* lz4 -9 --content-size --no-frame-crc oneletter /dev/stdout | hexdump -C */
static char kLz4Data[] = {0x04, 0x22, 0x4d, 0x18, 0x68, 0x40, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x01,
0x00, 0x00, 0x80, 0x61, 0x00, 0x00, 0x00, 0x00};
char *src = memcpy(tmalloc(sizeof(kLz4Data)), kLz4Data, sizeof(kLz4Data));
char *dst = tmalloc(1);
ASSERT_EQ(dst + 1, lz4decode(dst, src));
ASSERT_EQ('a', *dst);
tfree(dst);
tfree(src);
}
TEST(lz4, decompress_runLengthDecode) {
/* printf aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa >/tmp/a */
/* lz4 -9 --content-size --no-frame-crc /tmp/a - | hexdump -vC */
static char kLz4Data[] = {
0x04, 0x22, 0x4d, 0x18, 0x68, 0x40, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x30, 0x0b, 0x00, 0x00, 0x00, 0x1f, 0x61, 0x01, 0x00, 0x07,
0x50, 0x61, 0x61, 0x61, 0x61, 0x61, 0x00, 0x00, 0x00, 0x00};
char *src = memcpy(tmalloc(sizeof(kLz4Data)), kLz4Data, sizeof(kLz4Data));
const char *want = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
char *dst = tmalloc(strlen(want));
ASSERT_EQ(dst + strlen(want), lz4decode(dst, src));
ASSERT_STREQN(want, dst, strlen(want));
tfree(dst);
tfree(src);
}
TEST(lz4, zoneFileGmt) {
if (!fileexists("usr/share/zoneinfo.dict.lz4")) return;
struct MappedFile dict, gmt;
CHECK_NE(-1, mapfileread("usr/share/zoneinfo.dict.lz4", &dict));
CHECK_NE(-1, mapfileread("usr/share/zoneinfo/GMT.lz4", &gmt));
size_t mapsize, gmtsize;
char *mapping, *gmtdata;
lz4decode((gmtdata = lz4decode(
(mapping = mapanon(
(mapsize = roundup(
LZ4_FRAME_BLOCKCONTENTSIZE(lz4check(dict.addr)) +
(gmtsize = LZ4_FRAME_BLOCKCONTENTSIZE(
lz4check(gmt.addr))),
FRAMESIZE)))),
dict.addr)),
gmt.addr);
ASSERT_BINEQ(
u"TZif2                                         GMT   TZif2   "
u"                               ♦°              GMT   ◙GMT0◙",
gmtdata);
munmap(mapping, mapsize);
unmapfile(&dict);
unmapfile(&gmt);
}

View file

@ -0,0 +1,103 @@
/*-*- 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/bits/bits.h"
#include "libc/runtime/buffer.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/mappings.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#define ALIGN 128
#define BUFSIZE (8 * 32)
#define MASKSIZE (BUFSIZE / CHAR_BIT)
const char kX[] = "aaaaaaaaeeeeeeeeeeeeeeeeeeeeeeee"
"e e"
"e e"
"e e"
"e e"
"e e"
"e e"
"eeeeeeeeeeeeeeeeeeeeeeeeeeeeee-e";
const char kY[] = "aaaaaaaaefffffffffffeffffffffff-"
"f z-"
"f f"
"f f"
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
"f f"
"f f"
"ffffffffffffffffffffffffffffff-f";
const char kM[] = "11111111100000000000100000000000"
"01111111111111111111111111111100"
"01111111111111111111111111111110"
"01111111111111111111111111111110"
"00000000000000000000000000000000"
"01111111111111111111111111111110"
"01111111111111111111111111111110"
"00000000000000000000000000000010";
nodiscard char *binify(uint8_t *data, size_t size) {
uint8_t b;
size_t i, j;
char *s, *p;
p = s = xmalloc(size * CHAR_BIT + 1);
for (i = 0; i < size; ++i) {
b = data[i];
for (j = 0; j < CHAR_BIT; ++j) {
*p++ = "01"[b & 1];
b >>= 1;
}
}
*p = '\0';
return s;
}
TEST(memeqmask, test) {
struct GuardedBuffer x = {}, y = {}, m = {};
memcpy(balloc(&x, ALIGN, BUFSIZE), kX, BUFSIZE);
memcpy(balloc(&y, ALIGN, BUFSIZE), kY, BUFSIZE);
balloc(&m, ALIGN, MASKSIZE);
EXPECT_EQ((intptr_t)m.p, (intptr_t)memeqmask(m.p, x.p, y.p, BUFSIZE));
EXPECT_STREQ(kM, gc(binify(m.p, MASKSIZE)));
bfree(&m);
bfree(&x);
bfree(&y);
}
#if 0
#include "libc/rand/rand.h"
#include "libc/testlib/ezbench.h"
TEST(memeqmask, bench) {
size_t len = 64 * 1024;
char *m = xmemalign(64, DIMMASK(len));
char *x = xmemalign(64, len);
char *y = xmemalign(64, len);
EZBENCH(
{
rngset(x, len, rand64, -1);
rngset(y, len, rand64, -1);
},
memeqmask(m, x, y, len));
}
#endif

View file

@ -0,0 +1,28 @@
/*-*- 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/nexgen32e/nexgen32e.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(strsak32, test) {
EXPECT_EQ(0, wcslen(L""));
EXPECT_EQ(1, wcslen(L"1"));
EXPECT_EQ(5, wcslen(L"hello"));
}

View file

@ -0,0 +1,58 @@
/*-*- 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/nexgen32e/nexgen32e.h"
#include "libc/rand/rand.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
TEST(strtolower, testAligned) {
char s[128] = "AZCDabcdABCDabcdABCDabcdABCDabcdABCDabcd";
EXPECT_STREQ("azcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", strtolower(s));
}
TEST(strtolower, testUnaligned) {
char s[128] = "AZCDabcdABCDabcdABCDabcdABCDabcdABCDabcd";
strtolower(s + 1);
EXPECT_STREQ("Azcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", s);
}
TEST(strtoupper, testAligned) {
char s[128] = "AZCDabcdABCDabcdA0CDabcdABCDabcdABCDabcd";
EXPECT_STREQ("AZCDABCDABCDABCDA0CDABCDABCDABCDABCDABCD", strtoupper(s));
}
TEST(strtoupper, testUnaligned) {
char s[128] = "aZCDabcdABCDabcdABCDabcdABCDabcdABCDabcd";
strtoupper(s + 1);
EXPECT_STREQ("aZCDABCDABCDABCDABCDABCDABCDABCDABCDABCD", s);
}
BENCH(strtolower, bench) {
size_t size = FRAMESIZE;
char *data = tgc(tmalloc(size));
EZBENCH2(
"strtolower",
{
rngset(data, size, rand64, -1);
data[size - 1] = 0;
},
strtolower(data));
}

View file

@ -0,0 +1,68 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_LIBC_NEXGEN32E
TEST_LIBC_NEXGEN32E_SRCS := \
$(wildcard test/libc/nexgen32e/*.c)
TEST_LIBC_NEXGEN32E_SRCS_TEST = \
$(filter %_test.c,$(TEST_LIBC_NEXGEN32E_SRCS))
TEST_LIBC_NEXGEN32E_OBJS = \
$(TEST_LIBC_NEXGEN32E_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_LIBC_NEXGEN32E_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_NEXGEN32E_COMS = \
$(TEST_LIBC_NEXGEN32E_OBJS:%.o=%.com)
TEST_LIBC_NEXGEN32E_BINS = \
$(TEST_LIBC_NEXGEN32E_COMS) \
$(TEST_LIBC_NEXGEN32E_COMS:%=%.dbg)
TEST_LIBC_NEXGEN32E_TESTS = \
$(TEST_LIBC_NEXGEN32E_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_LIBC_NEXGEN32E_CHECKS = \
$(TEST_LIBC_NEXGEN32E_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_NEXGEN32E_DIRECTDEPS = \
LIBC_ALG \
LIBC_CALLS \
LIBC_CALLS_HEFTY \
LIBC_FMT \
LIBC_LOG \
LIBC_STDIO \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STUBS \
LIBC_STR \
LIBC_TESTLIB \
LIBC_X \
TOOL_VIZ_LIB
TEST_LIBC_NEXGEN32E_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_NEXGEN32E_DIRECTDEPS),$($(x))))
o/$(MODE)/test/libc/nexgen32e/nexgen32e.pkg: \
$(TEST_LIBC_NEXGEN32E_OBJS) \
$(foreach x,$(TEST_LIBC_NEXGEN32E_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/nexgen32e/%.com.dbg: \
$(TEST_LIBC_NEXGEN32E_DEPS) \
o/$(MODE)/test/libc/nexgen32e/%.o \
o/$(MODE)/test/libc/nexgen32e/nexgen32e.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
$(TEST_LIBC_NEXGEN32E_OBJS): \
DEFAULT_CCFLAGS += \
-fno-builtin
.PHONY: o/$(MODE)/test/libc/nexgen32e
o/$(MODE)/test/libc/nexgen32e: \
$(TEST_LIBC_NEXGEN32E_BINS) \
$(TEST_LIBC_NEXGEN32E_CHECKS)