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