This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- MULTIPROCESS_TEST_MAIN
- TEST_F
- itoa_r_wrapper
- TEST_F
#include <limits>
#include <sstream>
#include <string>
#include "base/debug/stack_trace.h"
#include "base/logging.h"
#include "base/process/kill.h"
#include "base/process/process_handle.h"
#include "base/test/test_timeouts.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/multiprocess_func_list.h"
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
#include "base/test/multiprocess_test.h"
#endif
namespace base {
namespace debug {
#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_IOS)
typedef MultiProcessTest StackTraceTest;
#else
typedef testing::Test StackTraceTest;
#endif
#if defined(OS_WIN)
#define MAYBE_OutputToStream DISABLED_OutputToStream
#else
#define MAYBE_OutputToStream OutputToStream
#endif
TEST_F(StackTraceTest, MAYBE_OutputToStream) {
StackTrace trace;
std::ostringstream os;
trace.OutputToStream(&os);
std::string backtrace_message = os.str();
EXPECT_EQ(backtrace_message, trace.ToString());
#if defined(OS_POSIX) && !defined(OS_MACOSX) && NDEBUG
return;
#endif
size_t frames_found = 0;
trace.Addresses(&frames_found);
ASSERT_GE(frames_found, 5u) <<
"No stack frames found. Skipping rest of test.";
ASSERT_EQ(backtrace_message.find("Dumping unresolved backtrace"),
std::string::npos) <<
"Unable to resolve symbols. Skipping rest of test.";
#if defined(OS_MACOSX)
#if 0
EXPECT_TRUE(backtrace_message.find("start") != std::string::npos)
<< "Expected to find start in backtrace:\n"
<< backtrace_message;
#endif
#elif defined(USE_SYMBOLIZE)
EXPECT_TRUE(backtrace_message.find("testing::Test::Run()") !=
std::string::npos)
<< "Expected a demangled symbol in backtrace:\n"
<< backtrace_message;
#elif 0
EXPECT_TRUE(backtrace_message.find("main") != std::string::npos)
<< "Expected to find main in backtrace:\n"
<< backtrace_message;
#if defined(OS_WIN)
#define __func__ __FUNCTION__
#endif
EXPECT_TRUE(backtrace_message.find(__func__) != std::string::npos)
<< "Expected to find " << __func__ << " in backtrace:\n"
<< backtrace_message;
#endif
}
TEST_F(StackTraceTest, DebugOutputToStream) {
StackTrace trace;
std::ostringstream os;
trace.OutputToStream(&os);
VLOG(1) << os.str();
}
TEST_F(StackTraceTest, DebugPrintBacktrace) {
StackTrace().Print();
}
#if defined(OS_POSIX) && !defined(OS_ANDROID)
#if !defined(OS_IOS)
MULTIPROCESS_TEST_MAIN(MismatchedMallocChildProcess) {
char* pointer = new char[10];
delete pointer;
return 2;
}
TEST_F(StackTraceTest, AsyncSignalUnsafeSignalHandlerHang) {
ProcessHandle child = SpawnChild("MismatchedMallocChildProcess");
ASSERT_NE(kNullProcessHandle, child);
ASSERT_TRUE(WaitForSingleProcess(child, TestTimeouts::action_timeout()));
}
#endif
namespace {
std::string itoa_r_wrapper(intptr_t i, size_t sz, int base, size_t padding) {
char buffer[1024];
CHECK_LE(sz, sizeof(buffer));
char* result = internal::itoa_r(i, buffer, sz, base, padding);
EXPECT_TRUE(result);
return std::string(buffer);
}
}
TEST_F(StackTraceTest, itoa_r) {
EXPECT_EQ("0", itoa_r_wrapper(0, 128, 10, 0));
EXPECT_EQ("-1", itoa_r_wrapper(-1, 128, 10, 0));
if (sizeof(intptr_t) == 4) {
EXPECT_EQ("ffffffff", itoa_r_wrapper(-1, 128, 16, 0));
EXPECT_EQ("-2147483648",
itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10, 0));
EXPECT_EQ("2147483647",
itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10, 0));
EXPECT_EQ("80000000",
itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16, 0));
EXPECT_EQ("7fffffff",
itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16, 0));
} else if (sizeof(intptr_t) == 8) {
EXPECT_EQ("ffffffffffffffff", itoa_r_wrapper(-1, 128, 16, 0));
EXPECT_EQ("-9223372036854775808",
itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 10, 0));
EXPECT_EQ("9223372036854775807",
itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 10, 0));
EXPECT_EQ("8000000000000000",
itoa_r_wrapper(std::numeric_limits<intptr_t>::min(), 128, 16, 0));
EXPECT_EQ("7fffffffffffffff",
itoa_r_wrapper(std::numeric_limits<intptr_t>::max(), 128, 16, 0));
} else {
ADD_FAILURE() << "Missing test case for your size of intptr_t ("
<< sizeof(intptr_t) << ")";
}
EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0));
EXPECT_EQ("deadbeef", itoa_r_wrapper(0xdeadbeef, 128, 16, 0));
char buffer[1024];
EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 10, 16, 0));
EXPECT_TRUE(internal::itoa_r(0xdeadbeef, buffer, 9, 16, 0));
EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 8, 16, 0));
EXPECT_FALSE(internal::itoa_r(0xdeadbeef, buffer, 7, 16, 0));
EXPECT_TRUE(internal::itoa_r(0xbeef, buffer, 5, 16, 4));
EXPECT_FALSE(internal::itoa_r(0xbeef, buffer, 5, 16, 5));
EXPECT_FALSE(internal::itoa_r(0xbeef, buffer, 5, 16, 6));
EXPECT_EQ("1", itoa_r_wrapper(1, 128, 10, 0));
EXPECT_EQ("1", itoa_r_wrapper(1, 128, 10, 1));
EXPECT_EQ("01", itoa_r_wrapper(1, 128, 10, 2));
EXPECT_EQ("001", itoa_r_wrapper(1, 128, 10, 3));
EXPECT_EQ("0001", itoa_r_wrapper(1, 128, 10, 4));
EXPECT_EQ("00001", itoa_r_wrapper(1, 128, 10, 5));
EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 0));
EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 1));
EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 2));
EXPECT_EQ("688", itoa_r_wrapper(0x688, 128, 16, 3));
EXPECT_EQ("0688", itoa_r_wrapper(0x688, 128, 16, 4));
EXPECT_EQ("00688", itoa_r_wrapper(0x688, 128, 16, 5));
}
#endif
}
}