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
37 // We need this macro instead of pasting directly to support nesting
38 // the DISABLED_ON_FOO macros, as in the definition of DISABLED_ON_CPU.
39 // Otherwise the pasting is applied before macro expansion completes.
40 #define XLA_TEST_PASTE(A, B) A##B
41
42 // We turn off clang-format so we can indent the macros for readability.
43 // clang-format off
44
45 #ifdef XLA_TEST_BACKEND_CPU
46 # undef DISABLED_ON_CPU
47 # define DISABLED_ON_CPU(X) XLA_TEST_PASTE(DISABLED_, X)
48 #endif // XLA_TEST_BACKEND_CPU
49
50 #ifdef XLA_TEST_BACKEND_GPU
51 # undef DISABLED_ON_GPU
52 # define DISABLED_ON_GPU(X) XLA_TEST_PASTE(DISABLED_, X)
53
54 #if TENSORFLOW_USE_ROCM
55 # undef DISABLED_ON_GPU_ROCM
56 # define DISABLED_ON_GPU_ROCM(X) XLA_TEST_PASTE(DISABLED_, X)
57 #endif // TENSORFLOW_USE_ROCM
58
59 #endif // XLA_TEST_BACKEND_GPU
60
61 #ifdef XLA_TEST_BACKEND_INTERPRETER
62 # undef DISABLED_ON_INTERPRETER
63 # define DISABLED_ON_INTERPRETER(X) XLA_TEST_PASTE(DISABLED_, X)
64
65 #ifdef THREAD_SANITIZER
66 # undef DISABLED_ON_INTERPRETER_TSAN
67 # define DISABLED_ON_INTERPRETER_TSAN(X) XLA_TEST_PASTE(DISABLED_, X)
68 #endif // THREAD_SANITIZER
69
70 #endif // XLA_TEST_BACKEND_INTERPRETER
71
72 // clang-format on
73
74 namespace xla {
75
DisabledManifestPath()76 inline const char** DisabledManifestPath() {
77 static const char* disabled_manifest_path = nullptr;
78 return &disabled_manifest_path;
79 }
80
TestPlatform()81 inline const char** TestPlatform() {
82 static const char* test_platform = nullptr;
83 return &test_platform;
84 }
85
86 } // namespace xla
87
88 #define XLA_TEST_F(test_fixture, test_name) TEST_F(test_fixture, test_name)
89
90 #define XLA_TEST_P(test_case_name, test_name) TEST_P(test_case_name, test_name)
91
92 #define XLA_TYPED_TEST(CaseName, TestName) TYPED_TEST(CaseName, TestName)
93
94 #endif // TENSORFLOW_COMPILER_XLA_TESTS_TEST_MACROS_H_
95