1 //
2 // Copyright 2014 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6
7 // angle_test_instantiate.h: Adds support for filtering parameterized
8 // tests by platform, so we skip unsupported configs.
9
10 #ifndef ANGLE_TEST_INSTANTIATE_H_
11 #define ANGLE_TEST_INSTANTIATE_H_
12
13 #include <gtest/gtest.h>
14
15 namespace angle
16 {
17 struct SystemInfo;
18 struct PlatformParameters;
19
20 // Operating systems
21 bool IsAndroid();
22 bool IsLinux();
23 bool IsOSX();
24 bool IsOzone();
25 bool IsWindows();
26 bool IsFuchsia();
27
28 // Android devices
29 bool IsNexus5X();
30 bool IsNexus6P();
31 bool IsNexus9();
32 bool IsPixelXL();
33 bool IsPixel2();
34 bool IsNVIDIAShield();
35
36 // Desktop devices.
37 bool IsIntel();
38 bool IsAMD();
39 bool IsNVIDIA();
40
41 bool IsPlatformAvailable(const PlatformParameters ¶m);
42
43 // This functions is used to filter which tests should be registered,
44 // T must be or inherit from angle::PlatformParameters.
45 template <typename T>
FilterTestParams(const T * params,size_t numParams)46 std::vector<T> FilterTestParams(const T *params, size_t numParams)
47 {
48 std::vector<T> filtered;
49
50 for (size_t i = 0; i < numParams; i++)
51 {
52 if (IsPlatformAvailable(params[i]))
53 {
54 filtered.push_back(params[i]);
55 }
56 }
57
58 return filtered;
59 }
60
61 template <typename T>
FilterTestParams(const std::vector<T> & params)62 std::vector<T> FilterTestParams(const std::vector<T> ¶ms)
63 {
64 return FilterTestParams(params.data(), params.size());
65 }
66
67 // Used to generate valid test names out of testing::PrintToStringParamName used in combined tests.
68 struct CombinedPrintToStringParamName
69 {
70 template <class ParamType>
operatorCombinedPrintToStringParamName71 std::string operator()(const testing::TestParamInfo<ParamType> &info) const
72 {
73 std::string name = testing::PrintToStringParamName()(info);
74 std::string sanitized;
75 for (const char c : name)
76 {
77 if (c == ',')
78 {
79 sanitized += '_';
80 }
81 else if (isalnum(c) || c == '_')
82 {
83 sanitized += c;
84 }
85 }
86 return sanitized;
87 }
88 };
89
90 #define ANGLE_INSTANTIATE_TEST_PLATFORMS(testName) \
91 testing::ValuesIn(::angle::FilterTestParams(testName##params, ArraySize(testName##params)))
92
93 // Instantiate the test once for each extra argument. The types of all the
94 // arguments must match, and getRenderer must be implemented for that type.
95 #define ANGLE_INSTANTIATE_TEST(testName, first, ...) \
96 const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
97 INSTANTIATE_TEST_SUITE_P(, testName, ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \
98 testing::PrintToStringParamName())
99
100 // Instantiate the test for a combination of N parameters and the enumeration of platforms in the
101 // extra args, similar to ANGLE_INSTANTIATE_TEST. The macros are defined only for the Ns currently
102 // in use, and can be expanded as necessary.
103 #define ANGLE_INSTANTIATE_TEST_COMBINE_1(testName, print, combine1, first, ...) \
104 const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
105 INSTANTIATE_TEST_SUITE_P( \
106 , testName, testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), combine1), print)
107 #define ANGLE_INSTANTIATE_TEST_COMBINE_4(testName, print, combine1, combine2, combine3, combine4, \
108 first, ...) \
109 const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
110 INSTANTIATE_TEST_SUITE_P(, testName, \
111 testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \
112 combine1, combine2, combine3, combine4), \
113 print)
114 #define ANGLE_INSTANTIATE_TEST_COMBINE_5(testName, print, combine1, combine2, combine3, combine4, \
115 combine5, first, ...) \
116 const decltype(first) testName##params[] = {first, ##__VA_ARGS__}; \
117 INSTANTIATE_TEST_SUITE_P(, testName, \
118 testing::Combine(ANGLE_INSTANTIATE_TEST_PLATFORMS(testName), \
119 combine1, combine2, combine3, combine4, combine5), \
120 print)
121
122 // Checks if a config is expected to be supported by checking a system-based white list.
123 bool IsConfigWhitelisted(const SystemInfo &systemInfo, const PlatformParameters ¶m);
124
125 // Determines if a config is supported by trying to initialize it. Does not require SystemInfo.
126 bool IsConfigSupported(const PlatformParameters ¶m);
127
128 // Returns shared test system information. Can be used globally in the tests.
129 SystemInfo *GetTestSystemInfo();
130
131 // Returns a list of all enabled test platform names. For use in configuration enumeration.
132 std::vector<std::string> GetAvailableTestPlatformNames();
133
134 // Active config (e.g. ES2_Vulkan).
135 extern std::string gSelectedConfig;
136
137 // Use a separate isolated process per test config. This works around driver flakiness when using
138 // multiple APIs/windows/etc in the same process.
139 extern bool gSeparateProcessPerConfig;
140 } // namespace angle
141
142 #endif // ANGLE_TEST_INSTANTIATE_H_
143