Pay off more technical debt

This makes breaking changes to add underscores to many non-standard
function names provided by the c library. MODE=tiny is now tinier and
we now use smaller locks that are better for tiny apps in this mode.
Some headers have been renamed to be in the same folder as the build
package, so it'll be easier to know which build dependency is needed.
Certain old misguided interfaces have been removed. Intel intrinsics
headers are now listed in libc/isystem (but not in the amalgamation)
to help further improve open source compatibility. Header complexity
has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
Justine Tunney 2022-09-12 23:10:38 -07:00
parent b69f3d2488
commit 6f7d0cb1c3
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
960 changed files with 4072 additions and 4873 deletions

View file

@ -17,10 +17,11 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/mem/alloca.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/ok.h"

View file

@ -24,7 +24,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"

View file

@ -20,9 +20,9 @@
#include "libc/calls/ucontext.h"
#include "libc/dce.h"
#include "libc/intrin/kprintf.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/nr.h"
#include "libc/testlib/testlib.h"

View file

@ -28,7 +28,7 @@
#include "libc/sysv/consts/fd.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xspawn.h"
char testlib_enable_tmp_setup_teardown;

View file

@ -21,7 +21,7 @@
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"

View file

@ -21,7 +21,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

View file

@ -23,7 +23,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/ifconf.h"
#include "libc/sock/struct/ifreq.h"

View file

@ -22,7 +22,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/ntspawn.h"
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/ntspawn.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
char tmp[ARG_MAX];

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/internal.h"
#include "libc/calls/syscall_support-nt.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
char16_t p[PATH_MAX];

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
#include "libc/testlib/testlib.h"

View file

@ -30,7 +30,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/mem/io.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"

View file

@ -18,13 +18,14 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/pledge.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/libfatal.internal.h"
#include "libc/mem/gc.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/nexgen32e/rdtscp.h"
#include "libc/nt/synchronization.h"
#include "libc/runtime/gc.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/sock/struct/sockaddr.h"
@ -36,6 +37,7 @@
#include "libc/sysv/consts/sock.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "third_party/chibicc/test/test.h"
#include "tool/decode/lib/flagger.h"
#include "tool/decode/lib/pollnames.h"
@ -58,8 +60,8 @@ void OnSig(int sig) {
dontdiscard char *FormatPollFd(struct pollfd p[2]) {
return xasprintf("fd:%d revents:%s\n"
"fd:%d revents:%s\n",
p[0].fd, gc(RecreateFlags(kPollNames, p[0].revents)),
p[1].fd, gc(RecreateFlags(kPollNames, p[1].revents)));
p[0].fd, _gc(RecreateFlags(kPollNames, p[0].revents)),
p[1].fd, _gc(RecreateFlags(kPollNames, p[1].revents)));
}
TEST(poll, allZero_doesNothingPrettyMuch) {
@ -97,7 +99,7 @@ TEST(poll, testNegativeOneFd_isIgnored) {
EXPECT_SYS(0, 0, poll(fds, ARRAYLEN(fds), 1));
EXPECT_STREQ("fd:-1 revents:0\n"
"fd:3 revents:0\n",
gc(FormatPollFd(&fds[0])));
_gc(FormatPollFd(&fds[0])));
ASSERT_SYS(0, 0, close(3));
}

View file

@ -18,9 +18,11 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
@ -110,7 +112,7 @@ TEST(readlinkat, realpathReturnsLongPath) {
struct stat st;
char buf[PATH_MAX];
if (!IsWindows()) return;
if (!startswith(getcwd(buf, PATH_MAX), "/c/")) return;
if (!_startswith(getcwd(buf, PATH_MAX), "/c/")) return;
ASSERT_SYS(0, 0, touch("froot", 0644));
ASSERT_STARTSWITH("/c/", realpath("froot", buf));
}

View file

@ -38,7 +38,8 @@
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
#include "libc/x/x.h"
#include "libc/x/xsigaction.h"
#include "libc/x/xspawn.h"
#define MEM (64 * 1024 * 1024)

View file

@ -17,6 +17,8 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/calls/struct/sigset.h"
#include "libc/dce.h"
#include "libc/errno.h"
@ -25,7 +27,7 @@
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xspawn.h"
volatile bool gotsig1;
volatile bool gotsig2;

View file

@ -23,7 +23,7 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nt/files.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"

View file

@ -24,8 +24,8 @@
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/kprintf.h"
#include "libc/mem/io.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
@ -43,6 +43,7 @@
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
STATIC_YOINK("zip_uri_support");

View file

@ -22,7 +22,7 @@
#include "libc/errno.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sysv/consts/auxv.h"

View file

@ -20,7 +20,7 @@
#include "libc/dns/dnsheader.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"

View file

@ -19,7 +19,7 @@
#include "libc/intrin/bits.h"
#include "libc/fmt/conv.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
#define BASENAME(x) basename(gc(strdup(x)))

View file

@ -20,7 +20,7 @@
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
TEST(dirname, test) {

View file

@ -20,279 +20,284 @@
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/math.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
TEST(fmt, d) {
EXPECT_STREQ("-123", gc(xasprintf("%d", -123)));
EXPECT_STREQ("-1", gc(xasprintf("%d", -1)));
EXPECT_STREQ("1", gc(xasprintf("%d", 1)));
EXPECT_STREQ("16", gc(xasprintf("%d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%d", INT_MIN)));
EXPECT_STREQ(" -123", gc(xasprintf("%10d", -123)));
EXPECT_STREQ(" -1", gc(xasprintf("%10d", -1)));
EXPECT_STREQ(" 1", gc(xasprintf("%10d", 1)));
EXPECT_STREQ(" 16", gc(xasprintf("%10d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%10d", INT_MIN)));
EXPECT_STREQ("-000000123", gc(xasprintf("%010d", -123)));
EXPECT_STREQ("-000000001", gc(xasprintf("%010d", -1)));
EXPECT_STREQ("0000000001", gc(xasprintf("%010d", 1)));
EXPECT_STREQ("0000000016", gc(xasprintf("%010d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%010d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%010d", INT_MIN)));
EXPECT_STREQ("-123 ", gc(xasprintf("%-10d", -123)));
EXPECT_STREQ("-1 ", gc(xasprintf("%-10d", -1)));
EXPECT_STREQ("1 ", gc(xasprintf("%-10d", 1)));
EXPECT_STREQ("16 ", gc(xasprintf("%-10d", 16)));
EXPECT_STREQ("2147483647", gc(xasprintf("%-10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%-10d", INT_MIN)));
EXPECT_STREQ(" -123", gc(xasprintf("%+10d", -123)));
EXPECT_STREQ(" -1", gc(xasprintf("%+10d", -1)));
EXPECT_STREQ(" +1", gc(xasprintf("%+10d", 1)));
EXPECT_STREQ(" +16", gc(xasprintf("%+10d", 16)));
EXPECT_STREQ("+2147483647", gc(xasprintf("%+10d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("%+10d", INT_MIN)));
EXPECT_STREQ("-123", gc(xasprintf("% d", -123)));
EXPECT_STREQ("-1", gc(xasprintf("% d", -1)));
EXPECT_STREQ(" 1", gc(xasprintf("% d", 1)));
EXPECT_STREQ(" 16", gc(xasprintf("% d", 16)));
EXPECT_STREQ(" 2147483647", gc(xasprintf("% d", INT_MAX)));
EXPECT_STREQ("-2147483648", gc(xasprintf("% d", INT_MIN)));
EXPECT_STREQ("-123", _gc(xasprintf("%d", -123)));
EXPECT_STREQ("-1", _gc(xasprintf("%d", -1)));
EXPECT_STREQ("1", _gc(xasprintf("%d", 1)));
EXPECT_STREQ("16", _gc(xasprintf("%d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%d", INT_MIN)));
EXPECT_STREQ(" -123", _gc(xasprintf("%10d", -123)));
EXPECT_STREQ(" -1", _gc(xasprintf("%10d", -1)));
EXPECT_STREQ(" 1", _gc(xasprintf("%10d", 1)));
EXPECT_STREQ(" 16", _gc(xasprintf("%10d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%10d", INT_MIN)));
EXPECT_STREQ("-000000123", _gc(xasprintf("%010d", -123)));
EXPECT_STREQ("-000000001", _gc(xasprintf("%010d", -1)));
EXPECT_STREQ("0000000001", _gc(xasprintf("%010d", 1)));
EXPECT_STREQ("0000000016", _gc(xasprintf("%010d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%010d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%010d", INT_MIN)));
EXPECT_STREQ("-123 ", _gc(xasprintf("%-10d", -123)));
EXPECT_STREQ("-1 ", _gc(xasprintf("%-10d", -1)));
EXPECT_STREQ("1 ", _gc(xasprintf("%-10d", 1)));
EXPECT_STREQ("16 ", _gc(xasprintf("%-10d", 16)));
EXPECT_STREQ("2147483647", _gc(xasprintf("%-10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%-10d", INT_MIN)));
EXPECT_STREQ(" -123", _gc(xasprintf("%+10d", -123)));
EXPECT_STREQ(" -1", _gc(xasprintf("%+10d", -1)));
EXPECT_STREQ(" +1", _gc(xasprintf("%+10d", 1)));
EXPECT_STREQ(" +16", _gc(xasprintf("%+10d", 16)));
EXPECT_STREQ("+2147483647", _gc(xasprintf("%+10d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("%+10d", INT_MIN)));
EXPECT_STREQ("-123", _gc(xasprintf("% d", -123)));
EXPECT_STREQ("-1", _gc(xasprintf("% d", -1)));
EXPECT_STREQ(" 1", _gc(xasprintf("% d", 1)));
EXPECT_STREQ(" 16", _gc(xasprintf("% d", 16)));
EXPECT_STREQ(" 2147483647", _gc(xasprintf("% d", INT_MAX)));
EXPECT_STREQ("-2147483648", _gc(xasprintf("% d", INT_MIN)));
}
TEST(fmt, g) {
EXPECT_STREQ("1", gc(xasprintf("%g", 1.)));
EXPECT_STREQ(" 1", gc(xasprintf("% g", 1.)));
EXPECT_STREQ("+1", gc(xasprintf("%+g", 1.)));
EXPECT_STREQ("-1", gc(xasprintf("%g", -1.)));
EXPECT_STREQ("10", gc(xasprintf("%g", 10.)));
EXPECT_STREQ("-10", gc(xasprintf("%g", -10.)));
EXPECT_STREQ("1e+01", gc(xasprintf("%.0g", 10.)));
EXPECT_STREQ("-1e+01", gc(xasprintf("%.0g", -10.)));
EXPECT_STREQ("1", gc(xasprintf("%.0g", 1.0)));
EXPECT_STREQ("1e-05", gc(xasprintf("%.0g", 0.00001)));
EXPECT_STREQ("0.0001", gc(xasprintf("%.0g", 0.0001)));
EXPECT_STREQ("1e+01", gc(xasprintf("%.1g", 10.)));
EXPECT_STREQ("-1e+01", gc(xasprintf("%.1g", -10.)));
EXPECT_STREQ("1", gc(xasprintf("%.1g", 1.0)));
EXPECT_STREQ("1e-05", gc(xasprintf("%.1g", 0.00001)));
EXPECT_STREQ("0.0001", gc(xasprintf("%.1g", 0.0001)));
EXPECT_STREQ("0.007812", gc(xasprintf("%.4g", 0.0078125)));
EXPECT_STREQ("0.023438", gc(xasprintf("%.5g", 0.0234375)));
EXPECT_STREQ("1e+100", gc(xasprintf("%g", 1e100)));
EXPECT_STREQ("1e-100", gc(xasprintf("%g", 1e-100)));
EXPECT_STREQ("-1e-100", gc(xasprintf("%g", -1e-100)));
EXPECT_STREQ("0.123456", gc(xasprintf("%g", 0.1234564)));
EXPECT_STREQ("0.123457", gc(xasprintf("%g", 0.1234566)));
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0", gc(xasprintf("%g", 0.)));
EXPECT_STREQ("-0", gc(xasprintf("%g", -0.)));
EXPECT_STREQ("nan", gc(xasprintf("%g", NAN)));
EXPECT_STREQ("-nan", gc(xasprintf("%g", -NAN)));
EXPECT_STREQ("inf", gc(xasprintf("%g", INFINITY)));
EXPECT_STREQ("-inf", gc(xasprintf("%g", -INFINITY)));
EXPECT_STREQ("2.22507e-308", gc(xasprintf("%g", __DBL_MIN__)));
EXPECT_STREQ("1.79769e+308", gc(xasprintf("%g", __DBL_MAX__)));
EXPECT_STREQ("0", gc(xasprintf("%G", 0.)));
EXPECT_STREQ("-0", gc(xasprintf("%G", -0.)));
EXPECT_STREQ("NAN", gc(xasprintf("%G", NAN)));
EXPECT_STREQ("-NAN", gc(xasprintf("%G", -NAN)));
EXPECT_STREQ("INF", gc(xasprintf("%G", INFINITY)));
EXPECT_STREQ("-INF", gc(xasprintf("%G", -INFINITY)));
EXPECT_STREQ("2.22507E-308", gc(xasprintf("%G", __DBL_MIN__)));
EXPECT_STREQ("1.79769E+308", gc(xasprintf("%G", __DBL_MAX__)));
EXPECT_STREQ(" 0", gc(xasprintf("%13g", 0.)));
EXPECT_STREQ(" -0", gc(xasprintf("%13g", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%13g", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%13g", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%13g", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%13g", -INFINITY)));
EXPECT_STREQ(" 2.22507e-308", gc(xasprintf("%13g", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769e+308", gc(xasprintf("%13g", __DBL_MAX__)));
EXPECT_STREQ(" 0", gc(xasprintf("%13G", 0.)));
EXPECT_STREQ(" -0", gc(xasprintf("%13G", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%13G", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%13G", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%13G", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%13G", -INFINITY)));
EXPECT_STREQ(" 2.22507E-308", gc(xasprintf("%13G", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769E+308", gc(xasprintf("%13G", __DBL_MAX__)));
EXPECT_STREQ("1", _gc(xasprintf("%g", 1.)));
EXPECT_STREQ(" 1", _gc(xasprintf("% g", 1.)));
EXPECT_STREQ("+1", _gc(xasprintf("%+g", 1.)));
EXPECT_STREQ("-1", _gc(xasprintf("%g", -1.)));
EXPECT_STREQ("10", _gc(xasprintf("%g", 10.)));
EXPECT_STREQ("-10", _gc(xasprintf("%g", -10.)));
EXPECT_STREQ("1e+01", _gc(xasprintf("%.0g", 10.)));
EXPECT_STREQ("-1e+01", _gc(xasprintf("%.0g", -10.)));
EXPECT_STREQ("1", _gc(xasprintf("%.0g", 1.0)));
EXPECT_STREQ("1e-05", _gc(xasprintf("%.0g", 0.00001)));
EXPECT_STREQ("0.0001", _gc(xasprintf("%.0g", 0.0001)));
EXPECT_STREQ("1e+01", _gc(xasprintf("%.1g", 10.)));
EXPECT_STREQ("-1e+01", _gc(xasprintf("%.1g", -10.)));
EXPECT_STREQ("1", _gc(xasprintf("%.1g", 1.0)));
EXPECT_STREQ("1e-05", _gc(xasprintf("%.1g", 0.00001)));
EXPECT_STREQ("0.0001", _gc(xasprintf("%.1g", 0.0001)));
EXPECT_STREQ("0.007812", _gc(xasprintf("%.4g", 0.0078125)));
EXPECT_STREQ("0.023438", _gc(xasprintf("%.5g", 0.0234375)));
EXPECT_STREQ("1e+100", _gc(xasprintf("%g", 1e100)));
EXPECT_STREQ("1e-100", _gc(xasprintf("%g", 1e-100)));
EXPECT_STREQ("-1e-100", _gc(xasprintf("%g", -1e-100)));
EXPECT_STREQ("0.123456", _gc(xasprintf("%g", 0.1234564)));
EXPECT_STREQ("0.123457", _gc(xasprintf("%g", 0.1234566)));
EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0", _gc(xasprintf("%g", 0.)));
EXPECT_STREQ("-0", _gc(xasprintf("%g", -0.)));
EXPECT_STREQ("nan", _gc(xasprintf("%g", NAN)));
EXPECT_STREQ("-nan", _gc(xasprintf("%g", -NAN)));
EXPECT_STREQ("inf", _gc(xasprintf("%g", INFINITY)));
EXPECT_STREQ("-inf", _gc(xasprintf("%g", -INFINITY)));
EXPECT_STREQ("2.22507e-308", _gc(xasprintf("%g", __DBL_MIN__)));
EXPECT_STREQ("1.79769e+308", _gc(xasprintf("%g", __DBL_MAX__)));
EXPECT_STREQ("0", _gc(xasprintf("%G", 0.)));
EXPECT_STREQ("-0", _gc(xasprintf("%G", -0.)));
EXPECT_STREQ("NAN", _gc(xasprintf("%G", NAN)));
EXPECT_STREQ("-NAN", _gc(xasprintf("%G", -NAN)));
EXPECT_STREQ("INF", _gc(xasprintf("%G", INFINITY)));
EXPECT_STREQ("-INF", _gc(xasprintf("%G", -INFINITY)));
EXPECT_STREQ("2.22507E-308", _gc(xasprintf("%G", __DBL_MIN__)));
EXPECT_STREQ("1.79769E+308", _gc(xasprintf("%G", __DBL_MAX__)));
EXPECT_STREQ(" 0", _gc(xasprintf("%13g", 0.)));
EXPECT_STREQ(" -0", _gc(xasprintf("%13g", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%13g", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%13g", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%13g", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%13g", -INFINITY)));
EXPECT_STREQ(" 2.22507e-308", _gc(xasprintf("%13g", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769e+308", _gc(xasprintf("%13g", __DBL_MAX__)));
EXPECT_STREQ(" 0", _gc(xasprintf("%13G", 0.)));
EXPECT_STREQ(" -0", _gc(xasprintf("%13G", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%13G", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%13G", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%13G", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%13G", -INFINITY)));
EXPECT_STREQ(" 2.22507E-308", _gc(xasprintf("%13G", __DBL_MIN__)));
EXPECT_STREQ(" 1.79769E+308", _gc(xasprintf("%13G", __DBL_MAX__)));
}
TEST(fmt, f) {
EXPECT_STREQ("3.141593", gc(xasprintf("%f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.141593", _gc(xasprintf("%f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.1415926535897931",
gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1)));
_gc(xasprintf("%.16f", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("100000000000000001590289110975991804683608085639452813"
"89781327557747838772170381060813469985856815104.000000",
gc(xasprintf("%f", 1e100)));
EXPECT_STREQ("0.000000", gc(xasprintf("%f", 0.)));
EXPECT_STREQ("-0.000000", gc(xasprintf("%f", -0.)));
EXPECT_STREQ("nan", gc(xasprintf("%f", NAN)));
EXPECT_STREQ("-nan", gc(xasprintf("%f", -NAN)));
EXPECT_STREQ("inf", gc(xasprintf("%f", INFINITY)));
EXPECT_STREQ("-inf", gc(xasprintf("%f", -INFINITY)));
EXPECT_STREQ("0.000000", gc(xasprintf("%f", __DBL_MIN__)));
_gc(xasprintf("%f", 1e100)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%f", 0.)));
EXPECT_STREQ("-0.000000", _gc(xasprintf("%f", -0.)));
EXPECT_STREQ("nan", _gc(xasprintf("%f", NAN)));
EXPECT_STREQ("-nan", _gc(xasprintf("%f", -NAN)));
EXPECT_STREQ("inf", _gc(xasprintf("%f", INFINITY)));
EXPECT_STREQ("-inf", _gc(xasprintf("%f", -INFINITY)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%f", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
gc(xasprintf("%f", __DBL_MAX__)));
EXPECT_STREQ("0.000000", gc(xasprintf("%F", 0.)));
EXPECT_STREQ("-0.000000", gc(xasprintf("%F", -0.)));
EXPECT_STREQ("NAN", gc(xasprintf("%F", NAN)));
EXPECT_STREQ("-NAN", gc(xasprintf("%F", -NAN)));
EXPECT_STREQ("INF", gc(xasprintf("%F", INFINITY)));
EXPECT_STREQ("-INF", gc(xasprintf("%F", -INFINITY)));
EXPECT_STREQ("0.000000", gc(xasprintf("%F", __DBL_MIN__)));
_gc(xasprintf("%f", __DBL_MAX__)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%F", 0.)));
EXPECT_STREQ("-0.000000", _gc(xasprintf("%F", -0.)));
EXPECT_STREQ("NAN", _gc(xasprintf("%F", NAN)));
EXPECT_STREQ("-NAN", _gc(xasprintf("%F", -NAN)));
EXPECT_STREQ("INF", _gc(xasprintf("%F", INFINITY)));
EXPECT_STREQ("-INF", _gc(xasprintf("%F", -INFINITY)));
EXPECT_STREQ("0.000000", _gc(xasprintf("%F", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
gc(xasprintf("%F", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", 0.)));
EXPECT_STREQ(" -0.000000", gc(xasprintf("%10f", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%10f", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%10f", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%10f", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%10f", -INFINITY)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10f", __DBL_MIN__)));
_gc(xasprintf("%F", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", 0.)));
EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10f", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%10f", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%10f", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%10f", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%10f", -INFINITY)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10f", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
gc(xasprintf("%10f", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", 0.)));
EXPECT_STREQ(" -0.000000", gc(xasprintf("%10F", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%10F", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%10F", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%10F", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%10F", -INFINITY)));
EXPECT_STREQ(" 0.000000", gc(xasprintf("%10F", __DBL_MIN__)));
_gc(xasprintf("%10f", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", 0.)));
EXPECT_STREQ(" -0.000000", _gc(xasprintf("%10F", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%10F", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%10F", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%10F", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%10F", -INFINITY)));
EXPECT_STREQ(" 0.000000", _gc(xasprintf("%10F", __DBL_MIN__)));
EXPECT_STREQ(
"179769313486231570814527423731704356798070567525844996598917476803157260"
"780028538760589558632766878171540458953514382464234321326889464182768467"
"546703537516986049910576551282076245490090389328944075868508455133942304"
"583236903222948165808559332123348274797826204144723168738177180919299881"
"250404026184124858368.000000",
gc(xasprintf("%10F", __DBL_MAX__)));
_gc(xasprintf("%10F", __DBL_MAX__)));
}
TEST(fmt, e) {
EXPECT_STREQ("3.14159", gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.14159", _gc(xasprintf("%g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("3.141592653589793",
gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("1.000000e+100", gc(xasprintf("%e", 1e100)));
EXPECT_STREQ("1.000000E+100", gc(xasprintf("%E", 1e100)));
EXPECT_STREQ(" 0.000000e+00", gc(xasprintf("%24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%24e", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%24e", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%24e", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%24e", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%24e", -INFINITY)));
EXPECT_STREQ(" 2.225074e-308", gc(xasprintf("%24e", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693e+308", gc(xasprintf("%24e", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000E+00", gc(xasprintf("%24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%24E", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%24E", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%24E", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%24E", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%24E", -INFINITY)));
EXPECT_STREQ(" 2.225074E-308", gc(xasprintf("%24E", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693E+308", gc(xasprintf("%24E", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000e+00", gc(xasprintf("%+24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", gc(xasprintf("%+24e", -0.)));
EXPECT_STREQ(" +nan", gc(xasprintf("%+24e", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%+24e", -NAN)));
EXPECT_STREQ(" +inf", gc(xasprintf("%+24e", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%+24e", -INFINITY)));
EXPECT_STREQ(" +2.225074e-308", gc(xasprintf("%+24e", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693e+308", gc(xasprintf("%+24e", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000E+00", gc(xasprintf("%+24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", gc(xasprintf("%+24E", -0.)));
EXPECT_STREQ(" +NAN", gc(xasprintf("%+24E", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%+24E", -NAN)));
EXPECT_STREQ(" +INF", gc(xasprintf("%+24E", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%+24E", -INFINITY)));
EXPECT_STREQ(" +2.225074E-308", gc(xasprintf("%+24E", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693E+308", gc(xasprintf("%+24E", __DBL_MAX__)));
_gc(xasprintf("%.16g", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("1.000000e+100", _gc(xasprintf("%e", 1e100)));
EXPECT_STREQ("1.000000E+100", _gc(xasprintf("%E", 1e100)));
EXPECT_STREQ(" 0.000000e+00", _gc(xasprintf("%24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%24e", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%24e", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%24e", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%24e", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%24e", -INFINITY)));
EXPECT_STREQ(" 2.225074e-308", _gc(xasprintf("%24e", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693e+308", _gc(xasprintf("%24e", __DBL_MAX__)));
EXPECT_STREQ(" 0.000000E+00", _gc(xasprintf("%24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%24E", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%24E", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%24E", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%24E", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%24E", -INFINITY)));
EXPECT_STREQ(" 2.225074E-308", _gc(xasprintf("%24E", __DBL_MIN__)));
EXPECT_STREQ(" 1.797693E+308", _gc(xasprintf("%24E", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000e+00", _gc(xasprintf("%+24e", 0.)));
EXPECT_STREQ(" -0.000000e+00", _gc(xasprintf("%+24e", -0.)));
EXPECT_STREQ(" +nan", _gc(xasprintf("%+24e", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%+24e", -NAN)));
EXPECT_STREQ(" +inf", _gc(xasprintf("%+24e", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%+24e", -INFINITY)));
EXPECT_STREQ(" +2.225074e-308",
_gc(xasprintf("%+24e", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693e+308",
_gc(xasprintf("%+24e", __DBL_MAX__)));
EXPECT_STREQ(" +0.000000E+00", _gc(xasprintf("%+24E", 0.)));
EXPECT_STREQ(" -0.000000E+00", _gc(xasprintf("%+24E", -0.)));
EXPECT_STREQ(" +NAN", _gc(xasprintf("%+24E", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%+24E", -NAN)));
EXPECT_STREQ(" +INF", _gc(xasprintf("%+24E", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%+24E", -INFINITY)));
EXPECT_STREQ(" +2.225074E-308",
_gc(xasprintf("%+24E", __DBL_MIN__)));
EXPECT_STREQ(" +1.797693E+308",
_gc(xasprintf("%+24E", __DBL_MAX__)));
}
TEST(fmt, a) {
EXPECT_STREQ("0x1.921fb54442d18p+1",
gc(xasprintf("%a", 0x1.921fb54442d1846ap+1)));
_gc(xasprintf("%a", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ("0X1.921FB54442D18P+1",
gc(xasprintf("%A", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ(" 0x0p+0", gc(xasprintf("%24a", 0.)));
EXPECT_STREQ(" -0x0p+0", gc(xasprintf("%24a", -0.)));
EXPECT_STREQ(" nan", gc(xasprintf("%24a", NAN)));
EXPECT_STREQ(" -nan", gc(xasprintf("%24a", -NAN)));
EXPECT_STREQ(" inf", gc(xasprintf("%24a", INFINITY)));
EXPECT_STREQ(" -inf", gc(xasprintf("%24a", -INFINITY)));
EXPECT_STREQ(" 0x1p-1022", gc(xasprintf("%24a", __DBL_MIN__)));
EXPECT_STREQ(" 0x1.fffffffffffffp+1023", gc(xasprintf("%24a", __DBL_MAX__)));
EXPECT_STREQ(" 0X0P+0", gc(xasprintf("%24A", 0.)));
EXPECT_STREQ(" -0X0P+0", gc(xasprintf("%24A", -0.)));
EXPECT_STREQ(" NAN", gc(xasprintf("%24A", NAN)));
EXPECT_STREQ(" -NAN", gc(xasprintf("%24A", -NAN)));
EXPECT_STREQ(" INF", gc(xasprintf("%24A", INFINITY)));
EXPECT_STREQ(" -INF", gc(xasprintf("%24A", -INFINITY)));
EXPECT_STREQ(" 0X1P-1022", gc(xasprintf("%24A", __DBL_MIN__)));
EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", gc(xasprintf("%24A", __DBL_MAX__)));
EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", 31337.1337)));
EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", gc(xasprintf("%24A", -31337.1337)));
_gc(xasprintf("%A", 0x1.921fb54442d1846ap+1)));
EXPECT_STREQ(" 0x0p+0", _gc(xasprintf("%24a", 0.)));
EXPECT_STREQ(" -0x0p+0", _gc(xasprintf("%24a", -0.)));
EXPECT_STREQ(" nan", _gc(xasprintf("%24a", NAN)));
EXPECT_STREQ(" -nan", _gc(xasprintf("%24a", -NAN)));
EXPECT_STREQ(" inf", _gc(xasprintf("%24a", INFINITY)));
EXPECT_STREQ(" -inf", _gc(xasprintf("%24a", -INFINITY)));
EXPECT_STREQ(" 0x1p-1022", _gc(xasprintf("%24a", __DBL_MIN__)));
EXPECT_STREQ(" 0x1.fffffffffffffp+1023", _gc(xasprintf("%24a", __DBL_MAX__)));
EXPECT_STREQ(" 0X0P+0", _gc(xasprintf("%24A", 0.)));
EXPECT_STREQ(" -0X0P+0", _gc(xasprintf("%24A", -0.)));
EXPECT_STREQ(" NAN", _gc(xasprintf("%24A", NAN)));
EXPECT_STREQ(" -NAN", _gc(xasprintf("%24A", -NAN)));
EXPECT_STREQ(" INF", _gc(xasprintf("%24A", INFINITY)));
EXPECT_STREQ(" -INF", _gc(xasprintf("%24A", -INFINITY)));
EXPECT_STREQ(" 0X1P-1022", _gc(xasprintf("%24A", __DBL_MIN__)));
EXPECT_STREQ(" 0X1.FFFFFFFFFFFFFP+1023", _gc(xasprintf("%24A", __DBL_MAX__)));
EXPECT_STREQ(" 0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", 31337.1337)));
EXPECT_STREQ(" -0X1.E9A488E8A71DEP+14", _gc(xasprintf("%24A", -31337.1337)));
}
TEST(fmt, p) {
EXPECT_STREQ("0x1", gc(xasprintf("%p", 1)));
EXPECT_STREQ("0x10", gc(xasprintf("%p", 16)));
EXPECT_STREQ("0x31337", gc(xasprintf("%p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("%10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("%10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("%10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", gc(xasprintf("%10p", 0xffff800000031337)));
EXPECT_STREQ("0x00000001", gc(xasprintf("%010p", 1)));
EXPECT_STREQ("0x00000010", gc(xasprintf("%010p", 16)));
EXPECT_STREQ("0x00031337", gc(xasprintf("%010p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%010p", 0xffffffff)));
EXPECT_STREQ("0x1", _gc(xasprintf("%p", 1)));
EXPECT_STREQ("0x10", _gc(xasprintf("%p", 16)));
EXPECT_STREQ("0x31337", _gc(xasprintf("%p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337", _gc(xasprintf("%p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("%10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("%10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("%10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
gc(xasprintf("%010p", 0xffff800000031337)));
EXPECT_STREQ("0x1 ", gc(xasprintf("%-10p", 1)));
EXPECT_STREQ("0x10 ", gc(xasprintf("%-10p", 16)));
EXPECT_STREQ("0x31337 ", gc(xasprintf("%-10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%-10p", 0xffffffff)));
_gc(xasprintf("%10p", 0xffff800000031337)));
EXPECT_STREQ("0x00000001", _gc(xasprintf("%010p", 1)));
EXPECT_STREQ("0x00000010", _gc(xasprintf("%010p", 16)));
EXPECT_STREQ("0x00031337", _gc(xasprintf("%010p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%010p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
gc(xasprintf("%-10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("%+10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("%+10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("%+10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("%+10p", 0xffffffff)));
_gc(xasprintf("%010p", 0xffff800000031337)));
EXPECT_STREQ("0x1 ", _gc(xasprintf("%-10p", 1)));
EXPECT_STREQ("0x10 ", _gc(xasprintf("%-10p", 16)));
EXPECT_STREQ("0x31337 ", _gc(xasprintf("%-10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%-10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
gc(xasprintf("%+10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", gc(xasprintf("% 10p", 1)));
EXPECT_STREQ(" 0x10", gc(xasprintf("% 10p", 16)));
EXPECT_STREQ(" 0x31337", gc(xasprintf("% 10p", 0x31337)));
EXPECT_STREQ("0xffffffff", gc(xasprintf("% 10p", 0xffffffff)));
_gc(xasprintf("%-10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("%+10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("%+10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("%+10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("%+10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
gc(xasprintf("% 10p", 0xffff800000031337)));
_gc(xasprintf("%+10p", 0xffff800000031337)));
EXPECT_STREQ(" 0x1", _gc(xasprintf("% 10p", 1)));
EXPECT_STREQ(" 0x10", _gc(xasprintf("% 10p", 16)));
EXPECT_STREQ(" 0x31337", _gc(xasprintf("% 10p", 0x31337)));
EXPECT_STREQ("0xffffffff", _gc(xasprintf("% 10p", 0xffffffff)));
EXPECT_STREQ("0xffff800000031337",
_gc(xasprintf("% 10p", 0xffff800000031337)));
}
TEST(fmt, quoted) {
ASSERT_STREQ(" \"hello\"", gc(xasprintf("%`*.*s", 10, 5, "hello")));
ASSERT_STREQ("\"hello\" ", gc(xasprintf("%-`*.*s", 10, 5, "hello")));
ASSERT_STREQ(" \"hello\"", _gc(xasprintf("%`*.*s", 10, 5, "hello")));
ASSERT_STREQ("\"hello\" ", _gc(xasprintf("%-`*.*s", 10, 5, "hello")));
}
TEST(fmt, nulCharacter) {

View file

@ -21,7 +21,6 @@
#include "libc/limits.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -31,15 +31,15 @@
#include "libc/intrin/safemacros.internal.h"
#include "libc/limits.h"
#include "libc/math.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
char buffer[1000];
/* #define Format(...) gc(xasprintf(__VA_ARGS__)) */
/* #define Format(...) _gc(xasprintf(__VA_ARGS__)) */
#define Format(...) (snprintf(buffer, sizeof(buffer), __VA_ARGS__), buffer)
TEST(sprintf, test_space_flag) {
@ -572,13 +572,13 @@ TEST(xasprintf, hugeNtoa) {
ASSERT_STREQ(
"0b1111111111111111111111111111111111111111111111111111111111111111111111"
"1111111111111111111111111111111111111111111111111111111111",
gc(xasprintf("%#jjb", UINT128_MAX)));
_gc(xasprintf("%#jjb", UINT128_MAX)));
}
TEST(xasprintf, twosBane) {
ASSERT_STREQ("-2147483648", gc(xasprintf("%d", 0x80000000)));
ASSERT_STREQ("-2147483648", _gc(xasprintf("%d", 0x80000000)));
ASSERT_STREQ("-9223372036854775808",
gc(xasprintf("%ld", 0x8000000000000000)));
_gc(xasprintf("%ld", 0x8000000000000000)));
}
TEST(snprintf, testFixedWidthString_wontOverrunInput) {
@ -611,8 +611,8 @@ TEST(snprintf, twosBaneWithTypePromotion) {
}
TEST(snprintf, formatStringLiteral) {
EXPECT_EQ('\\' | 'n' << 8, cescapec('\n'));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec('\377'));
EXPECT_EQ('\\' | 'n' << 8, _cescapec('\n'));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec('\377'));
EXPECT_STREQ("\"hi\\n\"", Format("%`'s", "hi\n"));
EXPECT_STREQ("\"\\000\"", Format("%`'.*s", 1, "\0"));
}

View file

@ -16,16 +16,17 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
static char buffer[128];
#define Format(...) gc(xasprintf(__VA_ARGS__))
#define Format(...) _gc(xasprintf(__VA_ARGS__))
/**
* @fileoverview String formatting tests.

View file

@ -18,7 +18,7 @@
*/
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

View file

@ -19,7 +19,7 @@
#include "libc/fmt/leb128.h"
#include "libc/limits.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
TEST(zleb64, testZero) {

View file

@ -22,7 +22,7 @@
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/intrin/bits.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -106,10 +106,10 @@ unsigned P[] = {
TEST(bextra, 9bit) {
int i;
for (i = 4; i < 257; ++i) {
ASSERT_EQ(i, bextra(P, i, 9));
ASSERT_EQ(i, _bextra(P, i, 9));
}
}
BENCH(bextra, bench) {
EZBENCH2("bextra 1/31", donothing, bextra(P, 1, 31));
EZBENCH2("bextra 1/31", donothing, _bextra(P, 1, 31));
}

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/intrin/bits.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -25,25 +25,19 @@ void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
}
TEST(bitreverse, test) {
EXPECT_EQ(0xde, BITREVERSE8(123));
EXPECT_EQ(0xde, bitreverse8(123));
EXPECT_EQ(0xde00, BITREVERSE16(123));
EXPECT_EQ(0xde00, bitreverse16(123));
EXPECT_EQ(0xde000000u, bitreverse32(123));
EXPECT_EQ(0xde00000000000000ul, bitreverse64(123));
EXPECT_EQ(0x482d96c305f7c697ul, bitreverse64(0xe963efa0c369b412));
TEST(_bitreverse, test) {
EXPECT_EQ(0xde, _bitreverse8(123));
EXPECT_EQ(0xde00, _bitreverse16(123));
EXPECT_EQ(0xde000000u, _bitreverse32(123));
EXPECT_EQ(0xde00000000000000ul, _bitreverse64(123));
EXPECT_EQ(0x482d96c305f7c697ul, _bitreverse64(0xe963efa0c369b412));
}
BENCH(bitreverse, bench) {
EZBENCH2("BITREVERSE8", donothing,
EXPROPRIATE(BITREVERSE8(CONCEAL("r", 123))));
EZBENCH2("bitreverse8", donothing,
EXPROPRIATE(bitreverse8(CONCEAL("r", 123))));
EZBENCH2("BITREVERSE16", donothing,
EXPROPRIATE(BITREVERSE16(CONCEAL("r", 123))));
EZBENCH2("bitreverse32", donothing,
EXPROPRIATE(bitreverse32(CONCEAL("r", 123))));
EZBENCH2("bitreverse64", donothing,
EXPROPRIATE(bitreverse64(CONCEAL("r", 123))));
BENCH(_bitreverse, bench) {
EZBENCH2("_bitreverse8", donothing,
EXPROPRIATE(_bitreverse8(CONCEAL("r", 123))));
EZBENCH2("_bitreverse32", donothing,
EXPROPRIATE(_bitreverse32(CONCEAL("r", 123))));
EZBENCH2("_bitreverse64", donothing,
EXPROPRIATE(_bitreverse64(CONCEAL("r", 123))));
}

View file

@ -20,7 +20,7 @@
#include "libc/intrin/popcnt.h"
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -104,7 +104,7 @@
#include "libc/nexgen32e/kcpuids.h"
#include "libc/stdio/lcg.internal.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -0,0 +1,248 @@
/*-*- 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 2022 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/timespec.h"
#include "libc/errno.h"
#include "libc/fmt/itoa.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/kprintf.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/clone.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/clone.h"
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#include "third_party/nsync/mu.h"
/**
* @fileoverview Austere Mutex Test
*
* 1. Tests what happens when *NSYNC isn't linked.
* 2. Tests what happens when TLS isn't enabled.
*
* If either:
*
* 1. malloc() isn't linked, or
* 2. we're in MODE=tiny
*
* Then we use Cosmopolitan's hand-rolled tiny locks. They're not
* scalable. They use a lot of CPU if you have lots of threads. But
* they're wicked fast and free of bloat if your app is tiny.
*/
// RAW means without *NSYNC
// TLS means gettid() is fast
// PTHREAD_MUTEX_NORMAL RAW TLS took 6ns
// PTHREAD_MUTEX_RECURSIVE RAW TLS took 12ns
// PTHREAD_MUTEX_ERRORCHECK RAW TLS took 13ns
// PTHREAD_MUTEX_NORMAL RAW TLS contended took 16ns (!!)
// PTHREAD_MUTEX_RECURSIVE RAW TLS contended took 205ns
// PTHREAD_MUTEX_ERRORCHECK RAW TLS contended took 219ns
// PTHREAD_MUTEX_NORMAL RAW took 6ns
// PTHREAD_MUTEX_RECURSIVE RAW took 236ns
// PTHREAD_MUTEX_ERRORCHECK RAW took 233ns
// PTHREAD_MUTEX_NORMAL RAW contended took 20ns (!!)
// PTHREAD_MUTEX_RECURSIVE RAW contended took 421ns
// PTHREAD_MUTEX_ERRORCHECK RAW contended took 435ns
atomic_int ready;
atomic_int counter;
atomic_int success;
pthread_mutex_t mu;
#define ASSERT_EQ(WANT, GOT) \
do { \
long _want = WANT, _got = GOT; \
if (_want != _got) \
__assert_eq_fail(__FILE__, __LINE__, #WANT, #GOT, _want, _got); \
} while (0)
void __assert_eq_fail(const char *file, int line, const char *wantstr,
const char *gotstr, long want, long got) {
kprintf("%s:%d: %s vs. %s was %ld vs. %ld (%s)\n", file, line, wantstr,
gotstr, want, got, !(got & ~255) ? _strerrno(got) : "n/a");
_Exit(1);
}
double time2dbl(struct timespec t) {
return (((double)t.tv_sec) + ((double)t.tv_nsec * 1e-9));
}
char *time2str(double s) {
static char buf[32];
static const struct {
const char *suffix;
double multiplier;
} scale[] = {
{"ns", 1.0e-9}, //
{"us", 1e-6}, //
{"ms", 1e-3}, //
{"s", 1.0}, //
{"hr", 3600.0}, //
};
int i = 0;
while (i + 1 != sizeof(scale) / sizeof(scale[0]) &&
scale[i + 1].multiplier <= s) {
i++;
}
stpcpy(FormatInt32(buf, s / scale[i].multiplier), scale[i].suffix);
return buf;
}
int Worker(void *arg) {
int i, x;
atomic_store(&ready, 1);
for (i = 0; i < 10000; ++i) {
ASSERT_EQ(0, pthread_mutex_lock(&mu));
x = atomic_load_explicit(&counter, memory_order_relaxed);
atomic_store_explicit(&counter, x + 1, memory_order_relaxed);
ASSERT_EQ(x + 1, atomic_load_explicit(&counter, memory_order_relaxed));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
}
atomic_store(&success, 1);
return 0;
}
void TestContendedLock(const char *name, int kind) {
char *stk;
double ns;
int tid, x, i, n = 10000;
struct timespec t1, t2;
pthread_mutexattr_t attr;
struct CosmoTib tib = {.tib_self = &tib, .tib_self2 = &tib, .tib_tid = -1};
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, kind);
pthread_mutex_init(&mu, &attr);
pthread_mutexattr_destroy(&attr);
atomic_store(&ready, 0);
atomic_store(&success, 0);
stk = _mapstack();
tid = clone(Worker, stk, GetStackSize() - 16 /* openbsd:stackbound */,
CLONE_VM | CLONE_THREAD | CLONE_FS | CLONE_FILES | CLONE_SIGHAND |
CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | CLONE_SETTLS,
0, 0, &tib, &tib.tib_tid);
if (tid == -1) {
kprintf("clone failed: %s\n", strerror(errno));
_Exit(1);
}
while (!atomic_load(&ready)) donothing;
t1 = _timespec_real();
for (i = 0; i < n; ++i) {
ASSERT_EQ(0, pthread_mutex_lock(&mu));
x = atomic_load_explicit(&counter, memory_order_relaxed);
atomic_store_explicit(&counter, x - 1, memory_order_relaxed);
ASSERT_EQ(x - 1, atomic_load_explicit(&counter, memory_order_relaxed));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
}
t2 = _timespec_real();
while (tib.tib_tid) donothing;
ASSERT_EQ(1, atomic_load(&success));
ASSERT_EQ(0, atomic_load(&counter));
_freestack(stk);
ASSERT_EQ(0, pthread_mutex_destroy(&mu));
ns = time2dbl(_timespec_sub(t2, t1)) / n;
kprintf("%s contended took %s\n", name, time2str(ns));
}
void TestUncontendedLock(const char *name, int kind) {
double ns;
long i, n = 10000;
struct timespec t1, t2;
pthread_mutex_t lock;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, kind);
pthread_mutex_init(&lock, &attr);
pthread_mutexattr_destroy(&attr);
t1 = _timespec_real();
for (i = 0; i < n; ++i) {
pthread_mutex_lock(&lock);
pthread_mutex_unlock(&lock);
}
t2 = _timespec_real();
pthread_mutex_destroy(&lock);
ns = time2dbl(_timespec_sub(t2, t1)) / n;
kprintf("%s took %s\n", name, time2str(ns));
}
int main(int argc, char *argv[]) {
pthread_mutexattr_t attr;
if (_weaken(nsync_mu_lock)) {
kprintf("*NSYNC should not be linked\n");
_Exit(1);
}
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL));
ASSERT_EQ(0, pthread_mutex_init(&mu, &attr));
ASSERT_EQ(0, pthread_mutexattr_destroy(&attr));
ASSERT_EQ(0, pthread_mutex_lock(&mu));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
ASSERT_EQ(0, pthread_mutex_destroy(&mu));
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE));
ASSERT_EQ(0, pthread_mutex_init(&mu, &attr));
ASSERT_EQ(0, pthread_mutexattr_destroy(&attr));
ASSERT_EQ(0, pthread_mutex_lock(&mu));
ASSERT_EQ(0, pthread_mutex_lock(&mu));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
ASSERT_EQ(0, pthread_mutex_destroy(&mu));
ASSERT_EQ(0, pthread_mutexattr_init(&attr));
ASSERT_EQ(0, pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
ASSERT_EQ(0, pthread_mutex_init(&mu, &attr));
ASSERT_EQ(0, pthread_mutexattr_destroy(&attr));
ASSERT_EQ(0, pthread_mutex_lock(&mu));
ASSERT_EQ(EDEADLK, pthread_mutex_lock(&mu));
ASSERT_EQ(0, pthread_mutex_unlock(&mu));
ASSERT_EQ(EPERM, pthread_mutex_unlock(&mu));
ASSERT_EQ(0, pthread_mutex_destroy(&mu));
ASSERT_EQ(1, __tls_enabled);
TestUncontendedLock("PTHREAD_MUTEX_NORMAL RAW TLS", PTHREAD_MUTEX_NORMAL);
TestUncontendedLock("PTHREAD_MUTEX_RECURSIVE RAW TLS",
PTHREAD_MUTEX_RECURSIVE);
TestUncontendedLock("PTHREAD_MUTEX_ERRORCHECK RAW TLS",
PTHREAD_MUTEX_ERRORCHECK);
TestContendedLock("PTHREAD_MUTEX_NORMAL RAW TLS", PTHREAD_MUTEX_NORMAL);
TestContendedLock("PTHREAD_MUTEX_RECURSIVE RAW TLS", PTHREAD_MUTEX_RECURSIVE);
TestContendedLock("PTHREAD_MUTEX_ERRORCHECK RAW TLS",
PTHREAD_MUTEX_ERRORCHECK);
__tls_enabled = 0;
TestUncontendedLock("PTHREAD_MUTEX_NORMAL RAW", PTHREAD_MUTEX_NORMAL);
TestUncontendedLock("PTHREAD_MUTEX_RECURSIVE RAW", PTHREAD_MUTEX_RECURSIVE);
TestUncontendedLock("PTHREAD_MUTEX_ERRORCHECK RAW", PTHREAD_MUTEX_ERRORCHECK);
TestContendedLock("PTHREAD_MUTEX_NORMAL RAW", PTHREAD_MUTEX_NORMAL);
TestContendedLock("PTHREAD_MUTEX_RECURSIVE RAW", PTHREAD_MUTEX_RECURSIVE);
TestContendedLock("PTHREAD_MUTEX_ERRORCHECK RAW", PTHREAD_MUTEX_ERRORCHECK);
//
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -20,7 +20,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -19,7 +19,7 @@
#include "libc/dce.h"
#include "libc/intrin/asan.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -21,7 +21,7 @@
#include "libc/calls/struct/timespec.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/posixthread.internal.h"

View file

@ -20,13 +20,13 @@
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/state.internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/errno.h"
#include "libc/intrin/strace.internal.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
@ -40,6 +40,7 @@
#include "libc/thread/thread.h"
#include "libc/thread/tls.h"
#include "libc/thread/wait0.internal.h"
#include "third_party/nsync/mu.h"
#define THREADS 8
#define ITERATIONS 512

View file

@ -19,7 +19,7 @@
#include "libc/atomic.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"
#include "libc/thread/thread.h"

View file

@ -16,24 +16,24 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/intrin/bits.h"
#include "libc/testlib/testlib.h"
void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
}
TEST(rounddown2pow, test) {
EXPECT_EQ(0, rounddown2pow(0));
EXPECT_EQ(1, rounddown2pow(1));
EXPECT_EQ(2, rounddown2pow(2));
EXPECT_EQ(2, rounddown2pow(3));
EXPECT_EQ(4, rounddown2pow(4));
EXPECT_EQ(PAGESIZE / 2, rounddown2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE + 1));
EXPECT_EQ(PAGESIZE / 2, rounddown2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE, rounddown2pow(PAGESIZE + 1));
TEST(_rounddown2pow, test) {
EXPECT_EQ(0, _rounddown2pow(0));
EXPECT_EQ(1, _rounddown2pow(1));
EXPECT_EQ(2, _rounddown2pow(2));
EXPECT_EQ(2, _rounddown2pow(3));
EXPECT_EQ(4, _rounddown2pow(4));
EXPECT_EQ(PAGESIZE / 2, _rounddown2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE + 1));
EXPECT_EQ(PAGESIZE / 2, _rounddown2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE, _rounddown2pow(PAGESIZE + 1));
}

View file

@ -16,24 +16,24 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/intrin/bits.h"
#include "libc/testlib/testlib.h"
void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
}
TEST(roundup2log, test) {
EXPECT_EQ(0, roundup2log(0));
EXPECT_EQ(1, roundup2log(1));
EXPECT_EQ(1, roundup2log(2));
EXPECT_EQ(2, roundup2log(3));
EXPECT_EQ(2, roundup2log(4));
EXPECT_EQ(12, roundup2log(PAGESIZE - 1));
EXPECT_EQ(12, roundup2log(PAGESIZE));
EXPECT_EQ(13, roundup2log(PAGESIZE + 1));
EXPECT_EQ(12, roundup2log(PAGESIZE - 1));
EXPECT_EQ(12, roundup2log(PAGESIZE));
EXPECT_EQ(13, roundup2log(PAGESIZE + 1));
TEST(_roundup2log, test) {
EXPECT_EQ(0, _roundup2log(0));
EXPECT_EQ(1, _roundup2log(1));
EXPECT_EQ(1, _roundup2log(2));
EXPECT_EQ(2, _roundup2log(3));
EXPECT_EQ(2, _roundup2log(4));
EXPECT_EQ(12, _roundup2log(PAGESIZE - 1));
EXPECT_EQ(12, _roundup2log(PAGESIZE));
EXPECT_EQ(13, _roundup2log(PAGESIZE + 1));
EXPECT_EQ(12, _roundup2log(PAGESIZE - 1));
EXPECT_EQ(12, _roundup2log(PAGESIZE));
EXPECT_EQ(13, _roundup2log(PAGESIZE + 1));
}

View file

@ -16,28 +16,24 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/intrin/bits.h"
#include "libc/calls/calls.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bits.h"
#include "libc/testlib/testlib.h"
void SetUpOnce(void) {
ASSERT_SYS(0, 0, pledge("stdio", 0));
}
TEST(roundup2pow, test) {
EXPECT_EQ(0, roundup2pow(0));
EXPECT_EQ(1, roundup2pow(1));
EXPECT_EQ(2, roundup2pow(2));
EXPECT_EQ(4, roundup2pow(3));
EXPECT_EQ(4, roundup2pow(4));
EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE * 2, roundup2pow(PAGESIZE + 1));
EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, roundup2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE * 2, roundup2pow(PAGESIZE + 1));
TEST(_roundup2pow, test) {
EXPECT_EQ(0, _roundup2pow(0));
EXPECT_EQ(1, _roundup2pow(1));
EXPECT_EQ(2, _roundup2pow(2));
EXPECT_EQ(4, _roundup2pow(3));
EXPECT_EQ(4, _roundup2pow(4));
EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE * 2, _roundup2pow(PAGESIZE + 1));
EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE - 1));
EXPECT_EQ(PAGESIZE, _roundup2pow(PAGESIZE));
EXPECT_EQ(PAGESIZE * 2, _roundup2pow(PAGESIZE + 1));
}

View file

@ -19,7 +19,6 @@
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -58,6 +58,15 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
# Test what happens when *NSYNC isn't linked.
o/$(MODE)/test/libc/intrin/lock_test.com.dbg: \
$(TEST_LIBC_INTRIN_DEPS) \
o/$(MODE)/test/libc/intrin/lock_test.o \
o/$(MODE)/test/libc/intrin/intrin.pkg \
$(CRT) \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
$(TEST_LIBC_INTRIN_OBJS): private \
OVERRIDE_CFLAGS += \
-fno-builtin

View file

@ -17,6 +17,8 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/rusage.h"
#include "libc/log/appendresourcereport.internal.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"

View file

@ -25,19 +25,19 @@
#include "libc/limits.h"
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
#include "libc/mem/io.h"
#include "libc/mem/gc.h"
#include "libc/calls/copyfd.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "net/http/escape.h"
STATIC_YOINK("zip_uri_support");
@ -128,14 +128,14 @@ TEST(ShowCrashReports, testMemoryLeakCrash) {
EXPECT_EQ(78, WEXITSTATUS(ws));
if (!strstr(output, "UNFREED MEMORY")) {
fprintf(stderr, "ERROR: crash report didn't report leak\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (IsAsan()) {
if (!OutputHasSymbol(output, "strdup") ||
!OutputHasSymbol(output, "MemoryLeakCrash")) {
fprintf(stderr, "ERROR: crash report didn't backtrace allocation\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -206,7 +206,7 @@ TEST(ShowCrashReports, testStackOverrunCrash) {
/* NULL is stopgap until we can copy symbol tablces into binary */
if (!OutputHasSymbol(output, "StackOverrunCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (strstr(output, "'int' index 10 into 'char [10]' out of bounds")) {
@ -215,12 +215,12 @@ TEST(ShowCrashReports, testStackOverrunCrash) {
// asan nailed it
if (!strstr(output, "☺☻♥♦♣♠•◘○")) {
fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "stack overrun")) {
fprintf(stderr, "ERROR: crash report misclassified stack overrun\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -315,7 +315,7 @@ TEST(ShowCrashReports, testDivideByZero) {
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "FpuCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
@ -323,29 +323,29 @@ TEST(ShowCrashReports, testDivideByZero) {
// UBSAN handled it
} else {
// ShowCrashReports() handled it
if (!strstr(output, gc(xasprintf("%d", pid)))) {
if (!strstr(output, _gc(xasprintf("%d", pid)))) {
fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "SIGFPE")) {
fprintf(stderr, "ERROR: crash report didn't have signal name\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "3.141")) {
fprintf(stderr, "ERROR: crash report didn't have fpu register\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "0f0e0d0c0b0a09080706050403020100")) {
fprintf(stderr, "ERROR: crash report didn't have sse register\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "3133731337")) {
fprintf(stderr, "ERROR: crash report didn't have general register\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -393,31 +393,31 @@ TEST(ShowCrashReports, testStackOverflow) {
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "StackOverflow")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
// ShowCrashReports() handled it
if (!strstr(output, gc(xasprintf("%d", pid)))) {
if (!strstr(output, _gc(xasprintf("%d", pid)))) {
fprintf(stderr, "ERROR: crash report didn't have pid\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!strstr(output, "SIGSEGV")) {
fprintf(stderr, "ERROR: crash report didn't have signal name\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
if (!IsTiny()) {
if (!strstr(output, "Stack Overflow")) {
fprintf(stderr, "ERROR: crash report didn't have 'Stack Overflow'\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
} else {
if (!strstr(output, "SEGV_MAPERR")) {
fprintf(stderr, "ERROR: crash report didn't have 'SEGV_MAPERR'\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -508,14 +508,14 @@ TEST(ShowCrashReports, testBssOverrunCrash) {
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "BssOverrunCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, "'int' index 10 into 'char [10]' out of bounds") &&
(!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone"))) {
fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
free(output);
@ -585,13 +585,13 @@ TEST(ShowCrashReports, testNpeCrash) {
/* NULL is stopgap until we can copy symbol tables into binary */
if (!strstr(output, "null pointer")) {
fprintf(stderr, "ERROR: crash report didn't diagnose the problem\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "NpeCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
@ -601,7 +601,7 @@ TEST(ShowCrashReports, testNpeCrash) {
// asan nailed it
if (!strstr(output, "∅∅∅∅")) {
fprintf(stderr, "ERROR: crash report didn't have shadow diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
}
@ -645,14 +645,14 @@ TEST(ShowCrashReports, testDataOverrunCrash) {
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "DataOverrunCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif
if (!strstr(output, "'int' index 10 into 'char [10]' out of bounds") &&
(!strstr(output, "☺☻♥♦♣♠•◘○") || !strstr(output, "global redzone"))) {
fprintf(stderr, "ERROR: crash report didn't have memory diagram\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
free(output);
@ -699,13 +699,13 @@ TEST(ShowCrashReports, testNpeCrashAfterFinalize) {
/* NULL is stopgap until we can copy symbol tables into binary */
if (!strstr(output, IsAsan() ? "null pointer" : "Uncaught SIGSEGV (SEGV_")) {
fprintf(stderr, "ERROR: crash report didn't diagnose the problem\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#ifdef __FNO_OMIT_FRAME_POINTER__
if (!OutputHasSymbol(output, "NpeCrash")) {
fprintf(stderr, "ERROR: crash report didn't have backtrace\n%s\n",
gc(IndentLines(output, -1, 0, 4)));
_gc(IndentLines(output, -1, 0, 4)));
__die();
}
#endif

View file

@ -19,8 +19,8 @@
#include "libc/log/libfatal.internal.h"
#include "libc/mem/arena.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -1,110 +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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/intrin/bits.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(comparator, testByteCompare) {
char *b1 = malloc(1);
char *b2 = malloc(1);
/* sign doesn't matter */
EXPECT_EQ(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0);
EXPECT_LT(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0);
EXPECT_GT(cmpsb(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0);
EXPECT_EQ(cmpub(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0);
EXPECT_LT(cmpub(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0);
EXPECT_GT(cmpub(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0);
/* sign matters */
EXPECT_EQ(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0);
EXPECT_LT(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0);
EXPECT_GT(cmpsb(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0);
EXPECT_EQ(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0);
EXPECT_GT(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0);
EXPECT_LT(cmpub(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0);
/* two's complement bane */
EXPECT_GT(cmpsb(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0);
EXPECT_LT(cmpub(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0);
free(b2);
free(b1);
}
TEST(comparator, testWordCompare) {
char *b1 = malloc(2);
char *b2 = malloc(2);
EXPECT_EQ(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0);
EXPECT_GT(cmpsw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0);
EXPECT_LT(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0);
EXPECT_EQ(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0);
EXPECT_LT(cmpuw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0);
EXPECT_GT(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0);
free(b2);
free(b1);
}
TEST(comparator, testDoublewordCompare) {
char *b1 = malloc(4);
char *b2 = malloc(4);
EXPECT_EQ(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4),
memcpy(b2, "\x00\x00\x00\x80", 4)),
0);
EXPECT_GT(cmpsl(memcpy(b1, "\x00\x00\x00\x7f", 4),
memcpy(b2, "\x00\x00\x00\x80", 4)),
0);
EXPECT_LT(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4),
memcpy(b2, "\x00\x00\x00\x7f", 4)),
0);
EXPECT_EQ(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4),
memcpy(b2, "\x00\x00\x00\x80", 4)),
0);
EXPECT_LT(cmpul(memcpy(b1, "\x00\x00\x00\x7f", 4),
memcpy(b2, "\x00\x00\x00\x80", 4)),
0);
EXPECT_GT(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4),
memcpy(b2, "\x00\x00\x00\x7f", 4)),
0);
free(b2);
free(b1);
}
TEST(comparator, testQuadwordCompare) {
char *b1 = malloc(8);
char *b2 = malloc(8);
EXPECT_EQ(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
0);
EXPECT_GT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
0);
EXPECT_LT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)),
0);
EXPECT_EQ(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
0);
EXPECT_LT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
0);
EXPECT_GT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)),
0);
free(b2);
free(b1);
}

View file

@ -23,7 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -24,7 +24,7 @@
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"

View file

@ -19,9 +19,8 @@
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
@ -29,6 +28,14 @@
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
int CompareInt(const void *a, const void *b) {
const int *x = a;
const int *y = b;
if (*x < *y) return -1;
if (*x > *y) return +1;
return 0;
}
int CompareLong(const void *a, const void *b) {
const long *x = a;
const long *y = b;
@ -46,7 +53,7 @@ TEST(qsort, test) {
{99, 'f'}, {782, 'i'}};
int32_t(*M)[2] = malloc(sizeof(A));
memcpy(M, B, sizeof(A));
qsort(M, ARRAYLEN(A), sizeof(*M), cmpsl);
qsort(M, ARRAYLEN(A), sizeof(*M), CompareInt);
EXPECT_EQ(0, memcmp(M, B, sizeof(B)));
free(M);
}
@ -54,9 +61,9 @@ TEST(qsort, test) {
TEST(qsort, equivalence_random) {
size_t i;
size_t n = 1000;
long *a = gc(malloc(n * sizeof(long)));
long *b = gc(malloc(n * sizeof(long)));
long *c = gc(malloc(n * sizeof(long)));
long *a = _gc(malloc(n * sizeof(long)));
long *b = _gc(malloc(n * sizeof(long)));
long *c = _gc(malloc(n * sizeof(long)));
for (i = 0; i < n; ++i) a[i] = lemur64();
memcpy(b, a, n * sizeof(long));
memcpy(c, a, n * sizeof(long));
@ -70,16 +77,16 @@ TEST(qsort, equivalence_random) {
smoothsort(c, n, sizeof(long), CompareLong);
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
memcpy(c, a, n * sizeof(long));
longsort(c, n);
_longsort(c, n);
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
}
TEST(qsort, equivalence_reverse) {
size_t i;
size_t n = 1000;
long *a = gc(malloc(n * sizeof(long)));
long *b = gc(malloc(n * sizeof(long)));
long *c = gc(malloc(n * sizeof(long)));
long *a = _gc(malloc(n * sizeof(long)));
long *b = _gc(malloc(n * sizeof(long)));
long *c = _gc(malloc(n * sizeof(long)));
for (i = 0; i < n; ++i) a[n - i - 1] = i;
memcpy(b, a, n * sizeof(long));
memcpy(c, a, n * sizeof(long));
@ -93,15 +100,15 @@ TEST(qsort, equivalence_reverse) {
smoothsort(c, n, sizeof(long), CompareLong);
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
memcpy(c, a, n * sizeof(long));
longsort(c, n);
_longsort(c, n);
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
}
BENCH(qsort, bench) {
size_t i;
size_t n = 1000;
long *p1 = gc(malloc(n * sizeof(long)));
long *p2 = gc(malloc(n * sizeof(long)));
long *p1 = _gc(malloc(n * sizeof(long)));
long *p2 = _gc(malloc(n * sizeof(long)));
printf("\n");
for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1);
@ -113,8 +120,8 @@ BENCH(qsort, bench) {
mergesort(p2, n, sizeof(long), CompareLong));
EZBENCH2("smoothsort nearly", memcpy(p2, p1, n * sizeof(long)),
smoothsort(p2, n, sizeof(long), CompareLong));
EZBENCH2("longsort nearly", memcpy(p2, p1, n * sizeof(long)),
longsort(p2, n));
EZBENCH2("_longsort nearly", memcpy(p2, p1, n * sizeof(long)),
_longsort(p2, n));
printf("\n");
for (i = 0; i < n; ++i) p1[i] = n - i;
@ -126,8 +133,8 @@ BENCH(qsort, bench) {
mergesort(p2, n, sizeof(long), CompareLong));
EZBENCH2("smoothsort reverse", memcpy(p2, p1, n * sizeof(long)),
smoothsort(p2, n, sizeof(long), CompareLong));
EZBENCH2("longsort reverse", memcpy(p2, p1, n * sizeof(long)),
longsort(p2, n));
EZBENCH2("_longsort reverse", memcpy(p2, p1, n * sizeof(long)),
_longsort(p2, n));
printf("\n");
rngset(p1, n * sizeof(long), 0, 0);
@ -139,8 +146,8 @@ BENCH(qsort, bench) {
mergesort(p2, n, sizeof(long), CompareLong));
EZBENCH2("smoothsort random", memcpy(p2, p1, n * sizeof(long)),
smoothsort(p2, n, sizeof(long), CompareLong));
EZBENCH2("longsort random", memcpy(p2, p1, n * sizeof(long)),
longsort(p2, n));
EZBENCH2("_longsort random", memcpy(p2, p1, n * sizeof(long)),
_longsort(p2, n));
printf("\n");
for (i = 0; i < n / 2; ++i) {
@ -155,5 +162,5 @@ BENCH(qsort, bench) {
mergesort(p2, n, sizeof(long), CompareLong));
EZBENCH2("smoothsort 2n", memcpy(p2, p1, n * sizeof(long)),
smoothsort(p2, n, sizeof(long), CompareLong));
EZBENCH2("longsort 2n", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n));
EZBENCH2("_longsort 2n", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n));
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -16,26 +16,26 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/errno.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/alg.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
TEST(replacestr, demo) {
TEST(_replacestr, demo) {
EXPECT_STREQ("hello friends",
gc(replacestr("hello world", "world", "friends")));
EXPECT_STREQ("bbbbbbbb", gc(replacestr("aaaa", "a", "bb")));
_gc(_replacestr("hello world", "world", "friends")));
EXPECT_STREQ("bbbbbbbb", _gc(_replacestr("aaaa", "a", "bb")));
}
TEST(replacestr, emptyString) {
EXPECT_STREQ("", gc(replacestr("", "x", "y")));
TEST(_replacestr, emptyString) {
EXPECT_STREQ("", _gc(_replacestr("", "x", "y")));
}
TEST(replacestr, emptyNeedle) {
EXPECT_EQ(NULL, gc(replacestr("a", "", "a")));
TEST(_replacestr, emptyNeedle) {
EXPECT_EQ(NULL, _gc(_replacestr("a", "", "a")));
EXPECT_EQ(EINVAL, errno);
}
TEST(replacestr, needleInReplacement_doesntExplode) {
EXPECT_STREQ("xxxxxxx", gc(replacestr("x", "x", "xxxxxxx")));
TEST(_replacestr, needleInReplacement_doesntExplode) {
EXPECT_STREQ("xxxxxxx", _gc(_replacestr("x", "x", "xxxxxxx")));
}

View file

@ -1,37 +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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
╚─────────────────────────────────────────────────────────────────────────────*/
TEST(REPLACESTR, demo) {
EXPECT_STREQ(S("hello friends"),
REPLACESTR(S("hello world"), S("world"), S("friends")));
EXPECT_STREQ(S("bbbbbbbb"), REPLACESTR(S("aaaa"), S("a"), S("bb")));
}
TEST(REPLACESTR, emptyString) {
EXPECT_STREQ(S(""), REPLACESTR(S(""), S("x"), S("y")));
}
TEST(REPLACESTR, emptyNeedle) {
EXPECT_EQ(NULL, REPLACESTR(S("a"), S(""), S("a")));
EXPECT_EQ(EINVAL, errno);
}
TEST(REPLACESTR, needleInReplacement_doesntExplode) {
EXPECT_STREQ(S("xxxxxxx"), REPLACESTR(S("x"), S("x"), S("xxxxxxx")));
}

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/macros.internal.h"
#include "libc/mem/alg.h"
#include "libc/testlib/testlib.h"
STATIC_YOINK("realloc");
@ -27,7 +27,7 @@ TEST(tarjan, empty_doesNothing) {
int edges[][2] = {{0, 0}};
int vertex_count = 0;
int edge_count = 0;
tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL);
_tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL);
ASSERT_EQ(-1, sorted_vertices[0]);
}
@ -53,8 +53,8 @@ TEST(tarjan, topologicalSort_noCycles) {
A
*/
int sorted[4], components[4], componentcount;
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
EXPECT_EQ(C, sorted[0]);
EXPECT_EQ(D, sorted[1]);
EXPECT_EQ(B, sorted[2]);
@ -76,8 +76,8 @@ TEST(tarjan, testOneBigCycle_isDetected_weDontCareAboutOrderInsideTheCycle) {
{C /* depends on → */, D /* which must come before C */},
{D /* depends on → */, A /* which must come before D */}};
int sorted[4], components[4], componentcount;
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
ASSERT_EQ(1, componentcount);
EXPECT_EQ(4, components[0]);
}
@ -110,8 +110,8 @@ TEST(tarjan, testHeaders) {
int sorted[ARRAYLEN(vertices)];
int components[ARRAYLEN(vertices)];
int componentcount;
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
sorted, components, &componentcount));
ASSERT_EQ(ARRAYLEN(vertices), componentcount);
EXPECT_STREQ("libc/dce.h", vertices[sorted[0]]);
EXPECT_STREQ("libc/integral.h", vertices[sorted[1]]);

View file

@ -19,15 +19,15 @@
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
TEST(cescapec, test) {
EXPECT_EQ(' ', cescapec(0x20));
EXPECT_EQ('~', cescapec(0x7E));
EXPECT_EQ('\\' | 'r' << 8, cescapec('\r'));
EXPECT_EQ('\\' | 'n' << 8, cescapec('\n'));
EXPECT_EQ('\\' | '0' << 8 | '0' << 16 | '0' << 24, cescapec(0));
EXPECT_EQ('\\' | '0' << 8 | '3' << 16 | '3' << 24, cescapec('\e'));
EXPECT_EQ('\\' | '1' << 8 | '7' << 16 | '7' << 24, cescapec(0x7F));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(0xFFFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, cescapec(-1));
TEST(_cescapec, test) {
EXPECT_EQ(' ', _cescapec(0x20));
EXPECT_EQ('~', _cescapec(0x7E));
EXPECT_EQ('\\' | 'r' << 8, _cescapec('\r'));
EXPECT_EQ('\\' | 'n' << 8, _cescapec('\n'));
EXPECT_EQ('\\' | '0' << 8 | '0' << 16 | '0' << 24, _cescapec(0));
EXPECT_EQ('\\' | '0' << 8 | '3' << 16 | '3' << 24, _cescapec('\e'));
EXPECT_EQ('\\' | '1' << 8 | '7' << 16 | '7' << 24, _cescapec(0x7F));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(0xFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(0xFFFF));
EXPECT_EQ('\\' | '3' << 8 | '7' << 16 | '7' << 24, _cescapec(-1));
}

View file

@ -20,8 +20,8 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/gc.internal.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
void *_memset(void *, int, size_t) asm("memset");

View file

@ -19,7 +19,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -18,32 +18,13 @@
*/
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/timespec.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/log/backtrace.internal.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/clone.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/nr.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"
#include "libc/thread/tls.h"
#include "libc/thread/tls2.h"
#include "libc/thread/wait0.internal.h"
#include "libc/time/time.h"
int x, me, tid;
atomic_int thechilde;

View file

@ -19,6 +19,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/ucontext.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/bits.h"
@ -27,8 +28,8 @@
#include "libc/linux/mmap.h"
#include "libc/linux/munmap.h"
#include "libc/log/log.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
@ -42,7 +43,7 @@
#include "libc/sysv/consts/sig.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xspawn.h"
#include "third_party/xed/x86.h"
char testlib_enable_tmp_setup_teardown;
@ -206,15 +207,15 @@ TEST(isheap, nullPtr) {
}
TEST(isheap, malloc) {
ASSERT_TRUE(_isheap(gc(malloc(1))));
ASSERT_TRUE(_isheap(_gc(malloc(1))));
}
TEST(isheap, emptyMalloc) {
ASSERT_TRUE(_isheap(gc(malloc(0))));
ASSERT_TRUE(_isheap(_gc(malloc(0))));
}
TEST(isheap, mallocOffset) {
char *p = gc(malloc(131072));
char *p = _gc(malloc(131072));
ASSERT_TRUE(_isheap(p + 100000));
}

View file

@ -22,8 +22,8 @@
#include "libc/errno.h"
#include "libc/fmt/fmt.h"
#include "libc/log/log.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -60,7 +60,7 @@ void OnSigBus(int sig, struct siginfo *si, void *vctx) {
#if 0
kprintf("SIGBUS%n");
kprintf("si->si_signo = %G%n", si->si_signo);
kprintf("si->si_errno = %s (%d)%n", strerrno(si->si_errno),
kprintf("si->si_errno = %s (%d)%n", _strerrno(si->si_errno),
si->si_errno);
kprintf("si->si_code = %s (%d)%n", GetSiCodeName(sig, si->si_code),
si->si_code);
@ -111,7 +111,7 @@ TEST(mprotect, testSegfault_writeToReadOnlyAnonymous) {
EXPECT_FALSE(gotsegv);
EXPECT_FALSE(gotbusted);
EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_READ));
missingno(p[0]);
_missingno(p[0]);
EXPECT_FALSE(gotsegv);
EXPECT_FALSE(gotbusted);
p[0] = 2;
@ -139,7 +139,7 @@ TEST(mprotect, testProtNone_cantEvenRead) {
volatile char *p;
p = gc(memalign(PAGESIZE, PAGESIZE));
EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_NONE));
missingno(p[0]);
_missingno(p[0]);
EXPECT_TRUE(gotsegv | gotbusted);
EXPECT_NE(-1, mprotect(p, PAGESIZE, PROT_READ | PROT_WRITE));
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/sockaddr.h"

View file

@ -21,7 +21,7 @@
#include "libc/calls/struct/iovec.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/sock/sock.h"
#include "libc/sock/struct/msghdr.h"
#include "libc/sock/struct/sockaddr.h"

View file

@ -19,7 +19,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"

View file

@ -20,13 +20,14 @@
#include "libc/calls/struct/dirent.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/dt.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
#include "libc/x/xiso8601.h"
STATIC_YOINK("zip_uri_support");
STATIC_YOINK("usr/share/zoneinfo/New_York");
@ -110,9 +111,9 @@ TEST(dirstream, test) {
bool hasfoo = false;
bool hasbar = false;
char *dpath, *file1, *file2;
dpath = gc(xasprintf("%s.%d", "dirstream", rand()));
file1 = gc(xasprintf("%s/%s", dpath, "foo"));
file2 = gc(xasprintf("%s/%s", dpath, "bar"));
dpath = _gc(xasprintf("%s.%d", "dirstream", rand()));
file1 = _gc(xasprintf("%s/%s", dpath, "foo"));
file2 = _gc(xasprintf("%s/%s", dpath, "bar"));
EXPECT_NE(-1, mkdir(dpath, 0755));
EXPECT_NE(-1, touch(file1, 0644));
EXPECT_NE(-1, touch(file2, 0644));
@ -151,9 +152,9 @@ TEST(rewinddir, test) {
bool hasfoo = false;
bool hasbar = false;
char *dpath, *file1, *file2;
dpath = gc(xasprintf("%s.%d", "dirstream", rand()));
file1 = gc(xasprintf("%s/%s", dpath, "foo"));
file2 = gc(xasprintf("%s/%s", dpath, "bar"));
dpath = _gc(xasprintf("%s.%d", "dirstream", rand()));
file1 = _gc(xasprintf("%s/%s", dpath, "foo"));
file2 = _gc(xasprintf("%s/%s", dpath, "bar"));
EXPECT_NE(-1, mkdir(dpath, 0755));
EXPECT_NE(-1, touch(file1, 0644));
EXPECT_NE(-1, touch(file2, 0644));

View file

@ -23,7 +23,7 @@
#include "libc/macros.internal.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/runtime/stack.h"
#include "libc/stdio/stdio.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/hex.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -17,14 +17,15 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
TEST(fcvt, test) {
int decpt, sign;
ASSERT_STREQ("3.14159265358979",
gc(xasprintf("%.14f", 3.14159265358979323846)));
_gc(xasprintf("%.14f", 3.14159265358979323846)));
ASSERT_STREQ("3141592653589793",
fcvt(3.14159265358979323846, 15, &decpt, &sign));
ASSERT_EQ(1, decpt);

View file

@ -17,18 +17,18 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/mem/gc.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xgetline.h"
TEST(fgetln, test) {
FILE *f;
f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+");
f = fmemopen(_gc(strdup(kHyperion)), kHyperionSize, "r+");
EXPECT_STREQ("The fall of Hyperion - a Dream\n", fgetln(f, 0));
EXPECT_STREQ("John Keats\n", fgetln(f, 0));
EXPECT_STREQ("\n", fgetln(f, 0));
@ -81,7 +81,7 @@ TEST(fgetln, testReadingFromStdin_doesntLeakMemory) {
}
BENCH(fgetln, bench) {
FILE *f = fmemopen(gc(strdup(kHyperion)), kHyperionSize, "r+");
FILE *f = fmemopen(_gc(strdup(kHyperion)), kHyperionSize, "r+");
EZBENCH2("fgetln", donothing, fgetln(f, 0));
EZBENCH2("xgetline", donothing, free(xgetline(f)));
fclose(f);

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"

View file

@ -22,7 +22,7 @@
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/iconv.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/intrin/bits.h"
#include "libc/mem/mem.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/stdio/strlist.internal.h"
#include "libc/testlib/testlib.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/stdio/stdio.h"
#include "libc/testlib/testlib.h"

View file

@ -22,7 +22,7 @@
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/grnd.h"

View file

@ -21,14 +21,14 @@
#include "libc/calls/struct/stat.h"
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/temp.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
char testlib_enable_tmp_setup_teardown;
char oldtmpdir[PATH_MAX];
@ -82,7 +82,7 @@ TEST(tmpfile, renameToRealFile) {
f = tmpfile();
ASSERT_EQ(2, fputs("hi", f));
ASSERT_SYS(0, 0,
linkat(AT_FDCWD, gc(xasprintf("/proc/self/fd/%d", fileno(f))),
linkat(AT_FDCWD, _gc(xasprintf("/proc/self/fd/%d", fileno(f))),
AT_FDCWD, "real", AT_SYMLINK_FOLLOW));
ASSERT_EQ(0, fclose(f));
ASSERT_NE(NULL, (f = fopen("real", "r")));

View file

@ -18,7 +18,7 @@
*/
#include "libc/intrin/bits.h"
#include "libc/mem/mem.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/append.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -16,11 +16,11 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/nexgen32e/bsr.h"
#include "libc/intrin/bsr.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
static unsigned Bsr(unsigned x) {
static unsigned _Bsr(unsigned x) {
static const char kDebruijn[32] = {
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31,
@ -35,6 +35,8 @@ static unsigned Bsr(unsigned x) {
return kDebruijn[x];
}
TEST(bsr, test) {
ASSERT_EQ(bsr(0xffffffff), Bsr(0xffffffff));
TEST(_bsr, test) {
for (int i = 1; i < 1000; ++i) {
ASSERT_EQ(_bsr(i), _Bsr(i));
}
}

View file

@ -18,7 +18,7 @@
*/
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -21,7 +21,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -23,7 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"

View file

@ -17,10 +17,10 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/alg.h"
#include "libc/mem/gc.internal.h"
#include "libc/mem/mem.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/rand.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -33,23 +33,23 @@ int CompareLong(const void *a, const void *b) {
return 0;
}
TEST(longsort, test) {
TEST(_longsort, test) {
size_t n = 5000;
long *a = gc(calloc(n, sizeof(long)));
long *b = gc(calloc(n, sizeof(long)));
rngset(a, n * sizeof(long), 0, 0);
memcpy(b, a, n * sizeof(long));
qsort(a, n, sizeof(long), CompareLong);
longsort(b, n);
_longsort(b, n);
ASSERT_EQ(0, memcmp(b, a, n * sizeof(long)));
}
BENCH(longsort, bench) {
BENCH(_longsort, bench) {
size_t n = 1000;
long *p1 = gc(malloc(n * sizeof(long)));
long *p2 = gc(malloc(n * sizeof(long)));
rngset(p1, n * sizeof(long), 0, 0);
EZBENCH2("longsort", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n));
EZBENCH2("_longsort", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n));
EZBENCH2("qsort", memcpy(p2, p1, n * sizeof(long)),
qsort(p2, n, sizeof(long), CompareLong));
}

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -17,7 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -23,7 +23,7 @@
#include "libc/mem/mem.h"
#include "libc/nexgen32e/cachesize.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -21,7 +21,7 @@
#include "libc/dce.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/str/internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"

View file

@ -20,7 +20,7 @@
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/tpenc.h"
#include "libc/intrin/tpenc.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
@ -28,34 +28,34 @@ STATIC_YOINK("strwidth");
volatile uint64_t v;
TEST(tpenc, test) {
EXPECT_EQ(0, tpenc(0));
EXPECT_EQ(1, tpenc(1));
EXPECT_EQ(' ', tpenc(' '));
EXPECT_EQ(0x7f, tpenc(0x7f));
EXPECT_EQ(0x008496E2, tpenc(L''));
EXPECT_EQ(0x8080808080FEul, tpenc(INT_MIN));
TEST(_tpenc, test) {
EXPECT_EQ(0, _tpenc(0));
EXPECT_EQ(1, _tpenc(1));
EXPECT_EQ(' ', _tpenc(' '));
EXPECT_EQ(0x7f, _tpenc(0x7f));
EXPECT_EQ(0x008496E2, _tpenc(L''));
EXPECT_EQ(0x8080808080FEul, _tpenc(INT_MIN));
}
TEST(tpenc, theimp) {
ASSERT_EQ(0x88989FF0, tpenc(L'😈'));
TEST(_tpenc, theimp) {
ASSERT_EQ(0x88989FF0, _tpenc(L'😈'));
}
TEST(tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, tpenc(-1));
TEST(_tpenc, testBeyondTheStandard) {
ASSERT_EQ(0xBFBFBFBFBFFF, _tpenc(-1));
}
uint64_t Tpenc(int x) {
return (v = EXPROPRIATE(tpenc(VEIL("r", x))));
uint64_t _Tpenc(int x) {
return (v = EXPROPRIATE(_tpenc(VEIL("r", x))));
}
BENCH(tpenc, bench) {
EZBENCH(donothing, Tpenc(0));
EZBENCH(donothing, Tpenc(1));
EZBENCH(donothing, Tpenc(' '));
EZBENCH(donothing, Tpenc(0x7f));
EZBENCH(donothing, Tpenc(L''));
EZBENCH(donothing, Tpenc(-1));
EZBENCH(donothing, Tpenc(INT_MIN));
BENCH(_tpenc, bench) {
EZBENCH(donothing, _Tpenc(0));
EZBENCH(donothing, _Tpenc(1));
EZBENCH(donothing, _Tpenc(' '));
EZBENCH(donothing, _Tpenc(0x7f));
EZBENCH(donothing, _Tpenc(L''));
EZBENCH(donothing, _Tpenc(-1));
EZBENCH(donothing, _Tpenc(INT_MIN));
fprintf(stderr, "\n");
}

View file

@ -1,168 +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
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/undeflate.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#include "libc/sysv/consts/s.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/hyperion.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/zip.h"
#include "libc/zipos/zipos.internal.h"
#include "third_party/zlib/puff.h"
#include "third_party/zlib/zlib.h"
STATIC_YOINK("zip_uri_support");
STATIC_YOINK("libc/testlib/hyperion.txt");
TEST(undeflate, testEmbeddedPlaintextConstant) {
EXPECT_STARTSWITH("The fall of Hyperion - a Dream", kHyperion);
}
TEST(undeflate, testStatCentralDirectory_notFound_noSysCalls) {
uint64_t c;
struct stat st;
stat("/zip/doge.txt", &st); /* warmup */
c = __syscount;
ASSERT_EQ(-1, stat("/zip/doge.txt", &st));
ASSERT_EQ(0, __syscount - c);
ASSERT_EQ(ENOENT, errno);
}
TEST(undeflate, testStatCentralDirectory_isFound_noSysCalls) {
uint64_t c;
struct stat st = {0};
c = __syscount;
ASSERT_NE(-1, stat("/zip/libc/testlib/hyperion.txt", &st));
ASSERT_TRUE(S_ISREG(st.st_mode));
ASSERT_EQ(kHyperionSize, st.st_size);
ASSERT_EQ(0, __syscount - c);
}
TEST(undeflate, testOpenReadCloseEmbeddedZip) {
int fd;
char *data;
ASSERT_NE(-1, (fd = open("/zip/libc/testlib/hyperion.txt", O_RDONLY)));
ASSERT_NE(NULL, (data = gc(malloc(kHyperionSize))));
ASSERT_EQ(kHyperionSize, read(fd, data, kHyperionSize));
EXPECT_EQ(0, memcmp(kHyperion, data, kHyperionSize));
EXPECT_NE(-1, close(fd));
}
TEST(undeflate, testEmbeddedCompressedZipFile_theHardWay) {
int fd;
size_t i;
bool found;
struct stat st;
struct DeflateState ds;
uint8_t *map, *cd, *cf, *lf, *data;
found = false;
ASSERT_NE(-1, (fd = open(FindComBinary(), O_RDONLY)));
ASSERT_NE(-1, fstat(fd, &st));
ASSERT_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0)));
ASSERT_NE(NULL, (cd = GetZipCdir(map, st.st_size)));
ASSERT_GE(ZIP_CDIR_RECORDS(cd), 1);
for (i = 0, cf = map + ZIP_CDIR_OFFSET(cd); i < ZIP_CDIR_RECORDS(cd);
++i, cf += ZIP_CFILE_HDRSIZE(cf)) {
if (strncmp("libc/testlib/hyperion.txt", ZIP_CFILE_NAME(cf),
ZIP_CFILE_NAMESIZE(cf)) == 0) {
lf = map + ZIP_CFILE_OFFSET(cf);
ASSERT_EQ(kZipCompressionDeflate, ZIP_LFILE_COMPRESSIONMETHOD(lf));
ASSERT_EQ(kHyperionSize, ZIP_LFILE_UNCOMPRESSEDSIZE(lf));
undeflate((data = gc(xmalloc(ZIP_LFILE_UNCOMPRESSEDSIZE(lf) * 24))),
ZIP_LFILE_UNCOMPRESSEDSIZE(lf), ZIP_LFILE_CONTENT(lf),
ZIP_LFILE_COMPRESSEDSIZE(lf), &ds);
ASSERT_EQ(ZIP_LFILE_CRC32(lf),
crc32_z(0, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf)));
ASSERT_EQ(0, memcmp(kHyperion, data, ZIP_LFILE_UNCOMPRESSEDSIZE(lf)));
found = true;
break;
}
}
ASSERT_NE(-1, munmap(map, st.st_size));
ASSERT_NE(-1, close(fd));
ASSERT_TRUE(found);
}
uint8_t *buf_;
size_t bufsize_;
uint8_t *data_;
size_t compressedsize_;
size_t uncompressedsize_;
struct DeflateState ds_;
void Inflate(void) {
z_stream stream;
stream.next_in = data_;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.avail_in = compressedsize_;
stream.total_in = compressedsize_;
stream.next_out = buf_;
stream.avail_out = bufsize_;
stream.total_out = bufsize_;
CHECK_EQ(Z_OK, inflateInit2(&stream, -MAX_WBITS));
CHECK_EQ(Z_STREAM_END, inflate(&stream, Z_FINISH));
CHECK_EQ(Z_OK, inflateEnd(&stream));
}
void Undeflate(void) {
undeflate(buf_, uncompressedsize_, data_, compressedsize_, &ds_);
}
void Puff(void) {
size_t insize = compressedsize_;
size_t outsize = uncompressedsize_;
CHECK_EQ(0, puff(buf_, &outsize, data_, &insize));
}
BENCH(undeflate, bench) {
size_t cf, lf;
struct Zipos *zipos;
struct ZiposUri path;
zipos = __zipos_get();
path.path = "libc/testlib/hyperion.txt";
path.len = strlen(path.path);
cf = __zipos_find(zipos, &path);
lf = GetZipCfileOffset(zipos->map + cf);
data_ = ZIP_LFILE_CONTENT(zipos->map + lf);
compressedsize_ = ZIP_LFILE_COMPRESSEDSIZE(zipos->map + lf);
uncompressedsize_ = ZIP_LFILE_UNCOMPRESSEDSIZE(zipos->map + lf);
bufsize_ = ROUNDUP(uncompressedsize_, FRAMESIZE / 2);
buf_ = gc(malloc(bufsize_));
EZBENCH(donothing, Puff());
EZBENCH(donothing, Inflate());
EZBENCH(donothing, Undeflate());
}

View file

@ -21,7 +21,7 @@
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"
#include "libc/thread/thread.h"

View file

@ -18,7 +18,7 @@
*/
#include "libc/atomic.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/mem/gc.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"
#include "libc/thread/thread.h"

View file

@ -23,7 +23,7 @@
#include "libc/intrin/atomic.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/runtime/internal.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/spawn.h"

View file

@ -19,7 +19,7 @@
#include "libc/calls/struct/timespec.h"
#include "libc/fmt/conv.h"
#include "libc/macros.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/mem/gc.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/clock.h"
#include "libc/testlib/testlib.h"

View file

@ -17,22 +17,22 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/math.h"
#include "libc/mem/gc.h"
#include "libc/stdio/rand.h"
#include "libc/runtime/gc.internal.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/x/x.h"
#include "libc/x/xasprintf.h"
double acos_(double) asm("acos");
#define acos acos_
TEST(acos, test) {
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(0.))));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(-0.))));
EXPECT_STREQ("1.0471975511966", gc(xasprintf("%.15g", acos(.5))));
EXPECT_STREQ("2.0943951023932", gc(xasprintf("%.15g", acos(-.5))));
EXPECT_STREQ("0", gc(xasprintf("%.15g", acos(1.))));
EXPECT_STREQ("3.14159265358979", gc(xasprintf("%.15g", acos(-1.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(0.))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(-0.))));
EXPECT_STREQ("1.0471975511966", _gc(xasprintf("%.15g", acos(.5))));
EXPECT_STREQ("2.0943951023932", _gc(xasprintf("%.15g", acos(-.5))));
EXPECT_STREQ("0", _gc(xasprintf("%.15g", acos(1.))));
EXPECT_STREQ("3.14159265358979", _gc(xasprintf("%.15g", acos(-1.))));
EXPECT_TRUE(isnan(acos(1.5)));
EXPECT_TRUE(isnan(acos(-1.5)));
EXPECT_TRUE(isnan(acos(2.)));
@ -40,7 +40,7 @@ TEST(acos, test) {
EXPECT_TRUE(isnan(acos(-NAN)));
EXPECT_TRUE(isnan(acos(INFINITY)));
EXPECT_TRUE(isnan(acos(-INFINITY)));
EXPECT_STREQ("1.5707963267949", gc(xasprintf("%.15g", acos(__DBL_MIN__))));
EXPECT_STREQ("1.5707963267949", _gc(xasprintf("%.15g", acos(__DBL_MIN__))));
EXPECT_TRUE(isnan(acos(__DBL_MAX__)));
}

Some files were not shown because too many files have changed in this diff Show more