commit 05b54f6a6a24ebdb47de4f7e41cf94f2f6be93bd Author: Nick Mathewson nickm@torproject.org Date: Thu Nov 1 14:13:36 2018 -0400
Use subsystems manager for subsystems used in tests. --- src/lib/subsys/subsys.h | 4 ++++ src/test/bench.c | 7 ++++--- src/test/fuzz/fuzzing_common.c | 9 ++++----- src/test/testing_common.c | 8 +++----- 4 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/lib/subsys/subsys.h b/src/lib/subsys/subsys.h index 012b218da..25451bc45 100644 --- a/src/lib/subsys/subsys.h +++ b/src/lib/subsys/subsys.h @@ -65,4 +65,8 @@ typedef struct subsys_fns_t { #define MIN_SUBSYS_LEVEL -100 #define MAX_SUBSYS_LEVEL 100
+/* All tor "libraries" (in src/libs) should have a subsystem level equal to or + * less than this value. */ +#define SUBSYS_LEVEL_LIBS -10 + #endif diff --git a/src/test/bench.c b/src/test/bench.c index 9da1b46a1..ff8707d41 100644 --- a/src/test/bench.c +++ b/src/test/bench.c @@ -24,6 +24,7 @@
#include "core/or/circuitlist.h" #include "app/config/config.h" +#include "app/main/subsysmgr.h" #include "lib/crypt_ops/crypto_curve25519.h" #include "lib/crypt_ops/crypto_dh.h" #include "core/crypto/onion_ntor.h" @@ -690,9 +691,10 @@ main(int argc, const char **argv) char *errmsg; or_options_t *options;
- tor_threads_init(); + subsystems_init_upto(SUBSYS_LEVEL_LIBS); + flush_log_messages_from_startup(); + tor_compress_init(); - init_logging(1);
if (argc == 4 && !strcmp(argv[1], "diff")) { const int N = 200; @@ -739,7 +741,6 @@ main(int argc, const char **argv)
init_protocol_warning_severity_level(); options = options_new(); - init_logging(1); options->command = CMD_RUN_UNITTESTS; options->DataDirectory = tor_strdup(""); options->KeyDirectory = tor_strdup(""); diff --git a/src/test/fuzz/fuzzing_common.c b/src/test/fuzz/fuzzing_common.c index 879f9e74d..21aa07cfe 100644 --- a/src/test/fuzz/fuzzing_common.c +++ b/src/test/fuzz/fuzzing_common.c @@ -3,6 +3,7 @@ #define CRYPTO_ED25519_PRIVATE #include "orconfig.h" #include "core/or/or.h" +#include "app/main/subsysmgr.h" #include "lib/err/backtrace.h" #include "app/config/config.h" #include "test/fuzz/fuzzing.h" @@ -95,12 +96,10 @@ disable_signature_checking(void) static void global_init(void) { - tor_threads_init(); - tor_compress_init(); + subsystems_init_upto(SUBSYS_LEVEL_LIBS); + flush_log_messages_from_startup();
- /* Initialise logging first */ - init_logging(1); - configure_backtrace_handler(get_version()); + tor_compress_init();
if (crypto_global_init(0, NULL, NULL) < 0) abort(); diff --git a/src/test/testing_common.c b/src/test/testing_common.c index 8d648ee17..eef393d3a 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -26,6 +26,7 @@ #include "lib/evloop/compat_libevent.h" #include "lib/crypt_ops/crypto_init.h" #include "lib/version/torversion.h" +#include "app/main/subsysmgr.h"
#include <stdio.h> #ifdef HAVE_FCNTL_H @@ -251,12 +252,9 @@ main(int c, const char **v) int loglevel = LOG_ERR; int accel_crypto = 0;
- /* We must initialise logs before we call tor_assert() */ - init_logging(1); + subsystems_init_upto(SUBSYS_LEVEL_LIBS);
- update_approx_time(time(NULL)); options = options_new(); - tor_threads_init(); tor_compress_init();
network_init(); @@ -268,7 +266,6 @@ main(int c, const char **v) tor_libevent_initialize(&cfg);
control_initialize_event_queue(); - configure_backtrace_handler(get_version());
for (i_out = i = 1; i < c; ++i) { if (!strcmp(v[i], "--warn")) { @@ -295,6 +292,7 @@ main(int c, const char **v) s.masks[LOG_WARN-LOG_ERR] |= LD_BUG; add_stream_log(&s, "", fileno(stdout)); } + flush_log_messages_from_startup(); init_protocol_warning_severity_level();
options->command = CMD_RUN_UNITTESTS;
tor-commits@lists.torproject.org