2 * Copyright (c) 2018 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <darwintest.h>
29 #include <mach/port_descriptions.h>
31 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
34 expect_special_port_description(const char *(*fn
)(int),
35 mach_port_t port
, const char *namestr
)
37 const char *desc
= fn((int)port
);
38 T_EXPECT_NOTNULL(desc
, "%s is %s", namestr
, desc
);
40 T_QUIET
; T_EXPECT_GT(strlen(desc
), strlen(""),
41 "%s's description string is not empty", namestr
);
45 T_DECL(host_special_port_descriptions
,
46 "verify that host special ports can be described")
48 #define TEST_HSP(portdef) \
49 expect_special_port_description(mach_host_special_port_description, \
53 TEST_HSP(HOST_PRIV_PORT
);
54 TEST_HSP(HOST_IO_MASTER_PORT
);
55 TEST_HSP(HOST_DYNAMIC_PAGER_PORT
);
56 TEST_HSP(HOST_AUDIT_CONTROL_PORT
);
57 TEST_HSP(HOST_USER_NOTIFICATION_PORT
);
58 TEST_HSP(HOST_AUTOMOUNTD_PORT
);
59 TEST_HSP(HOST_LOCKD_PORT
);
60 TEST_HSP(HOST_KTRACE_BACKGROUND_PORT
);
61 TEST_HSP(HOST_SEATBELT_PORT
);
62 TEST_HSP(HOST_KEXTD_PORT
);
63 TEST_HSP(HOST_LAUNCHCTL_PORT
);
64 TEST_HSP(HOST_UNFREED_PORT
);
65 TEST_HSP(HOST_AMFID_PORT
);
66 TEST_HSP(HOST_GSSD_PORT
);
67 TEST_HSP(HOST_TELEMETRY_PORT
);
68 TEST_HSP(HOST_ATM_NOTIFICATION_PORT
);
69 TEST_HSP(HOST_COALITION_PORT
);
70 TEST_HSP(HOST_SYSDIAGNOSE_PORT
);
71 TEST_HSP(HOST_XPC_EXCEPTION_PORT
);
72 TEST_HSP(HOST_CONTAINERD_PORT
);
73 TEST_HSP(HOST_NODE_PORT
);
74 TEST_HSP(HOST_RESOURCE_NOTIFY_PORT
);
75 TEST_HSP(HOST_CLOSURED_PORT
);
76 TEST_HSP(HOST_SYSPOLICYD_PORT
);
77 TEST_HSP(HOST_FILECOORDINATIOND_PORT
);
78 TEST_HSP(HOST_FAIRPLAYD_PORT
);
79 TEST_HSP(HOST_IOCOMPRESSIONSTATS_PORT
);
83 T_EXPECT_EQ(HOST_IOCOMPRESSIONSTATS_PORT
, HOST_MAX_SPECIAL_PORT
,
84 "checked all of the ports");
86 const char *invalid_hsp
=
87 mach_host_special_port_description(HOST_MAX_SPECIAL_PORT
+ 1);
88 T_EXPECT_NULL(invalid_hsp
,
89 "invalid host special port description should be NULL");
92 T_DECL(task_special_port_descriptions
,
93 "verify that task special ports can be described")
95 #define TEST_TSP(portdef) \
96 expect_special_port_description(mach_task_special_port_description, \
99 TEST_TSP(TASK_KERNEL_PORT
);
100 TEST_TSP(TASK_READ_PORT
);
101 TEST_TSP(TASK_INSPECT_PORT
);
102 TEST_TSP(TASK_HOST_PORT
);
103 TEST_TSP(TASK_NAME_PORT
);
104 TEST_TSP(TASK_BOOTSTRAP_PORT
);
105 TEST_TSP(TASK_SEATBELT_PORT
);
106 TEST_TSP(TASK_ACCESS_PORT
);
107 TEST_TSP(TASK_DEBUG_CONTROL_PORT
);
108 TEST_TSP(TASK_RESOURCE_NOTIFY_PORT
);
112 T_EXPECT_EQ(TASK_RESOURCE_NOTIFY_PORT
, TASK_MAX_SPECIAL_PORT
,
113 "checked all of the ports");
115 const char *invalid_tsp
=
116 mach_task_special_port_description(TASK_MAX_SPECIAL_PORT
+ 1);
117 T_EXPECT_NULL(invalid_tsp
,
118 "invalid task special port description should be NULL");
121 T_DECL(thread_special_port_descriptions
,
122 "verify that thread special ports can be described")
124 #define TEST_TSP(portdef) \
125 expect_special_port_description(mach_thread_special_port_description, \
128 TEST_TSP(THREAD_KERNEL_PORT
);
129 TEST_TSP(THREAD_READ_PORT
);
130 TEST_TSP(THREAD_INSPECT_PORT
);
134 T_EXPECT_EQ(THREAD_READ_PORT
, THREAD_MAX_SPECIAL_PORT
,
135 "checked all of the ports");
137 const char *invalid_tsp
=
138 mach_thread_special_port_description(THREAD_MAX_SPECIAL_PORT
+ 1);
139 T_EXPECT_NULL(invalid_tsp
,
140 "invalid thread special port description should be NULL");
144 expect_special_port_id(int (*fn
)(const char *id
), int port
, const char *portid
)
146 int observed_port
= fn(portid
);
148 T_EXPECT_EQ(observed_port
, port
, "%s is %d", portid
, observed_port
);
151 T_DECL(host_special_port_mapping
,
152 "verify that task special port names can be mapped to numbers")
154 #define TEST_HSP(portdef) \
155 expect_special_port_id(mach_host_special_port_for_id, \
159 TEST_HSP(HOST_PRIV_PORT
);
160 TEST_HSP(HOST_IO_MASTER_PORT
);
161 TEST_HSP(HOST_DYNAMIC_PAGER_PORT
);
162 TEST_HSP(HOST_AUDIT_CONTROL_PORT
);
163 TEST_HSP(HOST_USER_NOTIFICATION_PORT
);
164 TEST_HSP(HOST_AUTOMOUNTD_PORT
);
165 TEST_HSP(HOST_LOCKD_PORT
);
166 TEST_HSP(HOST_KTRACE_BACKGROUND_PORT
);
167 TEST_HSP(HOST_SEATBELT_PORT
);
168 TEST_HSP(HOST_KEXTD_PORT
);
169 TEST_HSP(HOST_LAUNCHCTL_PORT
);
170 TEST_HSP(HOST_UNFREED_PORT
);
171 TEST_HSP(HOST_AMFID_PORT
);
172 TEST_HSP(HOST_GSSD_PORT
);
173 TEST_HSP(HOST_TELEMETRY_PORT
);
174 TEST_HSP(HOST_ATM_NOTIFICATION_PORT
);
175 TEST_HSP(HOST_COALITION_PORT
);
176 TEST_HSP(HOST_SYSDIAGNOSE_PORT
);
177 TEST_HSP(HOST_XPC_EXCEPTION_PORT
);
178 TEST_HSP(HOST_CONTAINERD_PORT
);
179 TEST_HSP(HOST_NODE_PORT
);
180 TEST_HSP(HOST_RESOURCE_NOTIFY_PORT
);
181 TEST_HSP(HOST_CLOSURED_PORT
);
182 TEST_HSP(HOST_SYSPOLICYD_PORT
);
183 TEST_HSP(HOST_FILECOORDINATIOND_PORT
);
187 int invalid_tsp
= mach_host_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
188 T_EXPECT_EQ(invalid_tsp
, -1,
189 "invalid host special port IDs should return -1");
192 T_DECL(task_special_port_mapping
,
193 "verify that task special port names can be mapped to numbers")
195 #define TEST_TSP(portdef) \
196 expect_special_port_id(mach_task_special_port_for_id, \
199 TEST_TSP(TASK_KERNEL_PORT
);
200 TEST_TSP(TASK_READ_PORT
);
201 TEST_TSP(TASK_INSPECT_PORT
);
202 TEST_TSP(TASK_HOST_PORT
);
203 TEST_TSP(TASK_NAME_PORT
);
204 TEST_TSP(TASK_BOOTSTRAP_PORT
);
205 TEST_TSP(TASK_SEATBELT_PORT
);
206 TEST_TSP(TASK_ACCESS_PORT
);
207 TEST_TSP(TASK_DEBUG_CONTROL_PORT
);
208 TEST_TSP(TASK_RESOURCE_NOTIFY_PORT
);
212 int invalid_tsp
= mach_task_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
213 T_EXPECT_EQ(invalid_tsp
, -1,
214 "invalid task special port IDs should return -1");
217 T_DECL(thread_special_port_mapping
,
218 "verify that thread special port names can be mapped to numbers")
220 #define TEST_TSP(portdef) \
221 expect_special_port_id(mach_thread_special_port_for_id, \
224 TEST_TSP(THREAD_KERNEL_PORT
);
225 TEST_TSP(THREAD_READ_PORT
);
226 TEST_TSP(THREAD_INSPECT_PORT
);
230 int invalid_tsp
= mach_thread_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
231 T_EXPECT_EQ(invalid_tsp
, -1,
232 "invalid thread special port IDs should return -1");