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>
32 expect_special_port_description(const char *(*fn
)(mach_port_t
),
33 mach_port_t port
, const char *namestr
)
35 const char *desc
= fn(port
);
36 T_EXPECT_NOTNULL(desc
, "%s is %s", namestr
, desc
);
38 T_QUIET
; T_EXPECT_GT(strlen(desc
), strlen(""),
39 "%s's description string is not empty", namestr
);
43 T_DECL(host_special_port_descriptions
,
44 "verify that host special ports can be described")
46 #define TEST_HSP(portdef) \
47 expect_special_port_description(mach_host_special_port_description, \
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
);
78 T_EXPECT_EQ(HOST_SYSPOLICYD_PORT
, HOST_MAX_SPECIAL_PORT
,
79 "checked all of the ports");
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");
87 T_DECL(task_special_port_descriptions
,
88 "verify that task special ports can be described")
90 #define TEST_TSP(portdef) \
91 expect_special_port_description(mach_task_special_port_description, \
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
);
105 T_EXPECT_EQ(TASK_RESOURCE_NOTIFY_PORT
, TASK_MAX_SPECIAL_PORT
,
106 "checked all of the ports");
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");
115 expect_special_port_id(int (*fn
)(const char *id
), int port
, const char *portid
)
117 int observed_port
= fn(portid
);
119 T_EXPECT_EQ(observed_port
, port
, "%s is %d", portid
, observed_port
);
122 T_DECL(host_special_port_mapping
,
123 "verify that task special port names can be mapped to numbers")
125 #define TEST_HSP(portdef) \
126 expect_special_port_id(mach_host_special_port_for_id, \
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
);
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");
162 T_DECL(task_special_port_mapping
,
163 "verify that task special port names can be mapped to numbers")
165 #define TEST_TSP(portdef) \
166 expect_special_port_id(mach_task_special_port_for_id, \
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
);
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");