1 //
2 // Copyright 2021 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 #include "gmock/gmock.h"
8 #include "gtest/gtest.h"
9 
10 #include "tests/angle_unittests_utils.h"
11 
12 namespace rx
13 {
14 
15 extern std::string SanitizeRendererString(std::string rendererString);
16 extern std::string SanitizeVersionString(std::string versionString, bool isES);
17 
18 namespace testing
19 {
20 
21 namespace
22 {
23 
TEST(DisplayGLTest,SanitizeRendererStringIntel)24 TEST(DisplayGLTest, SanitizeRendererStringIntel)
25 {
26     std::string testString      = "Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)";
27     std::string testExpectation = "Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)";
28     EXPECT_EQ(SanitizeRendererString(testString), testExpectation);
29 }
30 
TEST(DisplayGLTest,SanitizeRendererStringLLVMPipe)31 TEST(DisplayGLTest, SanitizeRendererStringLLVMPipe)
32 {
33     std::string testString      = "llvmpipe (LLVM 11.0.0, 256 bits)";
34     std::string testExpectation = "llvmpipe (LLVM 11.0.0, 256 bits)";
35     EXPECT_EQ(SanitizeRendererString(testString), testExpectation);
36 }
37 
TEST(DisplayGLTest,SanitizeRendererStringRadeonVega)38 TEST(DisplayGLTest, SanitizeRendererStringRadeonVega)
39 {
40     std::string testString      = "Radeon RX Vega";
41     std::string testExpectation = "Radeon RX Vega";
42     EXPECT_EQ(SanitizeRendererString(testString), testExpectation);
43 }
44 
TEST(DisplayGLTest,SanitizeRendererStringRadeonTM)45 TEST(DisplayGLTest, SanitizeRendererStringRadeonTM)
46 {
47     std::string testString =
48         "AMD Radeon (TM) RX 460 Graphics (POLARIS11, DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)";
49     std::string testExpectation = "AMD Radeon (TM) RX 460 Graphics (POLARIS11)";
50     EXPECT_EQ(SanitizeRendererString(testString), testExpectation);
51 }
52 
TEST(DisplayGLTest,SanitizeRendererStringRadeonWithoutGeneration)53 TEST(DisplayGLTest, SanitizeRendererStringRadeonWithoutGeneration)
54 {
55     std::string testString      = "AMD Radeon RX 5700 (DRM 3.35.0, 5.4.0-65-generic, LLVM 11.0.0)";
56     std::string testExpectation = "AMD Radeon RX 5700";
57     EXPECT_EQ(SanitizeRendererString(testString), testExpectation);
58 }
59 
TEST(DisplayGLTest,SanitizeVersionStringOpenGLMissing)60 TEST(DisplayGLTest, SanitizeVersionStringOpenGLMissing)
61 {
62     std::string testString      = "4.6.0 NVIDIA 391.76";
63     std::string testExpectation = "OpenGL 4.6.0 NVIDIA 391.76";
64     EXPECT_EQ(SanitizeVersionString(testString, false), testExpectation);
65 }
66 
67 // Note: OpenGL renderers with this prefix don't actually seem to be present in the wild
TEST(DisplayGLTest,SanitizeVersionStringOpenGLPresent)68 TEST(DisplayGLTest, SanitizeVersionStringOpenGLPresent)
69 {
70     std::string testString      = "OpenGL 4.5.0 - Build 22.20.16.4749";
71     std::string testExpectation = "OpenGL 4.5.0 - Build 22.20.16.4749";
72     EXPECT_EQ(SanitizeVersionString(testString, false), testExpectation);
73 }
74 
TEST(DisplayGLTest,SanitizeVersionStringOpenGLESMissing)75 TEST(DisplayGLTest, SanitizeVersionStringOpenGLESMissing)
76 {
77     std::string testString      = "4.6.0 NVIDIA 419.67";
78     std::string testExpectation = "OpenGL ES 4.6.0 NVIDIA 419.67";
79     EXPECT_EQ(SanitizeVersionString(testString, true), testExpectation);
80 }
81 
TEST(DisplayGLTest,SanitizeVersionStringOpenGLESPresent)82 TEST(DisplayGLTest, SanitizeVersionStringOpenGLESPresent)
83 {
84     std::string testString      = "OpenGL ES 3.2 v1.r12p0-04rel0.44f2946824bb8739781564bffe2110c9";
85     std::string testExpectation = "OpenGL ES 3.2 v1.r12p0-04rel0.44f2946824bb8739781564bffe2110c9";
86     EXPECT_EQ(SanitizeVersionString(testString, true), testExpectation);
87 }
88 
89 }  // anonymous namespace
90 
91 }  // namespace testing
92 
93 }  // namespace rx
94