bin: consolidate clients
[awesomized/libmemcached] / test / setup.cpp
index 1f4c9a477d12b96ad48b6965d6e8ff8462ad3dcd..a506976a0c793d750a7d6f23169476e59941bf0d 100644 (file)
@@ -1,4 +1,7 @@
 #include "mem_config.h"
+#include "test/conf.h"
+#include "test/lib/env.hpp"
+#include "test/lib/random.hpp"
 #include <cstdlib>
 #include <cstdio>
 #include <cstring>
@@ -7,12 +10,6 @@
 #include <string>
 #include <unistd.h>
 
-#if HAVE_SETENV
-# define SET_ENV(n, k, v) setenv(k, v, 0)
-#else // !HAVE_SETENV
-# define SET_ENV(n, k, v) static char n ## _env[] = k "=" v; putenv(n ## _env)
-#endif
-
 static void sigchld(int, siginfo_t *si, void *) {
   switch (si->si_code) {
   case CLD_EXITED:
@@ -36,7 +33,6 @@ static void sigchld(int, siginfo_t *si, void *) {
 
 static inline void setup_signals() {
   struct sigaction sa;
-
   memset(&sa, 0, sizeof(sa));
   sa.sa_flags = SA_NOCLDSTOP | SA_RESTART | SA_SIGINFO | SA_NODEFER;
 
@@ -60,31 +56,70 @@ static inline void setup_signals() {
     "verify_asan_link_order=1," \
     "abort_on_error=0," \
     ""
+# define LSAN_OPTIONS \
+  "suppressions=" SOURCES_ROOT "/test/LeakSanitizer.suppressions," \
+  ""
+
 static inline void setup_asan(char **argv) {
   const auto set = getenv("ASAN_OPTIONS");
 
   if (!set || !*set) {
-    SET_ENV(asan, "ASAN_OPTIONS", ASAN_OPTIONS);
+    SET_ENV_EX(asan, "ASAN_OPTIONS", ASAN_OPTIONS, 0);
+    execvp(argv[0], argv);
+    perror("exec()");
+  }
+}
+static inline void setup_lsan(char **argv) {
+  const auto set = getenv("LSAN_OPTIONS");
+
+  if (!set || !*set) {
+    SET_ENV_EX(lsan, "LSAN_OPTIONS", LSAN_OPTIONS, 0);
     execvp(argv[0], argv);
     perror("exec()");
   }
 }
 #else
-# define setup_asan(a)
+# define setup_asan(a) (void) a
+# define setup_lsan(a) (void) a
+#endif
+
+#if HAVE_TSAN
+# define TSAN_OPTIONS \
+    "abort_on_error=0," \
+    "halt_on_error=0" \
+    ""
+static inline void setup_tsan(char **argv) {
+  const auto set = getenv("TSAN_OPTIONS");
+
+  if (!set || !*set) {
+    SET_ENV_EX(tsan, "TSAN_OPTIONS", TSAN_OPTIONS, 0);
+    execvp(argv[0], argv);
+    perror("exec()");
+  }
+}
+#else
+# define setup_tsan(a) (void) a
 #endif
 
 #if LIBMEMCACHED_WITH_SASL_SUPPORT
 static inline void setup_sasl() {
-  SET_ENV(sasl_pwdb, "MEMCACHED_SASL_PWDB", LIBMEMCACHED_WITH_SASL_PWDB);
-  SET_ENV(sasl_conf, "SASL_CONF_PATH", LIBMEMCACHED_WITH_SASL_CONF);
+  SET_ENV_EX(sasl_pwdb, "MEMCACHED_SASL_PWDB", LIBMEMCACHED_WITH_SASL_PWDB, 0);
+  SET_ENV_EX(sasl_conf, "SASL_CONF_PATH", LIBMEMCACHED_WITH_SASL_CONF, 0);
 }
 #else
 # define setup_sasl()
 #endif
 
+static inline void setup_random() {
+  random_setup();
+}
+
 int setup(int &, char ***argv) {
   setup_signals();
+  setup_random();
   setup_asan(*argv);
+  setup_lsan(*argv);
+  setup_tsan(*argv);
   setup_sasl();
 
   return 0;