4
4
// in a parameterized way, so as to avoid duplicating tests for both
5
5
// configurations:
6
6
//
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
9
9
//
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
12
12
//
13
13
// In order to easily instantiate the tests, this file also defines the macro
14
14
// `INSTANTIATE_TEST_SUITE_WITH_MODE(mode)`, where `mode` is either `kShow` or
31
31
namespace torch_xla {
32
32
33
33
// Enum to control whether C++ error context is shown in status messages
34
- enum class CppErrorContextMode {
34
+ enum class CppStacktracesMode {
35
35
kShow ,
36
36
kHide ,
37
37
};
38
38
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) {
41
41
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 " ;
46
46
}
47
47
}
48
48
49
49
// 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 > {
51
51
public:
52
52
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 );
55
55
}
56
56
57
57
protected:
58
- bool IsShowCppErrorContextMode () {
59
- return GetParam () == CppErrorContextMode ::kShow ;
58
+ bool IsShowCppStacktracesMode () {
59
+ return GetParam () == CppStacktracesMode ::kShow ;
60
60
}
61
61
};
62
62
@@ -66,10 +66,10 @@ class StatusTest : public testing::TestWithParam<CppErrorContextMode> {
66
66
// non-qualified identifier. That's because the underlying
67
67
// `INSTANTIATE_TEST_SUITE_P` GTest macro will concatenate it with other
68
68
// 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 >& \
73
73
info) { return ToString (info.param ); })
74
74
75
75
namespace testing {
@@ -104,7 +104,7 @@ TEST_P(StatusTest, GetValueOrThrowWithErrorStatusOr) {
104
104
TEST_P (StatusTest, MaybeWithLocationPropagatesErrorStatus) {
105
105
absl::Status error_status = absl::InvalidArgumentError (message);
106
106
absl::Status result = MaybeWithLocation (error_status, test_file, line);
107
- if (IsShowCppErrorContextMode ()) {
107
+ if (IsShowCppStacktracesMode ()) {
108
108
ASSERT_NE (result, error_status);
109
109
EXPECT_FALSE (result.ok ());
110
110
EXPECT_EQ (result.code (), error_status.code ());
@@ -129,7 +129,7 @@ TEST_P(StatusTest, MaybeWithNewMessageNonEmptyNewMessage) {
129
129
ASSERT_FALSE (result.ok ());
130
130
EXPECT_EQ (result.code (), error_status.code ());
131
131
132
- if (IsShowCppErrorContextMode ()) {
132
+ if (IsShowCppStacktracesMode ()) {
133
133
EXPECT_EQ (result.message (),
134
134
absl::StrCat (" New test error message (at test_file.cpp:42)\n "
135
135
" From Error: Test error message" ));
@@ -186,7 +186,7 @@ TEST_P(StatusTest, MacroReturnIfErrorWithNestedError) {
186
186
ASSERT_FALSE (result.ok ());
187
187
EXPECT_EQ (result.code (), absl::StatusCode::kInvalidArgument );
188
188
189
- if (IsShowCppErrorContextMode ()) {
189
+ if (IsShowCppStacktracesMode ()) {
190
190
EXPECT_EQ (result.message (), absl::StrCat (" Test error message (at " ,
191
191
__FILE__, " :" , errline, " )" ));
192
192
} else {
@@ -207,7 +207,7 @@ TEST_P(StatusTest, MacroReturnIfErrorWithErrorWithNewMessage) {
207
207
ASSERT_FALSE (result.ok ());
208
208
EXPECT_EQ (result.code (), absl::StatusCode::kInvalidArgument );
209
209
210
- if (IsShowCppErrorContextMode ()) {
210
+ if (IsShowCppStacktracesMode ()) {
211
211
EXPECT_EQ (result.message (),
212
212
absl::StrCat (" New test error message (at " , __FILE__, " :" ,
213
213
errline, " )\n From Error: Test error message" ));
@@ -258,7 +258,7 @@ TEST_P(StatusTest, MacroAssignOrReturnWithErrorWithNewMessage) {
258
258
ASSERT_FALSE (result.ok ());
259
259
EXPECT_EQ (result.status ().code (), absl::StatusCode::kInvalidArgument );
260
260
261
- if (IsShowCppErrorContextMode ()) {
261
+ if (IsShowCppStacktracesMode ()) {
262
262
EXPECT_EQ (result.status ().message (),
263
263
absl::StrCat (" New test error message (at " , __FILE__, " :" ,
264
264
errline, " )\n From Error: Test error message" ));
@@ -273,7 +273,7 @@ TEST_P(StatusTest, MacroErrorWithLocation) {
273
273
absl::Status result = XLA_ERROR_WITH_LOCATION (error_status);
274
274
ASSERT_FALSE (result.ok ());
275
275
EXPECT_EQ (result.code (), absl::StatusCode::kInvalidArgument );
276
- if (IsShowCppErrorContextMode ()) {
276
+ if (IsShowCppStacktracesMode ()) {
277
277
EXPECT_EQ (result.message (), absl::StrCat (" Test error message (at " ,
278
278
__FILE__, " :" , errline, " )" ));
279
279
} else {
0 commit comments