]> git.saurik.com Git - apple/xnu.git/blob - tests/port_descriptions.c
xnu-6153.121.1.tar.gz
[apple/xnu.git] / tests / port_descriptions.c
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
31 T_GLOBAL_META(T_META_RUN_CONCURRENTLY(true));
32
33 static void
34 expect_special_port_description(const char *(*fn)(int),
35 mach_port_t port, const char *namestr)
36 {
37 const char *desc = fn((int)port);
38 T_EXPECT_NOTNULL(desc, "%s is %s", namestr, desc);
39 if (desc) {
40 T_QUIET; T_EXPECT_GT(strlen(desc), strlen(""),
41 "%s's description string is not empty", namestr);
42 }
43 }
44
45 T_DECL(host_special_port_descriptions,
46 "verify that host special ports can be described")
47 {
48 #define TEST_HSP(portdef) \
49 expect_special_port_description(mach_host_special_port_description, \
50 portdef, #portdef)
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);
77 TEST_HSP(HOST_FILECOORDINATIOND_PORT);
78 TEST_HSP(HOST_FAIRPLAYD_PORT);
79
80 #undef TEST_HSP
81
82 T_EXPECT_EQ(HOST_FAIRPLAYD_PORT, HOST_MAX_SPECIAL_PORT,
83 "checked all of the ports");
84
85 const char *invalid_hsp =
86 mach_host_special_port_description(HOST_MAX_SPECIAL_PORT + 1);
87 T_EXPECT_NULL(invalid_hsp,
88 "invalid host special port description should be NULL");
89 }
90
91 T_DECL(task_special_port_descriptions,
92 "verify that task special ports can be described")
93 {
94 #define TEST_TSP(portdef) \
95 expect_special_port_description(mach_task_special_port_description, \
96 portdef, #portdef)
97
98 TEST_TSP(TASK_KERNEL_PORT);
99 TEST_TSP(TASK_HOST_PORT);
100 TEST_TSP(TASK_NAME_PORT);
101 TEST_TSP(TASK_BOOTSTRAP_PORT);
102 TEST_TSP(TASK_SEATBELT_PORT);
103 TEST_TSP(TASK_ACCESS_PORT);
104 TEST_TSP(TASK_DEBUG_CONTROL_PORT);
105 TEST_TSP(TASK_RESOURCE_NOTIFY_PORT);
106
107 #undef TEST_TSP
108
109 T_EXPECT_EQ(TASK_RESOURCE_NOTIFY_PORT, TASK_MAX_SPECIAL_PORT,
110 "checked all of the ports");
111
112 const char *invalid_tsp =
113 mach_task_special_port_description(TASK_MAX_SPECIAL_PORT + 1);
114 T_EXPECT_NULL(invalid_tsp,
115 "invalid task special port description should be NULL");
116 }
117
118 static void
119 expect_special_port_id(int (*fn)(const char *id), int port, const char *portid)
120 {
121 int observed_port = fn(portid);
122 T_WITH_ERRNO;
123 T_EXPECT_EQ(observed_port, port, "%s is %d", portid, observed_port);
124 }
125
126 T_DECL(host_special_port_mapping,
127 "verify that task special port names can be mapped to numbers")
128 {
129 #define TEST_HSP(portdef) \
130 expect_special_port_id(mach_host_special_port_for_id, \
131 portdef, #portdef)
132
133 TEST_HSP(HOST_PORT);
134 TEST_HSP(HOST_PRIV_PORT);
135 TEST_HSP(HOST_IO_MASTER_PORT);
136 TEST_HSP(HOST_DYNAMIC_PAGER_PORT);
137 TEST_HSP(HOST_AUDIT_CONTROL_PORT);
138 TEST_HSP(HOST_USER_NOTIFICATION_PORT);
139 TEST_HSP(HOST_AUTOMOUNTD_PORT);
140 TEST_HSP(HOST_LOCKD_PORT);
141 TEST_HSP(HOST_KTRACE_BACKGROUND_PORT);
142 TEST_HSP(HOST_SEATBELT_PORT);
143 TEST_HSP(HOST_KEXTD_PORT);
144 TEST_HSP(HOST_LAUNCHCTL_PORT);
145 TEST_HSP(HOST_UNFREED_PORT);
146 TEST_HSP(HOST_AMFID_PORT);
147 TEST_HSP(HOST_GSSD_PORT);
148 TEST_HSP(HOST_TELEMETRY_PORT);
149 TEST_HSP(HOST_ATM_NOTIFICATION_PORT);
150 TEST_HSP(HOST_COALITION_PORT);
151 TEST_HSP(HOST_SYSDIAGNOSE_PORT);
152 TEST_HSP(HOST_XPC_EXCEPTION_PORT);
153 TEST_HSP(HOST_CONTAINERD_PORT);
154 TEST_HSP(HOST_NODE_PORT);
155 TEST_HSP(HOST_RESOURCE_NOTIFY_PORT);
156 TEST_HSP(HOST_CLOSURED_PORT);
157 TEST_HSP(HOST_SYSPOLICYD_PORT);
158 TEST_HSP(HOST_FILECOORDINATIOND_PORT);
159
160 #undef TEST_HSP
161
162 int invalid_tsp = mach_host_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
163 T_EXPECT_EQ(invalid_tsp, -1,
164 "invalid host special port IDs should return -1");
165 }
166
167 T_DECL(task_special_port_mapping,
168 "verify that task special port names can be mapped to numbers")
169 {
170 #define TEST_TSP(portdef) \
171 expect_special_port_id(mach_task_special_port_for_id, \
172 portdef, #portdef)
173
174 TEST_TSP(TASK_KERNEL_PORT);
175 TEST_TSP(TASK_HOST_PORT);
176 TEST_TSP(TASK_NAME_PORT);
177 TEST_TSP(TASK_BOOTSTRAP_PORT);
178 TEST_TSP(TASK_SEATBELT_PORT);
179 TEST_TSP(TASK_ACCESS_PORT);
180 TEST_TSP(TASK_DEBUG_CONTROL_PORT);
181 TEST_TSP(TASK_RESOURCE_NOTIFY_PORT);
182
183 #undef TEST_TSP
184
185 int invalid_tsp = mach_task_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
186 T_EXPECT_EQ(invalid_tsp, -1,
187 "invalid task special port IDs should return -1");
188 }