1 //
2 // Copyright 2017 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 // SystemInfo_unittest.cpp: Unit tests for SystemInfo* helper functions.
7 //
8
9 #include "gpu_info_util/SystemInfo_internal.h"
10
11 #include <gtest/gtest.h>
12
13 using namespace angle;
14
15 namespace
16 {
17
18 // Test AMD Brahma driver version parsing
TEST(SystemInfoTest,AMDBrahmaVersionParsing)19 TEST(SystemInfoTest, AMDBrahmaVersionParsing)
20 {
21 std::string version;
22
23 // Check parsing fails when no version string is present.
24 ASSERT_FALSE(ParseAMDBrahmaDriverVersion("I am a lumberjack.", &version));
25 ASSERT_EQ("", version);
26
27 // Check parsing when the string is just the version string, with and without dots
28 ASSERT_TRUE(ParseAMDBrahmaDriverVersion("42", &version));
29 ASSERT_EQ("42", version);
30 ASSERT_TRUE(ParseAMDBrahmaDriverVersion("42.0.56", &version));
31 ASSERT_EQ("42.0.56", version);
32
33 // Check parsing with prefix / suffix
34 ASSERT_TRUE(ParseAMDBrahmaDriverVersion("Version=42.0.56", &version));
35 ASSERT_EQ("42.0.56", version);
36 ASSERT_TRUE(ParseAMDBrahmaDriverVersion("42.0.56 is the version", &version));
37 ASSERT_EQ("42.0.56", version);
38 ASSERT_TRUE(ParseAMDBrahmaDriverVersion("42.0.56 is the version, 111", &version));
39 ASSERT_EQ("42.0.56", version);
40 }
41
42 // Test AMD Catalyst version parsing
TEST(SystemInfoTest,AMDCatalystVersionParsing)43 TEST(SystemInfoTest, AMDCatalystVersionParsing)
44 {
45 std::string version;
46
47 // Check parsing fails when no version string is present.
48 ASSERT_FALSE(ParseAMDCatalystDriverVersion("I am a lumberjack.\nReleaseVersion=", &version));
49 ASSERT_EQ("", version);
50
51 // Check parsing fails when ReleaseVersion= is present but no number appears in the line
52 ASSERT_FALSE(ParseAMDCatalystDriverVersion("11\nReleaseVersion=\n12", &version));
53 ASSERT_EQ("", version);
54
55 // Check parsing works on the simple case
56 ASSERT_TRUE(ParseAMDCatalystDriverVersion("ReleaseVersion=42.0.56", &version));
57 ASSERT_EQ("42.0.56", version);
58
59 // Check parsing works if there are other lines
60 ASSERT_TRUE(ParseAMDCatalystDriverVersion("11\nReleaseVersion=42.0.56\n12", &version));
61 ASSERT_EQ("42.0.56", version);
62
63 // Check parsing get the first version string
64 ASSERT_TRUE(
65 ParseAMDCatalystDriverVersion("ReleaseVersion=42.0.56\nReleaseVersion=0", &version));
66 ASSERT_EQ("42.0.56", version);
67
68 // Check parsing with prefix / suffix
69 ASSERT_TRUE(ParseAMDCatalystDriverVersion("ReleaseVersion=version is 42.0.56", &version));
70 ASSERT_EQ("42.0.56", version);
71 ASSERT_TRUE(ParseAMDCatalystDriverVersion("ReleaseVersion=42.0.56 is the version", &version));
72 ASSERT_EQ("42.0.56", version);
73 }
74
75 // Test Mac machine model parsing
TEST(SystemInfoTest,MacMachineModelParsing)76 TEST(SystemInfoTest, MacMachineModelParsing)
77 {
78 std::string model;
79 int32_t major = 1, minor = 2;
80
81 // Test on the empty string, that is returned by GetMachineModel on an error
82 EXPECT_FALSE(ParseMacMachineModel("", &model, &major, &minor));
83 EXPECT_EQ(0U, model.length());
84 EXPECT_EQ(1, major);
85 EXPECT_EQ(2, minor);
86
87 // Test on an invalid string
88 EXPECT_FALSE(ParseMacMachineModel("FooBar", &model, &major, &minor));
89
90 // Test on a MacPro model
91 EXPECT_TRUE(ParseMacMachineModel("MacPro4,1", &model, &major, &minor));
92 EXPECT_EQ("MacPro", model);
93 EXPECT_EQ(4, major);
94 EXPECT_EQ(1, minor);
95
96 // Test on a MacBookPro model
97 EXPECT_TRUE(ParseMacMachineModel("MacBookPro6,2", &model, &major, &minor));
98 EXPECT_EQ("MacBookPro", model);
99 EXPECT_EQ(6, major);
100 EXPECT_EQ(2, minor);
101 }
102
103 // Test Windows CM Device ID parsing
TEST(SystemInfoTest,CMDeviceIDToDeviceAndVendorID)104 TEST(SystemInfoTest, CMDeviceIDToDeviceAndVendorID)
105 {
106 uint32_t vendor = 0;
107 uint32_t device = 0;
108
109 // Test on a real-life CM Device ID
110 EXPECT_TRUE(CMDeviceIDToDeviceAndVendorID(
111 "PCI\\VEN_10DE&DEV_0FFA&SUBSYS_094B10DE&REV_A1\\4&95673C&0&0018", &vendor, &device));
112 EXPECT_EQ(0x10deu, vendor);
113 EXPECT_EQ(0x0ffau, device);
114
115 // Test on a stripped-down but valid CM Device ID string
116 EXPECT_TRUE(CMDeviceIDToDeviceAndVendorID("PCI\\VEN_10DE&DEV_0FFA", &vendor, &device));
117 EXPECT_EQ(0x10deu, vendor);
118 EXPECT_EQ(0x0ffau, device);
119
120 // Test on a string that is too small
121 EXPECT_FALSE(CMDeviceIDToDeviceAndVendorID("\\VEN_10DE&DEV_0FFA", &vendor, &device));
122 EXPECT_EQ(0u, vendor);
123 EXPECT_EQ(0u, device);
124
125 // Test with invalid number
126 EXPECT_FALSE(CMDeviceIDToDeviceAndVendorID("PCI\\VEN_XXXX&DEV_XXXX", &vendor, &device));
127 EXPECT_EQ(0u, vendor);
128 EXPECT_EQ(0u, device);
129 }
130
131 } // anonymous namespace
132