]> git.saurik.com Git - apple/xnu.git/blame - tests/port_descriptions.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / port_descriptions.c
CommitLineData
d9a64523
A
1/*
2 * Copyright (c) 2018 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_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. 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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28#include <darwintest.h>
29#include <mach/port_descriptions.h>
30
cb323159
A
31T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
32
d9a64523 33static void
cb323159 34expect_special_port_description(const char *(*fn)(int),
0a7de745 35 mach_port_t port, const char *namestr)
d9a64523 36{
cb323159 37 const char *desc = fn((int)port);
d9a64523
A
38 T_EXPECT_NOTNULL(desc, "%s is %s", namestr, desc);
39 if (desc) {
40 T_QUIET; T_EXPECT_GT(strlen(desc), strlen(""),
0a7de745 41 "%s's description string is not empty", namestr);
d9a64523
A
42 }
43}
44
45T_DECL(host_special_port_descriptions,
0a7de745 46 "verify that host special ports can be described")
d9a64523
A
47{
48#define TEST_HSP(portdef) \
0a7de745
A
49 expect_special_port_description(mach_host_special_port_description, \
50 portdef, #portdef)
d9a64523
A
51
52 TEST_HSP(HOST_PORT);
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);
cb323159
A
77 TEST_HSP(HOST_FILECOORDINATIOND_PORT);
78 TEST_HSP(HOST_FAIRPLAYD_PORT);
c3c9b80d 79 TEST_HSP(HOST_IOCOMPRESSIONSTATS_PORT);
d9a64523
A
80
81#undef TEST_HSP
82
c3c9b80d 83 T_EXPECT_EQ(HOST_IOCOMPRESSIONSTATS_PORT, HOST_MAX_SPECIAL_PORT,
0a7de745 84 "checked all of the ports");
d9a64523
A
85
86 const char *invalid_hsp =
0a7de745 87 mach_host_special_port_description(HOST_MAX_SPECIAL_PORT + 1);
d9a64523 88 T_EXPECT_NULL(invalid_hsp,
0a7de745 89 "invalid host special port description should be NULL");
d9a64523
A
90}
91
92T_DECL(task_special_port_descriptions,
0a7de745 93 "verify that task special ports can be described")
d9a64523
A
94{
95#define TEST_TSP(portdef) \
0a7de745
A
96 expect_special_port_description(mach_task_special_port_description, \
97 portdef, #portdef)
d9a64523
A
98
99 TEST_TSP(TASK_KERNEL_PORT);
c3c9b80d
A
100 TEST_TSP(TASK_READ_PORT);
101 TEST_TSP(TASK_INSPECT_PORT);
d9a64523
A
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);
109
110#undef TEST_TSP
111
112 T_EXPECT_EQ(TASK_RESOURCE_NOTIFY_PORT, TASK_MAX_SPECIAL_PORT,
0a7de745 113 "checked all of the ports");
d9a64523
A
114
115 const char *invalid_tsp =
0a7de745 116 mach_task_special_port_description(TASK_MAX_SPECIAL_PORT + 1);
d9a64523 117 T_EXPECT_NULL(invalid_tsp,
0a7de745 118 "invalid task special port description should be NULL");
d9a64523
A
119}
120
c3c9b80d
A
121T_DECL(thread_special_port_descriptions,
122 "verify that thread special ports can be described")
123{
124#define TEST_TSP(portdef) \
125 expect_special_port_description(mach_thread_special_port_description, \
126 portdef, #portdef)
127
128 TEST_TSP(THREAD_KERNEL_PORT);
129 TEST_TSP(THREAD_READ_PORT);
130 TEST_TSP(THREAD_INSPECT_PORT);
131
132#undef TEST_TSP
133
134 T_EXPECT_EQ(THREAD_READ_PORT, THREAD_MAX_SPECIAL_PORT,
135 "checked all of the ports");
136
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");
141}
142
d9a64523
A
143static void
144expect_special_port_id(int (*fn)(const char *id), int port, const char *portid)
145{
146 int observed_port = fn(portid);
147 T_WITH_ERRNO;
148 T_EXPECT_EQ(observed_port, port, "%s is %d", portid, observed_port);
149}
150
151T_DECL(host_special_port_mapping,
0a7de745 152 "verify that task special port names can be mapped to numbers")
d9a64523
A
153{
154#define TEST_HSP(portdef) \
0a7de745
A
155 expect_special_port_id(mach_host_special_port_for_id, \
156 portdef, #portdef)
d9a64523
A
157
158 TEST_HSP(HOST_PORT);
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);
cb323159 183 TEST_HSP(HOST_FILECOORDINATIOND_PORT);
d9a64523
A
184
185#undef TEST_HSP
186
187 int invalid_tsp = mach_host_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
188 T_EXPECT_EQ(invalid_tsp, -1,
0a7de745 189 "invalid host special port IDs should return -1");
d9a64523
A
190}
191
192T_DECL(task_special_port_mapping,
0a7de745 193 "verify that task special port names can be mapped to numbers")
d9a64523
A
194{
195#define TEST_TSP(portdef) \
0a7de745
A
196 expect_special_port_id(mach_task_special_port_for_id, \
197 portdef, #portdef)
d9a64523
A
198
199 TEST_TSP(TASK_KERNEL_PORT);
c3c9b80d
A
200 TEST_TSP(TASK_READ_PORT);
201 TEST_TSP(TASK_INSPECT_PORT);
d9a64523
A
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);
209
210#undef TEST_TSP
211
212 int invalid_tsp = mach_task_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
213 T_EXPECT_EQ(invalid_tsp, -1,
0a7de745 214 "invalid task special port IDs should return -1");
d9a64523 215}
c3c9b80d
A
216
217T_DECL(thread_special_port_mapping,
218 "verify that thread special port names can be mapped to numbers")
219{
220#define TEST_TSP(portdef) \
221 expect_special_port_id(mach_thread_special_port_for_id, \
222 portdef, #portdef)
223
224 TEST_TSP(THREAD_KERNEL_PORT);
225 TEST_TSP(THREAD_READ_PORT);
226 TEST_TSP(THREAD_INSPECT_PORT);
227
228#undef TEST_TSP
229
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");
233}