1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 // Macros for use in enabling/disabling tests on particular
17 // platforms. Marking a gunit test as disabled still ensures that it
18 // compiles.
19 //
20 // Implementation note: the macros are structured as follows:
21 // * Define the disabled macro to just pass the test name through (which, in
22 // effect, does not disable it at all)
23 // * If a XLA_TEST_BACKEND_$TARGET macro indicates we're compiling for
24 // $TARGET platform, make the disabled macro truly disable the test; i.e. by
25 // redefining the DISABLED_ON_$TARGET macro to prepend "DISABLED_" to the test
26 // name.
27
28 #ifndef TENSORFLOW_COMPILER_XLA_TESTS_TEST_MACROS_H_
29 #define TENSORFLOW_COMPILER_XLA_TESTS_TEST_MACROS_H_
30
31 #define DISABLED_ON_CPU(X) X
32 #define DISABLED_ON_GPU(X) X
33 #define DISABLED_ON_GPU_ROCM(X) X
34 #define DISABLED_ON_INTERPRETER(X) X
35 #define DISABLED_ON_INTERPRETER_TSAN(X) X
36 #define DISABLED_ON_DEBUG(X) X
37
38 // We need this macro instead of pasting directly to support nesting
39 // the DISABLED_ON_FOO macros, as in the definition of DISABLED_ON_CPU.
40 // Otherwise the pasting is applied before macro expansion completes.
41 #define XLA_TEST_PASTE(A, B) A##B
42
43 // We turn off clang-format so we can indent the macros for readability.
44 // clang-format off
45
46 #ifdef XLA_TEST_BACKEND_CPU
47 # undef DISABLED_ON_CPU
48 # define DISABLED_ON_CPU(X) XLA_TEST_PASTE(DISABLED_, X)
49 #endif // XLA_TEST_BACKEND_CPU
50
51 #ifdef XLA_TEST_BACKEND_GPU
52 # undef DISABLED_ON_GPU
53 # define DISABLED_ON_GPU(X) XLA_TEST_PASTE(DISABLED_, X)
54
55 #if TENSORFLOW_USE_ROCM
56 # undef DISABLED_ON_GPU_ROCM
57 # define DISABLED_ON_GPU_ROCM(X) XLA_TEST_PASTE(DISABLED_, X)
58 #endif // TENSORFLOW_USE_ROCM
59
60 #endif // XLA_TEST_BACKEND_GPU
61
62 #ifdef XLA_TEST_BACKEND_INTERPRETER
63 # undef DISABLED_ON_INTERPRETER
64 # define DISABLED_ON_INTERPRETER(X) XLA_TEST_PASTE(DISABLED_, X)
65
66 #ifdef THREAD_SANITIZER
67 # undef DISABLED_ON_INTERPRETER_TSAN
68 # define DISABLED_ON_INTERPRETER_TSAN(X) XLA_TEST_PASTE(DISABLED_, X)
69 #endif // THREAD_SANITIZER
70
71 #endif // XLA_TEST_BACKEND_INTERPRETER
72
73 #ifndef NDEBUG
74 # undef DISABLED_ON_DEBUG
75 # define DISABLED_ON_DEBUG(X) XLA_TEST_PASTE(DISABLED_, X)
76 #endif // !NDEBUG
77
78 // clang-format on
79
80 namespace xla {
81
DisabledManifestPath()82 inline const char** DisabledManifestPath() {
83 static const char* disabled_manifest_path = nullptr;
84 return &disabled_manifest_path;
85 }
86
TestPlatform()87 inline const char** TestPlatform() {
88 static const char* test_platform = nullptr;
89 return &test_platform;
90 }
91
92 } // namespace xla
93
94 #define XLA_TEST_F(test_fixture, test_name) TEST_F(test_fixture, test_name)
95
96 #define XLA_TEST_P(test_case_name, test_name) TEST_P(test_case_name, test_name)
97
98 #define XLA_TYPED_TEST(CaseName, TestName) TYPED_TEST(CaseName, TestName)
99
100 #endif // TENSORFLOW_COMPILER_XLA_TESTS_TEST_MACROS_H_
101