1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_VR_TEST_CONDITIONAL_SKIPPING_H_
6 #define CHROME_BROWSER_VR_TEST_CONDITIONAL_SKIPPING_H_
7
8 #include <string>
9 #include <unordered_set>
10 #include <vector>
11
12 #include "base/logging.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 // A set of macros and functions for conditinoally skipping XR browser tests
16 // based on available hardware and software.
17
18 namespace vr {
19
20 enum class XrTestRequirement {
21 DIRECTX_11_1, // Only supported on machines with GPUs that support DX 11.1
22 };
23
24 std::string CheckXrRequirements(
25 const std::vector<XrTestRequirement>& requirements_vector,
26 const std::unordered_set<std::string>& ignored_set);
27
28 std::string XrTestRequirementToString(XrTestRequirement requirement);
29
CheckXrRequirementsHelper(const std::vector<XrTestRequirement> & requirements_vector,const std::unordered_set<std::string> & ignored_set,bool * setup_skipped)30 inline bool CheckXrRequirementsHelper(
31 const std::vector<XrTestRequirement>& requirements_vector,
32 const std::unordered_set<std::string>& ignored_set,
33 bool* setup_skipped) {
34 auto failure_message = CheckXrRequirements(requirements_vector, ignored_set);
35 if (failure_message != "") {
36 // Newlines to help the skip message stand out in the log.
37 LOG(WARNING) << "\n\nSkipping test due to reason: " << failure_message
38 << "\n";
39 if (setup_skipped) {
40 *setup_skipped = true;
41 }
42 return true;
43 }
44 return false;
45 }
46
47 } // namespace vr
48
49 // We use a macro instead of a function because we want to call GTEST_SKIP from
50 // either the test setup or test implementation. GTEST_SKIP aborts the current
51 // function only, meaning that if we call it in some sub function, the test will
52 // continue as normal and only be marked as skipped once it finishes.
53 #define XR_CONDITIONAL_SKIP(requirements_vector, ignored_set) \
54 XR_CONDITIONAL_SKIP_INTERNAL_(requirements_vector, ignored_set, nullptr)
55
56 // A special version only meant to be used during the browser test's SetUp
57 // function since we need to store whether we're skipping before we actually
58 // do so to work around browser tests not handling skipping in SetUp well due
59 // to internal checks.
60 #define XR_CONDITIONAL_SKIP_PRETEST(requirements_vector, ignored_set, \
61 setup_skipped) \
62 XR_CONDITIONAL_SKIP_INTERNAL_(requirements_vector, ignored_set, setup_skipped)
63
64 #define XR_CONDITIONAL_SKIP_INTERNAL_(requirements_vector, ignored_set, \
65 setup_skipped) \
66 if (CheckXrRequirementsHelper(requirements_vector, ignored_set, \
67 setup_skipped)) { \
68 GTEST_SKIP(); \
69 }
70
71 #endif // CHROME_BROWSER_VR_TEST_CONDITIONAL_SKIPPING_H_
72