1 //
2 // Copyright 2025 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 // ANGLETestCL:
7 // Implementation of ANGLE CL testing fixture.
8 //
9
10 #include "ANGLETestCL.h"
11
12 #include <algorithm>
13 #include <cstdlib>
14 #include "common/PackedEnums.h"
15 #include "common/platform.h"
16 #include "gpu_info_util/SystemInfo.h"
17 #include "test_expectations/GPUTestConfig.h"
18 #include "util/EGLWindow.h"
19 #include "util/OSWindow.h"
20 #include "util/random_utils.h"
21 #include "util/test_utils.h"
22
23 #if defined(ANGLE_PLATFORM_WINDOWS)
24 # include <VersionHelpers.h>
25 #endif // defined(ANGLE_PLATFORM_WINDOWS)
26
27 #if defined(ANGLE_HAS_RAPIDJSON)
28 # include "test_utils/runner/TestSuite.h"
29 #endif // defined(ANGLE_HAS_RAPIDJSON)
30
31 using namespace angle;
32
33 template <>
ANGLETestCL(const PlatformParameters & params)34 ANGLETestCL<PlatformParameters>::ANGLETestCL(const PlatformParameters ¶ms)
35 : mSetUpCalled(false), mIsSetUp(false), mTearDownCalled(false)
36 {
37 // Override the default platform methods with the ANGLE test methods pointer.
38 mCurrentParams = params;
39 mCurrentParams.eglParameters.platformMethods = &gDefaultPlatformMethods;
40
41 if (mCurrentParams.getRenderer() == EGL_PLATFORM_ANGLE_TYPE_VULKAN_ANGLE)
42 {
43 #if defined(ANGLE_ENABLE_VULKAN_VALIDATION_LAYERS)
44 mCurrentParams.eglParameters.debugLayersEnabled = true;
45 #else
46 mCurrentParams.eglParameters.debugLayersEnabled = false;
47 #endif
48 }
49
50 if (gEnableRenderDocCapture)
51 {
52 mRenderDoc.attach();
53 }
54 }
55
56 template <>
SetUp()57 void ANGLETestCL<angle::PlatformParameters>::SetUp()
58 {
59 mSetUpCalled = true;
60
61 // Delay test startup to allow a debugger to attach.
62 if (GetTestStartDelaySeconds())
63 {
64 angle::Sleep(GetTestStartDelaySeconds() * 1000);
65 }
66
67 const testing::TestInfo *testInfo = testing::UnitTest::GetInstance()->current_test_info();
68
69 // Check the skip list.
70
71 angle::GPUTestConfig::API api = GetTestConfigAPIFromRenderer(
72 mCurrentParams.driver, mCurrentParams.getRenderer(), mCurrentParams.getDeviceType());
73 GPUTestConfig testConfig = GPUTestConfig(api, 0);
74
75 std::stringstream fullTestNameStr;
76 fullTestNameStr << testInfo->test_suite_name() << "." << testInfo->name();
77 std::string fullTestName = fullTestNameStr.str();
78
79 // TODO(b/279980674): TestSuite depends on rapidjson which we don't have in aosp builds,
80 // for now disable both TestSuite and expectations.
81 #if defined(ANGLE_HAS_RAPIDJSON)
82 TestSuite *testSuite = TestSuite::GetInstance();
83 int32_t testExpectation =
84 testSuite->getTestExpectationWithConfigAndUpdateTimeout(testConfig, fullTestName);
85
86 if (testExpectation == GPUTestExpectationsParser::kGpuTestSkip)
87 {
88 GTEST_SKIP() << "Test skipped on this config";
89 }
90 #endif
91
92 if (IsWindows())
93 {
94 WriteDebugMessage("Entering %s\n", fullTestName.c_str());
95 }
96
97 if (gEnableANGLEPerTestCaptureLabel)
98 {
99 std::string testName = std::string{testInfo->name()};
100 std::replace(testName.begin(), testName.end(), '/', '_');
101 SetEnvironmentVar("ANGLE_CAPTURE_LABEL",
102 (std::string{testInfo->test_suite_name()} + "_" + testName).c_str());
103 }
104
105 mIsSetUp = true;
106
107 testSetUp();
108 }
109
110 template <>
TearDown()111 void ANGLETestCL<angle::PlatformParameters>::TearDown()
112 {
113 if (mIsSetUp)
114 {
115 testTearDown();
116 }
117
118 mTearDownCalled = true;
119
120 if (IsWindows())
121 {
122 const testing::TestInfo *info = testing::UnitTest::GetInstance()->current_test_info();
123 WriteDebugMessage("Exiting %s.%s\n", info->test_suite_name(), info->name());
124 }
125 }
126