mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-09-10 02:33:49 +00:00
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:
parent
416fd86676
commit
23d333c090
201 changed files with 14558 additions and 3082 deletions
|
@ -17,9 +17,14 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "dsp/core/q.h"
|
||||
#include "dsp/scale/cdecimate2xuint8x8.h"
|
||||
#include "dsp/scale/scale.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/fmt/bing.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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)));
|
||||
|
|
31
test/libc/math/atan2l_test.c
Normal file
31
test/libc/math/atan2l_test.c
Normal 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))));
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
|
45
test/libc/stdio/favail_test.c
Normal file
45
test/libc/stdio/favail_test.c
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 \
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
31
test/libc/tinymath/atan2l_test.c
Normal file
31
test/libc/tinymath/atan2l_test.c
Normal 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))));
|
||||
}
|
|
@ -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 \
|
||||
|
|
|
@ -17,49 +17,30 @@
|
|||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/xmmintrin.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/gc.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "third_party/blas/blas.h"
|
||||
#include "tool/viz/lib/formatstringtable-testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
||||
TEST(dgemm, test) {
|
||||
double alpha, beta;
|
||||
long m, n, k, lda, ldb, ldc;
|
||||
double A[3][3] = {{1 / 8.}, {6 / 8.}, {1 / 8.}};
|
||||
double B[1][3] = {{1 / 8., 6 / 8., 1 / 8.}};
|
||||
double C[3][3] = {0};
|
||||
m = 3;
|
||||
n = 3;
|
||||
k = 1;
|
||||
lda = 3;
|
||||
ldb = 3;
|
||||
ldc = 3;
|
||||
beta = 1;
|
||||
alpha = 1;
|
||||
dgemm_("T", "T", &m, &n, &k, &alpha, &A[0][0], &lda, &B[0][0], &ldb, &beta,
|
||||
&C[0][0], &ldc);
|
||||
EXPECT_DBLMATRIXEQ(6, rint, 3, 3, C, "\n\
|
||||
.015625 .09375 .015625\n\
|
||||
.09375 .5625 .09375\n\
|
||||
.015625 .09375 .015625");
|
||||
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));
|
||||
}
|
||||
|
||||
void dgemmer(long m, long n, long k, void *A, long lda, void *B, long ldb,
|
||||
void *C, long ldc) {
|
||||
double alpha, beta;
|
||||
beta = 1;
|
||||
alpha = 1;
|
||||
dgemm_("N", "N", &m, &n, &k, &alpha, A, &lda, B, &ldb, &beta, C, &ldc);
|
||||
}
|
||||
|
||||
BENCH(dgemm, bench) {
|
||||
double(*A)[128][128] = tgc(tmalloc(128 * 128 * 8));
|
||||
double(*B)[128][128] = tgc(tmalloc(128 * 128 * 8));
|
||||
double(*C)[128][128] = tgc(tmalloc(128 * 128 * 8));
|
||||
EZBENCH2("dgemm_", donothing, dgemmer(128, 128, 128, A, 128, B, 128, C, 128));
|
||||
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));
|
||||
}
|
|
@ -24,13 +24,12 @@
|
|||
char b1[64];
|
||||
char b2[64];
|
||||
struct Dis d[1];
|
||||
struct DisBuilder b = {d, d->xedd, 0};
|
||||
|
||||
TEST(DisInst, testInt3) {
|
||||
uint8_t op[] = {0xcc};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("int3 ", b1);
|
||||
}
|
||||
|
||||
|
@ -38,7 +37,7 @@ TEST(DisInst, testImmMem_needsSuffix) {
|
|||
uint8_t op[] = {0x80, 0x3c, 0x07, 0x00};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("cmpb $0,(%rdi,%rax)", b1);
|
||||
}
|
||||
|
||||
|
@ -46,7 +45,7 @@ TEST(DisInst, testImmReg_doesntNeedSuffix) {
|
|||
uint8_t op[] = {0xb8, 0x08, 0x70, 0x40, 0x00};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov $0x407008,%eax", b1);
|
||||
}
|
||||
|
||||
|
@ -60,23 +59,23 @@ TEST(DisInst, testPuttingOnTheRiz) {
|
|||
};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, ops[0], sizeof(ops[0])));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea (%rsi),%esi", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, ops[1], sizeof(ops[1])));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea (%esi,%eiz,8),%esi", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, ops[2], sizeof(ops[2])));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea 0(%ebp,%eiz,8),%esi", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, ops[3], sizeof(ops[3])));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea 0x31337,%esi", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, ops[4], sizeof(ops[4])));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea 0(%rbp,%riz,8),%esi", b1);
|
||||
}
|
||||
|
||||
|
@ -84,7 +83,7 @@ TEST(DisInst, testSibIndexOnly) {
|
|||
uint8_t op[] = {76, 141, 4, 141, 0, 0, 0, 0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("lea 0(,%rcx,4),%r8", b1);
|
||||
}
|
||||
|
||||
|
@ -92,7 +91,7 @@ TEST(DisInst, testRealMode) {
|
|||
uint8_t op[] = {0x89, 0xe5};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov %sp,%bp", b1);
|
||||
}
|
||||
|
||||
|
@ -100,7 +99,7 @@ TEST(DisInst, testNop) {
|
|||
uint8_t op[] = {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("nopw %cs:0(%rax,%rax)", b1);
|
||||
}
|
||||
|
||||
|
@ -110,7 +109,7 @@ TEST(DisInst, testPush) {
|
|||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
EXPECT_EQ(4, ModrmSrm(d->xedd->op.rde));
|
||||
EXPECT_EQ(1, Rexb(d->xedd->op.rde));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("pop %r12", b1);
|
||||
}
|
||||
|
||||
|
@ -118,11 +117,11 @@ TEST(DisInst, testMovb) {
|
|||
uint8_t op[] = {0x8a, 0x1e, 0x0c, 0x32};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov (%rsi),%bl", b1);
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("mov 0x320c,%bl", b1);
|
||||
}
|
||||
|
||||
|
@ -130,7 +129,7 @@ TEST(DisInst, testLes) {
|
|||
uint8_t op[] = {0xc4, 0x3e, 0x16, 0x32};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("les 0x3216,%di", b1);
|
||||
}
|
||||
|
||||
|
@ -138,7 +137,7 @@ TEST(DisInst, testStosbLong) {
|
|||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%rdi)", b1);
|
||||
}
|
||||
|
||||
|
@ -146,7 +145,7 @@ TEST(DisInst, testStosbReal) {
|
|||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%di)", b1);
|
||||
}
|
||||
|
||||
|
@ -154,7 +153,7 @@ TEST(DisInst, testStosbLegacy) {
|
|||
uint8_t op[] = {0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%edi)", b1);
|
||||
}
|
||||
|
||||
|
@ -162,7 +161,7 @@ TEST(DisInst, testStosbLongAsz) {
|
|||
uint8_t op[] = {0x67, 0xAA};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("stosb %al,(%edi)", b1);
|
||||
}
|
||||
|
||||
|
@ -170,7 +169,7 @@ TEST(DisInst, testAddLong) {
|
|||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
|
@ -178,7 +177,7 @@ TEST(DisInst, testAddLegacy) {
|
|||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
|
@ -186,7 +185,7 @@ TEST(DisInst, testAddReal) {
|
|||
uint8_t op[] = {0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
|
@ -194,7 +193,7 @@ TEST(DisInst, testAddLongOsz) {
|
|||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
|
@ -202,7 +201,7 @@ TEST(DisInst, testAddLegacyOsz) {
|
|||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %di,%di", b1);
|
||||
}
|
||||
|
||||
|
@ -210,7 +209,7 @@ TEST(DisInst, testAddRealOsz) {
|
|||
uint8_t op[] = {0x66, 0x01, 0xff};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("add %edi,%edi", b1);
|
||||
}
|
||||
|
||||
|
@ -219,6 +218,54 @@ TEST(DisInst, testFxam) {
|
|||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
ASSERT_EQ(4, ModrmReg(d->xedd->op.rde));
|
||||
DisInst(b, b1, DisSpec(d->xedd, b2));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("fxam ", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testOrImmCode16gcc) {
|
||||
uint8_t op[] = {0x67, 0x81, 0x4c, 0x24, 0x0c, 0x00, 0x0c};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("or $0xc00,12(%esp)", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testPause) {
|
||||
uint8_t op[] = {0xf3, 0x90};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("pause ", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testJmpEw) {
|
||||
uint8_t op[] = {0xff, 0xe0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("jmp %ax", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testJmpEv16) {
|
||||
uint8_t op[] = {0x66, 0xff, 0xe0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_REAL);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("jmp %eax", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testJmpEv32) {
|
||||
uint8_t op[] = {0xff, 0xe0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LEGACY_32);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("jmp %eax", b1);
|
||||
}
|
||||
|
||||
TEST(DisInst, testJmpEq) {
|
||||
uint8_t op[] = {0x66, 0xff, 0xe0};
|
||||
xed_decoded_inst_zero_set_mode(d->xedd, XED_MACHINE_MODE_LONG_64);
|
||||
ASSERT_EQ(0, xed_instruction_length_decode(d->xedd, op, sizeof(op)));
|
||||
DisInst(d, b1, DisSpec(d->xedd, b2));
|
||||
EXPECT_STREQ("jmp %rax", b1);
|
||||
}
|
||||
|
|
|
@ -124,6 +124,13 @@ TEST(pml4t, testFindPml4t_holeTooSmall_skipsOver) {
|
|||
ASSERT_EQ(0x700006000, FindPml4t(cr3, 0x700000000, 0x10000));
|
||||
}
|
||||
|
||||
TEST(pml4t, testFindPml4t_bigAllocation) {
|
||||
ASSERT_EQ(0x00200000, FindPml4t(cr3, 0x00200000, 0x00400000));
|
||||
ASSERT_EQ(0x00201000, FindPml4t(cr3, 0x00201000, 0x00400000));
|
||||
ASSERT_EQ(0xff200000, FindPml4t(cr3, 0xff200000, 0x00400000));
|
||||
ASSERT_EQ(0xff201000, FindPml4t(cr3, 0xff201000, 0x00400000));
|
||||
}
|
||||
|
||||
TEST(pml4t, testFreePmlt) {
|
||||
ASSERT_NE(-1, RegisterPml4t(cr3, 0x000005000, 0x123000, 0x2000, NewPage));
|
||||
ASSERT_NE(-1, RegisterPml4t(cr3, 0x000000000, 0x321000, 0x1000, NewPage));
|
||||
|
|
32
test/tool/build/lib/wut_test.c
Normal file
32
test/tool/build/lib/wut_test.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- 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/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue