Skip to content

Commit 58592c4

Browse files
authored
Rename XLA_SHOW_CPP_ERROR_CONTEXT to TORCH_SHOW_CPP_STACKTRACES (pytorch#9482)
1 parent 2c556e7 commit 58592c4

15 files changed

+61
-76
lines changed

.github/scripts/run_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ function run_torch_xla_cpp_tests() {
5757
#"test_xla_backend_intf"
5858
"test_xla_sharding"
5959
"test_runtime"
60-
"test_status_dont_show_cpp_error_context"
61-
"test_status_show_cpp_error_context"
60+
"test_status_dont_show_cpp_stacktraces"
61+
"test_status_show_cpp_stacktraces"
6262
"test_debug_macros")
6363
for name in "${test_names[@]}"; do
6464
echo "Running $name cpp test..."

BUILD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ test_suite(
7878
"//test/cpp:test_tensor",
7979
"//test/cpp:test_xla_sharding",
8080
"//test/cpp:test_runtime",
81-
"//test/cpp:test_status_dont_show_cpp_error_context",
82-
"//test/cpp:test_status_show_cpp_error_context",
81+
"//test/cpp:test_status_dont_show_cpp_stacktraces",
82+
"//test/cpp:test_status_show_cpp_stacktraces",
8383
"//test/cpp:test_debug_macros",
8484
"//torch_xla/csrc/runtime:pjrt_computation_client_test",
8585
# "//torch_xla/csrc/runtime:ifrt_computation_client_test",

test/cpp/BUILD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,17 @@ cc_library(
175175
)
176176

177177
ptxla_cc_test(
178-
name = "test_status_dont_show_cpp_error_context",
179-
srcs = ["test_status_dont_show_cpp_error_context.cpp"],
178+
name = "test_status_dont_show_cpp_stacktraces",
179+
srcs = ["test_status_dont_show_cpp_stacktraces.cpp"],
180180
deps = [
181181
":test_status_common",
182182
"@com_google_googletest//:gtest_main",
183183
],
184184
)
185185

186186
ptxla_cc_test(
187-
name = "test_status_show_cpp_error_context",
188-
srcs = ["test_status_show_cpp_error_context.cpp"],
187+
name = "test_status_show_cpp_stacktraces",
188+
srcs = ["test_status_show_cpp_stacktraces.cpp"],
189189
deps = [
190190
":test_status_common",
191191
"@com_google_googletest//:gtest_main",

test/cpp/run_tests.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ if [[ "$RUN_CPP_TESTS" == "cpp_tests" ]]; then
101101
#"test_xla_backend_intf"
102102
"test_xla_sharding"
103103
"test_runtime"
104-
"test_status_dont_show_cpp_error_context"
105-
"test_status_show_cpp_error_context"
104+
"test_status_dont_show_cpp_stacktraces"
105+
"test_status_show_cpp_stacktraces"
106106
"test_debug_macros")
107107
fi
108108
for name in "${test_names[@]}"; do

test/cpp/test_debug_macros.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ TEST_XLA_CHECK_GREATER(GT, <, 5, 8)
5656
} // namespace torch_xla
5757

5858
static void SetUp() {
59-
setenv(torch_xla::runtime::env::kEnvShowCppErrorContext, /* value= */ "true",
60-
/* replace= */ 1);
59+
setenv("TORCH_SHOW_CPP_STACKTRACES", /* value= */ "1", /* replace= */ 1);
6160
}
6261

6362
int main(int argc, char** argv) {

test/cpp/test_status_common.h

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
// in a parameterized way, so as to avoid duplicating tests for both
55
// configurations:
66
//
7-
// 1. `XLA_SHOW_CPP_ERROR_CONTEXT=true`: instantiated in
8-
// test_status_show_cpp_error_context.cpp
7+
// 1. `TORCH_SHOW_CPP_STACKTRACES=true`: instantiated in
8+
// test_status_show_cpp_stacktraces.cpp
99
//
10-
// 2. `XLA_SHOW_CPP_ERROR_CONTEXT=false`: instantiated in
11-
// test_status_dont_show_cpp_error_context.cpp
10+
// 2. `TORCH_SHOW_CPP_STACKTRACES=false`: instantiated in
11+
// test_status_dont_show_cpp_stacktraces.cpp
1212
//
1313
// In order to easily instantiate the tests, this file also defines the macro
1414
// `INSTANTIATE_TEST_SUITE_WITH_MODE(mode)`, where `mode` is either `kShow` or
@@ -31,32 +31,32 @@
3131
namespace torch_xla {
3232

3333
// Enum to control whether C++ error context is shown in status messages
34-
enum class CppErrorContextMode {
34+
enum class CppStacktracesMode {
3535
kShow,
3636
kHide,
3737
};
3838

39-
// Converts CppErrorContextMode enum to string for test parameter naming
40-
inline const char* const ToString(CppErrorContextMode mode) {
39+
// Converts CppStacktracesMode enum to string for test parameter naming
40+
inline const char* const ToString(CppStacktracesMode mode) {
4141
switch (mode) {
42-
case CppErrorContextMode::kShow:
43-
return "ShowCppErrorContext";
44-
case CppErrorContextMode::kHide:
45-
return "DontShowCppErrorContext";
42+
case CppStacktracesMode::kShow:
43+
return "ShowCppStacktraces";
44+
case CppStacktracesMode::kHide:
45+
return "DontShowCppStacktraces";
4646
}
4747
}
4848

4949
// Base test class for parameterized status tests with C++ error context control
50-
class StatusTest : public testing::TestWithParam<CppErrorContextMode> {
50+
class StatusTest : public testing::TestWithParam<CppStacktracesMode> {
5151
public:
5252
StatusTest() {
53-
const char* const value = IsShowCppErrorContextMode() ? "true" : "false";
54-
setenv(runtime::env::kEnvShowCppErrorContext, value, /* replace= */ 1);
53+
const char* const value = IsShowCppStacktracesMode() ? "1" : "0";
54+
setenv("TORCH_SHOW_CPP_STACKTRACES", value, /* replace= */ 1);
5555
}
5656

5757
protected:
58-
bool IsShowCppErrorContextMode() {
59-
return GetParam() == CppErrorContextMode::kShow;
58+
bool IsShowCppStacktracesMode() {
59+
return GetParam() == CppStacktracesMode::kShow;
6060
}
6161
};
6262

@@ -66,10 +66,10 @@ class StatusTest : public testing::TestWithParam<CppErrorContextMode> {
6666
// non-qualified identifier. That's because the underlying
6767
// `INSTANTIATE_TEST_SUITE_P` GTest macro will concatenate it with other
6868
// things for creating a unique identifier.
69-
#define INSTANTIATE_WITH_CPP_ERROR_CONTEXT_MODE(suite, test, mode) \
70-
INSTANTIATE_TEST_SUITE_P( \
71-
suite, test, ::testing::Values(::torch_xla::CppErrorContextMode::mode), \
72-
[](const ::testing::TestParamInfo<::torch_xla::CppErrorContextMode>& \
69+
#define INSTANTIATE_WITH_CPP_STACKTRACES_MODE(suite, test, mode) \
70+
INSTANTIATE_TEST_SUITE_P( \
71+
suite, test, ::testing::Values(::torch_xla::CppStacktracesMode::mode), \
72+
[](const ::testing::TestParamInfo<::torch_xla::CppStacktracesMode>& \
7373
info) { return ToString(info.param); })
7474

7575
namespace testing {
@@ -104,7 +104,7 @@ TEST_P(StatusTest, GetValueOrThrowWithErrorStatusOr) {
104104
TEST_P(StatusTest, MaybeWithLocationPropagatesErrorStatus) {
105105
absl::Status error_status = absl::InvalidArgumentError(message);
106106
absl::Status result = MaybeWithLocation(error_status, test_file, line);
107-
if (IsShowCppErrorContextMode()) {
107+
if (IsShowCppStacktracesMode()) {
108108
ASSERT_NE(result, error_status);
109109
EXPECT_FALSE(result.ok());
110110
EXPECT_EQ(result.code(), error_status.code());
@@ -129,7 +129,7 @@ TEST_P(StatusTest, MaybeWithNewMessageNonEmptyNewMessage) {
129129
ASSERT_FALSE(result.ok());
130130
EXPECT_EQ(result.code(), error_status.code());
131131

132-
if (IsShowCppErrorContextMode()) {
132+
if (IsShowCppStacktracesMode()) {
133133
EXPECT_EQ(result.message(),
134134
absl::StrCat("New test error message (at test_file.cpp:42)\n"
135135
"From Error: Test error message"));
@@ -186,7 +186,7 @@ TEST_P(StatusTest, MacroReturnIfErrorWithNestedError) {
186186
ASSERT_FALSE(result.ok());
187187
EXPECT_EQ(result.code(), absl::StatusCode::kInvalidArgument);
188188

189-
if (IsShowCppErrorContextMode()) {
189+
if (IsShowCppStacktracesMode()) {
190190
EXPECT_EQ(result.message(), absl::StrCat("Test error message (at ",
191191
__FILE__, ":", errline, ")"));
192192
} else {
@@ -207,7 +207,7 @@ TEST_P(StatusTest, MacroReturnIfErrorWithErrorWithNewMessage) {
207207
ASSERT_FALSE(result.ok());
208208
EXPECT_EQ(result.code(), absl::StatusCode::kInvalidArgument);
209209

210-
if (IsShowCppErrorContextMode()) {
210+
if (IsShowCppStacktracesMode()) {
211211
EXPECT_EQ(result.message(),
212212
absl::StrCat("New test error message (at ", __FILE__, ":",
213213
errline, ")\nFrom Error: Test error message"));
@@ -258,7 +258,7 @@ TEST_P(StatusTest, MacroAssignOrReturnWithErrorWithNewMessage) {
258258
ASSERT_FALSE(result.ok());
259259
EXPECT_EQ(result.status().code(), absl::StatusCode::kInvalidArgument);
260260

261-
if (IsShowCppErrorContextMode()) {
261+
if (IsShowCppStacktracesMode()) {
262262
EXPECT_EQ(result.status().message(),
263263
absl::StrCat("New test error message (at ", __FILE__, ":",
264264
errline, ")\nFrom Error: Test error message"));
@@ -273,7 +273,7 @@ TEST_P(StatusTest, MacroErrorWithLocation) {
273273
absl::Status result = XLA_ERROR_WITH_LOCATION(error_status);
274274
ASSERT_FALSE(result.ok());
275275
EXPECT_EQ(result.code(), absl::StatusCode::kInvalidArgument);
276-
if (IsShowCppErrorContextMode()) {
276+
if (IsShowCppStacktracesMode()) {
277277
EXPECT_EQ(result.message(), absl::StrCat("Test error message (at ",
278278
__FILE__, ":", errline, ")"));
279279
} else {

test/cpp/test_status_dont_show_cpp_error_context.cpp renamed to test/cpp/test_status_dont_show_cpp_stacktraces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ using torch_xla::StatusTest;
44

55
// This file instantiates the parameterized tests defined in
66
// `test_status_common.h`. It specifically configures the test environment by
7-
// explicitly setting the `XLA_SHOW_CPP_ERROR_CONTEXT` environment variable to
7+
// explicitly setting the `TORCH_SHOW_CPP_STACKTRACES` environment variable to
88
// 'false' in the test fixture's `SetUp` method.
99
//
1010
// Any new `TEST_P` test cases added to `test_status_common.h` will
1111
// automatically be run in this mode (without C++ error context).
1212
//
13-
INSTANTIATE_WITH_CPP_ERROR_CONTEXT_MODE(StatusTest, StatusTest, kHide);
13+
INSTANTIATE_WITH_CPP_STACKTRACES_MODE(StatusTest, StatusTest, kHide);

test/cpp/test_status_show_cpp_error_context.cpp renamed to test/cpp/test_status_show_cpp_stacktraces.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ using torch_xla::StatusTest;
44

55
// This file instantiates the parameterized tests defined in
66
// `test_status_common.h`. It specifically configures the test environment by
7-
// explicitly setting the `XLA_SHOW_CPP_ERROR_CONTEXT` environment variable to
7+
// explicitly setting the `TORCH_SHOW_CPP_STACKTRACES` environment variable to
88
// 'true' in the test fixture's `SetUp` method.
99
//
1010
// Any new `TEST_P` test cases added to `test_status_common.h` will
1111
// automatically be run in this mode (with C++ error context).
12-
INSTANTIATE_WITH_CPP_ERROR_CONTEXT_MODE(StatusWithCppErrorContextTest,
13-
StatusTest, kShow);
12+
INSTANTIATE_WITH_CPP_STACKTRACES_MODE(StatusWithCppErrorContextTest, StatusTest,
13+
kShow);

torch_xla/csrc/BUILD

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ cc_library(
376376
srcs = ["status.cpp"],
377377
hdrs = ["status.h"],
378378
deps = [
379-
"//torch_xla/csrc/runtime:sys_util",
380-
"//torch_xla/csrc/runtime:env_vars",
379+
"@torch//:headers",
381380
"@com_google_absl//absl/log:absl_check",
382381
"@com_google_absl//absl/status:statusor",
383382
],

torch_xla/csrc/runtime/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ cc_library(
166166
hdrs = ["debug_macros.h"],
167167
deps = [
168168
":tf_logging",
169+
"@torch//:headers",
169170
"@tsl//tsl/platform:statusor",
170171
"@tsl//tsl/platform:macros",
171172
],

0 commit comments

Comments
 (0)