]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge branch 'ticket31705_v2' into ticket31705_v2_merged
authorNick Mathewson <nickm@torproject.org>
Tue, 22 Oct 2019 13:39:06 +0000 (09:39 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 22 Oct 2019 13:39:06 +0000 (09:39 -0400)
Conflicts:
src/feature/dirparse/authcert_parse.c
src/feature/dirparse/ns_parse.c
src/feature/hs/hs_service.c
src/lib/conf/conftesting.h
src/lib/log/log.h
src/lib/thread/threads.h
src/test/test_options.c

These conflicts were mostly related to autostyle improvements, with
one or two due to doxygen fixes.

26 files changed:
1  2 
src/app/config/config.c
src/core/mainloop/mainloop.c
src/core/or/circuitpadding.c
src/feature/control/control_cmd.c
src/feature/control/control_events.c
src/feature/dircommon/consdiff.c
src/feature/hs/hs_service.c
src/lib/buf/buffers.c
src/lib/crypt_ops/crypto_openssl_mgt.c
src/lib/log/log.c
src/lib/log/log.h
src/lib/log/util_bug.h
src/lib/malloc/map_anon.c
src/lib/net/address.c
src/lib/thread/threads.h
src/lib/tls/tortls_openssl.c
src/test/test.h
src/test/test_addr.c
src/test/test_config.c
src/test/test_confparse.c
src/test/test_controller.c
src/test/test_crypto.c
src/test/test_dir.c
src/test/test_entrynodes.c
src/test/test_options.c
src/test/test_util.c

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 15db5dd1dedbfc1007f4421d79e6763ae518ae4a,600d64cacc8f7ed10aaea918a956c873566de3e7..964bf68a17b13c504e6eae81f9e373f354a40316
@@@ -67,7 -67,8 +67,8 @@@
  #include <unistd.h>
  #endif
  
 -/* Helper macro. Iterate over every service in the global map. The var is the
+ #ifndef COCCI
 +/** Helper macro. Iterate over every service in the global map. The var is the
   * name of the service pointer. */
  #define FOR_EACH_SERVICE_BEGIN(var)                          \
      STMT_BEGIN                                               \
Simple merge
Simple merge
Simple merge
index c3141754de61e0b8d6901cbfea74383057bed067,8c233da7356db3457c0283df377a56a806c2f1e8..dcff5fd9c3472699e2cffcd82ac831bddeffacf4
        if (bool_result && !var) {                                        \
          var = 1;                                                        \
          tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__,             \
-                           "!("#cond")", 1, NULL);                       \
+                           ("!("#cond")"), 1, NULL);                     \
        }                                                                 \
        bool_result; } ))
 -#else /* !(defined(__GNUC__)) */
 +#else /* !defined(__GNUC__) */
  #define IF_BUG_ONCE__(cond,var)                                         \
    static int var = 0;                                                   \
    if ((cond) ?                                                          \
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc src/test/test.h
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 82def205a9050cd3f9ceb7315431693c49c0ac10,62d477a63504e515d2a70bb1306e3106dc970fc8..aeb5de210a905fc496db9fdf38c01182576850a6
@@@ -3882,193 -4163,10 +3882,195 @@@ test_options_validate__accel(void *igno
    tor_free(msg);
  }
  
 +static int mocked_granularity;
 +
 +static void
 +mock_set_log_time_granularity(int g)
 +{
 +  mocked_granularity = g;
 +}
 +
 +static void
 +test_options_init_logs_granularity(void *arg)
 +{
 +  options_test_data_t *tdata = get_options_test_data("");
 +  int rv;
 +  (void) arg;
 +
 +  MOCK(set_log_time_granularity, mock_set_log_time_granularity);
 +
 +  /* Reasonable value. */
 +  tdata->opt->LogTimeGranularity = 100;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 100);
 +
 +  /* Doesn't divide 1000. */
 +  tdata->opt->LogTimeGranularity = 249;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 250);
 +
 +  /* Doesn't divide 1000. */
 +  tdata->opt->LogTimeGranularity = 3;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 4);
 +
 +  /* Not a multiple of 1000. */
 +  tdata->opt->LogTimeGranularity = 1500;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 2000);
 +
 +  /* Reasonable value. */
 +  tdata->opt->LogTimeGranularity = 3000;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 3000);
 +
 +  /* Negative. (Shouldn't be allowed by rest of config parsing.) */
 +  tdata->opt->LogTimeGranularity = -1;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, -1);
 +
 +  /* Very big */
 +  tdata->opt->LogTimeGranularity = 3600 * 1000;
 +  mocked_granularity = -1;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(mocked_granularity, OP_EQ, 3600 * 1000);
 +
 + done:
 +  free_options_test_data(tdata);
 +  UNMOCK(set_log_time_granularity);
 +}
 +
 +typedef struct {
 +  char *name;
 +  log_severity_list_t sev;
 +  int fd;
 +  bool stream;
 +} added_log_t;
 +
 +static smartlist_t *added_logs = NULL;
 +
 +static void
 +mock_add_stream_log_impl(const log_severity_list_t *sev, const char *name,
 +                         int fd)
 +{
 +  added_log_t *a = tor_malloc_zero(sizeof(added_log_t));
 +  a->name = tor_strdup(name);
 +  memcpy(&a->sev, sev, sizeof(log_severity_list_t));
 +  a->fd = fd;
 +  a->stream = true;
 +  smartlist_add(added_logs, a);
 +}
 +
 +static int
 +mock_add_file_log(const log_severity_list_t *sev, const char *name, int fd)
 +{
 +  added_log_t *a = tor_malloc_zero(sizeof(added_log_t));
 +  a->name = tor_strdup(name);
 +  memcpy(&a->sev, sev, sizeof(log_severity_list_t));
 +  a->fd = fd;
 +  smartlist_add(added_logs, a);
 +  return 0;
 +}
 +
 +static void
 +clear_added_logs(void)
 +{
 +  SMARTLIST_FOREACH(added_logs, added_log_t *, a,
 +                    { tor_free(a->name); tor_free(a); });
 +  smartlist_clear(added_logs);
 +}
 +
 +static void
 +test_options_init_logs_quiet(void *arg)
 +{
 +  (void)arg;
 +  char *cfg = NULL;
 +  options_test_data_t *tdata = get_options_test_data("");
 +  char *fn1 = tor_strdup(get_fname_rnd("log"));
 +  const added_log_t *a;
 +  int rv;
 +  tdata->opt->RunAsDaemon = 0;
 +
 +  added_logs = smartlist_new();
 +  MOCK(add_stream_log_impl, mock_add_stream_log_impl);
 +  MOCK(add_file_log, mock_add_file_log);
 +
 +  tt_ptr_op(tdata->opt->Logs, OP_EQ, NULL);
 +
 +  /* First, try with no configured logs, and make sure that our configured
 +     logs match the quiet level. */
 +  quiet_level = QUIET_SILENT;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(smartlist_len(added_logs), OP_EQ, 0);
 +
 +  quiet_level = QUIET_HUSH;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(smartlist_len(added_logs), OP_EQ, 1);
 +  a = smartlist_get(added_logs, 0);
 +  tt_assert(a);
 +  tt_assert(a->stream);
 +  tt_int_op(a->fd, OP_EQ, fileno(stdout));
 +  tt_int_op(a->sev.masks[LOG_INFO-LOG_ERR], OP_EQ, 0);
 +  tt_int_op(a->sev.masks[LOG_NOTICE-LOG_ERR], OP_EQ, 0);
 +  tt_int_op(a->sev.masks[LOG_WARN-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +  clear_added_logs();
 +
 +  quiet_level = QUIET_NONE;
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(smartlist_len(added_logs), OP_EQ, 1);
 +  a = smartlist_get(added_logs, 0);
 +  tt_assert(a);
 +  tt_assert(a->stream);
 +  tt_int_op(a->fd, OP_EQ, fileno(stdout));
 +  tt_int_op(a->sev.masks[LOG_INFO-LOG_ERR], OP_EQ, 0);
 +  tt_int_op(a->sev.masks[LOG_NOTICE-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +  tt_int_op(a->sev.masks[LOG_WARN-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +  clear_added_logs();
 +
 +  /* Make sure that adding a configured log makes the default logs go away. */
 +  tor_asprintf(&cfg, "Log info file %s\n", fn1);
 +  free_options_test_data(tdata);
 +  tdata = get_options_test_data(cfg);
 +  rv = options_init_logs(NULL, tdata->opt, 0);
 +  tt_int_op(rv, OP_EQ, 0);
 +  tt_int_op(smartlist_len(added_logs), OP_EQ, 1);
 +  a = smartlist_get(added_logs, 0);
 +  tt_assert(a);
 +  tt_assert(! a->stream);
 +  tt_int_op(a->fd, OP_NE, fileno(stdout));
 +  tt_int_op(a->sev.masks[LOG_INFO-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +  tt_int_op(a->sev.masks[LOG_NOTICE-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +  tt_int_op(a->sev.masks[LOG_WARN-LOG_ERR], OP_EQ, LD_ALL_DOMAINS);
 +
 + done:
 +  free_options_test_data(tdata);
 +  tor_free(fn1);
 +  tor_free(cfg);
 +  clear_added_logs();
 +  smartlist_free(added_logs);
 +  UNMOCK(add_stream_log_impl);
 +  UNMOCK(add_file_log);
 +}
 +
+ #ifndef COCCI
  #define LOCAL_VALIDATE_TEST(name) \
    { "validate__" #name, test_options_validate__ ## name, TT_FORK, NULL, NULL }
+ #endif
  
  struct testcase_t options_tests[] = {
    { "validate", test_options_validate, TT_FORK, NULL, NULL },
Simple merge