diff options
Diffstat (limited to 'src/test/test_circuitlist.c')
-rw-r--r-- | src/test/test_circuitlist.c | 146 |
1 files changed, 78 insertions, 68 deletions
diff --git a/src/test/test_circuitlist.c b/src/test/test_circuitlist.c index b19edd1fd4..0760accfc1 100644 --- a/src/test/test_circuitlist.c +++ b/src/test/test_circuitlist.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2013, The Tor Project, Inc. */ +/* Copyright (c) 2013-2015, The Tor Project, Inc. */ /* See LICENSE for licensing information */ #define TOR_CHANNEL_INTERNAL_ @@ -50,17 +50,17 @@ circuitmux_detach_mock(circuitmux_t *cmux, circuit_t *circ) } #define GOT_CMUX_ATTACH(mux_, circ_, dir_) do { \ - tt_int_op(cam.ncalls, ==, 1); \ - tt_ptr_op(cam.cmux, ==, (mux_)); \ - tt_ptr_op(cam.circ, ==, (circ_)); \ - tt_int_op(cam.dir, ==, (dir_)); \ + tt_int_op(cam.ncalls, OP_EQ, 1); \ + tt_ptr_op(cam.cmux, OP_EQ, (mux_)); \ + tt_ptr_op(cam.circ, OP_EQ, (circ_)); \ + tt_int_op(cam.dir, OP_EQ, (dir_)); \ memset(&cam, 0, sizeof(cam)); \ } while (0) #define GOT_CMUX_DETACH(mux_, circ_) do { \ - tt_int_op(cdm.ncalls, ==, 1); \ - tt_ptr_op(cdm.cmux, ==, (mux_)); \ - tt_ptr_op(cdm.circ, ==, (circ_)); \ + tt_int_op(cdm.ncalls, OP_EQ, 1); \ + tt_ptr_op(cdm.cmux, OP_EQ, (mux_)); \ + tt_ptr_op(cdm.circ, OP_EQ, (circ_)); \ memset(&cdm, 0, sizeof(cdm)); \ } while (0) @@ -79,21 +79,25 @@ test_clist_maps(void *arg) memset(&cam, 0, sizeof(cam)); memset(&cdm, 0, sizeof(cdm)); - ch1->cmux = (void*)0x1001; - ch2->cmux = (void*)0x1002; - ch3->cmux = (void*)0x1003; + tt_assert(ch1); + tt_assert(ch2); + tt_assert(ch3); + + ch1->cmux = tor_malloc(1); + ch2->cmux = tor_malloc(1); + ch3->cmux = tor_malloc(1); or_c1 = or_circuit_new(100, ch2); tt_assert(or_c1); GOT_CMUX_ATTACH(ch2->cmux, or_c1, CELL_DIRECTION_IN); - tt_int_op(or_c1->p_circ_id, ==, 100); - tt_ptr_op(or_c1->p_chan, ==, ch2); + tt_int_op(or_c1->p_circ_id, OP_EQ, 100); + tt_ptr_op(or_c1->p_chan, OP_EQ, ch2); or_c2 = or_circuit_new(100, ch1); tt_assert(or_c2); GOT_CMUX_ATTACH(ch1->cmux, or_c2, CELL_DIRECTION_IN); - tt_int_op(or_c2->p_circ_id, ==, 100); - tt_ptr_op(or_c2->p_chan, ==, ch1); + tt_int_op(or_c2->p_circ_id, OP_EQ, 100); + tt_ptr_op(or_c2->p_chan, OP_EQ, ch1); circuit_set_n_circid_chan(TO_CIRCUIT(or_c1), 200, ch1); GOT_CMUX_ATTACH(ch1->cmux, or_c1, CELL_DIRECTION_OUT); @@ -101,11 +105,11 @@ test_clist_maps(void *arg) circuit_set_n_circid_chan(TO_CIRCUIT(or_c2), 200, ch2); GOT_CMUX_ATTACH(ch2->cmux, or_c2, CELL_DIRECTION_OUT); - tt_ptr_op(circuit_get_by_circid_channel(200, ch1), ==, TO_CIRCUIT(or_c1)); - tt_ptr_op(circuit_get_by_circid_channel(200, ch2), ==, TO_CIRCUIT(or_c2)); - tt_ptr_op(circuit_get_by_circid_channel(100, ch2), ==, TO_CIRCUIT(or_c1)); + tt_ptr_op(circuit_get_by_circid_channel(200, ch1), OP_EQ, TO_CIRCUIT(or_c1)); + tt_ptr_op(circuit_get_by_circid_channel(200, ch2), OP_EQ, TO_CIRCUIT(or_c2)); + tt_ptr_op(circuit_get_by_circid_channel(100, ch2), OP_EQ, TO_CIRCUIT(or_c1)); /* Try the same thing again, to test the "fast" path. */ - tt_ptr_op(circuit_get_by_circid_channel(100, ch2), ==, TO_CIRCUIT(or_c1)); + tt_ptr_op(circuit_get_by_circid_channel(100, ch2), OP_EQ, TO_CIRCUIT(or_c1)); tt_assert(circuit_id_in_use_on_channel(100, ch2)); tt_assert(! circuit_id_in_use_on_channel(101, ch2)); @@ -113,9 +117,9 @@ test_clist_maps(void *arg) circuit_set_p_circid_chan(or_c1, 500, ch3); GOT_CMUX_DETACH(ch2->cmux, TO_CIRCUIT(or_c1)); GOT_CMUX_ATTACH(ch3->cmux, TO_CIRCUIT(or_c1), CELL_DIRECTION_IN); - tt_ptr_op(circuit_get_by_circid_channel(100, ch2), ==, NULL); + tt_ptr_op(circuit_get_by_circid_channel(100, ch2), OP_EQ, NULL); tt_assert(! circuit_id_in_use_on_channel(100, ch2)); - tt_ptr_op(circuit_get_by_circid_channel(500, ch3), ==, TO_CIRCUIT(or_c1)); + tt_ptr_op(circuit_get_by_circid_channel(500, ch3), OP_EQ, TO_CIRCUIT(or_c1)); /* Now let's see about destroy handling. */ tt_assert(! circuit_id_in_use_on_channel(205, ch2)); @@ -128,26 +132,26 @@ test_clist_maps(void *arg) tt_assert(circuit_id_in_use_on_channel(100, ch1)); tt_assert(TO_CIRCUIT(or_c2)->n_delete_pending != 0); - tt_ptr_op(circuit_get_by_circid_channel(200, ch2), ==, TO_CIRCUIT(or_c2)); - tt_ptr_op(circuit_get_by_circid_channel(100, ch1), ==, TO_CIRCUIT(or_c2)); + tt_ptr_op(circuit_get_by_circid_channel(200, ch2), OP_EQ, TO_CIRCUIT(or_c2)); + tt_ptr_op(circuit_get_by_circid_channel(100, ch1), OP_EQ, TO_CIRCUIT(or_c2)); /* Okay, now free ch2 and make sure that the circuit ID is STILL not * usable, because we haven't declared the destroy to be nonpending */ - tt_int_op(cdm.ncalls, ==, 0); + tt_int_op(cdm.ncalls, OP_EQ, 0); circuit_free(TO_CIRCUIT(or_c2)); or_c2 = NULL; /* prevent free */ - tt_int_op(cdm.ncalls, ==, 2); + tt_int_op(cdm.ncalls, OP_EQ, 2); memset(&cdm, 0, sizeof(cdm)); tt_assert(circuit_id_in_use_on_channel(200, ch2)); tt_assert(circuit_id_in_use_on_channel(100, ch1)); - tt_ptr_op(circuit_get_by_circid_channel(200, ch2), ==, NULL); - tt_ptr_op(circuit_get_by_circid_channel(100, ch1), ==, NULL); + tt_ptr_op(circuit_get_by_circid_channel(200, ch2), OP_EQ, NULL); + tt_ptr_op(circuit_get_by_circid_channel(100, ch1), OP_EQ, NULL); /* Now say that the destroy is nonpending */ channel_note_destroy_not_pending(ch2, 200); - tt_ptr_op(circuit_get_by_circid_channel(200, ch2), ==, NULL); + tt_ptr_op(circuit_get_by_circid_channel(200, ch2), OP_EQ, NULL); channel_note_destroy_not_pending(ch1, 100); - tt_ptr_op(circuit_get_by_circid_channel(100, ch1), ==, NULL); + tt_ptr_op(circuit_get_by_circid_channel(100, ch1), OP_EQ, NULL); tt_assert(! circuit_id_in_use_on_channel(200, ch2)); tt_assert(! circuit_id_in_use_on_channel(100, ch1)); @@ -156,6 +160,12 @@ test_clist_maps(void *arg) circuit_free(TO_CIRCUIT(or_c1)); if (or_c2) circuit_free(TO_CIRCUIT(or_c2)); + if (ch1) + tor_free(ch1->cmux); + if (ch2) + tor_free(ch2->cmux); + if (ch3) + tor_free(ch3->cmux); tor_free(ch1); tor_free(ch2); tor_free(ch3); @@ -180,73 +190,73 @@ test_rend_token_maps(void *arg) c4 = or_circuit_new(0, NULL); /* Make sure we really filled up the tok* variables */ - tt_int_op(tok1[REND_TOKEN_LEN-1], ==, 'y'); - tt_int_op(tok2[REND_TOKEN_LEN-1], ==, ' '); - tt_int_op(tok3[REND_TOKEN_LEN-1], ==, '.'); + tt_int_op(tok1[REND_TOKEN_LEN-1], OP_EQ, 'y'); + tt_int_op(tok2[REND_TOKEN_LEN-1], OP_EQ, ' '); + tt_int_op(tok3[REND_TOKEN_LEN-1], OP_EQ, '.'); /* No maps; nothing there. */ - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok1)); - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok1)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok1)); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok1)); circuit_set_rendezvous_cookie(c1, tok1); circuit_set_intro_point_digest(c2, tok2); - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok3)); - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok3)); - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok2)); - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok1)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok3)); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok3)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok2)); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok1)); /* Without purpose set, we don't get the circuits */ - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok1)); - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok2)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok1)); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok2)); c1->base_.purpose = CIRCUIT_PURPOSE_REND_POINT_WAITING; c2->base_.purpose = CIRCUIT_PURPOSE_INTRO_POINT; /* Okay, make sure they show up now. */ - tt_ptr_op(c1, ==, circuit_get_rendezvous(tok1)); - tt_ptr_op(c2, ==, circuit_get_intro_point(tok2)); + tt_ptr_op(c1, OP_EQ, circuit_get_rendezvous(tok1)); + tt_ptr_op(c2, OP_EQ, circuit_get_intro_point(tok2)); /* Two items at the same place with the same token. */ c3->base_.purpose = CIRCUIT_PURPOSE_REND_POINT_WAITING; circuit_set_rendezvous_cookie(c3, tok2); - tt_ptr_op(c2, ==, circuit_get_intro_point(tok2)); - tt_ptr_op(c3, ==, circuit_get_rendezvous(tok2)); + tt_ptr_op(c2, OP_EQ, circuit_get_intro_point(tok2)); + tt_ptr_op(c3, OP_EQ, circuit_get_rendezvous(tok2)); /* Marking a circuit makes it not get returned any more */ circuit_mark_for_close(TO_CIRCUIT(c1), END_CIRC_REASON_FINISHED); - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok1)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok1)); circuit_free(TO_CIRCUIT(c1)); c1 = NULL; /* Freeing a circuit makes it not get returned any more. */ circuit_free(TO_CIRCUIT(c2)); c2 = NULL; - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok2)); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok2)); /* c3 -- are you still there? */ - tt_ptr_op(c3, ==, circuit_get_rendezvous(tok2)); + tt_ptr_op(c3, OP_EQ, circuit_get_rendezvous(tok2)); /* Change its cookie. This never happens in Tor per se, but hey. */ c3->base_.purpose = CIRCUIT_PURPOSE_INTRO_POINT; circuit_set_intro_point_digest(c3, tok3); - tt_ptr_op(NULL, ==, circuit_get_rendezvous(tok2)); - tt_ptr_op(c3, ==, circuit_get_intro_point(tok3)); + tt_ptr_op(NULL, OP_EQ, circuit_get_rendezvous(tok2)); + tt_ptr_op(c3, OP_EQ, circuit_get_intro_point(tok3)); /* Now replace c3 with c4. */ c4->base_.purpose = CIRCUIT_PURPOSE_INTRO_POINT; circuit_set_intro_point_digest(c4, tok3); - tt_ptr_op(c4, ==, circuit_get_intro_point(tok3)); + tt_ptr_op(c4, OP_EQ, circuit_get_intro_point(tok3)); - tt_ptr_op(c3->rendinfo, ==, NULL); - tt_ptr_op(c4->rendinfo, !=, NULL); - test_mem_op(c4->rendinfo, ==, tok3, REND_TOKEN_LEN); + tt_ptr_op(c3->rendinfo, OP_EQ, NULL); + tt_ptr_op(c4->rendinfo, OP_NE, NULL); + tt_mem_op(c4->rendinfo, OP_EQ, tok3, REND_TOKEN_LEN); /* Now clear c4's cookie. */ circuit_set_intro_point_digest(c4, NULL); - tt_ptr_op(c4->rendinfo, ==, NULL); - tt_ptr_op(NULL, ==, circuit_get_intro_point(tok3)); + tt_ptr_op(c4->rendinfo, OP_EQ, NULL); + tt_ptr_op(NULL, OP_EQ, circuit_get_intro_point(tok3)); done: if (c1) @@ -273,32 +283,32 @@ test_pick_circid(void *arg) chan2->wide_circ_ids = 1; chan1->circ_id_type = CIRC_ID_TYPE_NEITHER; - tt_int_op(0, ==, get_unique_circ_id_by_chan(chan1)); + tt_int_op(0, OP_EQ, get_unique_circ_id_by_chan(chan1)); /* Basic tests, with no collisions */ chan1->circ_id_type = CIRC_ID_TYPE_LOWER; for (i = 0; i < 50; ++i) { circid = get_unique_circ_id_by_chan(chan1); - tt_uint_op(0, <, circid); - tt_uint_op(circid, <, (1<<15)); + tt_uint_op(0, OP_LT, circid); + tt_uint_op(circid, OP_LT, (1<<15)); } chan1->circ_id_type = CIRC_ID_TYPE_HIGHER; for (i = 0; i < 50; ++i) { circid = get_unique_circ_id_by_chan(chan1); - tt_uint_op((1<<15), <, circid); - tt_uint_op(circid, <, (1<<16)); + tt_uint_op((1<<15), OP_LT, circid); + tt_uint_op(circid, OP_LT, (1<<16)); } chan2->circ_id_type = CIRC_ID_TYPE_LOWER; for (i = 0; i < 50; ++i) { circid = get_unique_circ_id_by_chan(chan2); - tt_uint_op(0, <, circid); - tt_uint_op(circid, <, (1u<<31)); + tt_uint_op(0, OP_LT, circid); + tt_uint_op(circid, OP_LT, (1u<<31)); } chan2->circ_id_type = CIRC_ID_TYPE_HIGHER; for (i = 0; i < 50; ++i) { circid = get_unique_circ_id_by_chan(chan2); - tt_uint_op((1u<<31), <, circid); + tt_uint_op((1u<<31), OP_LT, circid); } /* Now make sure that we can behave well when we are full up on circuits */ @@ -309,20 +319,20 @@ test_pick_circid(void *arg) for (i = 0; i < (1<<15); ++i) { circid = get_unique_circ_id_by_chan(chan1); if (circid == 0) { - tt_int_op(i, >, (1<<14)); + tt_int_op(i, OP_GT, (1<<14)); break; } - tt_uint_op(circid, <, (1<<15)); + tt_uint_op(circid, OP_LT, (1<<15)); tt_assert(! bitarray_is_set(ba, circid)); bitarray_set(ba, circid); channel_mark_circid_unusable(chan1, circid); } - tt_int_op(i, <, (1<<15)); + tt_int_op(i, OP_LT, (1<<15)); /* Make sure that being full on chan1 does not interfere with chan2 */ for (i = 0; i < 100; ++i) { circid = get_unique_circ_id_by_chan(chan2); - tt_uint_op(circid, >, 0); - tt_uint_op(circid, <, (1<<15)); + tt_uint_op(circid, OP_GT, 0); + tt_uint_op(circid, OP_LT, (1<<15)); channel_mark_circid_unusable(chan2, circid); } |