Fix regression of r23.
[platform/upstream/glog.git] / src / symbolize_unittest.cc
index 2405362..77dfb29 100644 (file)
@@ -1,8 +1,38 @@
-// Copyright 2006 Google Inc. All Rights Reserved.
+// Copyright (c) 2006, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+//     * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
 // Author: Satoru Takabayashi
 //
 // Unit tests for functions in symbolize.cc.
 
+#include "utilities.h"
+
 #include <signal.h>
 #include <iostream>
 
@@ -10,7 +40,6 @@
 #include "symbolize.h"
 #include "googletest.h"
 #include "config.h"
-#include "utilities.h"
 
 using namespace std;
 using namespace GOOGLE_NAMESPACE;
@@ -126,7 +155,7 @@ const char kAlternateStackFillValue = 0x55;
 // These helper functions look at the alternate stack buffer, and figure
 // out what portion of this buffer has been touched - this is the stack
 // consumption of the signal handler running on this alternate stack.
-static bool StackGrowsDown(int *x) {
+static ATTRIBUTE_NOINLINE bool StackGrowsDown(int *x) {
   int y;
   return &y < x;
 }
@@ -277,7 +306,7 @@ void ATTRIBUTE_NOINLINE TestWithPCInsideNonInlineFunction() {
   void *pc = non_inline_func();
   const char *symbol = TrySymbolize(pc);
   CHECK(symbol != NULL);
-  CHECK_EQ(0, strcmp(symbol, "non_inline_func"));
+  CHECK_STREQ(symbol, "non_inline_func");
   cout << "Test case TestWithPCInsideNonInlineFunction passed." << endl;
 #endif
 }
@@ -287,7 +316,7 @@ void ATTRIBUTE_NOINLINE TestWithPCInsideInlineFunction() {
   void *pc = inline_func();  // Must be inlined.
   const char *symbol = TrySymbolize(pc);
   CHECK(symbol != NULL);
-  CHECK_EQ(0, strcmp(symbol, __FUNCTION__));
+  CHECK_STREQ(symbol, __FUNCTION__);
   cout << "Test case TestWithPCInsideInlineFunction passed." << endl;
 #endif
 }
@@ -299,7 +328,7 @@ void ATTRIBUTE_NOINLINE TestWithReturnAddress() {
   void *return_address = __builtin_return_address(0);
   const char *symbol = TrySymbolize(return_address);
   CHECK(symbol != NULL);
-  CHECK_EQ(0, strcmp(symbol, "main"));
+  CHECK_STREQ(symbol, "main");
   cout << "Test case TestWithReturnAddress passed." << endl;
 #endif
 }
@@ -307,22 +336,28 @@ void ATTRIBUTE_NOINLINE TestWithReturnAddress() {
 int main(int argc, char **argv) {
   FLAGS_logtostderr = true;
   InitGoogleLogging(argv[0]);
+  InitGoogleTest(&argc, argv);
+#ifdef HAVE_SYMBOLIZE
+  // We don't want to get affected by the callback interface, that may be
+  // used to install some callback function at InitGoogle() time.
+  InstallSymbolizeCallback(NULL);
 
-  // Symbolize() now only supports ELF binaries.
-  // The test makes sense only if __ELF__ is defined.
-#ifndef __ELF__
-  return 0;
-#else
   TestWithPCInsideInlineFunction();
   TestWithPCInsideNonInlineFunction();
   TestWithReturnAddress();
   return RUN_ALL_TESTS();
+#else
+  return 0;
 #endif
 }
 
 #else
 int main() {
+#ifdef HAVE_SYMBOLIZE
+  printf("PASS (no symbolize_unittest support)\n");
+#else
   printf("PASS (no symbolize support)\n");
+#endif
   return 0;
 }
 #endif  // HAVE_STACKTRACE