Fix bugs and have emulator emulate itself

This commit is contained in:
Justine Tunney 2020-08-31 05:17:31 -07:00
parent 5aabacb361
commit bd29223891
111 changed files with 1283 additions and 2073 deletions

View file

@ -27,6 +27,9 @@ TEST_LIBC_CONV_DIRECTDEPS = \
LIBC_CONV \
LIBC_NEXGEN32E \
LIBC_STUBS \
LIBC_TINYMATH \
LIBC_RUNTIME \
LIBC_X \
LIBC_TESTLIB
TEST_LIBC_CONV_DEPS := \

View file

@ -40,6 +40,11 @@ TEST(strerror, enosys) {
EXPECT_STARTSWITH("ENOSYS", strerror(ENOSYS));
}
TEST(strerror, einval) {
if (IsTiny()) return;
EXPECT_STARTSWITH("EINVAL", strerror(EINVAL));
}
TEST(strerror, symbolizingTheseNumbersAsErrorsIsHeresyInUnixStyle) {
EXPECT_STARTSWITH("E?/err=0/errno:0/GetLastError:0", strerror(0));
EXPECT_STARTSWITH("E?", strerror(-1));

View file

@ -97,8 +97,6 @@
#include "libc/intrin/punpcklqdq.h"
#include "libc/intrin/punpcklwd.h"
#include "libc/intrin/pxor.h"
#include "libc/intrin/shufpd.h"
#include "libc/intrin/shufps.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/nexgen32e/kcpuids.h"
@ -1674,50 +1672,6 @@ TEST(pshufhw, fuzz) {
}
}
TEST(shufps, fuzz) {
int i, j;
float x[4], a[4], b[4];
for (i = 0; i < 100; ++i) {
for (j = 0; j < 4; ++j) x[j] = Rando() % INT_MAX;
#define T(IMM) \
shufps(a, x, IMM); \
(shufps)(b, x, IMM); \
ASSERT_EQ(0, memcmp(a, b, 16)); \
shufps(a, (void *)a, IMM); \
(shufps)(b, (void *)b, IMM); \
ASSERT_EQ(0, memcmp(a, b, 16))
T(0b00000011);
T(0b00000110);
T(0b00001100);
T(0b00011000);
T(0b00110000);
T(0b01100000);
T(0b11000000);
T(0b10000000);
#undef T
}
}
TEST(shufpd, fuzz) {
int i, j;
double x[2], a[2], b[2];
for (i = 0; i < 100; ++i) {
for (j = 0; j < 2; ++j) x[j] = Rando() % INT_MAX;
#define T(IMM) \
shufpd(a, x, IMM); \
(shufpd)(b, x, IMM); \
ASSERT_EQ(0, memcmp(a, b, 16)); \
shufpd(a, (void *)a, IMM); \
(shufpd)(b, (void *)b, IMM); \
ASSERT_EQ(0, memcmp(a, b, 16))
T(0b00000000);
T(0b00000001);
T(0b00000010);
T(0b00000011);
#undef T
}
}
TEST(packuswb, test) {
const short S[8] = {0, 128, -128, 255, SHRT_MAX, SHRT_MIN, 0, 0};
unsigned char B[16] = {0};

View file

@ -0,0 +1,41 @@
/*-*- 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/stdio/stdio.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
TEST(ldexp, test) {
volatile int twopow = 5;
volatile double pi = 3.14;
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", ldexp(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", ldexpf(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", ldexpl(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalb(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbf(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalbl(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbn(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbnf(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalbnl(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalbln(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2f", scalblnf(pi, twopow))));
ASSERT_STREQ("100.48", gc(xasprintf("%.2Lf", scalblnl(pi, twopow))));
}