5 // Copyright (c) 2019 Apple Inc. All rights reserved.
11 #import <XCTest/XCTest.h>
14 #define XCTest_Framework_Runtime_Path "/AppleInternal/Developer/Library/Frameworks/XCTest.framework/XCTest"
16 #define XCTest_Framework_Runtime_Path "/Developer/Library/Frameworks/XCTest.framework/XCTest"
19 //===========================================================================================================================
21 //===========================================================================================================================
22 static bool _load_xctest_framework()
24 bool loaded = (NSClassFromString(@"XCTestSuite") != nil);
25 static void *s_xctest_handle;
27 s_xctest_handle = dlopen(XCTest_Framework_Runtime_Path, RTLD_LAZY | RTLD_LOCAL);
28 loaded = (NSClassFromString(@"XCTestSuite") != nil);
30 fprintf(stderr, "%s Failed to load XCTest framework from: %s\n", __FUNCTION__, XCTest_Framework_Runtime_Path);
36 //===========================================================================================================================
38 //===========================================================================================================================
40 bool run_xctest_named(const char *classname)
43 if (_load_xctest_framework()) {
44 NSString *name = [NSString stringWithUTF8String:classname];
45 NSBundle *testBundle = [NSBundle bundleWithPath:@"/AppleInternal/XCTests/com.apple.mDNSResponder/Tests.xctest"];
48 XCTestSuite *compiledSuite = [NSClassFromString(@"XCTestSuite") testSuiteForTestCaseWithName: name];
49 if (compiledSuite.tests.count) {
50 [compiledSuite runTest];
51 XCTestRun *testRun = compiledSuite.testRun;
52 result = (testRun.hasSucceeded != NO);
54 fprintf(stderr, "%s Test class %s not found\n", __FUNCTION__, classname);
60 bool audit_token_for_pid(pid_t pid, const audit_token_t *token)
64 mach_msg_type_number_t info_size = TASK_AUDIT_TOKEN_COUNT;
66 err = task_for_pid(mach_task_self(), pid, &task);
67 if (err != KERN_SUCCESS) {
71 err = task_info(task, TASK_AUDIT_TOKEN, (integer_t *) token, &info_size);
72 if (err != KERN_SUCCESS) {