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