#include <pthread.h>
#include <stdio.h>
+#include <sys/sysctl.h>
#include "darwintest_defaults.h"
T_ASSERT_POSIX_ZERO(pthread_key_delete(key), NULL);
}
+
+static uint32_t
+get_ncpu(void)
+{
+ static uint32_t activecpu;
+ if (!activecpu) {
+ uint32_t n;
+ size_t s = sizeof(activecpu);
+ sysctlbyname("hw.activecpu", &n, &s, NULL, 0);
+ activecpu = n;
+ }
+ return activecpu;
+}
+
+T_DECL(cpuid, "cpu id", T_META_ALL_VALID_ARCHS(YES))
+{
+ pthread_t child;
+
+ size_t cpu_id;
+ if (pthread_cpu_number_np(&cpu_id)) {
+ T_FAIL("Should not fail to get CPU id");
+ }
+
+ T_ASSERT_LE(cpu_id, get_ncpu(), "Got a valid CPU id");
+}