Hunt down more bugs

After going through the MODE=dbg and MODE=zero build modes, a bunch of
little issues were identified, which have been addressed. Fixing those
issues created even more troubles for the project, because it improved
our ability to detect latent problems which are getting fixed so fast.
This commit is contained in:
Justine Tunney 2023-07-03 17:35:11 -07:00
parent 73c0faa1b5
commit 97b7116953
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
39 changed files with 557 additions and 754 deletions

View file

@ -54,6 +54,7 @@ TEST(getcontext, test) {
TEST(getcontext, canReadAndWriteSignalMask) {
sigset_t ss, old;
volatile int n = 0;
EXPECT_TRUE(__interruptible);
sigemptyset(&ss);
sigaddset(&ss, SIGUSR1);
sigprocmask(SIG_SETMASK, &ss, &old);
@ -81,7 +82,10 @@ void SetGetContext(void) {
}
BENCH(getcontext, bench) {
EZBENCH2("get/setcontext", donothing, SetGetContext());
__interruptible = false;
EZBENCH2("getsetcontext nosig", donothing, SetGetContext());
__interruptible = true;
EZBENCH2("getsetcontext", donothing, SetGetContext());
}
BENCH(swapcontext, bench) {
@ -95,7 +99,11 @@ BENCH(swapcontext, bench) {
}
} else {
ready = true;
EZBENCH2("x2 swapcontext", donothing, swapcontext(&loop, &main));
__interruptible = false;
EZBENCH2("swapcontextx2 nosig", donothing, swapcontext(&loop, &main));
// kprintf("dollar\n");
__interruptible = true;
EZBENCH2("swapcontextx2", donothing, swapcontext(&loop, &main));
// kprintf("dollar\n");
}
}

View file

@ -1,401 +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 2023 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/stdckdint.h"
#include "libc/macros.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#define FAIL ++failed < 100
#define uintmax_t uint128_t
#define T int
#define TBIT (sizeof(T) * CHAR_BIT - 1)
#define TMIN (((T) ~(T)0) > 1 ? (T)0 : (T)((uintmax_t)1 << TBIT))
#define TMAX (((T) ~(T)0) > 1 ? (T) ~(T)0 : (T)(((uintmax_t)1 << TBIT) - 1))
T Vint[] = {5, 4, 2, 77, 4, 7,
0, 1, 2, 3, 4, -1,
-2, -3, -4, TMIN, TMIN + 1, TMIN + 2,
TMIN + 3, TMIN + 5, TMIN + 7, TMAX, TMAX - 1, TMAX - 2,
TMAX - 77, TMAX - 3, TMAX - 5, TMAX - 7, TMAX - 50, TMIN / 2,
TMAX / 2, TMAX / 2 - 3};
#undef TMAX
#undef TMIN
#undef TBIT
#undef T
#define T long
#define TBIT (sizeof(T) * CHAR_BIT - 1)
#define TMIN (((T) ~(T)0) > 1 ? (T)0 : (T)((uintmax_t)1 << TBIT))
#define TMAX (((T) ~(T)0) > 1 ? (T) ~(T)0 : (T)(((uintmax_t)1 << TBIT) - 1))
T Vlong[] = {5, 4, 2, 77, 4, 7,
0, 1, 2, 3, 4, -1,
-2, -3, -4, TMIN, TMIN + 1, TMIN + 2,
TMIN + 3, TMIN + 5, TMIN + 7, TMAX, TMAX - 1, TMAX - 2,
TMAX - 77, TMAX - 3, TMAX - 5, TMAX - 7, TMAX - 50, TMIN / 2,
TMAX / 2, TMAX / 2 - 3};
#undef TMAX
#undef TMIN
#undef TBIT
#undef T
#define T __int128
#define TBIT (sizeof(T) * CHAR_BIT - 1)
#define TMIN (((T) ~(T)0) > 1 ? (T)0 : (T)((uintmax_t)1 << TBIT))
#define TMAX (((T) ~(T)0) > 1 ? (T) ~(T)0 : (T)(((uintmax_t)1 << TBIT) - 1))
T Vint128[] = {5, 4, 2, 77, 4, 7,
0, 1, 2, 3, 4, -1,
-2, -3, -4, TMIN, TMIN + 1, TMIN + 2,
TMIN + 3, TMIN + 5, TMIN + 7, TMAX, TMAX - 1, TMAX - 2,
TMAX - 77, TMAX - 3, TMAX - 5, TMAX - 7, TMAX - 50, TMIN / 2,
TMAX / 2, TMAX / 2 - 3};
#undef TMAX
#undef TMIN
#undef TBIT
#undef T
int failed;
void test_ckd_add(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "add %d + %d = %d vs. %d\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "add %d + %d overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_sub(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "sub %d - %d = %d vs. %d\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "sub %d - %d overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mul(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "mul %d * %d = %d vs. %d\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "mul %d * %d overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_add_long(void) {
for (long i = 0; i < ARRAYLEN(Vlong); ++i) {
long x = Vlong[i];
for (long j = 0; j < ARRAYLEN(Vlong); ++j) {
long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "add %ld + %ld = %ld vs. %ld\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "add %ld + %ld overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_sub_long(void) {
for (long i = 0; i < ARRAYLEN(Vlong); ++i) {
long x = Vlong[i];
for (long j = 0; j < ARRAYLEN(Vlong); ++j) {
long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "sub %ld - %ld = %ld vs. %ld\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "sub %ld - %ld overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mul_long(void) {
for (long i = 0; i < ARRAYLEN(Vlong); ++i) {
long x = Vlong[i];
for (long j = 0; j < ARRAYLEN(Vlong); ++j) {
long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "mul %ld * %ld = %ld vs. %ld\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "mul %ld * %ld overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_add_int128(void) {
for (int128_t i = 0; i < ARRAYLEN(Vint128); ++i) {
int128_t x = Vint128[i];
for (int128_t j = 0; j < ARRAYLEN(Vint128); ++j) {
int128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "add %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "add %jjd * %jjd overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_sub_int128(void) {
for (int128_t i = 0; i < ARRAYLEN(Vint128); ++i) {
int128_t x = Vint128[i];
for (int128_t j = 0; j < ARRAYLEN(Vint128); ++j) {
int128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "sub %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "sub %jjd * %jjd overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mul_int128(void) {
for (int128_t i = 0; i < ARRAYLEN(Vint128); ++i) {
int128_t x = Vint128[i];
for (int128_t j = 0; j < ARRAYLEN(Vint128); ++j) {
int128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "mul %jjd * %jjd = %jjd vs. %jjd\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "mul %jjd * %jjd overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_addu(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
unsigned int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
unsigned int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "unsigned add %u + %u = %u vs. %u\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "unsigned add %u + %u overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_subu(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
unsigned int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
unsigned int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "unsigned sub %u - %u = %u vs. %u\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "unsigned sub %u - %u overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mulu(void) {
for (int i = 0; i < ARRAYLEN(Vint); ++i) {
unsigned int x = Vint[i];
for (int j = 0; j < ARRAYLEN(Vint); ++j) {
unsigned int z1, z2, o1, o2, y = Vint[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "unsigned mul %u * %u = %u vs. %u\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "unsigned mul %u * %u overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_addul(void) {
for (int i = 0; i < ARRAYLEN(Vlong); ++i) {
unsigned long x = Vlong[i];
for (int j = 0; j < ARRAYLEN(Vlong); ++j) {
unsigned long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "ulong add %lu + %lu = %lu vs. %lu\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "ulong add %lu + %lu overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_subul(void) {
for (int i = 0; i < ARRAYLEN(Vlong); ++i) {
unsigned long x = Vlong[i];
for (int j = 0; j < ARRAYLEN(Vlong); ++j) {
unsigned long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "ulong sub %lu - %lu = %lu vs. %lu\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "ulong sub %lu - %lu overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mulul(void) {
for (int i = 0; i < ARRAYLEN(Vlong); ++i) {
unsigned long x = Vlong[i];
for (int j = 0; j < ARRAYLEN(Vlong); ++j) {
unsigned long z1, z2, o1, o2, y = Vlong[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "ulong mul %lu * %lu = %lu vs. %lu\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "ulong mul %lu * %lu overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_addull(void) {
for (int i = 0; i < ARRAYLEN(Vint128); ++i) {
uint128_t x = Vint128[i];
for (int j = 0; j < ARRAYLEN(Vint128); ++j) {
uint128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_add(&z1, x, y);
o2 = __builtin_add_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "u128 add %jju + %jju = %jju vs. %jju\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "u128 add %jju + %jju overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_subull(void) {
for (int i = 0; i < ARRAYLEN(Vint128); ++i) {
uint128_t x = Vint128[i];
for (int j = 0; j < ARRAYLEN(Vint128); ++j) {
uint128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_sub(&z1, x, y);
o2 = __builtin_sub_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "u128 sub %jju - %jju = %jju vs. %jju\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "u128 sub %jju - %jju overflow disagreement\n", x, y);
}
}
}
}
void test_ckd_mulull(void) {
for (int i = 0; i < ARRAYLEN(Vint128); ++i) {
uint128_t x = Vint128[i];
for (int j = 0; j < ARRAYLEN(Vint128); ++j) {
uint128_t z1, z2, o1, o2, y = Vint128[i];
o1 = ckd_mul(&z1, x, y);
o2 = __builtin_mul_overflow(x, y, &z2);
if (z1 != z2 && FAIL) {
fprintf(stderr, "u128 mul %jju * %jju = %jju vs. %jju\n", x, y, z1, z2);
}
if (o1 != o2 && FAIL) {
fprintf(stderr, "u128 mul %jju * %jju overflow disagreement\n", x, y);
}
}
}
}
int main(int argc, char *argv[]) {
test_ckd_add();
test_ckd_sub();
test_ckd_mul();
test_ckd_add_long();
test_ckd_sub_long();
test_ckd_mul_long();
test_ckd_add_int128();
test_ckd_sub_int128();
test_ckd_mul_int128();
test_ckd_addu();
test_ckd_subu();
test_ckd_mulu();
test_ckd_addul();
test_ckd_subul();
test_ckd_mulul();
test_ckd_addull();
test_ckd_subull();
test_ckd_mulull();
return failed ? 1 : 0;
}

View file

@ -58,14 +58,6 @@ o/$(MODE)/test/libc/intrin/%.com.dbg: \
$(APE_NO_MODIFY_SELF)
@$(APELINK)
o/$(MODE)/test/libc/intrin/stdckdint_test.com.dbg: \
$(TEST_LIBC_INTRIN_DEPS) \
o/$(MODE)/test/libc/intrin/stdckdint_test.o \
o/$(MODE)/test/libc/intrin/intrin.pkg \
$(CRT) \
$(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) \

View file

@ -31,14 +31,46 @@
#include "libc/x/x.h"
#include "third_party/libcxx/math.h"
ucontext_t uc;
bool gotsome;
ucontext_t uc, goback;
char testlib_enable_tmp_setup_teardown;
void itsatrap(int x, int y) {
void check_args(long x0, long x1, long x2, long x3, long x4, long x5, double f0,
double f1, double f2, double f3, double f4, double f5) {
EXPECT_EQ(LONG_MIN + 100, x0);
EXPECT_EQ(LONG_MIN + 101, x1);
EXPECT_EQ(LONG_MIN + 102, x2);
EXPECT_EQ(LONG_MIN + 103, x3);
EXPECT_EQ(LONG_MIN + 104, x4);
EXPECT_EQ(LONG_MIN + 105, x5);
EXPECT_TRUE(20. == f0);
EXPECT_TRUE(21. == f1);
EXPECT_TRUE(22. == f2);
EXPECT_TRUE(23. == f3);
EXPECT_TRUE(24. == f4);
EXPECT_TRUE(25. == f5);
gotsome = true;
}
TEST(makecontext, args) {
char stack[1024];
__interruptible = false;
getcontext(&uc);
uc.uc_link = &goback;
uc.uc_stack.ss_sp = stack;
uc.uc_stack.ss_size = sizeof(stack);
makecontext(&uc, check_args, 12, 20., 21., 22., LONG_MIN + 100,
LONG_MIN + 101, LONG_MIN + 102, LONG_MIN + 103, LONG_MIN + 104,
LONG_MIN + 105, 23., 24., 25.);
swapcontext(&goback, &uc);
EXPECT_TRUE(gotsome);
}
noasan noubsan void itsatrap(int x, int y) {
*(int *)(intptr_t)x = scalbn(x, y);
}
TEST(makecontext, test) {
TEST(makecontext, crash) {
SPAWN(fork);
getcontext(&uc);
uc.uc_link = 0;

View file

@ -156,7 +156,8 @@ TEST(pthread_create, testCustomStack_withReallySmallSize) {
ASSERT_EQ(0, pthread_create(&id, &attr, Increment, 0));
ASSERT_EQ(0, pthread_attr_destroy(&attr));
ASSERT_EQ(0, pthread_join(id, 0));
// we still own the stack memory
free(stk);
stk = malloc(siz);
ASSERT_EQ(0, pthread_attr_init(&attr));
ASSERT_EQ(0, pthread_attr_setstack(&attr, stk, siz));
ASSERT_EQ(0, pthread_create(&id, &attr, Increment, 0));

View file

@ -17,11 +17,41 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/atomic.h"
#include "libc/calls/calls.h"
#include "libc/calls/syscall-sysv.internal.h"
#include "libc/calls/syscall_support-sysv.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/intrin/atomic.h"
#include "libc/intrin/kprintf.h"
#include "libc/runtime/runtime.h"
#include "libc/testlib/testlib.h"
#include "libc/thread/thread.h"
void SetUpOnce(void) {
if (IsXnu()) {
tinyprint(2, program_invocation_short_name,
": no custom thread names on apple\n", NULL);
exit(0);
}
if (IsWindows()) {
tinyprint(2, program_invocation_short_name,
": no custom thread names on windows\n", NULL);
exit(0);
}
if (IsLinux() || IsOpenbsd()) {
char buf[512];
if (pthread_getname_np(pthread_self(), buf, sizeof(buf)) == ENOSYS) {
tinyprint(2, program_invocation_short_name,
": kernel too old for thread name support\n", NULL);
exit(0);
}
}
}
static void *SetName(void *arg) {
ASSERT_EQ(0, pthread_setname_np(pthread_self(), "justine"));
return 0;
@ -29,7 +59,6 @@ static void *SetName(void *arg) {
TEST(pthread_setname_np, SetName_SystemCallSucceeds) {
pthread_t id;
if (!IsLinux() || !IsNetbsd() || !IsFreebsd()) return;
ASSERT_EQ(0, pthread_create(&id, 0, SetName, 0));
ASSERT_EQ(0, pthread_join(id, 0));
}
@ -44,25 +73,14 @@ static void *SetGetNameOfSelf(void *arg) {
TEST(pthread_setname_np, SetGetNameOfSelf) {
pthread_t id;
if (!IsLinux() || !IsNetbsd()) return;
if (IsFreebsd()) {
// no get thread name no freebsd (why??)
return;
}
ASSERT_EQ(0, pthread_create(&id, 0, SetGetNameOfSelf, 0));
ASSERT_EQ(0, pthread_join(id, 0));
}
static void *GetDefaultName(void *arg) {
char me[16];
ASSERT_EQ(0, pthread_getname_np(pthread_self(), me, sizeof(me)));
EXPECT_STREQ("", me);
return 0;
}
TEST(pthread_setname_np, GetDefaultName_IsEmptyString) {
pthread_t id;
if (!IsLinux() || !IsNetbsd()) return;
ASSERT_EQ(0, pthread_create(&id, 0, GetDefaultName, 0));
ASSERT_EQ(0, pthread_join(id, 0));
}
atomic_char sync1, sync2;
static void *GetNameOfOtherThreadWorker(void *arg) {
@ -75,10 +93,15 @@ static void *GetNameOfOtherThreadWorker(void *arg) {
TEST(pthread_setname_np, GetNameOfOtherThread) {
char me[16];
pthread_t id;
if (!IsLinux() || !IsNetbsd()) return;
if (IsFreebsd()) {
// no get thread name no freebsd (why??)
return;
}
ASSERT_EQ(0, pthread_create(&id, 0, GetNameOfOtherThreadWorker, 0));
while (!atomic_load(&sync1)) pthread_yield();
ASSERT_EQ(0, pthread_getname_np(id, me, sizeof(me)));
errno_t e = pthread_getname_np(id, me, sizeof(me));
if (IsLinux() && e == ENOENT) return; // bah old kernel
ASSERT_EQ(0, e);
EXPECT_STREQ("justine", me);
ASSERT_EQ(0, pthread_setname_np(id, "tunney"));
ASSERT_EQ(0, pthread_getname_np(id, me, sizeof(me)));

View file

@ -108,7 +108,7 @@ TEST(sem_close, withUnnamedSemaphore_isUndefinedBehavior) {
SPAWN(fork);
IgnoreStderr();
sem_close(&sem);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
ASSERT_SYS(0, 0, sem_destroy(&sem));
}
@ -119,7 +119,7 @@ TEST(sem_destroy, withNamedSemaphore_isUndefinedBehavior) {
SPAWN(fork);
IgnoreStderr();
sem_destroy(sem);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
ASSERT_SYS(0, 0, sem_unlink("/boop"));
ASSERT_SYS(0, 0, sem_close(sem));
}

View file

@ -51,7 +51,7 @@ TEST(sem_post, afterDestroyed_isUndefinedBehavior) {
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_post(&sem);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
}
TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) {
@ -63,7 +63,7 @@ TEST(sem_trywait, afterDestroyed_isUndefinedBehavior) {
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_trywait(&sem);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
}
TEST(sem_wait, afterDestroyed_isUndefinedBehavior) {
@ -75,7 +75,7 @@ TEST(sem_wait, afterDestroyed_isUndefinedBehavior) {
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_wait(&sem);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
}
TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) {
@ -87,7 +87,7 @@ TEST(sem_timedwait, afterDestroyed_isUndefinedBehavior) {
ASSERT_SYS(0, 0, sem_destroy(&sem));
IgnoreStderr();
sem_timedwait(&sem, 0);
EXITS(128 + SIGILL); // see __assert_fail
EXITS(128 + SIGABRT); // see __assert_fail
}
void *Worker(void *arg) {

View file

@ -32,6 +32,7 @@ TEST_LIBC_THREAD_DIRECTDEPS = \
LIBC_STDIO \
LIBC_STR \
LIBC_SYSV \
LIBC_SYSV_CALLS \
LIBC_TESTLIB \
LIBC_THREAD \
LIBC_TIME \