int main() { uint32_t i, irecvd, idiff; ut_connection utc; ut_init(&utc); for (i=0; i < 1000; i++) { irecvd = ut_next_index(&utc); idiff = i - irecvd; printf("%lu\t%lu\t%d\n", i, irecvd, idiff); } return 0; }
int main(int argc, char **argv) { ut_init(basename(argv[0])); ut_testing("skiplist_create(6, 50, libhl_cmp_keys_int32, free)"); skiplist_t *skl = skiplist_create(6, 50, libhl_cmp_keys_int32, free); if (skl) ut_success(); else ut_failure("Can't create a new binomial heap"); ut_testing("skiplist_insert(0..99)"); int i; for (i = 0; i < 100; i++) { char *val = malloc(4); snprintf(val, 4, "%d", i); skiplist_insert(skl, &i, sizeof(i), val); } ut_validate_int(skiplist_count(skl), 100); int test_key = 50; ut_testing("skiplist_search(50) = \"50\""); char *val = skiplist_search(skl, &test_key, sizeof(int)); ut_validate_string(val, "50"); ut_testing("skiplist_remove(50, &old_value)"); val = NULL; int rc = skiplist_remove(skl, &test_key, sizeof(int), (void **)&val); ut_validate_int(rc, 0); ut_testing("old_value is \"50\""); ut_validate_string(val, "50"); free(val); ut_testing("skiplist_search(50) = NULL"); val = skiplist_search(skl, &test_key, sizeof(int)); ut_validate_string(val, NULL); skiplist_destroy(skl); ut_summary(); return ut_failed; }
int main(int argc, char **argv) { ut_init(basename(argv[0])); ut_testing("binheap_create(binheap_keys_callbacks_int32(), BINHEAP_MODE_MAX)"); binheap_t *bh = binheap_create(binheap_keys_callbacks_int32_t(), BINHEAP_MODE_MAX); if (bh) ut_success(); else ut_failure("Can't create a new binomial heap"); ut_testing("binheap_insert(0..99)"); int i; for (i = 0; i < 100; i++) { binheap_insert(bh, &i, sizeof(i), NULL); } ut_validate_int(binheap_count(bh), 100); ut_testing("binheap_maximum() == 99"); int *max = NULL; binheap_maximum(bh, (void **)&max, NULL, NULL); ut_validate_int(*max, 99); ut_testing("binheap_minimum() == 0"); int *min = NULL; binheap_minimum(bh, (void **)&min, NULL, NULL); ut_validate_int(*min, 0); ut_testing("binheap_increase_minimum(bh, 1)"); binheap_increase_minimum(bh, 1); binheap_minimum(bh, (void **)&min, NULL, NULL); ut_validate_int(*min, 1); ut_testing("binheap_increase_maximum(bh, 1)"); binheap_increase_maximum(bh, 1); binheap_maximum(bh, (void **)&max, NULL, NULL); ut_validate_int(*max, 100); binheap_destroy(bh); ut_summary(); return ut_failed; }
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; }
/** * @brief Runs the test suite. */ int main (int argc, char **argv) { ut_prog_arg_config_t config; ut_init(&config, &argc, &argv); ut_suite_t *const s = ut_suite_new(&config, "game_tree_utils"); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "pve_create", pve_create_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "pve_internals_to_stream", pve_internals_to_stream_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "pve_is_invariant_satisfied", pve_is_invariant_satisfied_t); int failure_count = ut_suite_run(s); ut_suite_free(s); return failure_count; }
/** * @brief Runs the test suite. */ int main (int argc, char **argv) { ut_prog_arg_config_t config; ut_init(&config, &argc, &argv); aux_setup(); ut_suite_t *const s = ut_suite_new(&config, "file_utils"); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "fut_file_exists", fut_file_exists_t); int failure_count = ut_suite_run(s); ut_suite_free(s); aux_teardown(); return failure_count; }
/** * @brief Runs the test suite. */ int main (int argc, char **argv) { ut_prog_arg_config_t config; ut_init(&config, &argc, &argv); ut_suite_t *const s = ut_suite_new(&config, "sha3"); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_224", sha3_224_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_256", sha3_256_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_384", sha3_384_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_512", sha3_512_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_256_abc", sha3_256_abc_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_512_abc", sha3_512_abc_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_256_empty_string", sha3_256_empty_string_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_512_empty_string", sha3_512_empty_string_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_256_896_bits", sha3_256_896_bits_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_01, "sha3_256_1M_a_0", sha3_256_1M_a_0_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_01, "sha3_256_1M_a_1", sha3_256_1M_a_1_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_10, "sha3_256_extremely_long_message_0", sha3_256_extremely_long_message_0_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_10, "sha3_256_extremely_long_message_1", sha3_256_extremely_long_message_1_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_shake128_variable_output", sha3_shake128_variable_output_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_shake256_variable_output_0", sha3_shake256_variable_output_0_t); ut_suite_add_simple_test(s, UT_MODE_STND, UT_QUICKNESS_0001, "sha3_shake256_variable_output_1", sha3_shake256_variable_output_1_t); int failure_count = ut_suite_run(s); ut_suite_free(s); return failure_count; }
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; }
err_status_t 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, ws); if (status) { printf("replay_init failed with error code %d\n", status); exit(1); } /* * test sequential insertion */ printf("\ttesting sequential insertion..."); for (idx=0; idx < (uint32_t)num_trials; idx++) { status = rdbx_check_add(&rdbx, idx); if (status) return status; } printf("passed\n"); /* * test for false positives by checking all of the index * values which we've just added * * note that we limit the number of trials here, since allowing the * rollover counter to roll over would defeat this test */ num_fp_trials = num_trials % 0x10000; if (num_fp_trials == 0) { printf("warning: no false positive tests performed\n"); } printf("\ttesting for false positives..."); for (idx=0; idx < (uint32_t)num_fp_trials; idx++) { status = rdbx_check_expect_failure(&rdbx, idx); if (status) return status; } printf("passed\n"); /* re-initialize */ rdbx_uninit(&rdbx); if (rdbx_init(&rdbx, ws) != err_status_ok) { printf("replay_init failed\n"); return err_status_init_fail; } /* * test non-sequential insertion * * this test covers only fase negatives, since the values returned * by ut_next_index(...) are distinct */ ut_init(&utc); printf("\ttesting non-sequential insertion..."); for (idx=0; idx < (uint32_t)num_trials; idx++) { ircvd = ut_next_index(&utc); status = rdbx_check_unordered(&rdbx, ircvd); if (status) return status; } printf("passed\n"); /* * test a replay condition close to zero. */ rdbx_uninit(&rdbx); if (rdbx_init(&rdbx, ws) != err_status_ok) { printf("replay_init failed\n"); return err_status_init_fail; } printf("\ttesting replay close to zero..."); status = rdbx_check_add(&rdbx, 1); if (status) return status; status = rdbx_check_expect_failure(&rdbx, 64500); if (status) return status; status = rdbx_check_add(&rdbx, 2); if (status) return status; printf("passed\n"); rdbx_uninit(&rdbx); return err_status_ok; }
/** * initialize the Portscan Tracker. * * This takes several arguments, all, on the PS_CONFIG structure. * * @param trackerp tracker object to initialize * @param configp well-formed configuration to initialize this object * * @return FLOW_SUCCESS on success */ int flowps_init(PS_TRACKER *trackerp, PS_CONFIG *configp) { int ret; if(!trackerp || !configp) return FLOW_ENULL; /* we should validate this threshold object somewhat */ memcpy(&trackerp->config, configp, sizeof(PS_CONFIG)); ret = scoreboard_init(&trackerp->table_active, /* table */ "Active Talkers", /* description */ TRACKER_ACTIVE, /* position */ trackerp->config.sb_rows_talker, /* node count */ trackerp->config.sb_memcap_talker); /* memcap */ if(ret != FLOW_SUCCESS) { return ret; } ret = scoreboard_init(&trackerp->table_scanner, /* table */ "Portscanners", /* description */ TRACKER_SCANNER, /* position */ trackerp->config.sb_rows_scanner, /* node count */ trackerp->config.sb_memcap_scanner); /* memcap */ if(ret != FLOW_SUCCESS) { scoreboard_destroy(&trackerp->table_active); return ret; } /* setup the unique talkers table */ ret = ut_init(&trackerp->unique_tracker,trackerp->config.ut_rows, trackerp->config.ut_memcap); if(ret != FLOW_SUCCESS) { scoreboard_destroy(&trackerp->table_active); scoreboard_destroy(&trackerp->table_scanner); return ret; } /* the watchnet stuff is optional */ if(flowps_server_stats_enabled(trackerp) == FLOW_SUCCESS) { ret = server_stats_init(&trackerp->server_stats, trackerp->config.server_watchnet_ipv4, trackerp->config.server_rows, trackerp->config.server_memcap); if(ret != FLOW_SUCCESS) { scoreboard_destroy(&trackerp->table_active); scoreboard_destroy(&trackerp->table_scanner); ut_destroy(&trackerp->unique_tracker); return ret; } } s_enabled = 1; return FLOW_SUCCESS; }
srtp_err_status_t roc_test(int num_trials) { srtp_xtd_seq_num_t local, est, ref; ut_connection utc; int i, num_bad_est = 0; int delta; uint32_t ircvd; double failure_rate; srtp_index_init(&local); srtp_index_init(&ref); srtp_index_init(&est); printf("\n\ttesting sequential insertion..."); for (i=0; i < 2048; i++) { delta = srtp_index_guess(&local, &est, (uint16_t) ref); #if ROC_VERBOSE printf("%lld, %lld, %d\n", ref, est, i); #endif if (ref != est) { #if ROC_VERBOSE printf(" *bad estimate*\n"); #endif ++num_bad_est; } srtp_index_advance(&ref, 1); } failure_rate = (double) num_bad_est / num_trials; if (failure_rate > 0.01) { printf("error: failure rate too high (%d bad estimates in %d trials)\n", num_bad_est, num_trials); return srtp_err_status_algo_fail; } printf("done\n"); printf("\ttesting non-sequential insertion..."); srtp_index_init(&local); srtp_index_init(&ref); srtp_index_init(&est); ut_init(&utc); for (i=0; i < num_trials; i++) { /* get next seq num from unreliable transport simulator */ ircvd = ut_next_index(&utc); /* set ref to value of ircvd */ ref = ircvd; /* estimate index based on low bits of ircvd */ delta = srtp_index_guess(&local, &est, (uint16_t) ref); #if ROC_VERBOSE printf("ref: %lld, local: %lld, est: %lld, ircvd: %d, delta: %d\n", ref, local, est, ircvd, delta); #endif if (local + delta != est) { printf(" *bad delta*: local %llu + delta %d != est %llu\n", (unsigned long long)local, delta, (unsigned long long)est); return srtp_err_status_algo_fail; } /* now update local srtp_xtd_seq_num_t as necessary */ if (delta > 0) srtp_index_advance(&local, delta); if (ref != est) { #if ROC_VERBOSE printf(" *bad estimate*\n"); #endif /* record failure event */ ++num_bad_est; /* reset local value to correct value */ local = ref; } } failure_rate = (double) num_bad_est / num_trials; if (failure_rate > 0.01) { printf("error: failure rate too high (%d bad estimates in %d trials)\n", num_bad_est, num_trials); return srtp_err_status_algo_fail; } printf("done\n"); return srtp_err_status_ok; }