| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
|
| 9 |
#include "../../../src/rist-bandwidth-guard.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 -> %d (want %d)\n", name, got, want); |
| 17 |
failures++; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
#define MBPS(x) ((size_t)((x) * 1000000)) |
| 23 |
|
| 24 |
int main(void) |
| 25 |
{ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
check("ample_headroom", |
| 31 |
rist_retransmit_budget_starved(MBPS(9.2), MBPS(20)), false); |
| 32 |
|
| 33 |
|
| 34 |
check("thin_but_nonzero", |
| 35 |
rist_retransmit_budget_starved(MBPS(9.2), MBPS(9.3)), false); |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
check("ceiling_below_payload", |
| 41 |
rist_retransmit_budget_starved(MBPS(9.15), MBPS(8.8)), true); |
| 42 |
check("ceiling_equals_payload", |
| 43 |
rist_retransmit_budget_starved(MBPS(9), MBPS(9)), true); |
| 44 |
check("ceiling_just_above_payload", |
| 45 |
rist_retransmit_budget_starved(MBPS(9), MBPS(9) + 1), false); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
check("no_ceiling", rist_retransmit_budget_starved(MBPS(100), 0), false); |
| 50 |
|
| 51 |
check("idle_stream", rist_retransmit_budget_starved(0, MBPS(20)), false); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
check("first_time_always_due", rist_bandwidth_warn_due(0, 100, 0), true); |
| 56 |
check("not_due_yet", rist_bandwidth_warn_due(1000, 100, 1050), false); |
| 57 |
check("due_at_interval", rist_bandwidth_warn_due(1000, 100, 1100), true); |
| 58 |
check("due_past_interval", rist_bandwidth_warn_due(1000, 100, 5000), true); |
| 59 |
|
| 60 |
check("clock_went_backwards", rist_bandwidth_warn_due(1000, 100, 500), true); |
| 61 |
|
| 62 |
if (failures == 0) { |
| 63 |
printf("OK\n"); |
| 64 |
return 0; |
| 65 |
} |
| 66 |
fprintf(stderr, "Total failures: %d\n", failures); |
| 67 |
return 1; |
| 68 |
} |