Add x86_64-linux-gnu emulator

I wanted a tiny scriptable meltdown proof way to run userspace programs
and visualize how program execution impacts memory. It helps to explain
how things like Actually Portable Executable works. It can show you how
the GCC generated code is going about manipulating matrices and more. I
didn't feel fully comfortable with Qemu and Bochs because I'm not smart
enough to understand them. I wanted something like gVisor but with much
stronger levels of assurances. I wanted a single binary that'll run, on
all major operating systems with an embedded GPL barrier ZIP filesystem
that is tiny enough to transpile to JavaScript and run in browsers too.

https://justine.storage.googleapis.com/emulator625.mp4
This commit is contained in:
Justine Tunney 2020-08-25 04:23:25 -07:00
parent 467504308a
commit f4f4caab0e
1052 changed files with 65667 additions and 7825 deletions

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/dce.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
@ -40,9 +41,10 @@ TEST(crc32c, test) {
strlen(hyperion) - strlen(FANATICS)));
}
uint32_t crc32c$pure(uint32_t, const char *, size_t) hidden;
uint32_t crc32c$sse42(uint32_t, const char *, size_t) hidden;
FIXTURE(crc32c, pure) { *(void **)(&crc32c) = (void *)crc32c$pure; }
FIXTURE(crc32c, pure) {
*(void **)(&crc32c) = (void *)crc32c$pure;
}
FIXTURE(crc32c, sse42) {
if (X86_HAVE(SSE4_2)) {
*(void **)(&crc32c) = (void *)crc32c$sse42;

View file

@ -17,9 +17,14 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/tinymemccpy.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
void *memccpy2(void *, const void *, int, size_t);
TEST(memccpy, testStringCopy) {
char buf[16];
EXPECT_EQ(buf + 3, memccpy(buf, "hi", '\0', sizeof(buf)));
@ -35,3 +40,21 @@ TEST(memccpy, testZeroLength_doesNothing) {
char buf[1];
EXPECT_EQ(NULL, memccpy(buf, "hi", '\0', 0));
}
TEST(memccpy, memcpy) {
unsigned n, n2;
char *b1, *b2, *b3, *e1, *e2;
for (n = 0; n < 1026; ++n) {
b1 = tmalloc(n);
b2 = tmalloc(n);
b3 = tmalloc(n);
e1 = tinymemccpy(b2, b1, 31337, n);
e2 = memccpy(b3, b1, 31337, n);
n2 = e1 ? e1 - b1 : n;
ASSERT_EQ(e1, e2);
ASSERT_EQ(0, memcmp(b2, b3, n2));
tfree(b3);
tfree(b2);
tfree(b1);
}
}

View file

@ -17,40 +17,17 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "third_party/regex/regex.h"
#define N 256
#define S 7
TEST(memmove, overlapping) {
for (size_t i = 0; i < N; i += S) {
for (size_t j = 10; j < N; j += S) {
char *b1 = tmalloc(N);
char *b2 = tmalloc(N);
size_t n = min(N - i, N - j);
memcpy(b2, b1 + i, n);
ASSERT_EQ(b1 + j, memmove(b1 + j, b1 + i, n));
ASSERT_EQ(0, memcmp(b1 + j, b2, n));
tfree(b2);
tfree(b1);
}
}
}
TEST(memmove, overlappingDirect) {
for (size_t i = 0; i < N; i += S) {
for (size_t j = 10; j < N; j += S) {
char *b1 = tmalloc(N);
char *b2 = tmalloc(N);
size_t n = min(N - i, N - j);
memcpy(b2, b1 + i, n);
ASSERT_EQ(b1 + j, (memmove)(b1 + j, b1 + i, n));
ASSERT_EQ(0, memcmp(b1 + j, b2, n));
tfree(b2);
tfree(b1);
}
}
TEST(regex, test) {
regex_t rx;
EXPECT_EQ(REG_OK, regcomp(&rx, "^[A-Za-z\x7f-\uffff]{2}$", REG_EXTENDED));
EXPECT_EQ(REG_OK, regexec(&rx, "AZ", 0, NULL, 0));
EXPECT_EQ(REG_OK, regexec(&rx, "→→", 0, NULL, 0));
EXPECT_EQ(REG_NOMATCH, regexec(&rx, "A", 0, NULL, 0));
EXPECT_EQ(REG_NOMATCH, regexec(&rx, "", 0, NULL, 0));
EXPECT_EQ(REG_NOMATCH, regexec(&rx, "0", 0, NULL, 0));
regfree(&rx);
}

View file

@ -18,6 +18,7 @@
02110-1301 USA
*/
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
@ -30,8 +31,16 @@ uint8_t *sha256(const char *s) {
return hash;
}
TEST(sha256, testEmpty) {
EXPECT_BINEQ(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
sha256(""));
}
TEST(sha256, test) {
EXPECT_BINEQ(u",≥M║_░ú♫&Φ;*┼╣Γ€←▬▲╲▼ºB^s♦3bôïÿ$", sha256("hello"));
EXPECT_BINEQ(u",≥M║_░ú♫&Φ;*┼╣Γ€←▬▲\\▼ºB^s♦3bôïÿ$", sha256("hello"));
EXPECT_BINEQ("2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b98",
sha256("hello"));
}
TEST(sha256, testNontrivialSize) {

View file

@ -551,7 +551,8 @@ void longstringislong_dupe(size_t size, char data[size], char dupe[size]) {
BENCH(bench_00_strcmp, bench) {
size_t size;
char *dupe, *data;
size = ROUNDDOWN(getcachesize(kCpuCacheTypeData, 1) / 2, PAGESIZE);
size = ROUNDDOWN(MAX(FRAMESIZE, getcachesize(kCpuCacheTypeData, 1)) / 2,
PAGESIZE);
data = tgc(tmalloc(size));
dupe = tgc(tmalloc(size));
EZBENCH2("strcmp [identity]", longstringislong(size, data),
@ -569,7 +570,8 @@ BENCH(bench_00_strcmp, bench) {
BENCH(bench_01_strcasecmp, bench) {
size_t size;
char *dupe, *data;
size = ROUNDDOWN(getcachesize(kCpuCacheTypeData, 1) / 2, PAGESIZE);
size = ROUNDDOWN(MAX(FRAMESIZE, getcachesize(kCpuCacheTypeData, 1)) / 2,
PAGESIZE);
data = tgc(tmalloc(size));
dupe = tgc(tmalloc(size));
EZBENCH2("strcasecmp [identity]", longstringislong(size, data),

View file

@ -86,7 +86,7 @@ TEST(strnlen, nulNotFound_ReturnsSize) {
for (unsigned i = 0; i < ARRAYLEN(sizes); ++i) {
char *buf = tmalloc(sizes[i]);
memset(buf, ' ', sizes[i]);
ASSERT_EQ(sizes[i], strnlen(buf, sizes[i]));
ASSERT_EQ(sizes[i], strnlen(buf, sizes[i]), "%d", sizes[i]);
tfree(buf);
}
}

View file

@ -21,25 +21,29 @@
#include "libc/testlib/testlib.h"
#define T(NAME) NAME
#define S(S) S
#define C(C) C
#define S(S) S
#define C(C) C
#include "test/libc/str/strrchr_test.inc"
#undef C
#undef S
#undef T
#define T(NAME) NAME##16
#define S(S) u##S
#define C(C) u##C
#define T(NAME) NAME##16
#define S(S) u##S
#define C(C) u##C
#define strchr(x, y) strchr16(x, y)
#include "test/libc/str/strrchr_test.inc"
#undef strchr
#undef C
#undef S
#undef T
#define T(NAME) NAME##32
#define S(S) L##S
#define C(C) L##C
#define T(NAME) NAME##32
#define S(S) L##S
#define C(C) L##C
#define strchr(x, y) wcschr(x, y)
#include "test/libc/str/strrchr_test.inc"
#undef strchr
#undef C
#undef S
#undef T

View file

@ -5,12 +5,14 @@ PKGS += TEST_LIBC_STR
TEST_LIBC_STR_SRCS := $(wildcard test/libc/str/*.c)
TEST_LIBC_STR_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_STR_SRCS))
TEST_LIBC_STR_COMS = $(TEST_LIBC_STR_OBJS:%.o=%.com)
TEST_LIBC_STR_OBJS = \
$(TEST_LIBC_STR_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_LIBC_STR_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_STR_COMS = \
$(TEST_LIBC_STR_SRCS:%.c=o/$(MODE)/%.com)
TEST_LIBC_STR_BINS = \
$(TEST_LIBC_STR_COMS) \
$(TEST_LIBC_STR_COMS:%=%.dbg)
@ -38,6 +40,7 @@ TEST_LIBC_STR_DIRECTDEPS = \
LIBC_LOG \
LIBC_X \
LIBC_ZIPOS \
THIRD_PARTY_REGEX \
THIRD_PARTY_ZLIB
TEST_LIBC_STR_DEPS := \

View file

@ -23,6 +23,7 @@
#include "libc/log/check.h"
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/rbx.h"
#include "libc/runtime/runtime.h"
@ -50,6 +51,7 @@ TEST(undeflate, testEmbeddedPlaintextConstant) {
TEST(undeflate, testStatCentralDirectory_notFound_noSysCalls) {
uint64_t c;
struct stat st;
stat("zip:doge.txt", &st); /* warmup */
c = g_syscount;
ASSERT_EQ(-1, stat("zip:doge.txt", &st));
ASSERT_EQ(0, g_syscount - c);

View file

@ -1,301 +0,0 @@
/*-*- 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/fmt/bing.h"
#include "libc/limits.h"
#include "libc/macros.h"
#include "libc/runtime/gc.h"
#include "libc/str/str.h"
#include "libc/str/varint.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#define TV(X, B, I) __FILE__, __LINE__, #X, X, #B, B, #I, I
static const struct VarintTestVectors {
const char *file;
int line;
const char *xcode;
uint64_t x;
const char *bcode;
uint16_t b[11];
const char *icode;
uint8_t i;
} kv[] = {
{TV(0x0000000000000000ul, u"          ", 1)},
{TV(0x0000000000000001ul, u"☺         ", 1)},
{TV(0x0000000000000003ul, u"♥         ", 1)},
{TV(0x0000000000000007ul, u"•         ", 1)},
{TV(0x000000000000000ful, u"☼         ", 1)},
{TV(0x000000000000001ful, u"▼         ", 1)},
{TV(0x000000000000003ful, u"⁇         ", 1)},
{TV(0x000000000000007ful, u"⌂         ", 1)},
{TV(0x00000000000000fful, u"λ☺        ", 2)},
{TV(0x00000000000001fful, u"λ♥        ", 2)},
{TV(0x00000000000003fful, u"λ•        ", 2)},
{TV(0x00000000000007fful, u"λ☼        ", 2)},
{TV(0x0000000000000ffful, u"λ▼        ", 2)},
{TV(0x0000000000001ffful, u"λ⁇        ", 2)},
{TV(0x0000000000003ffful, u"λ⌂        ", 2)},
{TV(0x0000000000007ffful, u"λλ☺       ", 3)},
{TV(0x000000000000fffful, u"λλ♥       ", 3)},
{TV(0x000000000001fffful, u"λλ•       ", 3)},
{TV(0x000000000003fffful, u"λλ☼       ", 3)},
{TV(0x000000000007fffful, u"λλ▼       ", 3)},
{TV(0x00000000000ffffful, u"λλ⁇       ", 3)},
{TV(0x00000000001ffffful, u"λλ⌂       ", 3)},
{TV(0x00000000003ffffful, u"λλλ☺      ", 4)},
{TV(0x00000000007ffffful, u"λλλ♥      ", 4)},
{TV(0x0000000000fffffful, u"λλλ•      ", 4)},
{TV(0x0000000001fffffful, u"λλλ☼      ", 4)},
{TV(0x0000000003fffffful, u"λλλ▼      ", 4)},
{TV(0x0000000007fffffful, u"λλλ⁇      ", 4)},
{TV(0x000000000ffffffful, u"λλλ⌂      ", 4)},
{TV(0x000000001ffffffful, u"λλλλ☺     ", 5)},
{TV(0x000000003ffffffful, u"λλλλ♥     ", 5)},
{TV(0x000000007ffffffful, u"λλλλ•     ", 5)},
{TV(0x00000000fffffffful, u"λλλλ☼     ", 5)},
{TV(0x00000001fffffffful, u"λλλλ▼     ", 5)},
{TV(0x00000003fffffffful, u"λλλλ⁇     ", 5)},
{TV(0x00000007fffffffful, u"λλλλ⌂     ", 5)},
{TV(0x0000000ffffffffful, u"λλλλλ☺    ", 6)},
{TV(0x0000001ffffffffful, u"λλλλλ♥    ", 6)},
{TV(0x0000003ffffffffful, u"λλλλλ•    ", 6)},
{TV(0x0000007ffffffffful, u"λλλλλ☼    ", 6)},
{TV(0x000000fffffffffful, u"λλλλλ▼    ", 6)},
{TV(0x000001fffffffffful, u"λλλλλ⁇    ", 6)},
{TV(0x000003fffffffffful, u"λλλλλ⌂    ", 6)},
{TV(0x000007fffffffffful, u"λλλλλλ☺   ", 7)},
{TV(0x00000ffffffffffful, u"λλλλλλ♥   ", 7)},
{TV(0x00001ffffffffffful, u"λλλλλλ•   ", 7)},
{TV(0x00003ffffffffffful, u"λλλλλλ☼   ", 7)},
{TV(0x00007ffffffffffful, u"λλλλλλ▼   ", 7)},
{TV(0x0000fffffffffffful, u"λλλλλλ⁇   ", 7)},
{TV(0x0001fffffffffffful, u"λλλλλλ⌂   ", 7)},
{TV(0x0003fffffffffffful, u"λλλλλλλ☺  ", 8)},
{TV(0x0007fffffffffffful, u"λλλλλλλ♥  ", 8)},
{TV(0x000ffffffffffffful, u"λλλλλλλ•  ", 8)},
{TV(0x001ffffffffffffful, u"λλλλλλλ☼  ", 8)},
{TV(0x003ffffffffffffful, u"λλλλλλλ▼  ", 8)},
{TV(0x007ffffffffffffful, u"λλλλλλλ⁇  ", 8)},
{TV(0x00fffffffffffffful, u"λλλλλλλ⌂  ", 8)},
{TV(0x01fffffffffffffful, u"λλλλλλλλ☺ ", 9)},
{TV(0x03fffffffffffffful, u"λλλλλλλλ♥ ", 9)},
{TV(0x07fffffffffffffful, u"λλλλλλλλ• ", 9)},
{TV(0x0ffffffffffffffful, u"λλλλλλλλ☼ ", 9)},
{TV(0x1ffffffffffffffful, u"λλλλλλλλ▼ ", 9)},
{TV(0x3ffffffffffffffful, u"λλλλλλλλ⁇ ", 9)},
{TV(0x7ffffffffffffffful, u"λλλλλλλλ⌂ ", 9)},
{TV(0xfffffffffffffffful, u"λλλλλλλλλ☺", 10)},
};
const struct ZigzagTestVectors {
const char *file;
int line;
const char *xcode;
int64_t x;
const char *bcode;
uint16_t b[11];
const char *icode;
uint8_t i;
} kz[] = {
{TV(0, u" ", 1)},
{TV(1, u"", 1)},
{TV(-1, u"", 1)},
{TV(2, u"", 1)},
{TV(-2, u"", 1)},
{TV(4, u"", 1)},
{TV(-4, u"", 1)},
{TV(8, u"", 1)},
{TV(-8, u"", 1)},
{TV(16, u" ", 1)},
{TV(-16, u"", 1)},
{TV(32, u"@", 1)},
{TV(-32, u"", 1)},
{TV(64, u"Ç☺", 2)},
{TV(-64, u"", 1)},
{TV(128, u"Ç☻", 2)},
{TV(-128, u"λ☺", 2)},
{TV(256, u"Ç♦", 2)},
{TV(-256, u"λ♥", 2)},
{TV(512, u"Ç◘", 2)},
{TV(-512, u"λ•", 2)},
{TV(1024, u"Ç►", 2)},
{TV(-1024, u"λ☼", 2)},
{TV(2048, u"Ç ", 2)},
{TV(-2048, u"λ▼", 2)},
{TV(4096, u"Ç@", 2)},
{TV(-4096, u"λ⁇", 2)},
{TV(8192, u"ÇÇ☺", 3)},
{TV(-8192, u"λ⌂", 2)},
{TV(16384, u"ÇÇ☻", 3)},
{TV(-16384, u"λλ☺", 3)},
{TV(32768, u"ÇÇ♦", 3)},
{TV(-32768, u"λλ♥", 3)},
{TV(65536, u"ÇÇ◘", 3)},
{TV(-65536, u"λλ•", 3)},
{TV(131072, u"ÇÇ►", 3)},
{TV(-131072, u"λλ☼", 3)},
{TV(262144, u"ÇÇ ", 3)},
{TV(-262144, u"λλ▼", 3)},
{TV(524288, u"ÇÇ@", 3)},
{TV(-524288, u"λλ⁇", 3)},
{TV(1048576, u"ÇÇÇ☺", 4)},
{TV(-1048576, u"λλ⌂", 3)},
{TV(2097152, u"ÇÇÇ☻", 4)},
{TV(-2097152, u"λλλ☺", 4)},
{TV(4194304, u"ÇÇÇ♦", 4)},
{TV(-4194304, u"λλλ♥", 4)},
{TV(8388608, u"ÇÇÇ◘", 4)},
{TV(-8388608, u"λλλ•", 4)},
{TV(16777216, u"ÇÇÇ►", 4)},
{TV(-16777216, u"λλλ☼", 4)},
{TV(33554432, u"ÇÇÇ ", 4)},
{TV(-33554432, u"λλλ▼", 4)},
{TV(67108864, u"ÇÇÇ@", 4)},
{TV(-67108864, u"λλλ⁇", 4)},
{TV(134217728, u"ÇÇÇÇ☺", 5)},
{TV(-134217728, u"λλλ⌂", 4)},
{TV(268435456, u"ÇÇÇÇ☻", 5)},
{TV(-268435456, u"λλλλ☺", 5)},
{TV(536870912, u"ÇÇÇÇ♦", 5)},
{TV(-536870912, u"λλλλ♥", 5)},
{TV(1073741824, u"ÇÇÇÇ◘", 5)},
{TV(-1073741824, u"λλλλ•", 5)},
{TV(2147483648, u"ÇÇÇÇ►", 5)},
{TV(-2147483648, u"λλλλ☼", 5)},
{TV(4294967296, u"ÇÇÇÇ ", 5)},
{TV(-4294967296, u"λλλλ▼", 5)},
{TV(8589934592, u"ÇÇÇÇ@", 5)},
{TV(-8589934592, u"λλλλ⁇", 5)},
{TV(17179869184, u"ÇÇÇÇÇ☺", 6)},
{TV(-17179869184, u"λλλλ⌂", 5)},
{TV(34359738368, u"ÇÇÇÇÇ☻", 6)},
{TV(-34359738368, u"λλλλλ☺", 6)},
{TV(68719476736, u"ÇÇÇÇÇ♦", 6)},
{TV(-68719476736, u"λλλλλ♥", 6)},
{TV(137438953472, u"ÇÇÇÇÇ◘", 6)},
{TV(-137438953472, u"λλλλλ•", 6)},
{TV(274877906944, u"ÇÇÇÇÇ►", 6)},
{TV(-274877906944, u"λλλλλ☼", 6)},
{TV(549755813888, u"ÇÇÇÇÇ ", 6)},
{TV(-549755813888, u"λλλλλ▼", 6)},
{TV(1099511627776, u"ÇÇÇÇÇ@", 6)},
{TV(-1099511627776, u"λλλλλ⁇", 6)},
{TV(2199023255552, u"ÇÇÇÇÇÇ☺", 7)},
{TV(-2199023255552, u"λλλλλ⌂", 6)},
{TV(4398046511104, u"ÇÇÇÇÇÇ☻", 7)},
{TV(-4398046511104, u"λλλλλλ☺", 7)},
{TV(8796093022208, u"ÇÇÇÇÇÇ♦", 7)},
{TV(-8796093022208, u"λλλλλλ♥", 7)},
{TV(17592186044416, u"ÇÇÇÇÇÇ◘", 7)},
{TV(-17592186044416, u"λλλλλλ•", 7)},
{TV(35184372088832, u"ÇÇÇÇÇÇ►", 7)},
{TV(-35184372088832, u"λλλλλλ☼", 7)},
{TV(70368744177664, u"ÇÇÇÇÇÇ ", 7)},
{TV(-70368744177664, u"λλλλλλ▼", 7)},
{TV(140737488355328, u"ÇÇÇÇÇÇ@", 7)},
{TV(-140737488355328, u"λλλλλλ⁇", 7)},
{TV(281474976710656, u"ÇÇÇÇÇÇÇ☺", 8)},
{TV(-281474976710656, u"λλλλλλ⌂", 7)},
{TV(562949953421312, u"ÇÇÇÇÇÇÇ☻", 8)},
{TV(-562949953421312, u"λλλλλλλ☺", 8)},
{TV(1125899906842624, u"ÇÇÇÇÇÇÇ♦", 8)},
{TV(-1125899906842624, u"λλλλλλλ♥", 8)},
{TV(2251799813685248, u"ÇÇÇÇÇÇÇ◘", 8)},
{TV(-2251799813685248, u"λλλλλλλ•", 8)},
{TV(4503599627370496, u"ÇÇÇÇÇÇÇ►", 8)},
{TV(-4503599627370496, u"λλλλλλλ☼", 8)},
{TV(9007199254740992, u"ÇÇÇÇÇÇÇ ", 8)},
{TV(-9007199254740992, u"λλλλλλλ▼", 8)},
{TV(18014398509481984, u"ÇÇÇÇÇÇÇ@", 8)},
{TV(-18014398509481984, u"λλλλλλλ⁇", 8)},
{TV(36028797018963968, u"ÇÇÇÇÇÇÇÇ☺", 9)},
{TV(-36028797018963968, u"λλλλλλλ⌂", 8)},
{TV(72057594037927936, u"ÇÇÇÇÇÇÇÇ☻", 9)},
{TV(-72057594037927936, u"λλλλλλλλ☺", 9)},
{TV(144115188075855872, u"ÇÇÇÇÇÇÇÇ♦", 9)},
{TV(-144115188075855872, u"λλλλλλλλ♥", 9)},
{TV(288230376151711744, u"ÇÇÇÇÇÇÇÇ◘", 9)},
{TV(-288230376151711744, u"λλλλλλλλ•", 9)},
{TV(576460752303423488, u"ÇÇÇÇÇÇÇÇ►", 9)},
{TV(-576460752303423488, u"λλλλλλλλ☼", 9)},
{TV(1152921504606846976, u"ÇÇÇÇÇÇÇÇ ", 9)},
{TV(-1152921504606846976, u"λλλλλλλλ▼", 9)},
{TV(2305843009213693952, u"ÇÇÇÇÇÇÇÇ@", 9)},
{TV(-2305843009213693952, u"λλλλλλλλ⁇", 9)},
{TV(4611686018427387904, u"ÇÇÇÇÇÇÇÇÇ☺", 10)},
{TV(-4611686018427387904, u"λλλλλλλλ⌂", 9)},
{TV(INT64_MIN, u"λλλλλλλλλ☺", 10)},
{TV(INT64_MAX, u"■λλλλλλλλ☺", 10)}, /* wut */
};
TEST(writevint, test) {
size_t i;
uint8_t b[10], *p;
for (i = 0; i < ARRAYLEN(kv); ++i) {
memset(b, 0, sizeof(b));
p = writevint(b, kv[i].x);
__TEST_EQ(assert, kz[i].file, kz[i].line, __FUNCTION__, kz[i].icode,
kz[i].xcode, kv[i].i, p - b);
assertBinaryEquals$cp437(kz[i].file, kz[i].line, __FUNCTION__, kv[i].b, b,
strlen(kv[i].b), "", false);
}
}
TEST(readvint, test) {
size_t i;
uint64_t x;
uint8_t *b, *p;
for (i = 0; i < ARRAYLEN(kv); ++i) {
b = gc(unbingstr(kv[i].b));
p = readvint(b, b + strlen(kv[i].b), &x);
__TEST_EQ(assert, kv[i].file, kv[i].line, __FUNCTION__, kv[i].icode,
kv[i].xcode, kv[i].i, (intptr_t)(p - b));
assertBinaryEquals$cp437(kv[i].file, kv[i].line, __FUNCTION__, kv[i].b, b,
strlen(kv[i].b), "", false);
}
}
TEST(writesint, test) {
size_t i;
uint8_t b[10], *p;
for (i = 0; i < ARRAYLEN(kz); ++i) {
memset(b, 0, sizeof(b));
p = writesint(b, kz[i].x);
__TEST_EQ(assert, kz[i].file, kz[i].line, __FUNCTION__, kz[i].icode,
kz[i].xcode, kz[i].i, (intptr_t)(p - b));
assertBinaryEquals$cp437(kz[i].file, kz[i].line, __FUNCTION__, kz[i].b, b,
strlen(kz[i].b), "", false);
}
}
TEST(readsint, test) {
size_t i;
int64_t x;
uint8_t *b, *p;
for (i = 0; i < ARRAYLEN(kz); ++i) {
b = gc(unbingstr(kz[i].b));
p = readsint(b, b + strlen(kz[i].b), &x);
__TEST_EQ(assert, kz[i].file, kz[i].line, __FUNCTION__, kz[i].icode,
kz[i].xcode, kz[i].i, (intptr_t)(p - b));
assertBinaryEquals$cp437(kz[i].file, kz[i].line, __FUNCTION__, kz[i].b, b,
strlen(kz[i].b), "", false);
}
}