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_assigned
[ONION_HANDSHAKE_TYPE_TAP
] = 1;
337 onion_handshakes_requested
[ONION_HANDSHAKE_TYPE_TAP
] = 2;
338 onion_handshakes_assigned
[ONION_HANDSHAKE_TYPE_NTOR
] = 3;
339 onion_handshakes_requested
[ONION_HANDSHAKE_TYPE_NTOR
] = 4;
340 onion_handshakes_assigned
[ONION_HANDSHAKE_TYPE_NTOR_V3
] = 5;
341 onion_handshakes_requested
[ONION_HANDSHAKE_TYPE_NTOR_V3
] = 6;
344 setup_capture_of_logs(LOG_INFO
);
345 actual
= log_heartbeat(0);
346 tt_int_op(actual
, OP_EQ
, expected
);
348 expect_log_msg("Heartbeat: It seems like we are "
349 "not in the cached consensus.\n");
350 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
351 "with 0 circuits open. "
352 "I've sent 0 kB and received 0 kB. "
353 "I've received 0 connections on IPv4 and 0 on IPv6. "
354 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
355 expect_log_msg("Average packaged cell fullness: 100.000%. "
356 "TLS write overhead: 0%\n");
357 expect_log_msg("Circuit handshake stats since last time: 1/2 TAP, "
358 "3/4 NTor, 5/6 NTor (v3).\n");
359 expect_log_msg("Since startup we initiated 0 and received 0 v1 "
360 "connections; initiated 0 and received 0 v2 connections; "
361 "initiated 0 and received 0 v3 connections; "
362 "initiated 0 and received 0 v4 connections; "
363 "initiated 0 and received 0 v5 connections.\n");
364 expect_log_msg("Heartbeat: DoS mitigation since startup: 0 circuits killed "
365 "with too many cells, [DoSCircuitCreationEnabled disabled], "
366 "[DoSConnectionEnabled disabled], "
367 "[DoSRefuseSingleHopClientRendezvous disabled], "
368 "[DoSStreamCreationEnabled disabled], "
369 "0 INTRODUCE2 rejected.\n");
370 tt_int_op(mock_saved_log_n_entries(), OP_EQ
, 6);
373 teardown_capture_of_logs();
374 UNMOCK(tls_get_write_overhead_ratio
);
375 UNMOCK(we_are_hibernating
);
376 UNMOCK(public_server_mode
);
377 UNMOCK(router_get_my_routerinfo
);
378 UNMOCK(node_get_by_id
);
380 tor_free(mock_routerinfo
);
384 status_hb_not_in_consensus_tls_get_write_overhead_ratio(void)
390 status_hb_not_in_consensus_we_are_hibernating(void)
396 status_hb_not_in_consensus_public_server_mode(const or_options_t
*options
)
403 static const routerinfo_t
*
404 status_hb_not_in_consensus_get_my_routerinfo(void)
406 mock_routerinfo
= tor_malloc(sizeof(routerinfo_t
));
408 return mock_routerinfo
;
411 static const node_t
*
412 status_hb_not_in_consensus_node_get_by_id(const char *identity_digest
)
414 (void)identity_digest
;
420 status_hb_not_in_consensus_server_mode(const or_options_t
*options
)
428 * Tests that log_heartbeat() correctly logs heartbeat information
432 static double status_hb_simple_tls_get_write_overhead_ratio(void);
433 static int status_hb_simple_we_are_hibernating(void);
434 static int status_hb_simple_public_server_mode(const or_options_t
*options
);
435 static long status_hb_simple_get_uptime(void);
436 static uint64_t status_hb_simple_get_bytes_read(void);
437 static uint64_t status_hb_simple_get_bytes_written(void);
438 static int status_hb_simple_server_mode(const or_options_t
*options
);
441 test_status_hb_simple(void *arg
)
443 int expected
, actual
;
446 MOCK(tls_get_write_overhead_ratio
,
447 status_hb_simple_tls_get_write_overhead_ratio
);
448 MOCK(we_are_hibernating
,
449 status_hb_simple_we_are_hibernating
);
450 MOCK(public_server_mode
,
451 status_hb_simple_public_server_mode
);
453 status_hb_simple_get_uptime
);
455 status_hb_simple_get_bytes_read
);
456 MOCK(get_bytes_written
,
457 status_hb_simple_get_bytes_written
);
459 status_hb_simple_server_mode
);
461 log_global_min_severity_
= LOG_DEBUG
;
463 setup_capture_of_logs(LOG_INFO
);
465 actual
= log_heartbeat(0);
467 tt_int_op(actual
, OP_EQ
, expected
);
469 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
470 "with 0 circuits open. "
471 "I've sent 0 kB and received 0 kB. "
472 "I've received 0 connections on IPv4 and 0 on IPv6. "
473 "I've made 0 connections with IPv4 and 0 with IPv6. "
474 "We are currently hibernating.\n");
477 teardown_capture_of_logs();
478 UNMOCK(tls_get_write_overhead_ratio
);
479 UNMOCK(we_are_hibernating
);
480 UNMOCK(public_server_mode
);
482 UNMOCK(get_bytes_read
);
483 UNMOCK(get_bytes_written
);
488 status_hb_simple_tls_get_write_overhead_ratio(void)
494 status_hb_simple_we_are_hibernating(void)
500 status_hb_simple_public_server_mode(const or_options_t
*options
)
508 status_hb_simple_get_uptime(void)
514 status_hb_simple_get_bytes_read(void)
520 status_hb_simple_get_bytes_written(void)
526 status_hb_simple_server_mode(const or_options_t
*options
)
534 * Tests that log_heartbeat() correctly logs heartbeat information
535 * and accounting information when configured.
538 static double status_hb_calls_log_accounting_tls_get_write_overhead_ratio(
540 static int status_hb_calls_log_accounting_we_are_hibernating(void);
541 static int status_hb_calls_log_accounting_public_server_mode(
542 const or_options_t
*options
);
543 static long status_hb_calls_log_accounting_get_uptime(void);
544 static uint64_t status_hb_calls_log_accounting_get_bytes_read(void);
545 static uint64_t status_hb_calls_log_accounting_get_bytes_written(void);
546 static int status_hb_calls_log_accounting_server_mode(
547 const or_options_t
*options
);
548 static or_state_t
* status_hb_calls_log_accounting_get_or_state(void);
549 static int status_hb_calls_log_accounting_accounting_is_enabled(
550 const or_options_t
*options
);
551 static time_t status_hb_calls_log_accounting_accounting_get_end_time(void);
553 static or_state_t
* status_hb_calls_log_accounting_mock_state
= NULL
;
554 static or_options_t
* status_hb_calls_log_accounting_mock_options
= NULL
;
557 test_status_hb_calls_log_accounting(void *arg
)
559 int expected
, actual
;
562 MOCK(tls_get_write_overhead_ratio
,
563 status_hb_calls_log_accounting_tls_get_write_overhead_ratio
);
564 MOCK(we_are_hibernating
,
565 status_hb_calls_log_accounting_we_are_hibernating
);
566 MOCK(public_server_mode
,
567 status_hb_calls_log_accounting_public_server_mode
);
569 status_hb_calls_log_accounting_get_uptime
);
571 status_hb_calls_log_accounting_get_bytes_read
);
572 MOCK(get_bytes_written
,
573 status_hb_calls_log_accounting_get_bytes_written
);
575 status_hb_calls_log_accounting_server_mode
);
577 status_hb_calls_log_accounting_get_or_state
);
578 MOCK(accounting_is_enabled
,
579 status_hb_calls_log_accounting_accounting_is_enabled
);
580 MOCK(accounting_get_end_time
,
581 status_hb_calls_log_accounting_accounting_get_end_time
);
583 log_global_min_severity_
= LOG_DEBUG
;
585 setup_capture_of_logs(LOG_NOTICE
);
587 actual
= log_heartbeat(0);
589 tt_int_op(actual
, OP_EQ
, expected
);
591 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
592 "with 0 circuits open. "
593 "I've sent 0 kB and received 0 kB. "
594 "I've received 0 connections on IPv4 and 0 on IPv6. "
595 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
597 expect_log_msg_containing("Heartbeat: Accounting enabled. Sent: 0 kB, "
598 "Received: 0 kB, Used: 0 kB / 0 kB, Rule: max. "
599 "The current accounting interval ends on ");
600 tt_int_op(mock_saved_log_n_entries(), OP_EQ
, 2);
603 teardown_capture_of_logs();
604 UNMOCK(tls_get_write_overhead_ratio
);
605 UNMOCK(we_are_hibernating
);
606 UNMOCK(public_server_mode
);
608 UNMOCK(get_bytes_read
);
609 UNMOCK(get_bytes_written
);
611 UNMOCK(accounting_is_enabled
);
612 UNMOCK(accounting_get_end_time
);
613 tor_free_(status_hb_calls_log_accounting_mock_state
);
614 tor_free_(status_hb_calls_log_accounting_mock_options
);
618 status_hb_calls_log_accounting_tls_get_write_overhead_ratio(void)
624 status_hb_calls_log_accounting_we_are_hibernating(void)
630 status_hb_calls_log_accounting_public_server_mode(const or_options_t
*options
)
638 status_hb_calls_log_accounting_get_uptime(void)
644 status_hb_calls_log_accounting_get_bytes_read(void)
650 status_hb_calls_log_accounting_get_bytes_written(void)
656 status_hb_calls_log_accounting_server_mode(const or_options_t
*options
)
664 status_hb_calls_log_accounting_accounting_is_enabled(
665 const or_options_t
*options
)
673 status_hb_calls_log_accounting_accounting_get_end_time(void)
679 status_hb_calls_log_accounting_get_or_state(void)
681 status_hb_calls_log_accounting_mock_state
=
682 tor_malloc_zero(sizeof(or_state_t
));
683 status_hb_calls_log_accounting_mock_state
684 ->AccountingBytesReadInInterval
= 0;
685 status_hb_calls_log_accounting_mock_state
686 ->AccountingBytesWrittenInInterval
= 0;
688 return status_hb_calls_log_accounting_mock_state
;
692 * Tests that log_heartbeat() correctly logs packaged cell
693 * fullness information.
696 static double status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(
698 static int status_hb_packaged_cell_fullness_we_are_hibernating(void);
699 static int status_hb_packaged_cell_fullness_public_server_mode(
700 const or_options_t
*options
);
701 static long status_hb_packaged_cell_fullness_get_uptime(void);
702 static uint64_t status_hb_packaged_cell_fullness_get_bytes_read(void);
703 static uint64_t status_hb_packaged_cell_fullness_get_bytes_written(void);
704 static int status_hb_packaged_cell_fullness_server_mode(
705 const or_options_t
*options
);
706 static int status_hb_packaged_cell_fullness_accounting_is_enabled(
707 const or_options_t
*options
);
710 test_status_hb_packaged_cell_fullness(void *arg
)
712 int expected
, actual
;
715 MOCK(tls_get_write_overhead_ratio
,
716 status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio
);
717 MOCK(we_are_hibernating
,
718 status_hb_packaged_cell_fullness_we_are_hibernating
);
719 MOCK(public_server_mode
,
720 status_hb_packaged_cell_fullness_public_server_mode
);
722 status_hb_packaged_cell_fullness_get_uptime
);
724 status_hb_packaged_cell_fullness_get_bytes_read
);
725 MOCK(get_bytes_written
,
726 status_hb_packaged_cell_fullness_get_bytes_written
);
728 status_hb_packaged_cell_fullness_server_mode
);
729 MOCK(accounting_is_enabled
,
730 status_hb_packaged_cell_fullness_accounting_is_enabled
);
731 log_global_min_severity_
= LOG_DEBUG
;
733 stats_n_data_bytes_packaged
= RELAY_PAYLOAD_SIZE
;
734 stats_n_data_cells_packaged
= 2;
736 setup_capture_of_logs(LOG_INFO
);
737 actual
= log_heartbeat(0);
739 tt_int_op(actual
, OP_EQ
, expected
);
740 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
741 "with 0 circuits open. "
742 "I've sent 0 kB and received 0 kB. "
743 "I've received 0 connections on IPv4 and 0 on IPv6. "
744 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
745 expect_log_msg("Average packaged cell fullness: 50.000%. "
746 "TLS write overhead: 0%\n");
749 teardown_capture_of_logs();
750 stats_n_data_bytes_packaged
= 0;
751 stats_n_data_cells_packaged
= 0;
752 UNMOCK(tls_get_write_overhead_ratio
);
753 UNMOCK(we_are_hibernating
);
754 UNMOCK(public_server_mode
);
756 UNMOCK(get_bytes_read
);
757 UNMOCK(get_bytes_written
);
759 UNMOCK(accounting_is_enabled
);
763 status_hb_packaged_cell_fullness_tls_get_write_overhead_ratio(void)
769 status_hb_packaged_cell_fullness_we_are_hibernating(void)
775 status_hb_packaged_cell_fullness_public_server_mode(
776 const or_options_t
*options
)
784 status_hb_packaged_cell_fullness_get_uptime(void)
790 status_hb_packaged_cell_fullness_get_bytes_read(void)
796 status_hb_packaged_cell_fullness_get_bytes_written(void)
802 status_hb_packaged_cell_fullness_server_mode(const or_options_t
*options
)
810 status_hb_packaged_cell_fullness_accounting_is_enabled(
811 const or_options_t
*options
)
819 * Tests that log_heartbeat() correctly logs the TLS write overhead information
820 * when the TLS write overhead ratio exceeds 1.
823 static double status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void);
824 static int status_hb_tls_write_overhead_we_are_hibernating(void);
825 static int status_hb_tls_write_overhead_public_server_mode(
826 const or_options_t
*options
);
827 static long status_hb_tls_write_overhead_get_uptime(void);
828 static uint64_t status_hb_tls_write_overhead_get_bytes_read(void);
829 static uint64_t status_hb_tls_write_overhead_get_bytes_written(void);
830 static int status_hb_tls_write_overhead_server_mode(
831 const or_options_t
*options
);
832 static int status_hb_tls_write_overhead_accounting_is_enabled(
833 const or_options_t
*options
);
836 test_status_hb_tls_write_overhead(void *arg
)
838 int expected
, actual
;
841 MOCK(tls_get_write_overhead_ratio
,
842 status_hb_tls_write_overhead_tls_get_write_overhead_ratio
);
843 MOCK(we_are_hibernating
,
844 status_hb_tls_write_overhead_we_are_hibernating
);
845 MOCK(public_server_mode
,
846 status_hb_tls_write_overhead_public_server_mode
);
848 status_hb_tls_write_overhead_get_uptime
);
850 status_hb_tls_write_overhead_get_bytes_read
);
851 MOCK(get_bytes_written
,
852 status_hb_tls_write_overhead_get_bytes_written
);
854 status_hb_tls_write_overhead_server_mode
);
855 MOCK(accounting_is_enabled
,
856 status_hb_tls_write_overhead_accounting_is_enabled
);
857 stats_n_data_cells_packaged
= 0;
858 log_global_min_severity_
= LOG_DEBUG
;
861 setup_capture_of_logs(LOG_NOTICE
);
862 actual
= log_heartbeat(0);
864 tt_int_op(actual
, OP_EQ
, expected
);
865 expect_log_msg("Heartbeat: Tor's uptime is 0:00 hours, "
866 "with 0 circuits open. "
867 "I've sent 0 kB and received 0 kB. "
868 "I've received 0 connections on IPv4 and 0 on IPv6. "
869 "I've made 0 connections with IPv4 and 0 with IPv6.\n");
870 expect_log_msg("Average packaged cell fullness: 100.000%. "
871 "TLS write overhead: 100%\n");
874 teardown_capture_of_logs();
875 UNMOCK(tls_get_write_overhead_ratio
);
876 UNMOCK(we_are_hibernating
);
877 UNMOCK(public_server_mode
);
879 UNMOCK(get_bytes_read
);
880 UNMOCK(get_bytes_written
);
882 UNMOCK(accounting_is_enabled
);
886 status_hb_tls_write_overhead_tls_get_write_overhead_ratio(void)
892 status_hb_tls_write_overhead_we_are_hibernating(void)
898 status_hb_tls_write_overhead_public_server_mode(const or_options_t
*options
)
906 status_hb_tls_write_overhead_get_uptime(void)
912 status_hb_tls_write_overhead_get_bytes_read(void)
918 status_hb_tls_write_overhead_get_bytes_written(void)
924 status_hb_tls_write_overhead_server_mode(const or_options_t
*options
)
932 status_hb_tls_write_overhead_accounting_is_enabled(const or_options_t
*options
)
939 struct testcase_t status_tests
[] = {
940 { "count_circuits", test_status_count_circuits
, TT_FORK
, NULL
, NULL
},
941 { "secs_to_uptime", test_status_secs_to_uptime
, TT_FORK
, NULL
, NULL
},
942 { "bytes_to_usage", test_status_bytes_to_usage
, TT_FORK
, NULL
, NULL
},
943 { "hb_fails", test_status_hb_fails
, TT_FORK
, NULL
, NULL
},
944 { "hb_simple", test_status_hb_simple
, TT_FORK
, NULL
, NULL
},
945 { "hb_not_in_consensus", test_status_hb_not_in_consensus
,
946 TT_FORK
, NULL
, NULL
},
947 { "hb_calls_log_accounting", test_status_hb_calls_log_accounting
,
948 TT_FORK
, NULL
, NULL
},
949 { "hb_packaged_cell_fullness", test_status_hb_packaged_cell_fullness
,
950 TT_FORK
, NULL
, NULL
},
951 { "hb_tls_write_overhead", test_status_hb_tls_write_overhead
,
952 TT_FORK
, NULL
, NULL
},