mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 11:48:30 +00:00
parent
95f54eeb40
commit
c1d99676c4
1421 changed files with 5556 additions and 2198 deletions
|
@ -53,6 +53,12 @@ void testlib_benchwarmup(void) {
|
|||
*/
|
||||
void testlib_runallbenchmarks(void) {
|
||||
int e;
|
||||
e = errno;
|
||||
if (!IsWindows()) {
|
||||
mlockall(MCL_CURRENT);
|
||||
nice(-1);
|
||||
}
|
||||
errno = e;
|
||||
__log_level = kLogWarn;
|
||||
testlib_runtestcases(__bench_start, __bench_end, testlib_benchwarmup);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/x/x.h"
|
||||
|
|
|
@ -1,24 +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 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/errno.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int testlib_geterrno(void) {
|
||||
return errno;
|
||||
}
|
|
@ -1,24 +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 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/errno.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
void testlib_seterrno(int x) {
|
||||
errno = x;
|
||||
}
|
|
@ -19,13 +19,11 @@
|
|||
#include "libc/bits/atomic.h"
|
||||
#include "libc/bits/safemacros.internal.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
const char *testlib_showerror_errno;
|
||||
|
|
|
@ -1,25 +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 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/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
const char *testlib_strerror(void) {
|
||||
return strerror(errno);
|
||||
}
|
|
@ -1,11 +1,14 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_TESTLIB_H_
|
||||
#define COSMOPOLITAN_LIBC_TESTLIB_H_
|
||||
#include "libc/bits/weaken.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ugly.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § testing library ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#include "libc/macros.internal.h"
|
||||
|
||||
/**
|
||||
* Declares test case function.
|
||||
|
@ -63,34 +66,6 @@ COSMOPOLITAN_C_START_
|
|||
#define EXPECT_LE(C, X) _TEST2("EXPECT_LE", C, <=, (X), #C, " ≤ ", #X, 0)
|
||||
#define EXPECT_LT(C, X) _TEST2("EXPECT_LT", C, <, (X), #C, " < ", #X, 0)
|
||||
|
||||
#define __TEST_ARRAY(S) \
|
||||
_Section(".piro.relo.sort.testcase.2." #S ",\"aw\",@init_array #")
|
||||
|
||||
#define __BENCH_ARRAY(S) \
|
||||
_Section(".piro.relo.sort.bench.2." #S ",\"aw\",@init_array #")
|
||||
|
||||
#define __TEST_PROTOTYPE(S, N, A, K) \
|
||||
void S##_##N(void); \
|
||||
testfn_t S##_##N##_ptr[] A(S##_##N) = {S##_##N}; \
|
||||
testonly K void S##_##N(void)
|
||||
|
||||
#define __TEST_SECTION(NAME, CONTENT) \
|
||||
".section " NAME "\n" CONTENT "\n\t.previous\n"
|
||||
|
||||
#define __RELOSECTION(NAME, CONTENT) \
|
||||
__TEST_SECTION(".piro.relo.sort" NAME ",\"aw\",@progbits", CONTENT)
|
||||
|
||||
#define __ROSTR(STR) __TEST_SECTION(".rodata.str1.1,\"aSM\",@progbits,1", STR)
|
||||
|
||||
#define __FIXTURE(KIND, GROUP, ENTRY) \
|
||||
asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \
|
||||
"\t.quad\t1f\n" \
|
||||
"\t.quad\t2f\n" \
|
||||
"\t.quad\t" STRINGIFY(GROUP##_##ENTRY)) \
|
||||
__ROSTR("1:\t.asciz\t" STRINGIFY(#GROUP)) \
|
||||
__ROSTR("2:\t.asciz\t" STRINGIFY(#ENTRY))); \
|
||||
testonly void GROUP##_##ENTRY(void)
|
||||
|
||||
/**
|
||||
* Enables setup and teardown of test directories.
|
||||
*
|
||||
|
@ -138,12 +113,12 @@ void TearDownOnce(void);
|
|||
|
||||
#define ASSERT_SYS(ERRNO, WANT, GOT, ...) \
|
||||
do { \
|
||||
int e = testlib_geterrno(); \
|
||||
int e = errno; \
|
||||
__TEST_EQ(assert, __FILE__, __LINE__, __FUNCTION__, #WANT, #GOT, WANT, \
|
||||
GOT, __VA_ARGS__); \
|
||||
__TEST_EQ(assert, __FILE__, __LINE__, __FUNCTION__, #ERRNO, \
|
||||
testlib_strerror(), ERRNO, testlib_geterrno(), __VA_ARGS__); \
|
||||
testlib_seterrno(e); \
|
||||
strerror(errno), ERRNO, errno, __VA_ARGS__); \
|
||||
errno = e; \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_BETWEEN(BEG, END, GOT) \
|
||||
|
@ -213,11 +188,11 @@ void TearDownOnce(void);
|
|||
|
||||
#define EXPECT_SYS(ERRNO, WANT, GOT, ...) \
|
||||
do { \
|
||||
testlib_seterrno(0); \
|
||||
errno = 0; \
|
||||
__TEST_EQ(expect, __FILE__, __LINE__, __FUNCTION__, #WANT, #GOT, WANT, \
|
||||
GOT, __VA_ARGS__); \
|
||||
__TEST_EQ(expect, __FILE__, __LINE__, __FUNCTION__, #ERRNO, \
|
||||
testlib_strerror(), ERRNO, testlib_geterrno(), __VA_ARGS__); \
|
||||
strerror(errno), ERRNO, errno, __VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define EXPECT_FALSE(X) _TEST2("EXPECT_FALSE", false, ==, (X), #X, "", "", 0)
|
||||
|
@ -375,10 +350,7 @@ void testlib_showerror(const char *, int, const char *, const char *,
|
|||
void thrashcodecache(void);
|
||||
|
||||
void testlib_finish(void);
|
||||
int testlib_geterrno(void);
|
||||
void testlib_seterrno(int);
|
||||
void testlib_runalltests(void);
|
||||
const char *testlib_strerror(void);
|
||||
void testlib_runallbenchmarks(void);
|
||||
void testlib_runtestcases(testfn_t *, testfn_t *, testfn_t);
|
||||
void testlib_runcombos(testfn_t *, testfn_t *, const struct TestFixture *,
|
||||
|
|
|
@ -24,6 +24,7 @@ LIBC_TESTLIB_A_HDRS = \
|
|||
libc/testlib/fastrandomstring.h \
|
||||
libc/testlib/hyperion.h \
|
||||
libc/testlib/moby.h \
|
||||
libc/testlib/ugly.h \
|
||||
libc/testlib/testlib.h
|
||||
|
||||
LIBC_TESTLIB_A_SRCS_S = \
|
||||
|
@ -51,9 +52,6 @@ LIBC_TESTLIB_A_SRCS_C = \
|
|||
libc/testlib/almostequallongdouble.c \
|
||||
libc/testlib/benchrunner.c \
|
||||
libc/testlib/getcore.c \
|
||||
libc/testlib/geterrno.c \
|
||||
libc/testlib/seterrno.c \
|
||||
libc/testlib/strerror.c \
|
||||
libc/testlib/getinterrupts.c \
|
||||
libc/testlib/ezbenchwarn.c \
|
||||
libc/testlib/binequals.c \
|
||||
|
|
35
libc/testlib/ugly.h
Normal file
35
libc/testlib/ugly.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_TESTLIB_UGLY_H_
|
||||
#define COSMOPOLITAN_LIBC_TESTLIB_UGLY_H_
|
||||
#include "libc/macros.internal.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define __TEST_ARRAY(S) \
|
||||
_Section(".piro.relo.sort.testcase.2." #S ",\"aw\",@init_array #")
|
||||
|
||||
#define __BENCH_ARRAY(S) \
|
||||
_Section(".piro.relo.sort.bench.2." #S ",\"aw\",@init_array #")
|
||||
|
||||
#define __TEST_PROTOTYPE(S, N, A, K) \
|
||||
void S##_##N(void); \
|
||||
testfn_t S##_##N##_ptr[] A(S##_##N) = {S##_##N}; \
|
||||
testonly K void S##_##N(void)
|
||||
|
||||
#define __TEST_SECTION(NAME, CONTENT) \
|
||||
".section " NAME "\n" CONTENT "\n\t.previous\n"
|
||||
|
||||
#define __RELOSECTION(NAME, CONTENT) \
|
||||
__TEST_SECTION(".piro.relo.sort" NAME ",\"aw\",@progbits", CONTENT)
|
||||
|
||||
#define __ROSTR(STR) __TEST_SECTION(".rodata.str1.1,\"aSM\",@progbits,1", STR)
|
||||
|
||||
#define __FIXTURE(KIND, GROUP, ENTRY) \
|
||||
asm(__RELOSECTION("." KIND ".2." #GROUP #ENTRY, \
|
||||
"\t.quad\t1f\n" \
|
||||
"\t.quad\t2f\n" \
|
||||
"\t.quad\t" STRINGIFY(GROUP##_##ENTRY)) \
|
||||
__ROSTR("1:\t.asciz\t" STRINGIFY(#GROUP)) \
|
||||
__ROSTR("2:\t.asciz\t" STRINGIFY(#ENTRY))); \
|
||||
testonly void GROUP##_##ENTRY(void)
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_TESTLIB_UGLY_H_ */
|
Loading…
Add table
Add a link
Reference in a new issue