Debian Codegraph @

test/rist/unit/test_send_grace.c

raw symbols SCIP
1 /* librist. SPDX-License-Identifier: BSD-2-Clause
2 *
3 * Unit test for rist_peer_may_send() - the grace period that keeps a peer in
4 * the send rotation for one recovery buffer window after it is declared dead.
5 * Pure, link-free. */
6
7 #include <stdio.h>
8
9 #include "../../../src/rist-send-grace.h"
10
11 static int failures;
12
13 static void check(const char *name, bool got, bool want)
14 {
15 if (got != want) {
16 fprintf(stderr, "FAIL: %s -> %s (want %s)\n", name,
17 got ? "send" : "drop", want ? "send" : "drop");
18 failures++;
19 }
20 }
21
22 /* One buffer window, and a death well clear of zero so a backwards clock is
23 * expressible. */
24 #define GRACE 4000
25 #define DIED 100000
26
27 int main(void)
28 {
29 /* A live peer is always eligible, whatever the clock says. */
30 check("alive", rist_peer_may_send(false, 0, GRACE, DIED), true);
31 check("alive_no_grace", rist_peer_may_send(false, 0, 0, DIED), true);
32
33 /* A dead peer keeps its place until the window runs out. This is the
34 * single-path case from #196: the return path went quiet but the
35 * receiver is still there, so cutting the stream strands it. */
36 check("died_now", rist_peer_may_send(true, DIED, GRACE, DIED), true);
37 check("inside_window",
38 rist_peer_may_send(true, DIED, GRACE, DIED + GRACE / 2), true);
39 check("last_tick_of_window",
40 rist_peer_may_send(true, DIED, GRACE, DIED + GRACE), true);
41
42 /* Past the window there is nothing left to wait for. */
43 check("just_past_window",
44 rist_peer_may_send(true, DIED, GRACE, DIED + GRACE + 1), false);
45 check("long_gone",
46 rist_peer_may_send(true, DIED, GRACE, DIED + 100 * GRACE), false);
47
48 /* No configured window: a dead peer is dropped at once. */
49 check("no_grace", rist_peer_may_send(true, DIED, 0, DIED), true);
50 check("no_grace_next_tick", rist_peer_may_send(true, DIED, 0, DIED + 1),
51 false);
52
53 /* A clock that moved backwards must not read as an expired window and
54 * cut a stream that is still fine. */
55 check("clock_went_backwards",
56 rist_peer_may_send(true, DIED, GRACE, DIED - 10 * GRACE), true);
57 check("clock_went_back_one_tick",
58 rist_peer_may_send(true, DIED, GRACE, DIED - 1), true);
59
60 if (failures == 0) {
61 printf("OK\n");
62 return 0;
63 }
64 fprintf(stderr, "Total failures: %d\n", failures);
65 return 1;
66 }