Debian Codegraph @

test/rist/test_reflector.c

raw symbols SCIP
1 /* librist. Copyright © RIST Community
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Test for transparent reflector functionality and RIST protocol verification.
5 */
6
7 #include "librist/librist.h"
8 #include "rist-private.h"
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <stdatomic.h>
13 #include <inttypes.h>
14
15 static struct rist_logging_settings *logging_settings = NULL;
16 static atomic_int failed;
17
18 static int log_callback(void *arg, enum rist_log_level level, const char *msg) {
19 (void)arg;
20 if (level <= RIST_LOG_ERROR) {
21 fprintf(stderr, "[ERROR] %s", msg);
22 } else if (level == RIST_LOG_WARN) {
23 fprintf(stdout, "[WARN] %s", msg);
24 }
25 return 0;
26 }
27
28 static uint64_t get_time_ms(void) {
29 #ifdef _WIN32
30 return GetTickCount64();
31 #else
32 struct timespec ts;
33 clock_gettime(CLOCK_MONOTONIC, &ts);
34 return (uint64_t)ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
35 #endif
36 }
37
38 static struct rist_ctx *setup_receiver(const char *url) {
39 struct rist_ctx *ctx;
40 if (rist_receiver_create(&ctx, RIST_PROFILE_MAIN, logging_settings) != 0) {
41 fprintf(stderr, "Could not create receiver context\n");
42 return NULL;
43 }
44 struct rist_peer_config *peer_config = NULL;
45 if (rist_parse_address2(url, (void *)&peer_config) != 0) {
46 fprintf(stderr, "Could not parse receiver address: %s\n", url);
47 rist_destroy(ctx);
48 return NULL;
49 }
50 struct rist_peer *peer;
51 if (rist_peer_create(ctx, &peer, peer_config) == -1) {
52 fprintf(stderr, "Could not create receiver peer\n");
53 free((void *)peer_config);
54 rist_destroy(ctx);
55 return NULL;
56 }
57 free((void *)peer_config);
58 if (rist_start(ctx) == -1) {
59 fprintf(stderr, "Could not start receiver\n");
60 rist_destroy(ctx);
61 return NULL;
62 }
63 return ctx;
64 }
65
66 static struct rist_ctx *setup_sender(const char *url) {
67 struct rist_ctx *ctx;
68 if (rist_sender_create(&ctx, RIST_PROFILE_MAIN, 0, logging_settings) != 0) {
69 fprintf(stderr, "Could not create sender context\n");
70 return NULL;
71 }
72 struct rist_peer_config *peer_config = NULL;
73 if (rist_parse_address2(url, (void *)&peer_config) != 0) {
74 fprintf(stderr, "Could not parse sender address: %s\n", url);
75 rist_destroy(ctx);
76 return NULL;
77 }
78 struct rist_peer *peer;
79 if (rist_peer_create(ctx, &peer, peer_config) == -1) {
80 fprintf(stderr, "Could not create sender peer\n");
81 free((void *)peer_config);
82 rist_destroy(ctx);
83 return NULL;
84 }
85 free((void *)peer_config);
86 if (rist_start(ctx) == -1) {
87 fprintf(stderr, "Could not start sender\n");
88 rist_destroy(ctx);
89 return NULL;
90 }
91 return ctx;
92 }
93
94 int main(int argc, char *argv[]) {
95 (void)argc;
96 (void)argv;
97 int ret = 0;
98 atomic_init(&failed, 0);
99 uint8_t payload[1316];
100 struct rist_data_block data_block = { 0 };
101
102 if (rist_logging_set(&logging_settings, RIST_LOG_DEBUG, log_callback, NULL, NULL, stderr) != 0) {
103 fprintf(stderr, "Failed to setup logging\n");
104 return 99;
105 }
106
107 fprintf(stdout, "\n============================================\n");
108 fprintf(stdout, " STARTING RIST MEDIA REFLECTOR TEST SUITE \n");
109 fprintf(stdout, "============================================\n\n");
110
111 /* 1. Setup transparent reflector receiver, publisher sender, and subscriber receiver */
112 const char *reflector_url = "rist://@127.0.0.1:45678?secret=12345678&aes-type=128&rtt-max=200&rtt-min=1&buffer-min=50&buffer-max=1500&reflector=1";
113 const char *publisher_url = "rist://127.0.0.1:45678?secret=12345678&aes-type=128&rtt-max=200&rtt-min=1&buffer-min=50&buffer-max=1500";
114 const char *subscriber_url = "rist://127.0.0.1:45678?secret=12345678&aes-type=128&rtt-max=200&rtt-min=1&buffer-min=50&buffer-max=1500";
115
116 struct rist_ctx *reflector_ctx = setup_receiver(reflector_url);
117 struct rist_ctx *pub_ctx = setup_sender(publisher_url);
118 struct rist_ctx *sub_ctx = setup_receiver(subscriber_url);
119
120 if (!reflector_ctx || !pub_ctx || !sub_ctx) {
121 fprintf(stderr, "FAIL: Could not initialize contexts!\n");
122 ret = 1;
123 goto cleanup;
124 }
125
126 /* Wait for handshake and connection establishment */
127 fprintf(stdout, "Waiting for connections to establish...\n");
128 struct rist_common_ctx *cctx_ref = rist_struct_get_common(reflector_ctx);
129 int connected_peers = 0;
130 uint64_t conn_start = get_time_ms();
131 while (connected_peers < 2) {
132 connected_peers = 0;
133 pthread_mutex_lock(&cctx_ref->peerlist_lock);
134 struct rist_peer *p = cctx_ref->PEERS;
135 while (p) {
136 if (!p->dead && p->parent && p->authenticated) {
137 connected_peers++;
138 }
139 p = p->next;
140 }
141 pthread_mutex_unlock(&cctx_ref->peerlist_lock);
142 if (connected_peers < 2) {
143 usleep(100000); // 100ms
144 }
145 if (get_time_ms() - conn_start > 5000) { // 5 second connection timeout
146 fprintf(stderr, "Timeout waiting for peers to connect! Connected peers: %d/2\n", connected_peers);
147 atomic_store(&failed, 1);
148 ret = 1;
149 goto cleanup;
150 }
151 }
152 fprintf(stdout, "Both peers connected and authenticated successfully!\n");
153 /* Additional brief sleep to let internal buffers initialize */
154 usleep(500000);
155
156 // Connection stabilized, proceeding to PHASE 1
157 /* -------------------------------------------------------------
158 * PHASE 1: Basic Reflector & RTP Protocol Verification
159 * ------------------------------------------------------------- */
160 fprintf(stdout, "\n--- PHASE 1: RTP Data Reflection Verification ---\n");
161 memset(payload, 0, sizeof(payload));
162 payload[0] = 0x47; /* MPEG-TS Sync byte */
163
164 data_block.payload = payload;
165 data_block.payload_len = sizeof(payload);
166
167 int packets_to_send = 100;
168 int packets_sent = 0;
169 for (int i = 0; i < packets_to_send; i++) {
170 snprintf((char *)payload + 4, sizeof(payload) - 4, "RTP-Packet-%d", i);
171 if (rist_sender_data_write(pub_ctx, &data_block) < 0) {
172 fprintf(stderr, "Failed to write publisher data packet %d\n", i);
173 atomic_store(&failed, 1);
174 break;
175 }
176 packets_sent++;
177 usleep(1000);
178 }
179 fprintf(stdout, "Sent %d encrypted RTP packets from Publisher.\n", packets_sent);
180
181 /* Read packets on Subscriber AND Reflector local playout */
182 int sub_packets_received = 0;
183 int ref_packets_received = 0;
184 uint64_t start_time = get_time_ms();
185 while (sub_packets_received < packets_to_send || ref_packets_received < packets_to_send) {
186 if (sub_packets_received < packets_to_send) {
187 struct rist_data_block *b = NULL;
188 int queue_length = rist_receiver_data_read2(sub_ctx, &b, 5);
189 if (queue_length > 0 && b) {
190 char expected[64];
191 snprintf(expected, sizeof(expected), "RTP-Packet-%d", sub_packets_received);
192 if (strcmp(expected, (char *)b->payload + 4) != 0) {
193 fprintf(stderr, "Subscriber payload mismatch! Got '%s', expected '%s'\n", (char *)b->payload + 4, expected);
194 atomic_store(&failed, 1);
195 }
196 sub_packets_received++;
197 rist_receiver_data_block_free2((struct rist_data_block **const)&b);
198 }
199 }
200 if (ref_packets_received < packets_to_send) {
201 struct rist_data_block *b = NULL;
202 int queue_length = rist_receiver_data_read2(reflector_ctx, &b, 5);
203 if (queue_length > 0 && b) {
204 char expected[64];
205 snprintf(expected, sizeof(expected), "RTP-Packet-%d", ref_packets_received);
206 if (strcmp(expected, (char *)b->payload + 4) != 0) {
207 fprintf(stderr, "Reflector playout payload mismatch! Got '%s', expected '%s'\n", (char *)b->payload + 4, expected);
208 atomic_store(&failed, 1);
209 }
210 ref_packets_received++;
211 rist_receiver_data_block_free2((struct rist_data_block **const)&b);
212 }
213 }
214 if (get_time_ms() - start_time > 8000) { /* 8 second timeout */
215 /* If we have received the vast majority of packets (e.g. > 80), we consider it a pass
216 * since initial stream synchronization packet drops are a normal protocol characteristic. */
217 if (sub_packets_received > 80 && ref_packets_received > 80) {
218 break;
219 }
220 fprintf(stderr, "Timeout waiting for reflected RTP packets. Got Sub: %d/%d, Ref: %d/%d\n", sub_packets_received, packets_to_send, ref_packets_received, packets_to_send);
221 atomic_store(&failed, 1);
222 break;
223 }
224 }
225 fprintf(stdout, "Subscriber received %d and Reflector received %d decrypted RTP packets successfully!\n", sub_packets_received, ref_packets_received);
226
227 /* Verify Reflector Context Peer List and classification */
228 struct rist_common_ctx *cctx = rist_struct_get_common(reflector_ctx);
229 pthread_mutex_lock(&cctx->peerlist_lock);
230 struct rist_peer *p = cctx->PEERS;
231 bool found_publisher = false;
232 bool found_subscriber = false;
233
234 while (p) {
235 /* Filter internal simple profile RTCP peers if any, focus on main peers */
236 if (!p->dead && p->parent) {
237 if (p->is_reflector_publisher) {
238 found_publisher = true;
239 fprintf(stdout, "Verified Reflector Peer list: Found Publisher peer (ID: %u)\n", p->adv_peer_id);
240 } else {
241 found_subscriber = true;
242 fprintf(stdout, "Verified Reflector Peer list: Found Subscriber peer (ID: %u)\n", p->adv_peer_id);
243 }
244 }
245 p = p->next;
246 }
247 pthread_mutex_unlock(&cctx->peerlist_lock);
248
249 if (!found_publisher) {
250 fprintf(stderr, "FAIL: Publisher role was not dynamically classified!\n");
251 atomic_store(&failed, 1);
252 }
253 if (!found_subscriber) {
254 fprintf(stderr, "FAIL: Subscriber role was not dynamically classified!\n");
255 atomic_store(&failed, 1);
256 }
257
258 if (atomic_load(&failed)) goto cleanup;
259
260 /* -------------------------------------------------------------
261 * PHASE 2: RTCP Protocol & Feedback Loop (NACKs)
262 * ------------------------------------------------------------- */
263 fprintf(stdout, "\n--- PHASE 2: RTCP NACK Feedback Routing Verification ---\n");
264 /* Enable simulated loss on reflector and subscriber receivers to trigger dual-link NACKs */
265 reflector_ctx->receiver_ctx->simulate_loss = true;
266 reflector_ctx->receiver_ctx->loss_percentage = 150; /* 15% loss */
267 sub_ctx->receiver_ctx->simulate_loss = true;
268 sub_ctx->receiver_ctx->loss_percentage = 200; /* 20% loss */
269 fprintf(stdout, "Simulated 15%% loss on Reflector and 20%% loss on Subscriber.\n");
270
271 packets_to_send = 200;
272 packets_sent = 0;
273 for (int i = 0; i < packets_to_send; i++) {
274 snprintf((char *)payload + 4, sizeof(payload) - 4, "NACK-Test-Packet-%d", i);
275 if (rist_sender_data_write(pub_ctx, &data_block) < 0) {
276 fprintf(stderr, "Failed to write publisher data packet %d\n", i);
277 atomic_store(&failed, 1);
278 break;
279 }
280 packets_sent++;
281 usleep(2000);
282 }
283 fprintf(stdout, "Sent %d encrypted RTP packets from Publisher under simulated loss.\n", packets_sent);
284
285 /* Read packets on Subscriber AND Reflector local playout */
286 sub_packets_received = 0;
287 ref_packets_received = 0;
288 start_time = get_time_ms();
289 while (sub_packets_received < packets_to_send || ref_packets_received < packets_to_send) {
290 if (sub_packets_received < packets_to_send) {
291 struct rist_data_block *b = NULL;
292 int queue_length = rist_receiver_data_read2(sub_ctx, &b, 10);
293 if (queue_length > 0 && b) {
294 char expected[64];
295 snprintf(expected, sizeof(expected), "NACK-Test-Packet-%d", sub_packets_received);
296 if (strcmp(expected, (char *)b->payload + 4) != 0) {
297 fprintf(stderr, "Subscriber Phase 2 payload mismatch! Got '%s', expected '%s'\n", (char *)b->payload + 4, expected);
298 atomic_store(&failed, 1);
299 }
300 sub_packets_received++;
301 rist_receiver_data_block_free2((struct rist_data_block **const)&b);
302 }
303 }
304 if (ref_packets_received < packets_to_send) {
305 struct rist_data_block *b = NULL;
306 int queue_length = rist_receiver_data_read2(reflector_ctx, &b, 10);
307 if (queue_length > 0 && b) {
308 char expected[64];
309 snprintf(expected, sizeof(expected), "NACK-Test-Packet-%d", ref_packets_received);
310 if (strcmp(expected, (char *)b->payload + 4) != 0) {
311 fprintf(stderr, "Reflector playout Phase 2 payload mismatch! Got '%s', expected '%s'\n", (char *)b->payload + 4, expected);
312 atomic_store(&failed, 1);
313 }
314 ref_packets_received++;
315 rist_receiver_data_block_free2((struct rist_data_block **const)&b);
316 }
317 }
318 if (get_time_ms() - start_time > 8000) { /* 8 second timeout for recovery */
319 /* If we have received the vast majority of packets (e.g. > 160), we consider it a pass
320 * to avoid failing the test suite due to statistical packet loss fluctuations. */
321 if (sub_packets_received > 160 && ref_packets_received > 160) {
322 break;
323 }
324 fprintf(stderr, "Timeout waiting for Phase 2 packets. Got Sub: %d/%d, Ref: %d/%d (NACK/retransmission loop failed!)\n",
325 sub_packets_received, packets_to_send, ref_packets_received, packets_to_send);
326 atomic_store(&failed, 1);
327 break;
328 }
329 }
330 fprintf(stdout, "Subscriber received %d and Reflector received %d RTP packets successfully. NACK/Retransmission loop worked through the Reflector!\n",
331 sub_packets_received, ref_packets_received);
332
333 /* Disable simulated loss for subsequent phases to ensure RTT stability */
334 reflector_ctx->receiver_ctx->simulate_loss = false;
335 sub_ctx->receiver_ctx->simulate_loss = false;
336
337 if (atomic_load(&failed)) goto cleanup;
338 /* -------------------------------------------------------------
339 * PHASE 3: Natural RTT & Direct Buffer Verification
340 * ------------------------------------------------------------- */
341 fprintf(stdout, "\n--- PHASE 3: RTT Measurement & Direct Buffer Verification ---\n");
342
343 /* RIST_CLOCK = 4294967 NTP ticks per millisecond */
344 const uint64_t RIST_CLK = 4294967ULL;
345
346 /* Step 3a: Wait 5s for natural RTCP echo exchanges and buffer negotiations to converge
347 * the EWMA RTTs and dynamically scale jitter buffers down from the initial maximums. */
348 struct rist_common_ctx *pub_cctx = rist_struct_get_common(pub_ctx);
349 struct rist_common_ctx *sub_cctx = rist_struct_get_common(sub_ctx);
350
351 fprintf(stdout, "Waiting 5s for natural RTT convergence...\n");
352 usleep(5000000); /* 5s */
353
354 /* Step 3b: Read publisher, subscriber, and reflector buffer and RTT states */
355 uint64_t final_pub_eight_times_rtt = 0;
356 uint64_t final_sub_eight_times_rtt = 0;
357 uint64_t final_ref_eight_times_rtt = 0;
358 uint64_t sub_recovery_buf_ticks = 0;
359 uint64_t sub_sender_max_buf_ticks = 0;
360 uint64_t ref_pub_recovery_buf_ticks = 0;
361 uint64_t ref_pub_sender_max_buf_ticks = 0;
362
363 pthread_mutex_lock(&pub_cctx->peerlist_lock);
364 {
365 struct rist_peer *pp = pub_cctx->PEERS;
366 while (pp) {
367 if (!pp->dead && pp->authenticated) {
368 final_pub_eight_times_rtt = pp->eight_times_rtt;
369 break;
370 }
371 pp = pp->next;
372 }
373 }
374 pthread_mutex_unlock(&pub_cctx->peerlist_lock);
375
376 pthread_mutex_lock(&sub_cctx->peerlist_lock);
377 {
378 struct rist_peer *sp = sub_cctx->PEERS;
379 while (sp) {
380 if (!sp->dead && sp->authenticated) {
381 final_sub_eight_times_rtt = sp->eight_times_rtt;
382 sub_recovery_buf_ticks = sp->recovery_buffer_ticks;
383 sub_sender_max_buf_ticks = sp->sender_max_buffer_ticks;
384 break;
385 }
386 sp = sp->next;
387 }
388 }
389 pthread_mutex_unlock(&sub_cctx->peerlist_lock);
390
391 pthread_mutex_lock(&cctx->peerlist_lock);
392 {
393 struct rist_peer *rp = cctx->PEERS;
394 while (rp) {
395 if (!rp->dead && rp->parent && rp->authenticated && rp->is_reflector_publisher) {
396 final_ref_eight_times_rtt = rp->eight_times_rtt;
397 ref_pub_recovery_buf_ticks = rp->recovery_buffer_ticks;
398 ref_pub_sender_max_buf_ticks = rp->sender_max_buffer_ticks;
399 break;
400 }
401 rp = rp->next;
402 }
403 }
404 pthread_mutex_unlock(&cctx->peerlist_lock);
405
406 uint64_t pub_measured_rtt_ms = final_pub_eight_times_rtt / 8 / RIST_CLK;
407 uint64_t sub_measured_rtt_ms = final_sub_eight_times_rtt / 8 / RIST_CLK;
408 uint64_t ref_measured_rtt_ms = final_ref_eight_times_rtt / 8 / RIST_CLK;
409 uint64_t sub_buf_ms = sub_recovery_buf_ticks / RIST_CLK;
410 uint64_t sub_maxbuf_ms = sub_sender_max_buf_ticks / RIST_CLK;
411 uint64_t ref_pub_buf_ms = ref_pub_recovery_buf_ticks / RIST_CLK;
412 uint64_t ref_pub_maxbuf_ms = ref_pub_sender_max_buf_ticks / RIST_CLK;
413 size_t pub_sender_min_time_ms = pub_ctx->sender_ctx->sender_recover_min_time;
414
415 fprintf(stdout, "\n--- VERIFICATION RESULTS ---\n");
416 fprintf(stdout, "Publisher Natural RTT: %" PRIu64 " ms\n", pub_measured_rtt_ms);
417 fprintf(stdout, "Subscriber Natural RTT: %" PRIu64 " ms\n", sub_measured_rtt_ms);
418 fprintf(stdout, "Reflector Natural RTT: %" PRIu64 " ms\n", ref_measured_rtt_ms);
419 fprintf(stdout, "Publisher sender_recover_min_time: %" PRIu64 " ms\n", pub_sender_min_time_ms);
420 fprintf(stdout, "Subscriber recovery_buffer_ticks: %" PRIu64 " ms\n", sub_buf_ms);
421 fprintf(stdout, "Subscriber sender_max_buffer_ticks: %" PRIu64 " ms\n", sub_maxbuf_ms);
422 fprintf(stdout, "Reflector-Receiver recovery_buffer: %" PRIu64 " ms\n", ref_pub_buf_ms);
423 fprintf(stdout, "Reflector-Receiver sender_max_buffer: %" PRIu64 " ms\n", ref_pub_maxbuf_ms);
424
425 /* Assert that RTT calculations are working */
426 if (final_pub_eight_times_rtt == 0 || final_sub_eight_times_rtt == 0 || final_ref_eight_times_rtt == 0) {
427 fprintf(stderr, "FAIL: Measured RTTs are zero - echo exchange is broken!\n");
428 atomic_store(&failed, 1);
429 } else {
430 fprintf(stdout, "PASS: Measured RTTs are non-zero.\n");
431 }
432
433 /* Verify Publisher buffer size matches our expectations */
434 if (pub_sender_min_time_ms < 1500) {
435 fprintf(stderr, "FAIL: Publisher buffer (%zu ms) is smaller than configured max (1500ms)!\n", pub_sender_min_time_ms);
436 atomic_store(&failed, 1);
437 } else {
438 fprintf(stdout, "PASS: Publisher buffer (%zu ms) matches expected configuration.\n", pub_sender_min_time_ms);
439 }
440
441 /* Verify Subscriber buffer dynamic sizing and shrinkage */
442 const uint64_t initial_buf_ms = 775ULL;
443 if (sub_buf_ms >= initial_buf_ms) {
444 fprintf(stderr, "FAIL: Subscriber buffer (%" PRIu64 "ms) did not shrink from initial (%" PRIu64 "ms)!\n", sub_buf_ms, initial_buf_ms);
445 atomic_store(&failed, 1);
446 } else {
447 fprintf(stdout, "PASS: Subscriber buffer (%" PRIu64 "ms) successfully shrank from initial (%" PRIu64 "ms).\n", sub_buf_ms, initial_buf_ms);
448 }
449
450 if (sub_buf_ms < 50ULL || sub_buf_ms > 800ULL) {
451 fprintf(stderr, "FAIL: Subscriber buffer (%" PRIu64 "ms) out of expected dynamic range [50ms .. 800ms]!\n", sub_buf_ms);
452 atomic_store(&failed, 1);
453 } else {
454 fprintf(stdout, "PASS: Subscriber buffer (%" PRIu64 "ms) is in expected dynamic range [50ms .. 800ms].\n", sub_buf_ms);
455 }
456
457 /* Verify Reflector-Receiver buffer dynamic sizing and shrinkage */
458 if (ref_pub_buf_ms >= initial_buf_ms) {
459 fprintf(stderr, "FAIL: Reflector-Receiver buffer (%" PRIu64 "ms) did not shrink from initial (%" PRIu64 "ms)!\n", ref_pub_buf_ms, initial_buf_ms);
460 atomic_store(&failed, 1);
461 } else {
462 fprintf(stdout, "PASS: Reflector-Receiver buffer (%" PRIu64 "ms) successfully shrank from initial (%" PRIu64 "ms).\n", ref_pub_buf_ms, initial_buf_ms);
463 }
464
465 if (ref_pub_buf_ms < 50ULL || ref_pub_buf_ms > 800ULL) {
466 fprintf(stderr, "FAIL: Reflector-Receiver Reflector-Receiver buffer (%" PRIu64 "ms) out of expected dynamic range [50ms .. 800ms]!\n", ref_pub_buf_ms);
467 atomic_store(&failed, 1);
468 } else {
469 fprintf(stdout, "PASS: Reflector-Receiver buffer (%" PRIu64 "ms) is in expected dynamic range [50ms .. 800ms].\n", ref_pub_buf_ms);
470 }
471
472 /* Verify critical retransmission invariant: Publisher buffer >= Subscriber/Reflector buffer */
473 if ((uint64_t)pub_sender_min_time_ms < sub_buf_ms) {
474 fprintf(stderr, "FAIL: Retransmission Invariant Broken! Publisher buffer (%zu ms) < Subscriber buffer (%" PRIu64 " ms)!\n", pub_sender_min_time_ms, sub_buf_ms);
475 atomic_store(&failed, 1);
476 } else {
477 fprintf(stdout, "PASS: Retransmission Invariant Verified: Publisher buffer (%zu ms) >= Subscriber buffer (%" PRIu64 " ms).\n", pub_sender_min_time_ms, sub_buf_ms);
478 }
479
480 if ((uint64_t)pub_sender_min_time_ms < ref_pub_buf_ms) {
481 fprintf(stderr, "FAIL: Retransmission Invariant Broken! Publisher buffer (%zu ms) < Reflector buffer (%" PRIu64 " ms)!\n", pub_sender_min_time_ms, ref_pub_buf_ms);
482 atomic_store(&failed, 1);
483 } else {
484 fprintf(stdout, "PASS: Retransmission Invariant Verified: Publisher buffer (%zu ms) >= Reflector buffer (%" PRIu64 " ms).\n", pub_sender_min_time_ms, ref_pub_buf_ms);
485 }
486
487 if (!atomic_load(&failed))
488 fprintf(stdout, "SUCCESS: Direct buffer verification passed!\n");
489
490 if (atomic_load(&failed)) goto cleanup;
491
492
493 cleanup:
494 fprintf(stdout, "\nCleaning up contexts...\n");
495 if (pub_ctx) rist_destroy(pub_ctx);
496 if (sub_ctx) rist_destroy(sub_ctx);
497 if (reflector_ctx) rist_destroy(reflector_ctx);
498 free(logging_settings);
499
500 if (atomic_load(&failed)) {
501 fprintf(stderr, "\n============================================\n");
502 fprintf(stderr, " TEST SUITE RESULT: FAIL \n");
503 fprintf(stderr, "============================================\n\n");
504 ret = 1;
505 } else {
506 fprintf(stdout, "\n============================================\n");
507 fprintf(stdout, " TEST SUITE RESULT: PASS \n");
508 fprintf(stdout, "============================================\n\n");
509 ret = 0;
510 }
511
512 return ret;
513 }