Home | History | Annotate | Line # | Download | only in dnssdutil
      1 /*
      2  * Copyright (c) 2019-2024 Apple Inc. All rights reserved.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     https://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #import "TestUtils.h"
     18 
     19 #import <dlfcn.h>
     20 #import <XCTest/XCTest.h>
     21 
     22 //===========================================================================================================================
     23 //    Main Test Running
     24 //===========================================================================================================================
     25 
     26 bool run_xctest_named(const char *classname)
     27 {
     28     bool result = false;
     29 	NSString *name = [NSString stringWithUTF8String:classname];
     30 	NSBundle *testBundle = [NSBundle bundleWithPath:@"/AppleInternal/XCTests/com.apple.mDNSResponder/Tests.xctest"];
     31 	[testBundle load];
     32 
     33 	XCTestSuite *compiledSuite = [NSClassFromString(@"XCTestSuite") testSuiteForTestCaseWithName: name];
     34 	if (compiledSuite.tests.count) {
     35 		[compiledSuite runTest];
     36 		XCTestRun *testRun = compiledSuite.testRun;
     37 		result = (testRun.hasSucceeded != NO);
     38 	} else {
     39 		fprintf(stderr, "%s Test class %s not found\n", __FUNCTION__, classname);
     40 	}
     41     return result;
     42 }
     43 
     44 bool audit_token_for_pid(pid_t pid, const audit_token_t *token)
     45 {
     46     kern_return_t err;
     47     task_t task;
     48     mach_msg_type_number_t info_size = TASK_AUDIT_TOKEN_COUNT;
     49 
     50     err = task_name_for_pid(mach_task_self(), pid, &task);
     51     if (err != KERN_SUCCESS) {
     52         return false;
     53     }
     54 
     55     err = task_info(task, TASK_AUDIT_TOKEN, (integer_t *) token, &info_size);
     56     if (err != KERN_SUCCESS) {
     57         return false;
     58     }
     59 
     60     return true;
     61 }
     62