Adding a stacktrace test.
PiperOrigin-RevId: 266966740
This commit is contained in:
parent
7403920848
commit
9029fc24f6
@ -3735,6 +3735,7 @@ tf_cc_tests(
|
|||||||
"//tensorflow/core/platform:profile_utils/cpu_utils_test.cc",
|
"//tensorflow/core/platform:profile_utils/cpu_utils_test.cc",
|
||||||
"//tensorflow/core/platform:scanner_test.cc",
|
"//tensorflow/core/platform:scanner_test.cc",
|
||||||
"//tensorflow/core/platform:stacktrace_handler_test.cc",
|
"//tensorflow/core/platform:stacktrace_handler_test.cc",
|
||||||
|
"//tensorflow/core/platform:stacktrace_test.cc",
|
||||||
"//tensorflow/core/platform:str_util_test.cc",
|
"//tensorflow/core/platform:str_util_test.cc",
|
||||||
"//tensorflow/core/platform:strcat_test.cc",
|
"//tensorflow/core/platform:strcat_test.cc",
|
||||||
"//tensorflow/core/platform:stringpiece_test.cc",
|
"//tensorflow/core/platform:stringpiece_test.cc",
|
||||||
|
@ -21,11 +21,11 @@ limitations under the License.
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
#if !defined(IS_MOBILE_PLATFORM) && !defined(PLATFORM_WINDOWS) && \
|
#if !defined(IS_MOBILE_PLATFORM) && !defined(PLATFORM_WINDOWS) && \
|
||||||
defined(PLATFORM_POSIX) && (defined(__clang__) || defined(__GNUC__))
|
(defined(__clang__) || defined(__GNUC__))
|
||||||
#define TF_GENERATE_BACKTRACE
|
#define TF_HAS_STACKTRACE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(TF_GENERATE_BACKTRACE)
|
#if defined(TF_HAS_STACKTRACE)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <execinfo.h>
|
#include <execinfo.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -41,7 +41,7 @@ namespace tensorflow {
|
|||||||
|
|
||||||
// Function to create a pretty stacktrace.
|
// Function to create a pretty stacktrace.
|
||||||
inline std::string CurrentStackTrace() {
|
inline std::string CurrentStackTrace() {
|
||||||
#if defined(TF_GENERATE_BACKTRACE)
|
#if defined(TF_HAS_STACKTRACE)
|
||||||
std::stringstream ss("");
|
std::stringstream ss("");
|
||||||
ss << "*** Begin stack trace ***" << std::endl;
|
ss << "*** Begin stack trace ***" << std::endl;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ inline std::string CurrentStackTrace() {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
#else
|
#else
|
||||||
return std::string();
|
return std::string();
|
||||||
#endif // defined(TF_GENERATE_BACKTRACE)
|
#endif // defined(TF_HAS_STACKTRACE)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void DebugWriteToString(const char* data, void* arg) {
|
inline void DebugWriteToString(const char* data, void* arg) {
|
||||||
|
39
tensorflow/core/platform/stacktrace_test.cc
Normal file
39
tensorflow/core/platform/stacktrace_test.cc
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
==============================================================================*/
|
||||||
|
// Testing proper operation of the stacktrace handler.
|
||||||
|
|
||||||
|
#include "tensorflow/core/platform/stacktrace.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "tensorflow/core/platform/logging.h"
|
||||||
|
#include "tensorflow/core/platform/test.h"
|
||||||
|
|
||||||
|
namespace tensorflow {
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
#if defined(TF_HAS_STACKTRACE)
|
||||||
|
|
||||||
|
TEST(StacktraceTest, StacktraceWorks) {
|
||||||
|
std::string stacktrace = CurrentStackTrace();
|
||||||
|
LOG(INFO) << "CurrentStackTrace():\n" << stacktrace;
|
||||||
|
std::string expected_frame = "testing::internal::UnitTestImpl::RunAllTests";
|
||||||
|
EXPECT_NE(stacktrace.find(expected_frame), std::string::npos);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // defined(TF_HAS_STACKTRACE)
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace tensorflow
|
Loading…
Reference in New Issue
Block a user