dyld-832.7.1.tar.gz
[apple/dyld.git] / testing / test-cases / kernel-test-runner.h
1
2 #if __has_feature(ptrauth_calls)
3 #include <ptrauth.h>
4 #endif
5
6 typedef unsigned long long uint64_t;
7 extern int printf(const char*, ...);
8 extern void exit(int);
9
10 #if __cplusplus
11 extern "C" {
12 #endif /* __cplusplus */
13 __attribute__((format(printf, 3, 4)))
14 __attribute__ ((noreturn))
15 extern void _PASS(const char* file, unsigned line, const char* format, ...);
16
17 __attribute__((format(printf, 3, 4)))
18 __attribute__ ((noreturn))
19 extern void _FAIL(const char* file, unsigned line, const char* format, ...);
20
21 __attribute__((format(printf, 3, 4)))
22 extern void _LOG(const char* file, unsigned line, const char* format, ...);
23
24 extern void _TIMEOUT(const char* file, unsigned line, uint64_t seconds);
25 #if __cplusplus
26 };
27 #endif /* __cplusplus */
28
29 // The arm64e kernel/userland ABIs sign C function pointers differently.
30 // We aren't trying to test that ABI, so lets just force a different signature
31 #if __has_feature(ptrauth_calls)
32 # define PtrAuth __ptrauth(ptrauth_key_function_pointer, 1, 0xc671)
33 #else
34 # define PtrAuth
35 #endif
36
37 typedef struct TestRunnerFunctions {
38 uint64_t version;
39 const struct mach_header* mhs[4];
40 const void* basePointers[4];
41 PtrAuth __typeof(&printf) printf;
42 PtrAuth __typeof(&exit) exit;
43 PtrAuth __typeof(&_PASS) testPass;
44 PtrAuth __typeof(&_FAIL) testFail;
45 PtrAuth __typeof(&_LOG) testLog;
46 PtrAuth __typeof(&_TIMEOUT) testTimeout;
47 } TestRunnerFunctions;
48
49 static const TestRunnerFunctions* funcs = 0;
50
51 #define PASS(...) funcs->testPass(__FILE__,__LINE__,__VA_ARGS__)
52 #define FAIL(...) funcs->testFail(__FILE__,__LINE__,__VA_ARGS__)
53 #define LOG(...) funcs->testLog(__FILE__,__LINE__,__VA_ARGS__)
54 #define TIMEOUT(seconds) funcs->testTimeout(__FILE__,__LINE__,seconds)
55
56 #if __x86_64__
57 __attribute__((section(("__HIB, __text"))))
58 #else
59 __attribute__((section(("__TEXT_EXEC, __text"))))
60 #endif
61 static inline void setFuncs(const TestRunnerFunctions* v) {
62 funcs = v;
63 }