1 /* Copyright 2015 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 #ifndef TENSORFLOW_CORE_PLATFORM_TEST_H_ 17 #define TENSORFLOW_CORE_PLATFORM_TEST_H_ 18 19 #include <memory> 20 #include <vector> 21 22 #include <gtest/gtest.h> // IWYU pragma: export 23 #include "tensorflow/core/platform/macros.h" 24 #include "tensorflow/core/platform/platform.h" 25 #include "tensorflow/core/platform/types.h" 26 27 // Includes gmock.h and enables the use of gmock matchers in tensorflow tests. 28 // 29 // Test including this header can use the macros EXPECT_THAT(...) and 30 // ASSERT_THAT(...) in combination with gmock matchers. 31 // Example: 32 // std::vector<int> vec = Foo(); 33 // EXPECT_THAT(vec, ::testing::ElementsAre(1,2,3)); 34 // EXPECT_THAT(vec, ::testing::UnorderedElementsAre(2,3,1)); 35 // 36 // For more details on gmock matchers see: 37 // https://github.com/google/googletest/blob/master/googlemock/docs/CheatSheet.md#matchers 38 // 39 // The advantages of using gmock matchers instead of self defined matchers are 40 // better error messages, more maintainable tests and more test coverage. 41 #if !defined(PLATFORM_GOOGLE) && !defined(PLATFORM_GOOGLE_ANDROID) && \ 42 !defined(PLATFORM_CHROMIUMOS) 43 #include <gmock/gmock-generated-matchers.h> 44 #include <gmock/gmock-matchers.h> 45 #include <gmock/gmock-more-matchers.h> 46 #endif 47 #include <gmock/gmock.h> 48 49 #define DISABLED_ON_GPU_ROCM(X) X 50 #if TENSORFLOW_USE_ROCM 51 #undef DISABLED_ON_GPU_ROCM 52 #define DISABLED_ON_GPU_ROCM(X) DISABLED_##X 53 #endif // TENSORFLOW_USE_ROCM 54 55 namespace tensorflow { 56 namespace testing { 57 58 // Return a temporary directory suitable for temporary testing files. 59 // 60 // Where possible, consider using Env::LocalTempFilename over this function. 61 std::string TmpDir(); 62 63 // Returns the path to TensorFlow in the directory containing data 64 // dependencies. 65 // 66 // A better alternative would be making use if 67 // tensorflow/core/platform/resource_loader.h:GetDataDependencyFilepath. That 68 // function should do the right thing both within and outside of tests allowing 69 // avoiding test specific APIs. 70 std::string TensorFlowSrcRoot(); 71 72 // Return a random number generator seed to use in randomized tests. 73 // Returns the same value for the lifetime of the process. 74 int RandomSeed(); 75 76 // Returns an unused port number, for use in multi-process testing. 77 // NOTE: This function is not thread-safe. 78 int PickUnusedPortOrDie(); 79 80 } // namespace testing 81 } // namespace tensorflow 82 83 #endif // TENSORFLOW_CORE_PLATFORM_TEST_H_ 84