Skip to content

Commit

Permalink
tests: fix pthread_attr() test for host libc
Browse files Browse the repository at this point in the history
  • Loading branch information
Geertiebear committed Jul 7, 2022
1 parent 38f1cd6 commit 2c4e8cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ host_libc_excluded_test_cases = [
]
host_libc_noasan_test_cases = [
'posix/pthread_cancel',
'posix/pthread_attr', # does some stack overflowing to check stack size
'posix/posix_memalign',
'posix/search', # requires tdelete (#351)
]
Expand Down
13 changes: 11 additions & 2 deletions tests/posix/pthread_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <alloca.h>
#include <string.h>
#include <sys/mman.h>
#include <signal.h>

static void test_detachstate() {
pthread_attr_t attr;
Expand Down Expand Up @@ -101,7 +102,8 @@ static void *stackaddr_worker(void *arg) {
assert(addr >= sp);
return NULL;
}

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
static void test_stackaddr() {
pthread_attr_t attr;
assert(!pthread_attr_init(&attr));
Expand All @@ -119,7 +121,9 @@ static void test_stackaddr() {
assert(!pthread_create(&thread, &attr, stackaddr_worker, &addr));
assert(!pthread_join(thread, NULL));
}
#pragma GCC diagnostic pop

#if !defined(USE_HOST_LIBC) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32)
static void test_stack() {
pthread_attr_t attr;
void *stackaddr = (void*)1;
Expand All @@ -132,6 +136,7 @@ static void test_stack() {
assert(new_addr == stackaddr);
assert(new_size == stacksize);
}
#endif

static void test_affinity() {
pthread_attr_t attr;
Expand All @@ -145,6 +150,7 @@ static void test_affinity() {
assert(!memcmp(&set, &other_set, sizeof(cpu_set_t)));
}

#if !defined(USE_HOST_LIBC) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32)
static void test_sigmask() {
pthread_attr_t attr;
sigset_t set;
Expand Down Expand Up @@ -195,6 +201,7 @@ static void test_getattrnp() {
// of the stack.
assert(!*(char*)(stack + other_stacksize - 1));
}
#endif

int main() {
test_detachstate();
Expand All @@ -205,8 +212,10 @@ int main() {
test_schedparam();
test_schedpolicy();
test_stackaddr();
test_stack();
test_affinity();
#if !defined(USE_HOST_LIBC) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 32)
test_stack();
test_sigmask();
test_getattrnp();
#endif
}

0 comments on commit 2c4e8cc

Please sign in to comment.