|
@@ -511,26 +511,26 @@ static void
|
|
test_buffer_time_tracking(void *arg)
|
|
test_buffer_time_tracking(void *arg)
|
|
{
|
|
{
|
|
buf_t *buf=NULL, *buf2=NULL;
|
|
buf_t *buf=NULL, *buf2=NULL;
|
|
- struct timeval tv0;
|
|
|
|
const time_t START = 1389288246;
|
|
const time_t START = 1389288246;
|
|
- const uint32_t START_MSEC = (uint32_t) ((uint64_t)START * 1000);
|
|
+ const uint64_t START_NSEC = ((uint64_t)START) * 1000000000;
|
|
int i;
|
|
int i;
|
|
char tmp[4096];
|
|
char tmp[4096];
|
|
(void)arg;
|
|
(void)arg;
|
|
|
|
|
|
crypto_rand(tmp, sizeof(tmp));
|
|
crypto_rand(tmp, sizeof(tmp));
|
|
|
|
|
|
- tv0.tv_sec = START;
|
|
+ monotime_enable_test_mocking();
|
|
- tv0.tv_usec = 0;
|
|
|
|
|
|
|
|
buf = buf_new_with_capacity(3000);
|
|
buf = buf_new_with_capacity(3000);
|
|
tt_assert(buf);
|
|
tt_assert(buf);
|
|
|
|
|
|
|
|
+ monotime_coarse_set_mock_time_nsec(START_NSEC);
|
|
|
|
+ const uint32_t START_MSEC = (uint32_t)monotime_coarse_absolute_msec();
|
|
|
|
+
|
|
|
|
|
|
tt_int_op(0, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC));
|
|
tt_int_op(0, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC));
|
|
tt_int_op(0, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC+1000));
|
|
tt_int_op(0, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC+1000));
|
|
|
|
|
|
- tor_gettimeofday_cache_set(&tv0);
|
|
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
tt_int_op(1000, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC+1000));
|
|
tt_int_op(1000, OP_EQ, buf_get_oldest_chunk_timestamp(buf, START_MSEC+1000));
|
|
|
|
|
|
@@ -540,8 +540,7 @@ test_buffer_time_tracking(void *arg)
|
|
buf_get_oldest_chunk_timestamp(buf2, START_MSEC+1234));
|
|
buf_get_oldest_chunk_timestamp(buf2, START_MSEC+1234));
|
|
|
|
|
|
|
|
|
|
- tv0.tv_usec += 123 * 1000;
|
|
+ monotime_coarse_set_mock_time_nsec(START_NSEC + 123 * (uint64_t)1000000);
|
|
- tor_gettimeofday_cache_set(&tv0);
|
|
|
|
for (i = 0; i < 600; ++i)
|
|
for (i = 0; i < 600; ++i)
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
tt_int_op(4207, OP_EQ, buf_datalen(buf));
|
|
tt_int_op(4207, OP_EQ, buf_datalen(buf));
|
|
@@ -562,9 +561,7 @@ test_buffer_time_tracking(void *arg)
|
|
|
|
|
|
|
|
|
|
its time gets updated */
|
|
its time gets updated */
|
|
- tv0.tv_sec += 5;
|
|
+ monotime_coarse_set_mock_time_nsec(START_NSEC + 5617 * (uint64_t)1000000);
|
|
- tv0.tv_usec = 617*1000;
|
|
|
|
- tor_gettimeofday_cache_set(&tv0);
|
|
|
|
for (i = 0; i < 600; ++i)
|
|
for (i = 0; i < 600; ++i)
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
write_to_buf("ABCDEFG", 7, buf);
|
|
tt_int_op(4307, OP_EQ, buf_datalen(buf));
|
|
tt_int_op(4307, OP_EQ, buf_datalen(buf));
|
|
@@ -578,6 +575,7 @@ test_buffer_time_tracking(void *arg)
|
|
done:
|
|
done:
|
|
buf_free(buf);
|
|
buf_free(buf);
|
|
buf_free(buf2);
|
|
buf_free(buf2);
|
|
|
|
+ monotime_disable_test_mocking();
|
|
}
|
|
}
|
|
|
|
|
|
static void
|
|
static void
|