/** Invoked once per second. Checks whether it is time to hibernate, * record bandwidth used, etc. */ void accounting_run_housekeeping(time_t now) { if (now >= interval_end_time) { configure_accounting(now); } if (time_to_record_bandwidth_usage(now)) { if (accounting_record_bandwidth_usage(now, get_or_state())) { log_warn(LD_FS, "Couldn't record bandwidth usage to disk."); } } }
static void test_accounting_limits(void *arg) { or_options_t *options = get_options_mutable(); time_t fake_time = time(NULL); (void) arg; NS_MOCK(get_or_state); or_state = or_state_new(); options->AccountingMax = 100; options->AccountingRule = ACCT_MAX; tor_assert(accounting_is_enabled(options)); configure_accounting(fake_time); accounting_add_bytes(10, 0, 1); fake_time += 1; consider_hibernation(fake_time); tor_assert(we_are_hibernating() == 0); accounting_add_bytes(90, 0, 1); fake_time += 1; consider_hibernation(fake_time); tor_assert(we_are_hibernating() == 1); options->AccountingMax = 200; options->AccountingRule = ACCT_SUM; accounting_add_bytes(0, 10, 1); fake_time += 1; consider_hibernation(fake_time); tor_assert(we_are_hibernating() == 0); accounting_add_bytes(0, 90, 1); fake_time += 1; consider_hibernation(fake_time); tor_assert(we_are_hibernating() == 1); goto done; done: NS_UNMOCK(get_or_state); or_state_free(or_state); }