err_status_t test_rdb_db() { rdb_t rdb; uint32_t idx, ircvd; ut_connection utc; err_status_t err; if (rdb_init(&rdb) != err_status_ok) { printf("rdb_init failed\n"); return err_status_init_fail; } /* test sequential insertion */ for (idx=0; idx < num_trials; idx++) { err = rdb_check_add(&rdb, idx); if (err) return err; } /* test for false positives */ for (idx=0; idx < num_trials; idx++) { err = rdb_check_expect_failure(&rdb, idx); if (err) return err; } /* re-initialize */ if (rdb_init(&rdb) != err_status_ok) { printf("rdb_init failed\n"); return err_status_fail; } /* test non-sequential insertion */ ut_init(&utc); for (idx=0; idx < num_trials; idx++) { ircvd = ut_next_index(&utc); err = rdb_check_unordered(&rdb, ircvd); if (err) return err; } return err_status_ok; }
srtp_err_status_t test_rdb_db() { srtp_rdb_t rdb; uint32_t idx, ircvd; ut_connection utc; srtp_err_status_t err; if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); return srtp_err_status_init_fail; } /* test sequential insertion */ for (idx = 0; idx < num_trials; idx++) { err = rdb_check_add(&rdb, idx); if (err) return err; } /* test for false positives */ for (idx = 0; idx < num_trials; idx++) { err = rdb_check_expect_failure(&rdb, idx); if (err) return err; } /* re-initialize */ if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); return srtp_err_status_fail; } /* test non-sequential insertion */ ut_init(&utc); for (idx = 0; idx < num_trials; idx++) { ircvd = ut_next_index(&utc); err = rdb_check_add_unordered(&rdb, ircvd); if (err) return err; err = rdb_check_expect_failure(&rdb, ircvd); if (err) return err; } /* re-initialize */ if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); return srtp_err_status_fail; } /* test insertion with large gaps */ for (idx = 0, ircvd = 0; idx < num_trials; idx++, ircvd += (1 << (srtp_cipher_rand_u32_for_tests() % 10))) { err = rdb_check_add(&rdb, ircvd); if (err) return err; err = rdb_check_expect_failure(&rdb, ircvd); if (err) return err; } /* re-initialize */ if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); return srtp_err_status_fail; } /* test loss of first 513 packets */ for (idx = 0; idx < num_trials; idx++) { err = rdb_check_add(&rdb, idx + 513); if (err) return err; } /* test for false positives */ for (idx = 0; idx < num_trials + 513; idx++) { err = rdb_check_expect_failure(&rdb, idx); if (err) return err; } /* test for key expired */ if (srtp_rdb_init(&rdb) != srtp_err_status_ok) { printf("rdb_init failed\n"); return srtp_err_status_fail; } rdb.window_start = 0x7ffffffe; if (srtp_rdb_increment(&rdb) != srtp_err_status_ok) { printf("srtp_rdb_increment of 0x7ffffffe failed\n"); return srtp_err_status_fail; } if (srtp_rdb_get_value(&rdb) != 0x7fffffff) { printf("rdb valiue was not 0x7fffffff\n"); return srtp_err_status_fail; } if (srtp_rdb_increment(&rdb) != srtp_err_status_key_expired) { printf("srtp_rdb_increment of 0x7fffffff did not return " "srtp_err_status_key_expired\n"); return srtp_err_status_fail; } if (srtp_rdb_get_value(&rdb) != 0x7fffffff) { printf("rdb valiue was not 0x7fffffff\n"); return srtp_err_status_fail; } return srtp_err_status_ok; }