]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
unit tests: do standard ceph init before tests
authorColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 14 Jan 2011 13:57:36 +0000 (05:57 -0800)
committerColin Patrick McCabe <cmccabe@alumni.cmu.edu>
Fri, 14 Jan 2011 13:58:36 +0000 (05:58 -0800)
Signed-off-by: Colin McCabe <colin.mccabe@dreamhost.com>
src/common/common_init.cc
src/common/common_init.h
src/test/base64.cc
src/test/encoding.cc
src/test/unit_test_main.h [new file with mode: 0644]

index 71455089baf0f2390932edb45f7e2beb5f13708d..7fc6a917e8d7c8791f7360eb51a2616580d365da 100644 (file)
 #include "include/color.h"
 #include "tls.h"
 
-/* Set foreground logging
- *
- * Forces the process to log only to stderr, overriding whatever was in the ceph.conf.
- *
- * TODO: make this configurable by a command line switch or environment variable, if users want
- * an unusual logging setup for their foreground process.
- */
-void set_foreground_logging()
+static void set_no_logging_impl()
 {
   free((void*)g_conf.log_file);
   g_conf.log_file = NULL;
@@ -39,13 +32,38 @@ void set_foreground_logging()
 
   g_conf.log_sym_history = 0;
 
-  g_conf.log_to_stderr = LOG_TO_STDERR_ALL;
+  g_conf.log_to_stderr = LOG_TO_STDERR_NONE;
 
   g_conf.log_to_syslog = false;
 
   g_conf.log_per_instance = false;
 
   g_conf.log_to_file = false;
+}
+
+/* Set no logging
+ */
+void set_no_logging()
+{
+  set_no_logging_impl();
+
+  if (_dout_need_open) {
+    Mutex::Locker l(_dout_lock);
+    _dout_open_log(false);
+  }
+}
+
+/* Set foreground logging
+ *
+ * Forces the process to log only to stderr, overriding whatever was in the ceph.conf.
+ *
+ * TODO: make this configurable by a command line switch or environment variable, if users want
+ * an unusual logging setup for their foreground process.
+ */
+void set_foreground_logging()
+{
+  set_no_logging_impl();
+  g_conf.log_to_stderr = LOG_TO_STDERR_ALL;
 
   if (_dout_need_open) {
     Mutex::Locker l(_dout_lock);
index bcffc8ddf275500b0ad7e150b70a761de405d20c..772ca832f82416b5a6297845a8b13f26a390ff12 100644 (file)
@@ -7,6 +7,7 @@ void common_set_defaults(bool daemon);
 void common_init(std::vector<const char*>& args,
                 const char *module_type,
                  bool init_keys);
+void set_no_logging();
 void set_foreground_logging();
 
 #endif
index dc091221eb344d5d9e17edf2bb461edffa462415..17f34024a40af1c69944dbb41ad5be8e0efd833d 100644 (file)
@@ -59,3 +59,5 @@ TEST(IncorrectBase64Decoding2, StringSimple) {
   }
   ASSERT_EQ(failed, true);
 }
+
+#include <test/unit_test_main.h>
index 9ea1c84a4824d6310266b1d6ca704406e19900f6..730cb50611f1a73679bf7d868c88fb14968ee78d 100644 (file)
@@ -196,3 +196,5 @@ TEST(EncodingRoundTrip, MultimapConstructorCounter) {
   EXPECT_EQ(my_val_t::get_copy_ctor(), 10);
   EXPECT_EQ(my_val_t::get_assigns(), 0);
 }
+
+#include <test/unit_test_main.h>
diff --git a/src/test/unit_test_main.h b/src/test/unit_test_main.h
new file mode 100644 (file)
index 0000000..86c4230
--- /dev/null
@@ -0,0 +1,32 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2011 Dreamhost
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include "common/common_init.h"
+
+#include "gtest/gtest.h"
+
+/* The main function for Ceph unit tests */
+int main(int argc, char **argv)
+{
+  ::testing::InitGoogleTest(&argc, argv);
+
+  vector<const char*> args;
+  argv_to_vec(argc, const_cast<const char**>(argv), args);
+  env_to_vec(args);
+  common_set_defaults(false);
+  common_init(args, argv[0], false);
+  set_no_logging();
+
+  return RUN_ALL_TESTS();
+}