MB-20054: [BP] Add verbose (logging) output to ep_unit_tests_main 16/65516/8
authorDave Rigby <daver@couchbase.com>
Tue, 5 Jul 2016 11:31:59 +0000 (12:31 +0100)
committerDave Rigby <daver@couchbase.com>
Thu, 7 Jul 2016 15:59:33 +0000 (15:59 +0000)
Not originally part of MB-20054, but needed for test development for
this MB.

Change-Id: Ia38db00d4f8cd84b2c90b5bddbd0bc01f51b61de
Reviewed-on: http://review.couchbase.org/65516
Well-Formed: buildbot <build@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Will Gardner <will.gardner@couchbase.com>
Reviewed-by: Jim Walker <jim@couchbase.com>
src/ep_engine.cc
src/ep_engine.h
tests/module_tests/ep_unit_tests_main.cc
tests/module_tests/evp_store_test.cc

index fd19d9b..8dc4f82 100644 (file)
@@ -52,7 +52,8 @@
 #include <JSON_checker.h>
 
 static ALLOCATOR_HOOKS_API *hooksApi;
-static SERVER_LOG_API *loggerApi;
+SERVER_LOG_API* EventuallyPersistentEngine::loggerApi;
+
 
 static size_t percentOf(size_t val, double percent) {
     return static_cast<size_t>(static_cast<double>(val) * percent);
@@ -1724,7 +1725,7 @@ extern "C" {
         }
 
         hooksApi = api->alloc_hooks;
-        loggerApi = api->log;
+        EventuallyPersistentEngine::loggerApi = api->log;
         MemoryTracker::getInstance();
         ObjectRegistry::initialize(api->alloc_hooks->get_allocation_size);
 
@@ -1809,11 +1810,11 @@ extern "C" {
 void LOG(EXTENSION_LOG_LEVEL severity, const char *fmt, ...) {
     char buffer[2048];
 
-    if (loggerApi != NULL) {
+    if (EventuallyPersistentEngine::loggerApi != NULL) {
         EXTENSION_LOGGER_DESCRIPTOR* logger =
-            (EXTENSION_LOGGER_DESCRIPTOR*)loggerApi->get_logger();
+            (EXTENSION_LOGGER_DESCRIPTOR*)EventuallyPersistentEngine::loggerApi->get_logger();
 
-        if (loggerApi->get_level() <= severity) {
+        if (EventuallyPersistentEngine::loggerApi->get_level() <= severity) {
             EventuallyPersistentEngine *engine = ObjectRegistry::onSwitchThread(NULL, true);
             va_list va;
             va_start(va, fmt);
index 08ea991..a1fa67f 100644 (file)
@@ -740,6 +740,8 @@ public:
     ENGINE_ERROR_CODE getAllVBucketSequenceNumbers(const void *cookie,
                                                    ADD_RESPONSE response);
 
+    static SERVER_LOG_API *loggerApi;
+
 protected:
     friend class EpEngineValueChangeListener;
 
index 2f299d6..4923636 100644 (file)
 static char allow_no_stats_env[] = "ALLOW_NO_STATS_UPDATE=yeah";
 
 int main(int argc, char **argv) {
+    bool log_to_stderr = false;
+    // Parse command-line options.
+    int cmd;
+    bool invalid_argument = false;
+    while (!invalid_argument &&
+           (cmd = getopt(argc, argv, "v")) != EOF) {
+        switch (cmd) {
+        case 'v':
+            log_to_stderr = true;
+            break;
+        default:
+            std::cerr << "Usage: " << argv[0] << " [-v] [gtest_options...]" << std::endl
+                      << std::endl
+                      << "  -v Verbose - Print verbose output to stderr."
+                      << std::endl << std::endl;
+            invalid_argument = true;
+            break;
+        }
+    }
+
     putenv(allow_no_stats_env);
 
-    init_mock_server(false);
+    init_mock_server(log_to_stderr);
+    get_mock_server_api()->log->set_level(EXTENSION_LOG_DEBUG);
+
+    if (memcached_initialize_stderr_logger(get_mock_server_api) != EXTENSION_SUCCESS) {
+        std::cerr << argv[0] << ": Failed to initialize log system" << std::endl;
+        return 1;
+    }
+
 
     // Default number of hashtable locks is too large for TSan to
     // track. Use the value in configuration.json (47 at time of
index ef1408f..50e698a 100644 (file)
@@ -41,6 +41,8 @@ SynchronousEPEngine::SynchronousEPEngine(const std::string& extra_config)
     : EventuallyPersistentEngine(get_mock_server_api) {
     maxFailoverEntries = 1;
 
+    EventuallyPersistentEngine::loggerApi = get_mock_server_api()->log;
+
     // Merge any extra config into the main configuration.
     if (extra_config.size() > 0) {
         if (!configuration.parseConfiguration(extra_config.c_str(),