diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-09-15 21:18:21 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-09-15 21:18:21 -0400 |
commit | 0243895792f937399839464ab5744b35734969a9 (patch) | |
tree | 991b6dbc5dfd1733283b5a07decc003b07879bae /src/test/test.c | |
parent | 0bd220adcb82670893c85b1cc24d64e615855b4f (diff) | |
download | tor-0243895792f937399839464ab5744b35734969a9.tar.gz tor-0243895792f937399839464ab5744b35734969a9.zip |
Use coccinelle scripts to clean up our unit tests
This should get rid of most of the users of the old test_*
functions. Some are in macros and will need manual cleanup, though.
This patch is for 13119, and was automatically generated with these
scripts. The perl scripts are there because coccinelle hates
operators as macro arguments.
------------------------------
s/==,/_X_EQ_,/g;
s/!=,/_X_NE_,/g;
s/<,/_X_LT_,/g;
s/>,/_X_GT_,/g;
s/>=,/_X_GEQ_,/g;
s/<=,/_X_LEQ_,/g;
------------------------------
@@
expression a;
identifier func;
@@
func (...) {
<...
-test_fail_msg
+TT_DIE
(
+(
a
+)
)
...>
}
@@
identifier func;
@@
func (...) {
<...
-test_fail()
+TT_DIE(("Assertion failed."))
...>
}
@@
expression a;
identifier func;
@@
func (...) {
<...
-test_assert
+tt_assert
(a)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_eq
+tt_int_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_neq
+tt_int_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_streq
+tt_str_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_strneq
+tt_str_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func (...) {
<...
-test_eq_ptr
+tt_ptr_op
(a,
+_X_EQ_,
b)
...>
}
@@
expression a, b;
identifier func;
@@
func() {
<...
-test_neq_ptr
+tt_ptr_op
(a,
+_X_NEQ_,
b)
...>
}
@@
expression a, b, len;
identifier func;
@@
func (...) {
<...
-test_memeq
+tt_mem_op
(a,
+_X_EQ_,
b, len)
...>
}
@@
expression a, b, len;
identifier func;
@@
func (...) {
<...
-test_memneq
+tt_mem_op
(a,
+_X_NEQ_,
b, len)
...>
}
------------------------------
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a == b
+a, _X_EQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a != b
+a, _X_NEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a >= b
+a, _X_GEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a <= b
+a, _X_LEQ_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a > b
+a, _X_GT_, b
)
...>
}
@@
char a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_int_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
unsigned int a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a < b
+a, _X_LT_, b
)
...>
}
@@
unsigned long a, b;
identifier func;
@@
func (...) {
<...
-tt_assert
+tt_uint_op
(
-a < b
+a, _X_LT_, b
)
...>
}
------------------------------
s/_X_NEQ_/!=/g;
s/_X_NE_/!=/g;
s/_X_EQ_/==/g;
s/_X_GT_/>/g;
s/_X_LT_/</g;
s/_X_GEQ_/>=/g;
s/_X_LEQ_/<=/g;
s/test_mem_op\(/tt_mem_op\(/g;
Diffstat (limited to 'src/test/test.c')
-rw-r--r-- | src/test/test.c | 246 |
1 files changed, 123 insertions, 123 deletions
diff --git a/src/test/test.c b/src/test/test.c index e836160bf4..516fa42b41 100644 --- a/src/test/test.c +++ b/src/test/test.c @@ -250,7 +250,7 @@ test_onion_handshake(void) /* client handshake 1. */ memset(c_buf, 0, TAP_ONIONSKIN_CHALLENGE_LEN); - test_assert(! onion_skin_TAP_create(pk, &c_dh, c_buf)); + tt_assert(! onion_skin_TAP_create(pk, &c_dh, c_buf)); for (i = 1; i <= 3; ++i) { crypto_pk_t *k1, *k2; @@ -267,16 +267,16 @@ test_onion_handshake(void) memset(s_buf, 0, TAP_ONIONSKIN_REPLY_LEN); memset(s_keys, 0, 40); - test_assert(! onion_skin_TAP_server_handshake(c_buf, k1, k2, + tt_assert(! onion_skin_TAP_server_handshake(c_buf, k1, k2, s_buf, s_keys, 40)); /* client handshake 2 */ memset(c_keys, 0, 40); - test_assert(! onion_skin_TAP_client_handshake(c_dh, s_buf, c_keys, 40)); + tt_assert(! onion_skin_TAP_client_handshake(c_dh, s_buf, c_keys, 40)); - test_memeq(c_keys, s_keys, 40); + tt_mem_op(c_keys,==, s_keys, 40); memset(s_buf, 0, 40); - test_memneq(c_keys, s_buf, 40); + tt_mem_op(c_keys,!=, s_buf, 40); } done: crypto_dh_free(c_dh); @@ -323,7 +323,7 @@ test_bad_onion_handshake(void *arg) /* client handshake 1: do it straight. */ memset(c_buf, 0, TAP_ONIONSKIN_CHALLENGE_LEN); - test_assert(! onion_skin_TAP_create(pk, &c_dh, c_buf)); + tt_assert(! onion_skin_TAP_create(pk, &c_dh, c_buf)); /* Server: Case 3: we just don't have the right key. */ tt_int_op(-1, ==, @@ -351,7 +351,7 @@ test_bad_onion_handshake(void *arg) /* Let the client finish; make sure it can. */ tt_int_op(0, ==, onion_skin_TAP_client_handshake(c_dh, s_buf, c_keys, 40)); - test_memeq(s_keys, c_keys, 40); + tt_mem_op(s_keys,==, c_keys, 40); /* Client: Case 2: The server sent back a degenerate DH. */ memset(s_buf, 0, sizeof(s_buf)); @@ -408,9 +408,9 @@ test_ntor_handshake(void *arg) tt_int_op(0, ==, onion_skin_ntor_client_handshake(c_state, s_buf, c_keys, 400)); - test_memeq(c_keys, s_keys, 400); + tt_mem_op(c_keys,==, s_keys, 400); memset(s_buf, 0, 40); - test_memneq(c_keys, s_buf, 40); + tt_mem_op(c_keys,!=, s_buf, 40); done: ntor_handshake_state_free(c_state); @@ -438,24 +438,24 @@ test_onion_queues(void) create_cell_init(create2, CELL_CREATE, ONION_HANDSHAKE_TYPE_NTOR, NTOR_ONIONSKIN_LEN, buf2); - test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); - test_eq(0, onion_pending_add(circ1, create1)); + tt_int_op(0,==, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); + tt_int_op(0,==, onion_pending_add(circ1, create1)); create1 = NULL; - test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); + tt_int_op(1,==, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); - test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); - test_eq(0, onion_pending_add(circ2, create2)); + tt_int_op(0,==, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); + tt_int_op(0,==, onion_pending_add(circ2, create2)); create2 = NULL; - test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); + tt_int_op(1,==, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); - test_eq_ptr(circ2, onion_next_task(&onionskin)); - test_eq(1, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); - test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); + tt_ptr_op(circ2,==, onion_next_task(&onionskin)); + tt_int_op(1,==, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); + tt_int_op(0,==, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); tt_ptr_op(onionskin, ==, create2_ptr); clear_pending_onions(); - test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); - test_eq(0, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); + tt_int_op(0,==, onion_num_pending(ONION_HANDSHAKE_TYPE_TAP)); + tt_int_op(0,==, onion_num_pending(ONION_HANDSHAKE_TYPE_NTOR)); done: circuit_free(TO_CIRCUIT(circ1)); @@ -518,11 +518,11 @@ test_circuit_timeout(void) } while (fabs(circuit_build_times_cdf(&initial, timeout0) - circuit_build_times_cdf(&initial, timeout1)) > 0.02); - test_assert(estimate.total_build_times <= CBT_NCIRCUITS_TO_OBSERVE); + tt_assert(estimate.total_build_times <= CBT_NCIRCUITS_TO_OBSERVE); circuit_build_times_update_state(&estimate, state); circuit_build_times_free_timeouts(&final); - test_assert(circuit_build_times_parse_state(&final, state) == 0); + tt_assert(circuit_build_times_parse_state(&final, state) == 0); circuit_build_times_update_alpha(&final); timeout2 = circuit_build_times_calculate_timeout(&final, @@ -532,7 +532,7 @@ test_circuit_timeout(void) log_notice(LD_CIRC, "Timeout2 is %f, Xm is %d", timeout2, final.Xm); /* 5% here because some accuracy is lost due to histogram conversion */ - test_assert(fabs(circuit_build_times_cdf(&initial, timeout0) - + tt_assert(fabs(circuit_build_times_cdf(&initial, timeout0) - circuit_build_times_cdf(&initial, timeout2)) < 0.05); for (runs = 0; runs < 50; runs++) { @@ -555,8 +555,8 @@ test_circuit_timeout(void) CBT_DEFAULT_QUANTILE_CUTOFF/100.0)); } - test_assert(!circuit_build_times_network_check_changed(&estimate)); - test_assert(!circuit_build_times_network_check_changed(&final)); + tt_assert(!circuit_build_times_network_check_changed(&estimate)); + tt_assert(!circuit_build_times_network_check_changed(&final)); /* Reset liveness to be non-live */ final.liveness.network_last_live = 0; @@ -565,27 +565,27 @@ test_circuit_timeout(void) build_times_idx = estimate.build_times_idx; total_build_times = estimate.total_build_times; - test_assert(circuit_build_times_network_check_live(&estimate)); - test_assert(circuit_build_times_network_check_live(&final)); + tt_assert(circuit_build_times_network_check_live(&estimate)); + tt_assert(circuit_build_times_network_check_live(&final)); circuit_build_times_count_close(&estimate, 0, (time_t)(approx_time()-estimate.close_ms/1000.0-1)); circuit_build_times_count_close(&final, 0, (time_t)(approx_time()-final.close_ms/1000.0-1)); - test_assert(!circuit_build_times_network_check_live(&estimate)); - test_assert(!circuit_build_times_network_check_live(&final)); + tt_assert(!circuit_build_times_network_check_live(&estimate)); + tt_assert(!circuit_build_times_network_check_live(&final)); log_info(LD_CIRC, "idx: %d %d, tot: %d %d", build_times_idx, estimate.build_times_idx, total_build_times, estimate.total_build_times); /* Check rollback index. Should match top of loop. */ - test_assert(build_times_idx == estimate.build_times_idx); + tt_assert(build_times_idx == estimate.build_times_idx); // This can fail if estimate.total_build_times == 1000, because // in that case, rewind actually causes us to lose timeouts if (total_build_times != CBT_NCIRCUITS_TO_OBSERVE) - test_assert(total_build_times == estimate.total_build_times); + tt_assert(total_build_times == estimate.total_build_times); /* Now simulate that the network has become live and we need * a change */ @@ -600,12 +600,12 @@ test_circuit_timeout(void) } } - test_assert(estimate.liveness.after_firsthop_idx == 0); - test_assert(final.liveness.after_firsthop_idx == + tt_assert(estimate.liveness.after_firsthop_idx == 0); + tt_assert(final.liveness.after_firsthop_idx == CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT-1); - test_assert(circuit_build_times_network_check_live(&estimate)); - test_assert(circuit_build_times_network_check_live(&final)); + tt_assert(circuit_build_times_network_check_live(&estimate)); + tt_assert(circuit_build_times_network_check_live(&final)); circuit_build_times_count_timeout(&final, 1); } @@ -642,16 +642,16 @@ test_rend_fns(void) char address6[] = "foo.bar.abcdefghijklmnop.onion"; char address7[] = ".abcdefghijklmnop.onion"; - test_assert(BAD_HOSTNAME == parse_extended_hostname(address1)); - test_assert(ONION_HOSTNAME == parse_extended_hostname(address2)); - test_streq(address2, "aaaaaaaaaaaaaaaa"); - test_assert(EXIT_HOSTNAME == parse_extended_hostname(address3)); - test_assert(NORMAL_HOSTNAME == parse_extended_hostname(address4)); - test_assert(ONION_HOSTNAME == parse_extended_hostname(address5)); - test_streq(address5, "abcdefghijklmnop"); - test_assert(ONION_HOSTNAME == parse_extended_hostname(address6)); - test_streq(address6, "abcdefghijklmnop"); - test_assert(BAD_HOSTNAME == parse_extended_hostname(address7)); + tt_assert(BAD_HOSTNAME == parse_extended_hostname(address1)); + tt_assert(ONION_HOSTNAME == parse_extended_hostname(address2)); + tt_str_op(address2,==, "aaaaaaaaaaaaaaaa"); + tt_assert(EXIT_HOSTNAME == parse_extended_hostname(address3)); + tt_assert(NORMAL_HOSTNAME == parse_extended_hostname(address4)); + tt_assert(ONION_HOSTNAME == parse_extended_hostname(address5)); + tt_str_op(address5,==, "abcdefghijklmnop"); + tt_assert(ONION_HOSTNAME == parse_extended_hostname(address6)); + tt_str_op(address6,==, "abcdefghijklmnop"); + tt_assert(BAD_HOSTNAME == parse_extended_hostname(address7)); pk1 = pk_generate(0); pk2 = pk_generate(1); @@ -684,40 +684,40 @@ test_rend_fns(void) intro->intro_key = crypto_pk_dup_key(pk2); smartlist_add(generated->intro_nodes, intro); } - test_assert(rend_encode_v2_descriptors(descs, generated, now, 0, + tt_assert(rend_encode_v2_descriptors(descs, generated, now, 0, REND_NO_AUTH, NULL, NULL) > 0); - test_assert(rend_compute_v2_desc_id(computed_desc_id, service_id_base32, + tt_assert(rend_compute_v2_desc_id(computed_desc_id, service_id_base32, NULL, now, 0) == 0); - test_memeq(((rend_encoded_v2_service_descriptor_t *) - smartlist_get(descs, 0))->desc_id, computed_desc_id, DIGEST_LEN); - test_assert(rend_parse_v2_service_descriptor(&parsed, parsed_desc_id, + tt_mem_op(((rend_encoded_v2_service_descriptor_t *) + smartlist_get(descs, 0))->desc_id,==, computed_desc_id, DIGEST_LEN); + tt_assert(rend_parse_v2_service_descriptor(&parsed, parsed_desc_id, &intro_points_encrypted, &intro_points_size, &encoded_size, &next_desc, ((rend_encoded_v2_service_descriptor_t *) smartlist_get(descs, 0))->desc_str) == 0); - test_assert(parsed); - test_memeq(((rend_encoded_v2_service_descriptor_t *) - smartlist_get(descs, 0))->desc_id, parsed_desc_id, DIGEST_LEN); - test_eq(rend_parse_introduction_points(parsed, intro_points_encrypted, - intro_points_size), 3); - test_assert(!crypto_pk_cmp_keys(generated->pk, parsed->pk)); - test_eq(parsed->timestamp, now); - test_eq(parsed->version, 2); - test_eq(parsed->protocols, 42); - test_eq(smartlist_len(parsed->intro_nodes), 3); + tt_assert(parsed); + tt_mem_op(((rend_encoded_v2_service_descriptor_t *) + smartlist_get(descs, 0))->desc_id,==, parsed_desc_id, DIGEST_LEN); + tt_int_op(rend_parse_introduction_points(parsed, intro_points_encrypted, + intro_points_size),==, 3); + tt_assert(!crypto_pk_cmp_keys(generated->pk, parsed->pk)); + tt_int_op(parsed->timestamp,==, now); + tt_int_op(parsed->version,==, 2); + tt_int_op(parsed->protocols,==, 42); + tt_int_op(smartlist_len(parsed->intro_nodes),==, 3); for (i = 0; i < smartlist_len(parsed->intro_nodes); i++) { rend_intro_point_t *par_intro = smartlist_get(parsed->intro_nodes, i), *gen_intro = smartlist_get(generated->intro_nodes, i); extend_info_t *par_info = par_intro->extend_info; extend_info_t *gen_info = gen_intro->extend_info; - test_assert(!crypto_pk_cmp_keys(gen_info->onion_key, par_info->onion_key)); - test_memeq(gen_info->identity_digest, par_info->identity_digest, + tt_assert(!crypto_pk_cmp_keys(gen_info->onion_key, par_info->onion_key)); + tt_mem_op(gen_info->identity_digest,==, par_info->identity_digest, DIGEST_LEN); - test_streq(gen_info->nickname, par_info->nickname); - test_assert(tor_addr_eq(&gen_info->addr, &par_info->addr)); - test_eq(gen_info->port, par_info->port); + tt_str_op(gen_info->nickname,==, par_info->nickname); + tt_assert(tor_addr_eq(&gen_info->addr, &par_info->addr)); + tt_int_op(gen_info->port,==, par_info->port); } rend_service_descriptor_free(parsed); @@ -825,23 +825,23 @@ test_geoip(void) /* Populate the DB a bit. Add these in order, since we can't do the final * 'sort' step. These aren't very good IP addresses, but they're perfectly * fine uint32_t values. */ - test_eq(0, geoip_parse_entry("10,50,AB", AF_INET)); - test_eq(0, geoip_parse_entry("52,90,XY", AF_INET)); - test_eq(0, geoip_parse_entry("95,100,AB", AF_INET)); - test_eq(0, geoip_parse_entry("\"105\",\"140\",\"ZZ\"", AF_INET)); - test_eq(0, geoip_parse_entry("\"150\",\"190\",\"XY\"", AF_INET)); - test_eq(0, geoip_parse_entry("\"200\",\"250\",\"AB\"", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("10,50,AB", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("52,90,XY", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("95,100,AB", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("\"105\",\"140\",\"ZZ\"", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("\"150\",\"190\",\"XY\"", AF_INET)); + tt_int_op(0,==, geoip_parse_entry("\"200\",\"250\",\"AB\"", AF_INET)); /* Populate the IPv6 DB equivalently with fake IPs in the same range */ - test_eq(0, geoip_parse_entry("::a,::32,AB", AF_INET6)); - test_eq(0, geoip_parse_entry("::34,::5a,XY", AF_INET6)); - test_eq(0, geoip_parse_entry("::5f,::64,AB", AF_INET6)); - test_eq(0, geoip_parse_entry("::69,::8c,ZZ", AF_INET6)); - test_eq(0, geoip_parse_entry("::96,::be,XY", AF_INET6)); - test_eq(0, geoip_parse_entry("::c8,::fa,AB", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::a,::32,AB", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::34,::5a,XY", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::5f,::64,AB", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::69,::8c,ZZ", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::96,::be,XY", AF_INET6)); + tt_int_op(0,==, geoip_parse_entry("::c8,::fa,AB", AF_INET6)); /* We should have 4 countries: ??, ab, xy, zz. */ - test_eq(4, geoip_get_n_countries()); + tt_int_op(4,==, geoip_get_n_countries()); memset(&in6, 0, sizeof(in6)); CHECK_COUNTRY("??", 3); @@ -852,9 +852,9 @@ test_geoip(void) CHECK_COUNTRY("xy", 190); CHECK_COUNTRY("??", 2000); - test_eq(0, geoip_get_country_by_ipv4(3)); + tt_int_op(0,==, geoip_get_country_by_ipv4(3)); SET_TEST_IPV6(3); - test_eq(0, geoip_get_country_by_ipv6(&in6)); + tt_int_op(0,==, geoip_get_country_by_ipv6(&in6)); get_options_mutable()->BridgeRelay = 1; get_options_mutable()->BridgeRecordUsageByCountry = 1; @@ -877,41 +877,41 @@ test_geoip(void) geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now); } geoip_get_client_history(GEOIP_CLIENT_CONNECT, &s, &v); - test_assert(s); - test_assert(v); - test_streq("zz=24,ab=16,xy=8", s); - test_streq("v4=16,v6=16", v); + tt_assert(s); + tt_assert(v); + tt_str_op("zz=24,ab=16,xy=8",==, s); + tt_str_op("v4=16,v6=16",==, v); tor_free(s); tor_free(v); /* Now clear out all the AB observations. */ geoip_remove_old_clients(now-6000); geoip_get_client_history(GEOIP_CLIENT_CONNECT, &s, &v); - test_assert(s); - test_assert(v); - test_streq("zz=24,xy=8", s); - test_streq("v4=16,v6=16", v); + tt_assert(s); + tt_assert(v); + tt_str_op("zz=24,xy=8",==, s); + tt_str_op("v4=16,v6=16",==, v); tor_free(s); tor_free(v); /* Start testing bridge statistics by making sure that we don't output * bridge stats without initializing them. */ s = geoip_format_bridge_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats and generate the bridge-stats history string out of * the connecting clients added above. */ geoip_bridge_stats_init(now); s = geoip_format_bridge_stats(now + 86400); - test_assert(s); - test_streq(bridge_stats_1, s); + tt_assert(s); + tt_str_op(bridge_stats_1,==, s); tor_free(s); /* Stop collecting bridge stats and make sure we don't write a history * string anymore. */ geoip_bridge_stats_term(); s = geoip_format_bridge_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Stop being a bridge and start being a directory mirror that gathers * directory request statistics. */ @@ -925,7 +925,7 @@ test_geoip(void) SET_TEST_ADDRESS(100); geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now); s = geoip_format_dirreq_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats, note one connecting client, and generate the * dirreq-stats history string. */ @@ -933,7 +933,7 @@ test_geoip(void) SET_TEST_ADDRESS(100); geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now); s = geoip_format_dirreq_stats(now + 86400); - test_streq(dirreq_stats_1, s); + tt_str_op(dirreq_stats_1,==, s); tor_free(s); /* Stop collecting stats, add another connecting client, and ensure we @@ -942,7 +942,7 @@ test_geoip(void) SET_TEST_ADDRESS(101); geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now); s = geoip_format_dirreq_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Re-start stats, add a connecting client, reset stats, and make sure * that we get an all empty history string. */ @@ -951,20 +951,20 @@ test_geoip(void) geoip_note_client_seen(GEOIP_CLIENT_NETWORKSTATUS, &addr, NULL, now); geoip_reset_dirreq_stats(now); s = geoip_format_dirreq_stats(now + 86400); - test_streq(dirreq_stats_2, s); + tt_str_op(dirreq_stats_2,==, s); tor_free(s); /* Note a successful network status response and make sure that it * appears in the history string. */ geoip_note_ns_response(GEOIP_SUCCESS); s = geoip_format_dirreq_stats(now + 86400); - test_streq(dirreq_stats_3, s); + tt_str_op(dirreq_stats_3,==, s); tor_free(s); /* Start a tunneled directory request. */ geoip_start_dirreq((uint64_t) 1, 1024, DIRREQ_TUNNELED); s = geoip_format_dirreq_stats(now + 86400); - test_streq(dirreq_stats_4, s); + tt_str_op(dirreq_stats_4,==, s); tor_free(s); /* Stop collecting directory request statistics and start gathering @@ -978,7 +978,7 @@ test_geoip(void) SET_TEST_ADDRESS(100); geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now); s = geoip_format_entry_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats, note one connecting client, and generate the * entry-stats history string. */ @@ -986,7 +986,7 @@ test_geoip(void) SET_TEST_ADDRESS(100); geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now); s = geoip_format_entry_stats(now + 86400); - test_streq(entry_stats_1, s); + tt_str_op(entry_stats_1,==, s); tor_free(s); /* Stop collecting stats, add another connecting client, and ensure we @@ -995,7 +995,7 @@ test_geoip(void) SET_TEST_ADDRESS(101); geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now); s = geoip_format_entry_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Re-start stats, add a connecting client, reset stats, and make sure * that we get an all empty history string. */ @@ -1004,7 +1004,7 @@ test_geoip(void) geoip_note_client_seen(GEOIP_CLIENT_CONNECT, &addr, NULL, now); geoip_reset_entry_stats(now); s = geoip_format_entry_stats(now + 86400); - test_streq(entry_stats_2, s); + tt_str_op(entry_stats_2,==, s); tor_free(s); /* Stop collecting entry statistics. */ @@ -1076,7 +1076,7 @@ test_geoip_with_pt(void) /* Test the transport history string. */ s = geoip_get_transport_history(); tor_assert(s); - test_streq(s, "<OR>=8,alpha=16,beta=8,charlie=16,ddr=136," + tt_str_op(s,==, "<OR>=8,alpha=16,beta=8,charlie=16,ddr=136," "entropy=8,fire=8,google=8"); /* Stop collecting entry statistics. */ @@ -1104,7 +1104,7 @@ test_stats(void) rep_hist_note_exit_stream_opened(80); rep_hist_note_exit_bytes(80, 100, 10000); s = rep_hist_format_exit_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats, note some streams and bytes, and generate history * string. */ @@ -1115,10 +1115,10 @@ test_stats(void) rep_hist_note_exit_bytes(443, 100, 10000); rep_hist_note_exit_bytes(443, 100, 10000); s = rep_hist_format_exit_stats(now + 86400); - test_streq("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" "exit-kibibytes-written 80=1,443=1,other=0\n" "exit-kibibytes-read 80=10,443=20,other=0\n" - "exit-streams-opened 80=4,443=4,other=0\n", s); + "exit-streams-opened 80=4,443=4,other=0\n",==, s); tor_free(s); /* Add a few bytes on 10 more ports and ensure that only the top 10 @@ -1128,13 +1128,13 @@ test_stats(void) rep_hist_note_exit_stream_opened(i); } s = rep_hist_format_exit_stats(now + 86400); - test_streq("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" "exit-kibibytes-written 52=1,53=1,54=1,55=1,56=1,57=1,58=1," "59=1,80=1,443=1,other=1\n" "exit-kibibytes-read 52=1,53=1,54=1,55=1,56=1,57=1,58=1," "59=1,80=10,443=20,other=1\n" "exit-streams-opened 52=4,53=4,54=4,55=4,56=4,57=4,58=4," - "59=4,80=4,443=4,other=4\n", s); + "59=4,80=4,443=4,other=4\n",==, s); tor_free(s); /* Stop collecting stats, add some bytes, and ensure we don't generate @@ -1142,7 +1142,7 @@ test_stats(void) rep_hist_exit_stats_term(); rep_hist_note_exit_bytes(80, 100, 10000); s = rep_hist_format_exit_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Re-start stats, add some bytes, reset stats, and see what history we * get when observing no streams or bytes at all. */ @@ -1151,17 +1151,17 @@ test_stats(void) rep_hist_note_exit_bytes(80, 100, 10000); rep_hist_reset_exit_stats(now); s = rep_hist_format_exit_stats(now + 86400); - test_streq("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("exit-stats-end 2010-08-12 13:27:30 (86400 s)\n" "exit-kibibytes-written other=0\n" "exit-kibibytes-read other=0\n" - "exit-streams-opened other=0\n", s); + "exit-streams-opened other=0\n",==, s); tor_free(s); /* Continue with testing connection statistics; we shouldn't collect * conn stats without initializing them. */ rep_hist_note_or_conn_bytes(1, 20, 400, now); s = rep_hist_format_conn_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats, note bytes, and generate history string. */ rep_hist_conn_stats_init(now); @@ -1170,7 +1170,7 @@ test_stats(void) rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 10); rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); s = rep_hist_format_conn_stats(now + 86400); - test_streq("conn-bi-direct 2010-08-12 13:27:30 (86400 s) 0,0,1,0\n", s); + tt_str_op("conn-bi-direct 2010-08-12 13:27:30 (86400 s) 0,0,1,0\n",==, s); tor_free(s); /* Stop collecting stats, add some bytes, and ensure we don't generate @@ -1178,7 +1178,7 @@ test_stats(void) rep_hist_conn_stats_term(); rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); s = rep_hist_format_conn_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Re-start stats, add some bytes, reset stats, and see what history we * get when observing no bytes at all. */ @@ -1189,26 +1189,26 @@ test_stats(void) rep_hist_note_or_conn_bytes(2, 400000, 30000, now + 15); rep_hist_reset_conn_stats(now); s = rep_hist_format_conn_stats(now + 86400); - test_streq("conn-bi-direct 2010-08-12 13:27:30 (86400 s) 0,0,0,0\n", s); + tt_str_op("conn-bi-direct 2010-08-12 13:27:30 (86400 s) 0,0,0,0\n",==, s); tor_free(s); /* Continue with testing buffer statistics; we shouldn't collect buffer * stats without initializing them. */ rep_hist_add_buffer_stats(2.0, 2.0, 20); s = rep_hist_format_buffer_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Initialize stats, add statistics for a single circuit, and generate * the history string. */ rep_hist_buffer_stats_init(now); rep_hist_add_buffer_stats(2.0, 2.0, 20); s = rep_hist_format_buffer_stats(now + 86400); - test_streq("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" "cell-processed-cells 20,0,0,0,0,0,0,0,0,0\n" "cell-queued-cells 2.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00," "0.00,0.00\n" "cell-time-in-queue 2,0,0,0,0,0,0,0,0,0\n" - "cell-circuits-per-decile 1\n", s); + "cell-circuits-per-decile 1\n",==, s); tor_free(s); /* Add nineteen more circuit statistics to the one that's already in the @@ -1218,12 +1218,12 @@ test_stats(void) for (i = 20; i < 30; i++) rep_hist_add_buffer_stats(3.5, 3.5, i); s = rep_hist_format_buffer_stats(now + 86400); - test_streq("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" "cell-processed-cells 29,28,27,26,25,24,23,22,21,20\n" "cell-queued-cells 2.75,2.75,2.75,2.75,2.75,2.75,2.75,2.75," "2.75,2.75\n" "cell-time-in-queue 3,3,3,3,3,3,3,3,3,3\n" - "cell-circuits-per-decile 2\n", s); + "cell-circuits-per-decile 2\n",==, s); tor_free(s); /* Stop collecting stats, add statistics for one circuit, and ensure we @@ -1231,7 +1231,7 @@ test_stats(void) rep_hist_buffer_stats_term(); rep_hist_add_buffer_stats(2.0, 2.0, 20); s = rep_hist_format_buffer_stats(now + 86400); - test_assert(!s); + tt_assert(!s); /* Re-start stats, add statistics for one circuit, reset stats, and make * sure that the history has all zeros. */ @@ -1239,12 +1239,12 @@ test_stats(void) rep_hist_add_buffer_stats(2.0, 2.0, 20); rep_hist_reset_buffer_stats(now); s = rep_hist_format_buffer_stats(now + 86400); - test_streq("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" + tt_str_op("cell-stats-end 2010-08-12 13:27:30 (86400 s)\n" "cell-processed-cells 0,0,0,0,0,0,0,0,0,0\n" "cell-queued-cells 0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00," "0.00,0.00\n" "cell-time-in-queue 0,0,0,0,0,0,0,0,0,0\n" - "cell-circuits-per-decile 0\n", s); + "cell-circuits-per-decile 0\n",==, s); done: tor_free(s); |