Skip to content

Commit e286ef7

Browse files
SoltiGGAngle LUCI CQ
authored andcommitted
ANGLE: Add validation test for GL_RENDERER string format
This change introduces a new ANGLE end-to-end test to validate the format of the GL_RENDERER string, preventing regressions caused by downstream modifications. A recent issue (b/318636997) was caused by a partner modifying the ANGLE GL_RENDERER string in a way that broke Skia's parser. This revealed that the string format is a de-facto API contract that must be enforced. This new test, RendererTest.ValidateCanonicalFormat, serves as an automated guardrail and will become part of the Android CTS. The test enforces the following structural contract: 1. The overall structure must be "ANGLE (Vendor, Renderer, Version)". 2. The separator between components must be ", ". 3. The Vendor, Renderer, and Version components must not be empty. This ensures the string is parsable by clients like Skia without over-constraining the content of the component strings, which may originate from underlying drivers. The test correctly skips validation on the Null backend, which is not subject to this contract. Test: autoninja -C out/Android angle_end2end_tests && out/Android/angle_end2end_tests --gtest_filter="RendererTest.*" --num-retries=0 Bug: b/432805963 Change-Id: I1202074cc9f4413ee88e4534fb72fb71101721e3 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6788522 Reviewed-by: Cody Northrop <[email protected]> Commit-Queue: Solti Ho <[email protected]> Reviewed-by: Shahbaz Youssefi <[email protected]>
1 parent b4d8445 commit e286ef7

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

src/tests/gl_tests/RendererTest.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// configured incorrectly. For example, they might be using the D3D11 renderer when the test is
1010
// meant to be using the D3D9 renderer.
1111

12+
#include <regex>
1213
#include "common/string_utils.h"
1314
#include "test_utils/ANGLETest.h"
1415
#include "test_utils/gl_raii.h"
@@ -212,10 +213,51 @@ TEST_P(RendererTest, Draw)
212213
glDrawArrays(GL_TRIANGLES, 0, 3);
213214
}
214215

216+
// This test validates that the GL_RENDERER string reported by ANGLE adheres to the
217+
// canonical format: "ANGLE (Vendor, Renderer, Version)".
218+
// This format is a de-facto API contract relied upon by upstream clients like Skia
219+
// to enable workarounds and optimizations.
220+
TEST_P(RendererTest, ValidateCanonicalFormat)
221+
{
222+
// Use the idiomatic IsNULL() check to skip this test on the Null backend.
223+
if (IsNULL())
224+
{
225+
std::cout << "Skipping canonical format validation for the Null backend." << std::endl;
226+
return;
227+
}
228+
229+
// 1. Query the renderer string from the driver.
230+
const char *rendererCStr = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
231+
ASSERT_NE(rendererCStr, nullptr);
232+
std::string rendererStr(rendererCStr);
233+
std::cout << "Renderer string: \"" << rendererStr << "\"" << std::endl;
234+
235+
// 2. Validate the entire string structure using a single regular expression.
236+
// This regex enforces the "ANGLE (...)" wrapper and the presence of three
237+
// comma-space-separated components, while allowing components to be empty.
238+
const std::regex kRendererFormat("^ANGLE \\((.*), (.*), (.*)\\)$");
239+
std::smatch match;
240+
241+
bool matches = std::regex_match(rendererStr, match, kRendererFormat);
242+
243+
// 3. Assert that the string matches the format and contains the correct number of groups.
244+
// match[0] is the full string, match[1-3] are the captured components.
245+
ASSERT_TRUE(matches && match.size() == 4)
246+
<< "Renderer string does not match the expected format 'ANGLE (Vendor, Renderer, Version)'."
247+
<< "\n Actual string: " << rendererStr;
248+
249+
// 4. For clarity in test logs, print the parsed components.
250+
std::cout << "Successfully parsed renderer string components:" << std::endl;
251+
std::cout << " - Vendor: \"" << match[1].str() << "\"" << std::endl;
252+
std::cout << " - Renderer: \"" << match[2].str() << "\"" << std::endl;
253+
std::cout << " - Version: \"" << match[3].str() << "\"" << std::endl;
254+
255+
EXPECT_GL_NO_ERROR();
256+
}
257+
215258
// Select configurations (e.g. which renderer, which GLES major version) these tests should be run
216259
// against.
217260
// TODO(http://anglebug.com/42266907): move ES2_WEBGPU to the definition of
218261
// ANGLE_ALL_TEST_PLATFORMS_ES2 once webgpu is developed enough to run more tests.
219-
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31_AND_NULL_AND(RendererTest,
220-
ES2_WEBGPU());
262+
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND_ES31_AND_NULL_AND(RendererTest, ES2_WEBGPU());
221263
} // namespace angle

0 commit comments

Comments
 (0)