Files
clang-p2996/compiler-rt/test/sanitizer_common/TestCases/Linux/pthread_getaffinity_np.cpp
David Spickett d231efe1ee [compiler-rt] Relax pthread_getaffinity test to account for cgroups/docker
Fixes #58283

When running in a docker container you can have fewer cores assigned
to you than get_nrpoc would suggest.

Since the test just wants to know that interception worked, allow
any result > 0 and <= the global core count.

Reviewed By: MaskRay, vitalybuka

Differential Revision: https://reviews.llvm.org/D135677
2022-10-17 10:45:30 +00:00

24 lines
574 B
C++

// RUN: %clangxx -O0 %s -o %t && %run %t
// Android does not implement pthread_getaffinity_np.
// (Note: libresolv is integrated with libc, but apparently only
// sched_getaffinity).
// UNSUPPORTED: android
#include <assert.h>
#include <pthread.h>
#include <sys/sysinfo.h>
#include <sanitizer/msan_interface.h>
int main() {
cpu_set_t set_x[4];
pthread_t tid = pthread_self();
int res = pthread_getaffinity_np(tid, sizeof(set_x), set_x);
assert(res == 0);
int cpus = CPU_COUNT_S(sizeof(set_x), set_x);
assert(cpus > 0 && cpus <= get_nprocs());
return 0;
}