mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/36768 Follow LOG(WARNING) format for c++ side warnings in order to play well with larger services, especially when using glog. I need to hook up into GLOG internals a bit in order to override FILE/LINE without having to change the whole thing to be macros, but it seems to be stable between glog versions. Note, this also changes caffe2_log_level to warning by default - I think it's a much better default when compiling without glog (or maybe even have info) Test Plan: Run unittest in both glog and non-glog build mode: glog: ``` W0416 12:06:49.778215 3311666 exception_test.cpp:23] Warning: I'm a warning (function TestBody) ``` no-glog: ``` [W exception_test.cpp:23] Warning: I'm a warning (function TestBody) ``` Reviewed By: ilia-cher Differential Revision: D21078446 fbshipit-source-id: b5d36aac54d6b6295a72de6754696ccafbcb84ca
25 lines
647 B
C++
25 lines
647 B
C++
#include <c10/util/Exception.h>
|
|
#include <gtest/gtest.h>
|
|
#include <stdexcept>
|
|
|
|
namespace {
|
|
bool throw_func() {
|
|
throw std::runtime_error("I'm throwing...");
|
|
}
|
|
} // namespace
|
|
|
|
TEST(ExceptionTest, TORCH_INTERNAL_ASSERT_DEBUG_ONLY) {
|
|
#ifdef NDEBUG
|
|
ASSERT_NO_THROW(TORCH_INTERNAL_ASSERT_DEBUG_ONLY(false));
|
|
// Does nothing - `throw_func()` should not be evaluated
|
|
ASSERT_NO_THROW(TORCH_INTERNAL_ASSERT_DEBUG_ONLY(throw_func()));
|
|
#else
|
|
ASSERT_THROW(TORCH_INTERNAL_ASSERT_DEBUG_ONLY(false), c10::Error);
|
|
ASSERT_NO_THROW(TORCH_INTERNAL_ASSERT_DEBUG_ONLY(true));
|
|
#endif
|
|
}
|
|
|
|
TEST(WarningTest, JustPrintWarning) {
|
|
TORCH_WARN("I'm a warning");
|
|
}
|