diff options
Diffstat (limited to 'third_party/srtp/test/rdbx_driver.c')
-rw-r--r-- | third_party/srtp/test/rdbx_driver.c | 106 |
1 files changed, 83 insertions, 23 deletions
diff --git a/third_party/srtp/test/rdbx_driver.c b/third_party/srtp/test/rdbx_driver.c index 7db67a2b..90bd72e7 100644 --- a/third_party/srtp/test/rdbx_driver.c +++ b/third_party/srtp/test/rdbx_driver.c @@ -43,6 +43,10 @@ * */ +#ifdef HAVE_CONFIG_H + #include <config.h> +#endif + #include <stdio.h> /* for printf() */ #include "getopt_s.h" /* for local getopt() */ @@ -55,10 +59,10 @@ #include "ut_sim.h" err_status_t -test_replay_dbx(int num_trials); +test_replay_dbx(int num_trials, unsigned long ws); double -rdbx_check_adds_per_second(int num_trials); +rdbx_check_adds_per_second(int num_trials, unsigned long ws); void usage(char *prog_name) { @@ -70,7 +74,7 @@ int main (int argc, char *argv[]) { double rate; err_status_t status; - char q; + int q; unsigned do_timing_test = 0; unsigned do_validation = 0; @@ -99,9 +103,18 @@ main (int argc, char *argv[]) { usage(argv[0]); if (do_validation) { - printf("testing rdbx_t...\n"); + printf("testing rdbx_t (ws=128)...\n"); + + status = test_replay_dbx(1 << 12, 128); + if (status) { + printf("failed\n"); + exit(1); + } + printf("passed\n"); - status = test_replay_dbx(1 << 12); + printf("testing rdbx_t (ws=1024)...\n"); + + status = test_replay_dbx(1 << 12, 1024); if (status) { printf("failed\n"); exit(1); @@ -110,8 +123,10 @@ main (int argc, char *argv[]) { } if (do_timing_test) { - rate = rdbx_check_adds_per_second(1 << 18); - printf("rdbx_check/replay_adds per second: %e\n", rate); + rate = rdbx_check_adds_per_second(1 << 18, 128); + printf("rdbx_check/replay_adds per second (ws=128): %e\n", rate); + rate = rdbx_check_adds_per_second(1 << 18, 1024); + printf("rdbx_check/replay_adds per second (ws=1024): %e\n", rate); } return 0; @@ -119,8 +134,11 @@ main (int argc, char *argv[]) { void print_rdbx(rdbx_t *rdbx) { + char buf[2048]; printf("rdbx: {%llu, %s}\n", - (unsigned long long)(rdbx->index), v128_bit_string(&rdbx->bitmask)); + (unsigned long long)(rdbx->index), + bitvector_bit_string(&rdbx->bitmask, buf, sizeof(buf)) +); } @@ -183,28 +201,38 @@ rdbx_check_expect_failure(rdbx_t *rdbx, uint32_t idx) { } err_status_t -rdbx_check_unordered(rdbx_t *rdbx, uint32_t idx) { +rdbx_check_add_unordered(rdbx_t *rdbx, uint32_t idx) { + int delta; + xtd_seq_num_t est; err_status_t rstat; - rstat = rdbx_check(rdbx, idx); + delta = index_guess(&rdbx->index, &est, idx); + + rstat = rdbx_check(rdbx, delta); if ((rstat != err_status_ok) && (rstat != err_status_replay_old)) { - printf("replay_check_unordered failed at index %u\n", idx); + printf("replay_check_add_unordered failed at index %u\n", idx); return err_status_algo_fail; } + if (rstat == err_status_replay_old) { + return err_status_ok; + } + if (rdbx_add_index(rdbx, delta) != err_status_ok) { + printf("rdbx_add_index failed at index %u\n", idx); + return err_status_algo_fail; + } + return err_status_ok; } -#define MAX_IDX 160 - err_status_t -test_replay_dbx(int num_trials) { +test_replay_dbx(int num_trials, unsigned long ws) { rdbx_t rdbx; uint32_t idx, ircvd; ut_connection utc; err_status_t status; int num_fp_trials; - status = rdbx_init(&rdbx); + status = rdbx_init(&rdbx, ws); if (status) { printf("replay_init failed with error code %d\n", status); exit(1); @@ -214,7 +242,7 @@ test_replay_dbx(int num_trials) { * test sequential insertion */ printf("\ttesting sequential insertion..."); - for (idx=0; idx < num_trials; idx++) { + for (idx=0; (int) idx < num_trials; idx++) { status = rdbx_check_add(&rdbx, idx); if (status) return status; @@ -233,7 +261,7 @@ test_replay_dbx(int num_trials) { printf("warning: no false positive tests performed\n"); } printf("\ttesting for false positives..."); - for (idx=0; idx < num_fp_trials; idx++) { + for (idx=0; (int) idx < num_fp_trials; idx++) { status = rdbx_check_expect_failure(&rdbx, idx); if (status) return status; @@ -241,7 +269,9 @@ test_replay_dbx(int num_trials) { printf("passed\n"); /* re-initialize */ - if (rdbx_init(&rdbx) != err_status_ok) { + rdbx_dealloc(&rdbx); + + if (rdbx_init(&rdbx, ws) != err_status_ok) { printf("replay_init failed\n"); return err_status_init_fail; } @@ -255,14 +285,42 @@ test_replay_dbx(int num_trials) { ut_init(&utc); printf("\ttesting non-sequential insertion..."); - for (idx=0; idx < num_trials; idx++) { + for (idx=0; (int) idx < num_trials; idx++) { ircvd = ut_next_index(&utc); - status = rdbx_check_unordered(&rdbx, ircvd); + status = rdbx_check_add_unordered(&rdbx, ircvd); if (status) return status; + status = rdbx_check_expect_failure(&rdbx, ircvd); + if (status) + return status; } printf("passed\n"); + /* re-initialize */ + rdbx_dealloc(&rdbx); + + if (rdbx_init(&rdbx, ws) != err_status_ok) { + printf("replay_init failed\n"); + return err_status_init_fail; + } + + /* + * test insertion with large gaps. + * check for false positives for each insertion. + */ + printf("\ttesting insertion with large gaps..."); + for (idx=0, ircvd=0; (int) idx < num_trials; idx++, ircvd += (1 << (rand() % 12))) { + status = rdbx_check_add(&rdbx, ircvd); + if (status) + return status; + status = rdbx_check_expect_failure(&rdbx, ircvd); + if (status) + return status; + } + printf("passed\n"); + + rdbx_dealloc(&rdbx); + return err_status_ok; } @@ -272,7 +330,7 @@ test_replay_dbx(int num_trials) { #include <stdlib.h> /* for random() */ double -rdbx_check_adds_per_second(int num_trials) { +rdbx_check_adds_per_second(int num_trials, unsigned long ws) { uint32_t i; int delta; rdbx_t rdbx; @@ -280,14 +338,14 @@ rdbx_check_adds_per_second(int num_trials) { clock_t timer; int failures; /* count number of failures */ - if (rdbx_init(&rdbx) != err_status_ok) { + if (rdbx_init(&rdbx, ws) != err_status_ok) { printf("replay_init failed\n"); exit(1); } failures = 0; timer = clock(); - for(i=0; i < num_trials; i++) { + for(i=0; (int) i < num_trials; i++) { delta = index_guess(&rdbx.index, &est, i); @@ -301,6 +359,8 @@ rdbx_check_adds_per_second(int num_trials) { printf("number of failures: %d \n", failures); + rdbx_dealloc(&rdbx); + return (double) CLOCKS_PER_SEC * num_trials / timer; } |