• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "tensorflow/core/platform/macros.h"
23 #include "tensorflow/core/platform/platform.h"
24 #include "tensorflow/core/platform/types.h"
25 
26 #include <gtest/gtest.h>  // IWYU pragma: export
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 #include "testing/base/public/gmock.h"  // IWYU pragma: export
44 #else
45 #include <gmock/gmock-generated-matchers.h>
46 #include <gmock/gmock-matchers.h>
47 #include <gmock/gmock-more-matchers.h>
48 #include <gmock/gmock.h>
49 #endif
50 
51 namespace tensorflow {
52 namespace testing {
53 
54 // Return a temporary directory suitable for temporary testing files.
55 //
56 // Where possible, consider using Env::LocalTempFilename over this function.
57 std::string TmpDir();
58 
59 // Returns the path to TensorFlow in the directory containing data
60 // dependencies.
61 //
62 // A better alternative would be making use if
63 // tensorflow/core/platform/resource_loader.h:GetDataDependencyFilepath. That
64 // function should do the right thing both within and outside of tests allowing
65 // avoiding test specific APIs.
66 std::string TensorFlowSrcRoot();
67 
68 // Return a random number generator seed to use in randomized tests.
69 // Returns the same value for the lifetime of the process.
70 int RandomSeed();
71 
72 // Returns an unused port number, for use in multi-process testing.
73 // NOTE: This function is not thread-safe.
74 int PickUnusedPortOrDie();
75 
76 }  // namespace testing
77 }  // namespace tensorflow
78 
79 #endif  // TENSORFLOW_CORE_PLATFORM_TEST_H_
80