3 #define HIBERNATE_PRIVATE
6 #define STATEFILE_PRIVATE
9 #define NS_MODULE accounting
11 #define NS_SUBMODULE limits
14 * Test to make sure accounting triggers hibernation
15 * correctly with both sum or max rules set
18 static or_state_t
*or_state
;
19 NS_DECL(or_state_t
*, get_or_state
, (void));
21 NS(get_or_state
)(void)
27 test_accounting_limits(void *arg
)
29 or_options_t
*options
= get_options_mutable();
30 time_t fake_time
= time(NULL
);
33 NS_MOCK(get_or_state
);
34 or_state
= or_state_new();
36 options
->AccountingMax
= 100;
37 options
->AccountingRule
= ACCT_MAX
;
39 tor_assert(accounting_is_enabled(options
));
40 configure_accounting(fake_time
);
42 accounting_add_bytes(10, 0, 1);
44 consider_hibernation(fake_time
);
45 tor_assert(we_are_hibernating() == 0);
47 accounting_add_bytes(90, 0, 1);
49 consider_hibernation(fake_time
);
50 tor_assert(we_are_hibernating() == 1);
52 options
->AccountingMax
= 200;
53 options
->AccountingRule
= ACCT_SUM
;
55 accounting_add_bytes(0, 10, 1);
57 consider_hibernation(fake_time
);
58 tor_assert(we_are_hibernating() == 0);
60 accounting_add_bytes(0, 90, 1);
62 consider_hibernation(fake_time
);
63 tor_assert(we_are_hibernating() == 1);
66 NS_UNMOCK(get_or_state
);
67 or_state_free(or_state
);
72 struct testcase_t accounting_tests
[] = {
73 { "bwlimits", test_accounting_limits
, TT_FORK
, NULL
, NULL
},