]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
test: Use SEVERITY_MASK_IDX() to find the LOG_* mask indexes
authorteor <teor@torproject.org>
Wed, 25 Sep 2019 06:35:02 +0000 (16:35 +1000)
committerteor <teor@torproject.org>
Wed, 25 Sep 2019 06:40:09 +0000 (16:40 +1000)
In the unit tests and fuzzers.

Fixes bug 31334; bugfix on 0.2.5.2-alpha.

changes/bug31334 [new file with mode: 0644]
src/test/fuzz/fuzzing_common.c
src/test/test_logging.c
src/test/test_options.c
src/test/testing_common.c

diff --git a/changes/bug31334 b/changes/bug31334
new file mode 100644 (file)
index 0000000..dfc9cc5
--- /dev/null
@@ -0,0 +1,4 @@
+  o Code simplification and refactoring:
+    - Use SEVERITY_MASK_IDX() to find the LOG_* mask indexes in the unit
+      tests and fuzzers, rather than using hard-coded values.
+      Closes ticket 31334.
index 862acb2b351f6f4d3ed9ed70c53c1d38168cd394..e269c36b421c4b9ca20c5ed10e9d0a4b10f88446 100644 (file)
@@ -167,7 +167,7 @@ main(int argc, char **argv)
     memset(&s, 0, sizeof(s));
     set_log_severity_config(loglevel, LOG_ERR, &s);
     /* ALWAYS log bug warnings. */
-    s.masks[LOG_WARN-LOG_ERR] |= LD_BUG;
+    s.masks[SEVERITY_MASK_IDX(LOG_WARN)] |= LD_BUG;
     add_stream_log(&s, "", fileno(stdout));
   }
 
index bb7018fe1c36f1f367021b776d1b674d91923c46..203ce64e32e982a9a07932611103d7702787c24f 100644 (file)
@@ -35,7 +35,7 @@ test_get_sigsafe_err_fds(void *arg)
 
   set_log_severity_config(LOG_WARN, LOG_ERR, &include_bug);
   set_log_severity_config(LOG_WARN, LOG_ERR, &no_bug);
-  no_bug.masks[0] &= ~(LD_BUG|LD_GENERAL);
+  no_bug.masks[SEVERITY_MASK_IDX(LOG_ERR)] &= ~(LD_BUG|LD_GENERAL);
   set_log_severity_config(LOG_INFO, LOG_NOTICE, &no_bug2);
 
   /* Add some logs; make sure the output is as expected. */
index 0747a2e0627b718ee9e4cc934e343d6836900a75..b3654ede7d1508f813991b15da8218b1c056f1e2 100644 (file)
@@ -54,9 +54,9 @@ setup_log_callback(void)
 {
   log_severity_list_t lst;
   memset(&lst, 0, sizeof(lst));
-  lst.masks[LOG_ERR - LOG_ERR] = ~0;
-  lst.masks[LOG_WARN - LOG_ERR] = ~0;
-  lst.masks[LOG_NOTICE - LOG_ERR] = ~0;
+  lst.masks[SEVERITY_MASK_IDX(LOG_ERR)] = ~0;
+  lst.masks[SEVERITY_MASK_IDX(LOG_WARN)] = ~0;
+  lst.masks[SEVERITY_MASK_IDX(LOG_NOTICE)] = ~0;
   add_callback_log(&lst, log_cback);
   mark_logs_temp();
 }
index ad22898ce51d6e29540728bbdd71e334fcd8bf06..9e7d83dcdc5b9d164bd8fa821c21dc4fced61b85 100644 (file)
@@ -295,7 +295,7 @@ main(int c, const char **v)
     memset(&s, 0, sizeof(s));
     set_log_severity_config(loglevel, LOG_ERR, &s);
     /* ALWAYS log bug warnings. */
-    s.masks[LOG_WARN-LOG_ERR] |= LD_BUG;
+    s.masks[SEVERITY_MASK_IDX(LOG_WARN)] |= LD_BUG;
     add_stream_log(&s, "", fileno(stdout));
   }
   {
@@ -303,7 +303,7 @@ main(int c, const char **v)
     log_severity_list_t s;
     memset(&s, 0, sizeof(s));
     set_log_severity_config(LOG_ERR, LOG_ERR, &s);
-    s.masks[LOG_WARN-LOG_ERR] |= LD_BUG;
+    s.masks[SEVERITY_MASK_IDX(LOG_WARN)] |= LD_BUG;
     add_callback_log(&s, log_callback_failure);
   }
   flush_log_messages_from_startup();