aboutsummaryrefslogtreecommitdiff
path: root/tensorflow/core/platform/test.h
blob: e49f479cac7d894763ac20ea8977cf18c168dc18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright 2015 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef TENSORFLOW_CORE_PLATFORM_TEST_H_
#define TENSORFLOW_CORE_PLATFORM_TEST_H_

#include <gtest/gtest.h>  // IWYU pragma: export

#include <memory>
#include <vector>

#include "tensorflow/core/platform/macros.h"
#include "tensorflow/core/platform/platform.h"
#include "tensorflow/core/platform/types.h"

// Includes gmock.h and enables the use of gmock matchers in tensorflow tests.
//
// Test including this header can use the macros EXPECT_THAT(...) and
// ASSERT_THAT(...) in combination with gmock matchers.
// Example:
//  std::vector<int> vec = Foo();
//  EXPECT_THAT(vec, ::testing::ElementsAre(1,2,3));
//  EXPECT_THAT(vec, ::testing::UnorderedElementsAre(2,3,1));
//
// For more details on gmock matchers see:
// https://github.com/google/googletest/blob/master/googlemock/docs/CheatSheet.md#matchers
//
// The advantages of using gmock matchers instead of self defined matchers are
// better error messages, more maintainable tests and more test coverage.
#if !defined(PLATFORM_GOOGLE) && !defined(PLATFORM_GOOGLE_ANDROID) && \
    !defined(PLATFORM_CHROMIUMOS) &&                                  \
    !defined(IS_MOBILE_PLATFORM)  // We have gmock.h in AOSP.
#include <gmock/gmock-generated-matchers.h>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock-more-matchers.h>
#endif
#include <gmock/gmock.h>

#define DISABLED_ON_GPU_ROCM(X) X
#if TENSORFLOW_USE_ROCM
#undef DISABLED_ON_GPU_ROCM
#define DISABLED_ON_GPU_ROCM(X) DISABLED_##X
#endif  // TENSORFLOW_USE_ROCM

namespace tensorflow {
namespace testing {

// Return a temporary directory suitable for temporary testing files.
//
// Where possible, consider using Env::LocalTempFilename over this function.
std::string TmpDir();

// Returns the path to TensorFlow in the directory containing data
// dependencies.
//
// A better alternative would be making use if
// tensorflow/core/platform/resource_loader.h:GetDataDependencyFilepath. That
// function should do the right thing both within and outside of tests allowing
// avoiding test specific APIs.
std::string TensorFlowSrcRoot();

// Return a random number generator seed to use in randomized tests.
// Returns the same value for the lifetime of the process.
int RandomSeed();

// Returns an unused port number, for use in multi-process testing.
// NOTE: This function is not thread-safe.
int PickUnusedPortOrDie();

}  // namespace testing
}  // namespace tensorflow

#endif  // TENSORFLOW_CORE_PLATFORM_TEST_H_