forked from apple/darwin-xnu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport_descriptions.c
183 lines (163 loc) · 5.71 KB
/
port_descriptions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
* Copyright (c) 2018 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#include <darwintest.h>
#include <mach/port_descriptions.h>
static void
expect_special_port_description(const char *(*fn)(mach_port_t),
mach_port_t port, const char *namestr)
{
const char *desc = fn(port);
T_EXPECT_NOTNULL(desc, "%s is %s", namestr, desc);
if (desc) {
T_QUIET; T_EXPECT_GT(strlen(desc), strlen(""),
"%s's description string is not empty", namestr);
}
}
T_DECL(host_special_port_descriptions,
"verify that host special ports can be described")
{
#define TEST_HSP(portdef) \
expect_special_port_description(mach_host_special_port_description, \
portdef, #portdef)
TEST_HSP(HOST_PORT);
TEST_HSP(HOST_PRIV_PORT);
TEST_HSP(HOST_IO_MASTER_PORT);
TEST_HSP(HOST_DYNAMIC_PAGER_PORT);
TEST_HSP(HOST_AUDIT_CONTROL_PORT);
TEST_HSP(HOST_USER_NOTIFICATION_PORT);
TEST_HSP(HOST_AUTOMOUNTD_PORT);
TEST_HSP(HOST_LOCKD_PORT);
TEST_HSP(HOST_KTRACE_BACKGROUND_PORT);
TEST_HSP(HOST_SEATBELT_PORT);
TEST_HSP(HOST_KEXTD_PORT);
TEST_HSP(HOST_LAUNCHCTL_PORT);
TEST_HSP(HOST_UNFREED_PORT);
TEST_HSP(HOST_AMFID_PORT);
TEST_HSP(HOST_GSSD_PORT);
TEST_HSP(HOST_TELEMETRY_PORT);
TEST_HSP(HOST_ATM_NOTIFICATION_PORT);
TEST_HSP(HOST_COALITION_PORT);
TEST_HSP(HOST_SYSDIAGNOSE_PORT);
TEST_HSP(HOST_XPC_EXCEPTION_PORT);
TEST_HSP(HOST_CONTAINERD_PORT);
TEST_HSP(HOST_NODE_PORT);
TEST_HSP(HOST_RESOURCE_NOTIFY_PORT);
TEST_HSP(HOST_CLOSURED_PORT);
TEST_HSP(HOST_SYSPOLICYD_PORT);
#undef TEST_HSP
T_EXPECT_EQ(HOST_SYSPOLICYD_PORT, HOST_MAX_SPECIAL_PORT,
"checked all of the ports");
const char *invalid_hsp =
mach_host_special_port_description(HOST_MAX_SPECIAL_PORT + 1);
T_EXPECT_NULL(invalid_hsp,
"invalid host special port description should be NULL");
}
T_DECL(task_special_port_descriptions,
"verify that task special ports can be described")
{
#define TEST_TSP(portdef) \
expect_special_port_description(mach_task_special_port_description, \
portdef, #portdef)
TEST_TSP(TASK_KERNEL_PORT);
TEST_TSP(TASK_HOST_PORT);
TEST_TSP(TASK_NAME_PORT);
TEST_TSP(TASK_BOOTSTRAP_PORT);
TEST_TSP(TASK_SEATBELT_PORT);
TEST_TSP(TASK_ACCESS_PORT);
TEST_TSP(TASK_DEBUG_CONTROL_PORT);
TEST_TSP(TASK_RESOURCE_NOTIFY_PORT);
#undef TEST_TSP
T_EXPECT_EQ(TASK_RESOURCE_NOTIFY_PORT, TASK_MAX_SPECIAL_PORT,
"checked all of the ports");
const char *invalid_tsp =
mach_task_special_port_description(TASK_MAX_SPECIAL_PORT + 1);
T_EXPECT_NULL(invalid_tsp,
"invalid task special port description should be NULL");
}
static void
expect_special_port_id(int (*fn)(const char *id), int port, const char *portid)
{
int observed_port = fn(portid);
T_WITH_ERRNO;
T_EXPECT_EQ(observed_port, port, "%s is %d", portid, observed_port);
}
T_DECL(host_special_port_mapping,
"verify that task special port names can be mapped to numbers")
{
#define TEST_HSP(portdef) \
expect_special_port_id(mach_host_special_port_for_id, \
portdef, #portdef)
TEST_HSP(HOST_PORT);
TEST_HSP(HOST_PRIV_PORT);
TEST_HSP(HOST_IO_MASTER_PORT);
TEST_HSP(HOST_DYNAMIC_PAGER_PORT);
TEST_HSP(HOST_AUDIT_CONTROL_PORT);
TEST_HSP(HOST_USER_NOTIFICATION_PORT);
TEST_HSP(HOST_AUTOMOUNTD_PORT);
TEST_HSP(HOST_LOCKD_PORT);
TEST_HSP(HOST_KTRACE_BACKGROUND_PORT);
TEST_HSP(HOST_SEATBELT_PORT);
TEST_HSP(HOST_KEXTD_PORT);
TEST_HSP(HOST_LAUNCHCTL_PORT);
TEST_HSP(HOST_UNFREED_PORT);
TEST_HSP(HOST_AMFID_PORT);
TEST_HSP(HOST_GSSD_PORT);
TEST_HSP(HOST_TELEMETRY_PORT);
TEST_HSP(HOST_ATM_NOTIFICATION_PORT);
TEST_HSP(HOST_COALITION_PORT);
TEST_HSP(HOST_SYSDIAGNOSE_PORT);
TEST_HSP(HOST_XPC_EXCEPTION_PORT);
TEST_HSP(HOST_CONTAINERD_PORT);
TEST_HSP(HOST_NODE_PORT);
TEST_HSP(HOST_RESOURCE_NOTIFY_PORT);
TEST_HSP(HOST_CLOSURED_PORT);
TEST_HSP(HOST_SYSPOLICYD_PORT);
#undef TEST_HSP
int invalid_tsp = mach_host_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
T_EXPECT_EQ(invalid_tsp, -1,
"invalid host special port IDs should return -1");
}
T_DECL(task_special_port_mapping,
"verify that task special port names can be mapped to numbers")
{
#define TEST_TSP(portdef) \
expect_special_port_id(mach_task_special_port_for_id, \
portdef, #portdef)
TEST_TSP(TASK_KERNEL_PORT);
TEST_TSP(TASK_HOST_PORT);
TEST_TSP(TASK_NAME_PORT);
TEST_TSP(TASK_BOOTSTRAP_PORT);
TEST_TSP(TASK_SEATBELT_PORT);
TEST_TSP(TASK_ACCESS_PORT);
TEST_TSP(TASK_DEBUG_CONTROL_PORT);
TEST_TSP(TASK_RESOURCE_NOTIFY_PORT);
#undef TEST_TSP
int invalid_tsp = mach_task_special_port_for_id("BOGUS_SPECIAL_PORT_NAME");
T_EXPECT_EQ(invalid_tsp, -1,
"invalid task special port IDs should return -1");
}