commit 9c37e8c8d14a86d9cbbc6b203f4883c934391a3b Author: Nick Mathewson nickm@torproject.org Date: Wed Nov 22 14:38:10 2017 -0500
Fix unit tests that depended on monotonic msec. --- src/test/test_oom.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-)
diff --git a/src/test/test_oom.c b/src/test/test_oom.c index ad590b843..973501c3d 100644 --- a/src/test/test_oom.c +++ b/src/test/test_oom.c @@ -222,7 +222,6 @@ test_oom_streambuf(void *arg) tt_int_op(buf_get_total_allocation(), OP_EQ, 0);
monotime_coarse_set_mock_time_nsec(start_ns); - const uint32_t ts_start = monotime_coarse_get_stamp();
/* Start all circuits with a bit of data queued in cells */
@@ -272,23 +271,27 @@ test_oom_streambuf(void *arg) now_ns += 1000000000; monotime_coarse_set_mock_time_nsec(now_ns); tvts = monotime_coarse_get_stamp(); - const uint32_t diff = tvts - ts_start; - printf("\n!!!! %u\n", (unsigned) diff);
- tt_int_op(circuit_max_queued_cell_age(c1, tvts), OP_EQ, 500); - tt_int_op(circuit_max_queued_cell_age(c2, tvts), OP_EQ, 490); - tt_int_op(circuit_max_queued_cell_age(c3, tvts), OP_EQ, 480); - tt_int_op(circuit_max_queued_cell_age(c4, tvts), OP_EQ, 0); +#define ts_is_approx(ts, val) do { \ + uint32_t x_ = (uint32_t) monotime_coarse_stamp_units_to_approx_msec(ts); \ + tt_int_op(x_, OP_GE, val - 5); \ + tt_int_op(x_, OP_LE, val + 5); \ + } while (0)
- tt_int_op(circuit_max_queued_data_age(c1, tvts), OP_EQ, 390); - tt_int_op(circuit_max_queued_data_age(c2, tvts), OP_EQ, 380); - tt_int_op(circuit_max_queued_data_age(c3, tvts), OP_EQ, 0); - tt_int_op(circuit_max_queued_data_age(c4, tvts), OP_EQ, 370); + ts_is_approx(circuit_max_queued_cell_age(c1, tvts), 500); + ts_is_approx(circuit_max_queued_cell_age(c2, tvts), 490); + ts_is_approx(circuit_max_queued_cell_age(c3, tvts), 480); + ts_is_approx(circuit_max_queued_cell_age(c4, tvts), 0);
- tt_int_op(circuit_max_queued_item_age(c1, tvts), OP_EQ, 500); - tt_int_op(circuit_max_queued_item_age(c2, tvts), OP_EQ, 490); - tt_int_op(circuit_max_queued_item_age(c3, tvts), OP_EQ, 480); - tt_int_op(circuit_max_queued_item_age(c4, tvts), OP_EQ, 370); + ts_is_approx(circuit_max_queued_data_age(c1, tvts), 390); + ts_is_approx(circuit_max_queued_data_age(c2, tvts), 380); + ts_is_approx(circuit_max_queued_data_age(c3, tvts), 0); + ts_is_approx(circuit_max_queued_data_age(c4, tvts), 370); + + ts_is_approx(circuit_max_queued_item_age(c1, tvts), 500); + ts_is_approx(circuit_max_queued_item_age(c2, tvts), 490); + ts_is_approx(circuit_max_queued_item_age(c3, tvts), 480); + ts_is_approx(circuit_max_queued_item_age(c4, tvts), 370);
tt_int_op(cell_queues_get_total_allocation(), OP_EQ, packed_cell_mem_cost() * 80); @@ -304,7 +307,7 @@ test_oom_streambuf(void *arg) smartlist_add(edgeconns, ec); } tt_int_op(buf_get_total_allocation(), OP_EQ, 4096*17*2); - tt_int_op(circuit_max_queued_item_age(c4, tvts), OP_EQ, 1000); + ts_is_approx(circuit_max_queued_item_age(c4, tvts), 1000);
tt_int_op(cell_queues_check_size(), OP_EQ, 0);
tor-commits@lists.torproject.org