]> git.saurik.com Git - apple/configd.git/blob - sctest/SCTest.m
configd-963.270.3.tar.gz
[apple/configd.git] / sctest / SCTest.m
1 /*
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #import "SCTest.h"
25
26 @implementation SCTest
27
28 - (instancetype)initWithOptions:(NSDictionary *)options
29 {
30 self = [super init];
31 if (self) {
32 self.options = options;
33 self.globalCPU = malloc(sizeof(CPUUsageInfo));
34 self.globalTimer = malloc(sizeof(timerInfo));
35 }
36 return self;
37 }
38
39 - (void)dealloc
40 {
41 if (self.globalTimer != NULL) {
42 free(self.globalTimer);
43 }
44 if (self.globalCPU != NULL) {
45 free(self.globalCPU);
46 }
47 }
48
49 + (NSString *)command
50 {
51 return @"sctest";
52 }
53
54 + (NSString *)commandDescription
55 {
56 return @"This is a generic class";
57 }
58
59 + (NSString *)commandHelp
60 {
61 return @"This is a generic help";
62 }
63
64 - (void)start
65 {
66 return;
67 }
68
69 - (void)waitFor:(double)seconds
70 {
71 dispatch_semaphore_t sem = dispatch_semaphore_create(0);
72 dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
73 dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 0);
74 dispatch_source_set_event_handler(timer, ^{
75 dispatch_semaphore_signal(sem);
76 });
77 dispatch_resume(timer);
78 dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
79 }
80
81 - (void)cleanupAndExitWithErrorCode:(int)error
82 {
83 if (self.options[kSCTestGlobalOptionTime] != nil) {
84 timerEnd(self.globalTimer);
85 SCTestLog("Time: %@ s", createUsageStringForTimer(self.globalTimer));
86 }
87
88 if (self.options[kSCTestGlobalOptionCPU] != nil) {
89 cpuEnd(self.globalCPU);
90 SCTestLog("CPU: %@", createUsageStringForCPU(self.globalCPU));
91 }
92
93 if (self.options[kSCTestGlobalOptionWait] != nil) {
94 return;
95 }
96 exit(error);
97 }
98
99 - (BOOL)unitTest
100 {
101 return YES;
102 }
103
104 @end