1 /*
2 * Copyright (c) 2017-2024 Apple 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
29 /* Attempts to run upipes in parallel.
30 * Every upipe endpipe gets a thread
31 * Todo: create variant that uses multiple rings per channel.
32 */
33
34 #include <assert.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <uuid/uuid.h>
40 #include <sys/select.h>
41 #include <poll.h>
42 #include <sys/event.h>
43 #include <darwintest.h>
44 #include "skywalk_test_driver.h"
45 #include "skywalk_test_common.h"
46 #include "skywalk_test_utils.h"
47
48 static int
skt_pllupipe_main(int argc,char * argv[])49 skt_pllupipe_main(int argc, char *argv[])
50 {
51 int error;
52 uuid_t channel_uuid;
53 int len = 10;
54
55 error = uuid_parse(argv[3], channel_uuid);
56 SKTC_ASSERT_ERR(!error);
57
58 sktc_setup_channel_worker(channel_uuid, 0, CHANNEL_RING_ID_ANY,
59 NULL, 0, false, true);
60
61 for (int i = 0; i < len; i++) {
62 sleep(1);
63 T_LOG("time %d of %d\n", i, len);
64 }
65
66 sktc_cleanup_channel_worker();
67
68 return 0;
69 }
70
71 #define MMSLOTS 10000000
72
73 static int
skt_pllupipe_txk_main(int argc,char * argv[])74 skt_pllupipe_txk_main(int argc, char *argv[])
75 {
76 int error;
77 channel_t channel;
78 ring_id_t ringid;
79 channel_ring_t ring;
80 uuid_t channel_uuid;
81
82 error = uuid_parse(argv[3], channel_uuid);
83 SKTC_ASSERT_ERR(!error);
84
85 channel = sktu_channel_create_extended(channel_uuid, 0,
86 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
87 -1, -1, -1, -1, -1, -1, 1, -1, -1);
88 assert(channel);
89
90 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_TX_RING);
91 ring = os_channel_tx_ring(channel, ringid);
92 assert(ring);
93
94 sktc_pump_ring_nslots_kq(channel, ring, CHANNEL_SYNC_TX, true, MMSLOTS, true);
95
96 return 0;
97 }
98
99 static int
skt_pllupipe_txs_main(int argc,char * argv[])100 skt_pllupipe_txs_main(int argc, char *argv[])
101 {
102 int error;
103 channel_t channel;
104 ring_id_t ringid;
105 channel_ring_t ring;
106 uuid_t channel_uuid;
107
108 error = uuid_parse(argv[3], channel_uuid);
109 SKTC_ASSERT_ERR(!error);
110
111 channel = sktu_channel_create_extended(channel_uuid, 0,
112 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
113 -1, -1, -1, -1, -1, -1, 1, -1, -1);
114 assert(channel);
115
116 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_TX_RING);
117 ring = os_channel_tx_ring(channel, ringid);
118 assert(ring);
119
120 sktc_pump_ring_nslots_select(channel, ring, CHANNEL_SYNC_TX, true, MMSLOTS, true);
121
122 return 0;
123 }
124
125 static int
skt_pllupipe_txp_main(int argc,char * argv[])126 skt_pllupipe_txp_main(int argc, char *argv[])
127 {
128 int error;
129 channel_t channel;
130 ring_id_t ringid;
131 channel_ring_t ring;
132 uuid_t channel_uuid;
133
134 error = uuid_parse(argv[3], channel_uuid);
135 SKTC_ASSERT_ERR(!error);
136
137 channel = sktu_channel_create_extended(channel_uuid, 0,
138 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
139 -1, -1, -1, -1, -1, -1, 1, -1, -1);
140 assert(channel);
141
142 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_TX_RING);
143 ring = os_channel_tx_ring(channel, ringid);
144 assert(ring);
145
146 sktc_pump_ring_nslots_poll(channel, ring, CHANNEL_SYNC_TX, true, MMSLOTS, true);
147
148 return 0;
149 }
150
151 static int
skt_pllupipe_rxk_main(int argc,char * argv[])152 skt_pllupipe_rxk_main(int argc, char *argv[])
153 {
154 int error;
155 channel_t channel;
156 ring_id_t ringid;
157 channel_ring_t ring;
158 uuid_t channel_uuid;
159
160 error = uuid_parse(argv[3], channel_uuid);
161 SKTC_ASSERT_ERR(!error);
162
163 channel = sktu_channel_create_extended(channel_uuid, 0,
164 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
165 -1, -1, -1, -1, -1, -1, 1, -1, -1);
166 assert(channel);
167
168 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_RX_RING);
169 ring = os_channel_rx_ring(channel, ringid);
170 assert(ring);
171
172 sktc_pump_ring_nslots_kq(channel, ring, CHANNEL_SYNC_RX, true, MMSLOTS, true);
173
174 return 0;
175 }
176
177 static int
skt_pllupipe_rxs_main(int argc,char * argv[])178 skt_pllupipe_rxs_main(int argc, char *argv[])
179 {
180 int error;
181 channel_t channel;
182 ring_id_t ringid;
183 channel_ring_t ring;
184 uuid_t channel_uuid;
185
186 error = uuid_parse(argv[3], channel_uuid);
187 SKTC_ASSERT_ERR(!error);
188
189 channel = sktu_channel_create_extended(channel_uuid, 0,
190 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
191 -1, -1, -1, -1, -1, -1, 1, -1, -1);
192 assert(channel);
193
194 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_RX_RING);
195 ring = os_channel_rx_ring(channel, ringid);
196 assert(ring);
197
198 sktc_pump_ring_nslots_select(channel, ring, CHANNEL_SYNC_RX, true, MMSLOTS, true);
199
200 return 0;
201 }
202
203 static int
skt_pllupipe_rxp_main(int argc,char * argv[])204 skt_pllupipe_rxp_main(int argc, char *argv[])
205 {
206 int error;
207 channel_t channel;
208 ring_id_t ringid;
209 channel_ring_t ring;
210 uuid_t channel_uuid;
211
212 error = uuid_parse(argv[3], channel_uuid);
213 SKTC_ASSERT_ERR(!error);
214
215 channel = sktu_channel_create_extended(channel_uuid, 0,
216 CHANNEL_DIR_TX_RX, CHANNEL_RING_ID_ANY, NULL,
217 -1, -1, -1, -1, -1, -1, 1, -1, -1);
218 assert(channel);
219
220 ringid = os_channel_ring_id(channel, CHANNEL_FIRST_RX_RING);
221 ring = os_channel_rx_ring(channel, ringid);
222 assert(ring);
223
224 sktc_pump_ring_nslots_poll(channel, ring, CHANNEL_SYNC_RX, true, MMSLOTS, true);
225
226 return 0;
227 }
228
229 struct skywalk_test skt_pllupipe = {
230 "pllupipe", "fully parallel upipe for 10 seconds",
231 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
232 skt_pllupipe_main, SKTC_GENERIC_UPIPE_ARGV,
233 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
234 };
235
236 struct skywalk_test skt_pllutxk = {
237 "pllutxk", "send 10000000 slots to upipe sink using kqueue",
238 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
239 skt_pllupipe_txk_main, SKTC_GENERIC_UPIPE_ARGV,
240 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
241 };
242
243 struct skywalk_test skt_pllutxs = {
244 "pllutxs", "send 10000000 slots to upipe sink using select",
245 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
246 skt_pllupipe_txs_main, SKTC_GENERIC_UPIPE_ARGV,
247 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
248 };
249
250 struct skywalk_test skt_pllutxp = {
251 "pllutxp", "send 10000000 slots to upipe sink using poll",
252 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
253 skt_pllupipe_txp_main, SKTC_GENERIC_UPIPE_ARGV,
254 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
255 };
256
257 struct skywalk_test skt_pllurxk = {
258 "pllurxk", "receive 10000000 slots from upipe source using kqueue",
259 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
260 skt_pllupipe_rxk_main, SKTC_GENERIC_UPIPE_ARGV,
261 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
262 };
263
264 struct skywalk_test skt_pllurxs = {
265 "pllurxs", "receive 10000000 slots from upipe source using select",
266 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
267 skt_pllupipe_rxs_main, SKTC_GENERIC_UPIPE_ARGV,
268 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
269 };
270
271 struct skywalk_test skt_pllurxp = {
272 "pllurxp", "receive 10000000 slots to upipe source using poll",
273 SK_FEATURE_SKYWALK | SK_FEATURE_NEXUS_USER_PIPE,
274 skt_pllupipe_rxp_main, SKTC_GENERIC_UPIPE_ARGV,
275 sktc_generic_upipe_null_init, sktc_generic_upipe_fini,
276 };
277