[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Merge branch 'ticket31705_v2' into ticket31705_v2_merged



commit b2d487ae2249a307cd23255dbb1a22241eefd6ef
Merge: 2d013bbe5 7e7a4874b
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Oct 22 09:39:06 2019 -0400

    Merge branch 'ticket31705_v2' into ticket31705_v2_merged
    
    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.

 changes/ticket31705                      |  9 +++++
 scripts/coccinelle/apply.sh              |  9 +++++
 scripts/coccinelle/test-operator-cleanup | 13 +++++++
 scripts/coccinelle/tor-coccinelle.h      | 60 ++++++++++++++++++++++++++++++++
 scripts/coccinelle/try_parse.sh          | 29 +++++++++++++++
 src/app/config/config.c                  | 10 ++++++
 src/core/mainloop/mainloop.c             |  9 ++++-
 src/core/mainloop/periodic.h             |  2 ++
 src/core/or/circuitpadding.c             |  2 ++
 src/core/or/or_periodic.c                |  2 ++
 src/feature/control/control_cmd.c        |  2 ++
 src/feature/control/control_events.c     |  2 ++
 src/feature/dirauth/dirauth_periodic.c   |  2 ++
 src/feature/dircommon/consdiff.c         |  2 ++
 src/feature/hs/hs_service.c              |  2 ++
 src/feature/relay/relay_periodic.c       |  2 ++
 src/lib/buf/buffers.c                    |  2 ++
 src/lib/cc/ctassert.h                    |  2 +-
 src/lib/conf/confmacros.h                |  2 ++
 src/lib/conf/conftesting.h               |  9 ++---
 src/lib/container/namemap_st.h           |  2 ++
 src/lib/container/smartlist.h            |  2 ++
 src/lib/crypt_ops/crypto_openssl_mgt.c   |  6 ++--
 src/lib/dispatch/dispatch_naming.c       |  2 ++
 src/lib/evloop/timers.c                  |  4 ++-
 src/lib/intmath/weakrng.h                |  3 ++
 src/lib/log/log.c                        |  2 +-
 src/lib/log/log.h                        |  4 ++-
 src/lib/log/ratelim.h                    |  2 ++
 src/lib/log/util_bug.h                   |  9 +++--
 src/lib/malloc/map_anon.c                |  4 +--
 src/lib/net/address.c                    |  2 +-
 src/lib/string/parse_int.c               |  5 ++-
 src/lib/thread/threads.h                 |  4 ++-
 src/lib/tls/tortls_openssl.c             |  2 ++
 src/lib/version/git_revision.c           |  4 +++
 src/lib/wallclock/timeval.h              |  2 ++
 src/test/hs_test_helpers.c               | 28 +++++++--------
 src/test/test.h                          |  6 ++++
 src/test/test_addr.c                     |  6 ++++
 src/test/test_config.c                   |  2 ++
 src/test/test_confparse.c                |  2 ++
 src/test/test_connection.c               |  2 ++
 src/test/test_controller.c               |  4 +++
 src/test/test_crypto.c                   |  2 ++
 src/test/test_crypto_slow.c              |  2 ++
 src/test/test_dir.c                      |  2 ++
 src/test/test_entrynodes.c               |  2 ++
 src/test/test_link_handshake.c           |  2 ++
 src/test/test_options.c                  |  2 ++
 src/test/test_router.c                   | 10 +++---
 src/test/test_scheduler.c                | 52 +++++++++++++--------------
 src/test/test_util.c                     |  4 +++
 53 files changed, 296 insertions(+), 63 deletions(-)

diff --cc src/feature/hs/hs_service.c
index 15db5dd1d,600d64cac..964bf68a1
--- a/src/feature/hs/hs_service.c
+++ b/src/feature/hs/hs_service.c
@@@ -67,7 -67,8 +67,8 @@@
  #include <unistd.h>
  #endif
  
+ #ifndef COCCI
 -/* Helper macro. Iterate over every service in the global map. The var is the
 +/** 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                                               \
diff --cc src/lib/log/util_bug.h
index c3141754d,8c233da73..dcff5fd9c
--- a/src/lib/log/util_bug.h
+++ b/src/lib/log/util_bug.h
@@@ -208,10 -211,10 +211,10 @@@
        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) ?                                                          \
diff --cc src/test/test_options.c
index 82def205a,62d477a63..aeb5de210
--- a/src/test/test_options.c
+++ b/src/test/test_options.c
@@@ -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 },



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits