1 #include <darwintest.h>
2 #include <darwintest_utils.h>
3 #include <test_utils.h>
4
5 T_GLOBAL_META(
6 T_META_NAMESPACE("xnu.misc"),
7 T_META_RUN_CONCURRENTLY(true),
8 T_META_CHECK_LEAKS(false),
9 T_META_OWNER("gparker"));
10
11 static int64_t
run_sysctl_test(const char * t,int64_t value)12 run_sysctl_test(const char *t, int64_t value)
13 {
14 char name[1024];
15 int64_t result = 0;
16 size_t s = sizeof(value);
17 int rc;
18
19 snprintf(name, sizeof(name), "debug.test.%s", t);
20 rc = sysctlbyname(name, &result, &s, &value, s);
21 T_QUIET; T_ASSERT_POSIX_SUCCESS(rc, "sysctlbyname(%s)", t);
22 return result;
23 }
24
25 T_DECL(thread_test_context,
26 "infrastructure for threads running kernel tests",
27 XNU_T_META_REQUIRES_DEVELOPMENT_KERNEL)
28 {
29 int64_t bad_line = run_sysctl_test("thread_test_context", 0);
30 /* return value is one or two line numbers in thread.c */
31 int64_t bad_line_2 = bad_line >> 32;
32 bad_line = (bad_line << 32) >> 32;
33
34 if (bad_line_2) {
35 T_FAIL("error at osfmk/kern/thread.c:%lld from thread.c:%lld",
36 bad_line_2, bad_line);
37 } else if (bad_line) {
38 T_FAIL("error at osfmk/kern/thread.c:%lld",
39 bad_line);
40 } else {
41 T_PASS("thread_test_context");
42 }
43 }
44