1 /* Copyright (c) 2014-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
5 #define HIBERNATE_PRIVATE
7 #define REPHIST_PRIVATE
14 #include "core/or/or.h"
15 #include "lib/log/log.h"
16 #include "tor_queue.h"
17 #include "core/or/status.h"
18 #include "core/or/circuitlist.h"
19 #include "app/config/config.h"
20 #include "feature/hibernate/hibernate.h"
21 #include "feature/stats/rephist.h"
22 #include "core/or/relay.h"
23 #include "feature/relay/router.h"
24 #include "feature/relay/routermode.h"
25 #include "core/mainloop/mainloop.h"
26 #include "feature/nodelist/nodelist.h"
27 #include "app/config/statefile.h"
28 #include "lib/tls/tortls.h"
29 #include "test/log_test_helpers.h"
31 #include "core/or/origin_circuit_st.h"
32 #include "app/config/or_state_st.h"
33 #include "feature/nodelist/routerinfo_st.h"
35 #include "test/test.h"
38 * Test that count_circuits() is correctly counting the number of
42 static smartlist_t
* mock_global_circuitlist
= NULL
;
44 static smartlist_t
* status_count_circuits_circuit_get_global_list(void);
47 test_status_count_circuits(void *arg
)
49 /* Choose origin_circuit_t wlog. */
50 origin_circuit_t
*mock_circuit1
, *mock_circuit2
;
51 int expected_circuits
= 2, actual_circuits
;
55 mock_circuit1
= tor_malloc_zero(sizeof(origin_circuit_t
));
56 mock_circuit2
= tor_malloc_zero(sizeof(origin_circuit_t
));
57 mock_global_circuitlist
= smartlist_new();
58 smartlist_add(mock_global_circuitlist
, TO_CIRCUIT(mock_circuit1
));
59 smartlist_add(mock_global_circuitlist
, TO_CIRCUIT(mock_circuit2
));
61 MOCK(circuit_get_global_list
,
62 status_count_circuits_circuit_get_global_list
);
64 actual_circuits
= count_circuits();
66 tt_assert(expected_circuits
== actual_circuits
);
69 tor_free(mock_circuit1
);
70 tor_free(mock_circuit2
);
71 smartlist_free(mock_global_circuitlist
);
72 mock_global_circuitlist
= NULL
;
73 UNMOCK(circuit_get_global_list
);
77 status_count_circuits_circuit_get_global_list(void)
79 return mock_global_circuitlist
;
83 * Test that secs_to_uptime() is converting the number of seconds that
84 * Tor is up for into the appropriate string form containing hours and minutes.
88 test_status_secs_to_uptime(void *arg
)
94 expected
= "0:00 hours";
95 actual
= secs_to_uptime(0);
96 tt_str_op(actual
, OP_EQ
, expected
);
99 expected
= "0:00 hours";
100 actual
= secs_to_uptime(1);
101 tt_str_op(actual
, OP_EQ
, expected
);
104 expected
= "0:01 hours";
105 actual
= secs_to_uptime(60);
106 tt_str_op(actual
, OP_EQ
, expected
);
109 expected
= "0:59 hours";
110 actual
= secs_to_uptime(60 * 59);
111 tt_str_op(actual
, OP_EQ
, expected
);
114 expected
= "1:00 hours";
115 actual
= secs_to_uptime(60 * 60);
116 tt_str_op(actual
, OP_EQ
, expected
);
119 expected
= "23:59 hours";
120 actual
= secs_to_uptime(60 * 60 * 23 + 60 * 59);
121 tt_str_op(actual
, OP_EQ
, expected
);
124 expected
= "1 day 0:00 hours";
125 actual
= secs_to_uptime(60 * 60 * 23 + 60 * 60);
126 tt_str_op(actual
, OP_EQ
, expected
);
129 expected
= "1 day 0:00 hours";
130 actual
= secs_to_uptime(86400 + 1);
131 tt_str_op(actual
, OP_EQ
, expected
);
134 expected
= "1 day 0:01 hours";
135 actual
= secs_to_uptime(86400 + 60);
136 tt_str_op(actual
, OP_EQ
, expected
);
139 expected
= "10 days 0:00 hours";
140 actual
= secs_to_uptime(86400 * 10);
141 tt_str_op(actual
, OP_EQ
, expected
);
144 expected
= "10 days 0:00 hours";
145 actual
= secs_to_uptime(864000 + 1);
146 tt_str_op(actual
, OP_EQ
, expected
);
149 expected
= "10 days 0:01 hours";
150 actual
= secs_to_uptime(864000 + 60);
151 tt_str_op(actual
, OP_EQ
, expected
);
160 * Test that bytes_to_usage() is correctly converting the number of bytes that
161 * Tor has read/written into the appropriate string form containing kilobytes,
162 * megabytes, or gigabytes.
166 test_status_bytes_to_usage(void *arg
)
168 const char *expected
;
173 actual
= bytes_to_usage(0);
174 tt_str_op(actual
, OP_EQ
, expected
);
178 actual
= bytes_to_usage(1);
179 tt_str_op(actual
, OP_EQ
, expected
);
183 actual
= bytes_to_usage(1024);
184 tt_str_op(actual
, OP_EQ
, expected
);
187 expected
= "1023 kB";
188 actual
= bytes_to_usage((1 << 20) - 1);
189 tt_str_op(actual
, OP_EQ
, expected
);
192 expected
= "1.00 MB";
193 actual
= bytes_to_usage((1 << 20));
194 tt_str_op(actual
, OP_EQ
, expected
);
197 expected
= "1.00 MB";
198 actual
= bytes_to_usage((1 << 20) + 5242);
199 tt_str_op(actual
, OP_EQ
, expected
);
202 expected
= "1.01 MB";
203 actual
= bytes_to_usage((1 << 20) + 5243);
204 tt_str_op(actual
, OP_EQ
, expected
);
207 expected
= "1024.00 MB";
208 actual
= bytes_to_usage((1 << 30) - 1);
209 tt_str_op(actual
, OP_EQ
, expected
);
212 expected
= "1.00 GB";
213 actual
= bytes_to_usage((1 << 30));
214 tt_str_op(actual
, OP_EQ
, expected
);
217 expected
= "1.00 GB";
218 actual
= bytes_to_usage((1 << 30) + 5368709);
219 tt_str_op(actual
, OP_EQ
, expected
);
222 expected
= "1.01 GB";
223 actual
= bytes_to_usage((1 << 30) + 5368710);
224 tt_str_op(actual
, OP_EQ
, expected
);
227 expected
= "10.00 GB";
228 actual
= bytes_to_usage((UINT64_C(1) << 30) * 10L);
229 tt_str_op(actual
, OP_EQ
, expected
);
238 * Tests that log_heartbeat() fails when in the public server mode,
239 * not hibernating, and we couldn't get the current routerinfo.
242 static double status_hb_fails_tls_get_write_overhead_ratio(void);
243 static int status_hb_fails_we_are_hibernating(void);
244 static int status_hb_fails_public_server_mode(const or_options_t
*options
);
245 static const routerinfo_t
* status_hb_fails_router_get_my_routerinfo(void);
248 test_status_hb_fails(void *arg
)
250 int expected
, actual
;
253 MOCK(tls_get_write_overhead_ratio
,
254 status_hb_fails_tls_get_write_overhead_ratio
);
255 MOCK(we_are_hibernating
,
256 status_hb_fails_we_are_hibernating
);
257 MOCK(public_server_mode
,
258 status_hb_fails_public_server_mode
);
259 MOCK(router_get_my_routerinfo
,
260 status_hb_fails_router_get_my_routerinfo
);
263 actual
= log_heartbeat(0);
265 tt_int_op(actual
, OP_EQ
, expected
);
268 UNMOCK(tls_get_write_overhead_ratio
);
269 UNMOCK(we_are_hibernating
);
270 UNMOCK(public_server_mode
);
271 UNMOCK(router_get_my_routerinfo
);
275 status_hb_fails_tls_get_write_overhead_ratio(void)
281 status_hb_fails_we_are_hibernating(void)
287 status_hb_fails_public_server_mode(const or_options_t
*options
)
294 static const routerinfo_t
*
295 status_hb_fails_router_get_my_routerinfo(void)
301 * Tests that log_heartbeat() logs appropriately if we are not in the cached
305 static double status_hb_not_in_consensus_tls_get_write_overhead_ratio(void);
306 static int status_hb_not_in_consensus_we_are_hibernating(void);
307 static int status_hb_not_in_consensus_public_server_mode(
308 const or_options_t
*options
);
309 static const routerinfo_t
*status_hb_not_in_consensus_get_my_routerinfo(void);
310 static const node_t
* status_hb_not_in_consensus_node_get_by_id(
311 const char *identity_digest
);
312 static int status_hb_not_in_consensus_server_mode(const or_options_t
*options
);
314 static routerinfo_t
*mock_routerinfo
;
317 test_status_hb_not_in_consensus(void *arg
)
319 int expected
, actual
;
322 MOCK(tls_get_write_overhead_ratio
,
323 status_hb_not_in_consensus_tls_get_write_overhead_ratio
);
324 MOCK(we_are_hibernating
,
325 status_hb_not_in_consensus_we_are_hibernating
);
326 MOCK(public_server_mode
,
327 status_hb_not_in_consensus_public_server_mode
);
328 MOCK(router_get_my_routerinfo
,
329 status_hb_not_in_consensus_get_my_routerinfo
);
331 status_hb_not_in_consensus_node_get_by_id
);
333 status_hb_not_in_consensus_server_mode
);
335 log_global_min_severity_
= LOG_DEBUG
;
336 onion_handshakes_requested
[ONION_HANDSHAKE_TYPE_TAP
] = 1;
337 onion_handshakes_assigned
[ONION_HANDSHAKE_TYPE_TAP
] = 1;
338 onion_handshakes_requested
[ONION_HANDSHAKE_TYPE_NTOR
] = 1;
339 onion_handshakes_assigned
[ONION_HANDSHAKE_TYPE_NTOR
] = 1;
342 setup_capture_of_logs(LOG_INFO
);
343 actual
= log_heartbeat(0);
344 tt_int_op(actual
, OP_EQ
, expected
);
346 expect_log_msg("Heartbeat: It seems like we are "
347 "not in the cached consensus.\n");
348 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
349 "with 0 circuits open. "
350 "I've sent 0 kB and received 0 kB. "
351 "I've received 0 connections on IPv4 and 0 on IPv6. "
352 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
353 expect_log_msg("Average packaged cell fullness: 100.000%. "
354 "TLS write overhead: 0%\n");
355 expect_log_msg("Circuit handshake stats since last time: 1/1 TAP, "
357 expect_log_msg("Since startup we initiated 0 and received 0 v1 "
358 "connections; initiated 0 and received 0 v2 connections; "
359 "initiated 0 and received 0 v3 connections; "
360 "initiated 0 and received 0 v4 connections; "
361 "initiated 0 and received 0 v5 connections.\n");
362 expect_log_msg("Heartbeat: DoS mitigation since startup: 0 circuits killed "
363 "with too many cells, [DoSCircuitCreationEnabled disabled], "
364 "[DoSConnectionEnabled disabled], "
365 "[DoSRefuseSingleHopClientRendezvous disabled], "
366 "0 INTRODUCE2 rejected.\n");
367 tt_int_op(mock_saved_log_n_entries(), OP_EQ
, 6);
370 teardown_capture_of_logs();
371 UNMOCK(tls_get_write_overhead_ratio
);
372 UNMOCK(we_are_hibernating
);
373 UNMOCK(public_server_mode
);
374 UNMOCK(router_get_my_routerinfo
);
375 UNMOCK(node_get_by_id
);
377 tor_free(mock_routerinfo
);
381 status_hb_not_in_consensus_tls_get_write_overhead_ratio(void)
387 status_hb_not_in_consensus_we_are_hibernating(void)
393 status_hb_not_in_consensus_public_server_mode(const or_options_t
*options
)
400 static const routerinfo_t
*
401 status_hb_not_in_consensus_get_my_routerinfo(void)
403 mock_routerinfo
= tor_malloc(sizeof(routerinfo_t
));
405 return mock_routerinfo
;
408 static const node_t
*
409 status_hb_not_in_consensus_node_get_by_id(const char *identity_digest
)
411 (void)identity_digest
;
417 status_hb_not_in_consensus_server_mode(const or_options_t
*options
)
425 * Tests that log_heartbeat() correctly logs heartbeat information
429 static double status_hb_simple_tls_get_write_overhead_ratio(void);
430 static int status_hb_simple_we_are_hibernating(void);
431 static int status_hb_simple_public_server_mode(const or_options_t
*options
);
432 static long status_hb_simple_get_uptime(void);
433 static uint64_t status_hb_simple_get_bytes_read(void);
434 static uint64_t status_hb_simple_get_bytes_written(void);
435 static int status_hb_simple_server_mode(const or_options_t
*options
);
438 test_status_hb_simple(void *arg
)
440 int expected
, actual
;
443 MOCK(tls_get_write_overhead_ratio
,
444 status_hb_simple_tls_get_write_overhead_ratio
);
445 MOCK(we_are_hibernating
,
446 status_hb_simple_we_are_hibernating
);
447 MOCK(public_server_mode
,
448 status_hb_simple_public_server_mode
);
450 status_hb_simple_get_uptime
);
452 status_hb_simple_get_bytes_read
);
453 MOCK(get_bytes_written
,
454 status_hb_simple_get_bytes_written
);
456 status_hb_simple_server_mode
);
458 log_global_min_severity_
= LOG_DEBUG
;
460 setup_capture_of_logs(LOG_INFO
);
462 actual
= log_heartbeat(0);
464 tt_int_op(actual
, OP_EQ
, expected
);
466 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
467 "with 0 circuits open. "
468 "I've sent 0 kB and received 0 kB. "
469 "I've received 0 connections on IPv4 and 0 on IPv6. "
470 "I've made 0 connections with IPv4 and 0 with IPv6. "
471 "We are currently hibernating.\n");
474 teardown_capture_of_logs();
475 UNMOCK(tls_get_write_overhead_ratio
);
476 UNMOCK(we_are_hibernating
);
477 UNMOCK(public_server_mode
);
479 UNMOCK(get_bytes_read
);
480 UNMOCK(get_bytes_written
);
485 status_hb_simple_tls_get_write_overhead_ratio(void)
491 status_hb_simple_we_are_hibernating(void)
497 status_hb_simple_public_server_mode(const or_options_t
*options
)
505 status_hb_simple_get_uptime(void)
511 status_hb_simple_get_bytes_read(void)
517 status_hb_simple_get_bytes_written(void)
523 status_hb_simple_server_mode(const or_options_t
*options
)
531 * Tests that log_heartbeat() correctly logs heartbeat information
532 * and accounting information when configured.
535 static double status_hb_calls_log_accounting_tls_get_write_overhead_ratio(
537 static int status_hb_calls_log_accounting_we_are_hibernating(void);
538 static int status_hb_calls_log_accounting_public_server_mode(
539 const or_options_t
*options
);
540 static long status_hb_calls_log_accounting_get_uptime(void);
541 static uint64_t status_hb_calls_log_accounting_get_bytes_read(void);
542 static uint64_t status_hb_calls_log_accounting_get_bytes_written(void);
543 static int status_hb_calls_log_accounting_server_mode(
544 const or_options_t
*options
);
545 static or_state_t
* status_hb_calls_log_accounting_get_or_state(void);
546 static int status_hb_calls_log_accounting_accounting_is_enabled(
547 const or_options_t
*options
);
548 static time_t status_hb_calls_log_accounting_accounting_get_end_time(void);
550 static or_state_t
* status_hb_calls_log_accounting_mock_state
= NULL
;
551 static or_options_t
* status_hb_calls_log_accounting_mock_options
= NULL
;
554 test_status_hb_calls_log_accounting(void *arg
)
556 int expected
, actual
;
559 MOCK(tls_get_write_overhead_ratio
,
560 status_hb_calls_log_accounting_tls_get_write_overhead_ratio
);
561 MOCK(we_are_hibernating
,
562 status_hb_calls_log_accounting_we_are_hibernating
);
563 MOCK(public_server_mode
,
564 status_hb_calls_log_accounting_public_server_mode
);
566 status_hb_calls_log_accounting_get_uptime
);
568 status_hb_calls_log_accounting_get_bytes_read
);
569 MOCK(get_bytes_written
,
570 status_hb_calls_log_accounting_get_bytes_written
);
572 status_hb_calls_log_accounting_server_mode
);
574 status_hb_calls_log_accounting_get_or_state
);
575 MOCK(accounting_is_enabled
,
576 status_hb_calls_log_accounting_accounting_is_enabled
);
577 MOCK(accounting_get_end_time
,
578 status_hb_calls_log_accounting_accounting_get_end_time
);
580 log_global_min_severity_
= LOG_DEBUG
;
582 setup_capture_of_logs(LOG_NOTICE
);
584 actual
= log_heartbeat(0);
586 tt_int_op(actual
, OP_EQ
, expected
);
588 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
589 "with 0 circuits open. "
590 "I've sent 0 kB and received 0 kB. "
591 "I've received 0 connections on IPv4 and 0 on IPv6. "
592 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
594 expect_log_msg_containing("Heartbeat: Accounting enabled. Sent: 0 kB, "
595 "Received: 0 kB, Used: 0 kB / 0 kB, Rule: max. "
596 "The current accounting interval ends on ");
597 tt_int_op(mock_saved_log_n_entries(), OP_EQ
, 2);
600 teardown_capture_of_logs();
601 UNMOCK(tls_get_write_overhead_ratio
);
602 UNMOCK(we_are_hibernating
);
603 UNMOCK(public_server_mode
);
605 UNMOCK(get_bytes_read
);
606 UNMOCK(get_bytes_written
);
608 UNMOCK(accounting_is_enabled
);
609 UNMOCK(accounting_get_end_time
);
610 tor_free_(status_hb_calls_log_accounting_mock_state
);
611 tor_free_(status_hb_calls_log_accounting_mock_options
);
615 status_hb_calls_log_accounting_tls_get_write_overhead_ratio(void)
621 status_hb_calls_log_accounting_we_are_hibernating(void)
627 status_hb_calls_log_accounting_public_server_mode(const or_options_t
*options
)
635 status_hb_calls_log_accounting_get_uptime(void)
641 status_hb_calls_log_accounting_get_bytes_read(void)
647 status_hb_calls_log_accounting_get_bytes_written(void)
653 status_hb_calls_log_accounting_server_mode(const or_options_t
*options
)
661 status_hb_calls_log_accounting_accounting_is_enabled(
662 const or_options_t
*options
)
670 status_hb_calls_log_accounting_accounting_get_end_time(void)
676 status_hb_calls_log_accounting_get_or_state(void)
678 status_hb_calls_log_accounting_mock_state
=
679 tor_malloc_zero(sizeof(or_state_t
));
680 status_hb_calls_log_accounting_mock_state
681 ->AccountingBytesReadInInterval
= 0;
682 status_hb_calls_log_accounting_mock_state
683 ->AccountingBytesWrittenInInterval
= 0;
685 return status_hb_calls_log_accounting_mock_state
;
689 * Tests that log_heartbeat() correctly logs packaged cell
690 * fullness information.
693 static double status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(
695 static int status_hb_packaged_cell_fullness_we_are_hibernating(void);
696 static int status_hb_packaged_cell_fullness_public_server_mode(
697 const or_options_t
*options
);
698 static long status_hb_packaged_cell_fullness_get_uptime(void);
699 static uint64_t status_hb_packaged_cell_fullness_get_bytes_read(void);
700 static uint64_t status_hb_packaged_cell_fullness_get_bytes_written(void);
701 static int status_hb_packaged_cell_fullness_server_mode(
702 const or_options_t
*options
);
703 static int status_hb_packaged_cell_fullness_accounting_is_enabled(
704 const or_options_t
*options
);
707 test_status_hb_packaged_cell_fullness(void *arg
)
709 int expected
, actual
;
712 MOCK(tls_get_write_overhead_ratio
,
713 status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio
);
714 MOCK(we_are_hibernating
,
715 status_hb_packaged_cell_fullness_we_are_hibernating
);
716 MOCK(public_server_mode
,
717 status_hb_packaged_cell_fullness_public_server_mode
);
719 status_hb_packaged_cell_fullness_get_uptime
);
721 status_hb_packaged_cell_fullness_get_bytes_read
);
722 MOCK(get_bytes_written
,
723 status_hb_packaged_cell_fullness_get_bytes_written
);
725 status_hb_packaged_cell_fullness_server_mode
);
726 MOCK(accounting_is_enabled
,
727 status_hb_packaged_cell_fullness_accounting_is_enabled
);
728 log_global_min_severity_
= LOG_DEBUG
;
730 stats_n_data_bytes_packaged
= RELAY_PAYLOAD_SIZE
;
731 stats_n_data_cells_packaged
= 2;
733 setup_capture_of_logs(LOG_INFO
);
734 actual
= log_heartbeat(0);
736 tt_int_op(actual
, OP_EQ
, expected
);
737 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
738 "with 0 circuits open. "
739 "I've sent 0 kB and received 0 kB. "
740 "I've received 0 connections on IPv4 and 0 on IPv6. "
741 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
742 expect_log_msg("Average packaged cell fullness: 50.000%. "
743 "TLS write overhead: 0%\n");
746 teardown_capture_of_logs();
747 stats_n_data_bytes_packaged
= 0;
748 stats_n_data_cells_packaged
= 0;
749 UNMOCK(tls_get_write_overhead_ratio
);
750 UNMOCK(we_are_hibernating
);
751 UNMOCK(public_server_mode
);
753 UNMOCK(get_bytes_read
);
754 UNMOCK(get_bytes_written
);
756 UNMOCK(accounting_is_enabled
);
760 status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(void)
766 status_hb_packaged_cell_fullness_we_are_hibernating(void)
772 status_hb_packaged_cell_fullness_public_server_mode(
773 const or_options_t
*options
)
781 status_hb_packaged_cell_fullness_get_uptime(void)
787 status_hb_packaged_cell_fullness_get_bytes_read(void)
793 status_hb_packaged_cell_fullness_get_bytes_written(void)
799 status_hb_packaged_cell_fullness_server_mode(const or_options_t
*options
)
807 status_hb_packaged_cell_fullness_accounting_is_enabled(
808 const or_options_t
*options
)
816 * Tests that log_heartbeat() correctly logs the TLS write overhead information
817 * when the TLS write overhead ratio exceeds 1.
820 static double status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void);
821 static int status_hb_tls_write_overhead_we_are_hibernating(void);
822 static int status_hb_tls_write_overhead_public_server_mode(
823 const or_options_t
*options
);
824 static long status_hb_tls_write_overhead_get_uptime(void);
825 static uint64_t status_hb_tls_write_overhead_get_bytes_read(void);
826 static uint64_t status_hb_tls_write_overhead_get_bytes_written(void);
827 static int status_hb_tls_write_overhead_server_mode(
828 const or_options_t
*options
);
829 static int status_hb_tls_write_overhead_accounting_is_enabled(
830 const or_options_t
*options
);
833 test_status_hb_tls_write_overhead(void *arg
)
835 int expected
, actual
;
838 MOCK(tls_get_write_overhead_ratio
,
839 status_hb_tls_write_overhead_tls_get_write_overhead_ratio
);
840 MOCK(we_are_hibernating
,
841 status_hb_tls_write_overhead_we_are_hibernating
);
842 MOCK(public_server_mode
,
843 status_hb_tls_write_overhead_public_server_mode
);
845 status_hb_tls_write_overhead_get_uptime
);
847 status_hb_tls_write_overhead_get_bytes_read
);
848 MOCK(get_bytes_written
,
849 status_hb_tls_write_overhead_get_bytes_written
);
851 status_hb_tls_write_overhead_server_mode
);
852 MOCK(accounting_is_enabled
,
853 status_hb_tls_write_overhead_accounting_is_enabled
);
854 stats_n_data_cells_packaged
= 0;
855 log_global_min_severity_
= LOG_DEBUG
;
858 setup_capture_of_logs(LOG_NOTICE
);
859 actual
= log_heartbeat(0);
861 tt_int_op(actual
, OP_EQ
, expected
);
862 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
863 "with 0 circuits open. "
864 "I've sent 0 kB and received 0 kB. "
865 "I've received 0 connections on IPv4 and 0 on IPv6. "
866 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
867 expect_log_msg("Average packaged cell fullness: 100.000%. "
868 "TLS write overhead: 100%\n");
871 teardown_capture_of_logs();
872 UNMOCK(tls_get_write_overhead_ratio
);
873 UNMOCK(we_are_hibernating
);
874 UNMOCK(public_server_mode
);
876 UNMOCK(get_bytes_read
);
877 UNMOCK(get_bytes_written
);
879 UNMOCK(accounting_is_enabled
);
883 status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void)
889 status_hb_tls_write_overhead_we_are_hibernating(void)
895 status_hb_tls_write_overhead_public_server_mode(const or_options_t
*options
)
903 status_hb_tls_write_overhead_get_uptime(void)
909 status_hb_tls_write_overhead_get_bytes_read(void)
915 status_hb_tls_write_overhead_get_bytes_written(void)
921 status_hb_tls_write_overhead_server_mode(const or_options_t
*options
)
929 status_hb_tls_write_overhead_accounting_is_enabled(const or_options_t
*options
)
936 struct testcase_t status_tests
[] = {
937 { "count_circuits", test_status_count_circuits
, TT_FORK
, NULL
, NULL
},
938 { "secs_to_uptime", test_status_secs_to_uptime
, TT_FORK
, NULL
, NULL
},
939 { "bytes_to_usage", test_status_bytes_to_usage
, TT_FORK
, NULL
, NULL
},
940 { "hb_fails", test_status_hb_fails
, TT_FORK
, NULL
, NULL
},
941 { "hb_simple", test_status_hb_simple
, TT_FORK
, NULL
, NULL
},
942 { "hb_not_in_consensus", test_status_hb_not_in_consensus
,
943 TT_FORK
, NULL
, NULL
},
944 { "hb_calls_log_accounting", test_status_hb_calls_log_accounting
,
945 TT_FORK
, NULL
, NULL
},
946 { "hb_packaged_cell_fullness", test_status_hb_packaged_cell_fullness
,
947 TT_FORK
, NULL
, NULL
},
948 { "hb_tls_write_overhead", test_status_hb_tls_write_overhead
,
949 TT_FORK
, NULL
, NULL
},