test_voting_schedule.c (1812B)
1 /* Copyright (c) 2018-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 #include "orconfig.h" 5 6 #include "core/or/or.h" 7 #include "feature/dirauth/voting_schedule.h" 8 #include "feature/nodelist/networkstatus.h" 9 10 #include "test/test.h" 11 12 static void 13 test_voting_schedule_interval_start(void *arg) 14 { 15 #define next_interval voting_sched_get_start_of_interval_after 16 (void)arg; 17 char buf[ISO_TIME_LEN+1]; 18 19 // Midnight UTC tonight (as I am writing this test) 20 const time_t midnight = 1525651200; 21 format_iso_time(buf, midnight); 22 tt_str_op(buf, OP_EQ, "2018-05-07 00:00:00"); 23 24 /* Some simple tests with a 50-minute voting interval */ 25 26 tt_i64_op(next_interval(midnight, 3000, 0), OP_EQ, 27 midnight+3000); 28 29 tt_i64_op(next_interval(midnight+100, 3000, 0), OP_EQ, 30 midnight+3000); 31 32 tt_i64_op(next_interval(midnight+3000, 3000, 0), OP_EQ, 33 midnight+6000); 34 35 tt_i64_op(next_interval(midnight+3001, 3000, 0), OP_EQ, 36 midnight+6000); 37 38 /* Make sure that we roll around properly at midnight */ 39 tt_i64_op(next_interval(midnight+83000, 3000, 0), OP_EQ, 40 midnight+84000); 41 42 /* We start fresh at midnight UTC, even if there are leftover seconds. */ 43 tt_i64_op(next_interval(midnight+84005, 3000, 0), OP_EQ, 44 midnight+86400); 45 46 /* Now try with offsets. (These are only used for test networks.) */ 47 tt_i64_op(next_interval(midnight, 3000, 99), OP_EQ, 48 midnight+99); 49 50 tt_i64_op(next_interval(midnight+100, 3000, 99), OP_EQ, 51 midnight+3099); 52 53 done: 54 ; 55 #undef next_interval 56 } 57 58 #define VS(name,flags) \ 59 { #name, test_voting_schedule_##name, (flags), NULL, NULL } 60 61 struct testcase_t voting_schedule_tests[] = { 62 VS(interval_start, 0), 63 END_OF_TESTCASES 64 };