| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <inttypes.h> |
| 8 |
#include <stdio.h> |
| 9 |
|
| 10 |
#include "../../../src/rist-reanchor.h" |
| 11 |
|
| 12 |
static int failures; |
| 13 |
|
| 14 |
static const char *name_of(enum rist_reanchor_action a) |
| 15 |
{ |
| 16 |
switch (a) { |
| 17 |
case RIST_REANCHOR_OK: |
| 18 |
return "OK"; |
| 19 |
case RIST_REANCHOR_WAIT: |
| 20 |
return "WAIT"; |
| 21 |
case RIST_REANCHOR_FORCED: |
| 22 |
return "FORCED"; |
| 23 |
} |
| 24 |
return "?"; |
| 25 |
} |
| 26 |
|
| 27 |
static void check(const char *name, enum rist_reanchor_action got, |
| 28 |
enum rist_reanchor_action want) |
| 29 |
{ |
| 30 |
if (got != want) { |
| 31 |
fprintf(stderr, "FAIL: %s -> %s (want %s)\n", name, name_of(got), |
| 32 |
name_of(want)); |
| 33 |
failures++; |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
#define BUF 1800 |
| 39 |
#define MAX 100000 |
| 40 |
|
| 41 |
int main(void) |
| 42 |
{ |
| 43 |
|
| 44 |
|
| 45 |
check("no_baseline", rist_flow_reanchor_check(50000, 0, BUF, 0, 0), |
| 46 |
RIST_REANCHOR_OK); |
| 47 |
|
| 48 |
check("no_buffer", rist_flow_reanchor_check(50000, MAX, 0, 0, 0), |
| 49 |
RIST_REANCHOR_OK); |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
check("ahead", rist_flow_reanchor_check(MAX + 500, MAX, BUF, 0, 0), |
| 54 |
RIST_REANCHOR_OK); |
| 55 |
check("behind_within_buffer", |
| 56 |
rist_flow_reanchor_check(MAX - 1000, MAX, BUF, 0, 0), RIST_REANCHOR_OK); |
| 57 |
|
| 58 |
check("behind_exactly_buffer", |
| 59 |
rist_flow_reanchor_check(MAX - BUF, MAX, BUF, 0, 0), RIST_REANCHOR_OK); |
| 60 |
|
| 61 |
|
| 62 |
check("behind_past_buffer", |
| 63 |
rist_flow_reanchor_check(MAX - BUF - 1, MAX, BUF, 0, 0), |
| 64 |
RIST_REANCHOR_WAIT); |
| 65 |
|
| 66 |
check("behind_lagged_leg", |
| 67 |
rist_flow_reanchor_check(MAX - 15000, MAX, BUF, 0, 0), |
| 68 |
RIST_REANCHOR_WAIT); |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
check("wait_still_short", |
| 73 |
rist_flow_reanchor_check(MAX - 15000, MAX, BUF, 1000, 1000 + BUF - 1), |
| 74 |
RIST_REANCHOR_WAIT); |
| 75 |
check("wait_expired", |
| 76 |
rist_flow_reanchor_check(MAX - 15000, MAX, BUF, 1000, 1000 + BUF), |
| 77 |
RIST_REANCHOR_FORCED); |
| 78 |
check("wait_long_expired", |
| 79 |
rist_flow_reanchor_check(MAX - 15000, MAX, BUF, 1000, 1000 + 10 * BUF), |
| 80 |
RIST_REANCHOR_FORCED); |
| 81 |
|
| 82 |
if (failures == 0) { |
| 83 |
printf("OK\n"); |
| 84 |
return 0; |
| 85 |
} |
| 86 |
fprintf(stderr, "Total failures: %d\n", failures); |
| 87 |
return 1; |
| 88 |
} |