KWin
Loading...
Searching...
No Matches
kwinglplatformtest.cpp
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9#include "mock_gl.h"
10#include "opengl/glplatform.h"
11#include <QTest>
12
13#include <KConfig>
14#include <KConfigGroup>
15
18
19using namespace KWin;
20
21void KWin::cleanupGL()
22{
23 GLPlatform::cleanup();
24}
25
26class GLPlatformTest : public QObject
27{
28 Q_OBJECT
29private Q_SLOTS:
30 void cleanup();
31
32 void testDriverToString_data();
33 void testDriverToString();
34 void testChipClassToString_data();
35 void testChipClassToString();
36 void testPriorDetect();
37 void testDetect_data();
38 void testDetect();
39};
40
41void GLPlatformTest::cleanup()
42{
43 cleanupGL();
44 delete s_gl;
45 s_gl = nullptr;
46}
47
48void GLPlatformTest::testDriverToString_data()
49{
50 QTest::addColumn<Driver>("driver");
51 QTest::addColumn<QString>("expected");
52
53 QTest::newRow("R100") << Driver_R100 << QStringLiteral("Radeon");
54 QTest::newRow("R200") << Driver_R200 << QStringLiteral("R200");
55 QTest::newRow("R300C") << Driver_R300C << QStringLiteral("R300C");
56 QTest::newRow("R300G") << Driver_R300G << QStringLiteral("R300G");
57 QTest::newRow("R600C") << Driver_R600C << QStringLiteral("R600C");
58 QTest::newRow("R600G") << Driver_R600G << QStringLiteral("R600G");
59 QTest::newRow("RadeonSI") << Driver_RadeonSI << QStringLiteral("RadeonSI");
60 QTest::newRow("Nouveau") << Driver_Nouveau << QStringLiteral("Nouveau");
61 QTest::newRow("Intel") << Driver_Intel << QStringLiteral("Intel");
62 QTest::newRow("NVidia") << Driver_NVidia << QStringLiteral("NVIDIA");
63 QTest::newRow("Catalyst") << Driver_Catalyst << QStringLiteral("Catalyst");
64 QTest::newRow("Swrast") << Driver_Swrast << QStringLiteral("Software rasterizer");
65 QTest::newRow("Softpipe") << Driver_Softpipe << QStringLiteral("softpipe");
66 QTest::newRow("Llvmpipe") << Driver_Llvmpipe << QStringLiteral("LLVMpipe");
67 QTest::newRow("VirtualBox") << Driver_VirtualBox << QStringLiteral("VirtualBox (Chromium)");
68 QTest::newRow("VMware") << Driver_VMware << QStringLiteral("VMware (SVGA3D)");
69 QTest::newRow("Qualcomm") << Driver_Qualcomm << QStringLiteral("Qualcomm");
70 QTest::newRow("Virgl") << Driver_Virgl << QStringLiteral("Virgl (virtio-gpu, Qemu/KVM guest)");
71 QTest::newRow("Panfrost") << Driver_Panfrost << QStringLiteral("Panfrost");
72 QTest::newRow("Lima") << Driver_Lima << QStringLiteral("Mali (Lima)");
73 QTest::newRow("VC4") << Driver_VC4 << QStringLiteral("VideoCore IV");
74 QTest::newRow("V3D") << Driver_V3D << QStringLiteral("VideoCore 3D");
75 QTest::newRow("Unknown") << Driver_Unknown << QStringLiteral("Unknown");
76}
77
78void GLPlatformTest::testDriverToString()
79{
80 QFETCH(Driver, driver);
81 QTEST(GLPlatform::driverToString(driver), "expected");
82}
83
84void GLPlatformTest::testChipClassToString_data()
85{
86 QTest::addColumn<ChipClass>("chipClass");
87 QTest::addColumn<QString>("expected");
88
89 QTest::newRow("R100") << R100 << QStringLiteral("R100");
90 QTest::newRow("R200") << R200 << QStringLiteral("R200");
91 QTest::newRow("R300") << R300 << QStringLiteral("R300");
92 QTest::newRow("R400") << R400 << QStringLiteral("R400");
93 QTest::newRow("R500") << R500 << QStringLiteral("R500");
94 QTest::newRow("R600") << R600 << QStringLiteral("R600");
95 QTest::newRow("R700") << R700 << QStringLiteral("R700");
96 QTest::newRow("Evergreen") << Evergreen << QStringLiteral("EVERGREEN");
97 QTest::newRow("NorthernIslands") << NorthernIslands << QStringLiteral("Northern Islands");
98 QTest::newRow("SouthernIslands") << SouthernIslands << QStringLiteral("Southern Islands");
99 QTest::newRow("SeaIslands") << SeaIslands << QStringLiteral("Sea Islands");
100 QTest::newRow("VolcanicIslands") << VolcanicIslands << QStringLiteral("Volcanic Islands");
101 QTest::newRow("Arctic Islands") << ArcticIslands << QStringLiteral("Arctic Islands");
102 QTest::newRow("Vega") << Vega << QStringLiteral("Vega");
103 QTest::newRow("UnknownRadeon") << UnknownRadeon << QStringLiteral("Unknown");
104 QTest::newRow("NV10") << NV10 << QStringLiteral("NV10");
105 QTest::newRow("NV20") << NV20 << QStringLiteral("NV20");
106 QTest::newRow("NV30") << NV30 << QStringLiteral("NV30");
107 QTest::newRow("NV40") << NV40 << QStringLiteral("NV40/G70");
108 QTest::newRow("G80") << G80 << QStringLiteral("G80/G90");
109 QTest::newRow("GF100") << GF100 << QStringLiteral("GF100");
110 QTest::newRow("UnknownNVidia") << UnknownNVidia << QStringLiteral("Unknown");
111 QTest::newRow("I8XX") << I8XX << QStringLiteral("i830/i835");
112 QTest::newRow("I915") << I915 << QStringLiteral("i915/i945");
113 QTest::newRow("I965") << I965 << QStringLiteral("i965");
114 QTest::newRow("SandyBridge") << SandyBridge << QStringLiteral("SandyBridge");
115 QTest::newRow("IvyBridge") << IvyBridge << QStringLiteral("IvyBridge");
116 QTest::newRow("Haswell") << Haswell << QStringLiteral("Haswell");
117 QTest::newRow("UnknownIntel") << UnknownIntel << QStringLiteral("Unknown");
118 QTest::newRow("Adreno1XX") << Adreno1XX << QStringLiteral("Adreno 1xx series");
119 QTest::newRow("Adreno2XX") << Adreno2XX << QStringLiteral("Adreno 2xx series");
120 QTest::newRow("Adreno3XX") << Adreno3XX << QStringLiteral("Adreno 3xx series");
121 QTest::newRow("Adreno4XX") << Adreno4XX << QStringLiteral("Adreno 4xx series");
122 QTest::newRow("Adreno5XX") << Adreno5XX << QStringLiteral("Adreno 5xx series");
123 QTest::newRow("UnknownAdreno") << UnknownAdreno << QStringLiteral("Unknown");
124 QTest::newRow("MaliT7XX") << MaliT7XX << QStringLiteral("Mali T7xx series");
125 QTest::newRow("MaliT8XX") << MaliT8XX << QStringLiteral("Mali T8xx series");
126 QTest::newRow("MaliGXX") << MaliGXX << QStringLiteral("Mali Gxx series");
127 QTest::newRow("UnknownPanfrost") << UnknownPanfrost << QStringLiteral("Unknown");
128 QTest::newRow("Mali400") << Mali400 << QStringLiteral("Mali 400 series");
129 QTest::newRow("Mali450") << Mali450 << QStringLiteral("Mali 450 series");
130 QTest::newRow("Mali470") << Mali470 << QStringLiteral("Mali 470 series");
131 QTest::newRow("UnknownLima") << UnknownLima << QStringLiteral("Unknown");
132 QTest::newRow("VC4_2_1") << VC4_2_1 << QStringLiteral("VideoCore IV");
133 QTest::newRow("UnknownVideoCore4") << UnknownVideoCore4 << QStringLiteral("Unknown");
134 QTest::newRow("V3D_4_2") << V3D_4_2 << QStringLiteral("VideoCore 3D");
135 QTest::newRow("UnknownVideoCore3D") << UnknownVideoCore3D << QStringLiteral("Unknown");
136 QTest::newRow("UnknownChipClass") << UnknownChipClass << QStringLiteral("Unknown");
137}
138
139void GLPlatformTest::testChipClassToString()
140{
141 QFETCH(ChipClass, chipClass);
142 QTEST(GLPlatform::chipClassToString(chipClass), "expected");
143}
144
145void GLPlatformTest::testPriorDetect()
146{
147 auto *gl = GLPlatform::instance();
148 QVERIFY(gl);
149 QCOMPARE(gl->supports(GLFeature::LooseBinding), false);
150
151 QCOMPARE(gl->glVersion(), Version());
152 QCOMPARE(gl->glslVersion(), Version());
153 QCOMPARE(gl->mesaVersion(), Version());
154 QCOMPARE(gl->driverVersion(), Version());
155
156 QCOMPARE(gl->driver(), Driver_Unknown);
157 QCOMPARE(gl->chipClass(), UnknownChipClass);
158
159 QCOMPARE(gl->isMesaDriver(), false);
160 QCOMPARE(gl->isRadeon(), false);
161 QCOMPARE(gl->isNvidia(), false);
162 QCOMPARE(gl->isIntel(), false);
163 QCOMPARE(gl->isPanfrost(), false);
164 QCOMPARE(gl->isLima(), false);
165 QCOMPARE(gl->isVideoCore4(), false);
166 QCOMPARE(gl->isVideoCore3D(), false);
167
168 QCOMPARE(gl->isVirtualBox(), false);
169 QCOMPARE(gl->isVMware(), false);
170
171 QCOMPARE(gl->isSoftwareEmulation(), false);
172 QCOMPARE(gl->isVirtualMachine(), false);
173
174 QCOMPARE(gl->glVersionString(), QByteArray());
175 QCOMPARE(gl->glRendererString(), QByteArray());
176 QCOMPARE(gl->glVendorString(), QByteArray());
177 QCOMPARE(gl->glShadingLanguageVersionString(), QByteArray());
178
179 QCOMPARE(gl->isLooseBinding(), false);
180 QCOMPARE(gl->isGLES(), false);
181 QCOMPARE(gl->recommendedCompositor(), QPainterCompositing);
182 QCOMPARE(gl->preferBufferSubData(), false);
183 QCOMPARE(gl->platformInterface(), NoOpenGLPlatformInterface);
184}
185
186void GLPlatformTest::testDetect_data()
187{
188 QTest::addColumn<QString>("configFile");
189
190 QDir dir(QFINDTESTDATA("data/glplatform"));
191 const QStringList entries = dir.entryList(QDir::NoDotAndDotDot | QDir::Files);
192
193 for (const QString &file : entries) {
194 QTest::newRow(file.toUtf8().constData()) << dir.absoluteFilePath(file);
195 }
196}
197
198static Version readVersion(const KConfigGroup &group, const char *entry)
199{
200 const QStringList parts = group.readEntry(entry, QString()).split(',');
201 if (parts.count() < 2) {
202 return Version();
203 }
204 QList<qint64> versionParts;
205 for (int i = 0; i < parts.count(); ++i) {
206 bool ok = false;
207 const auto value = parts.at(i).toLongLong(&ok);
208 if (ok) {
209 versionParts << value;
210 } else {
211 versionParts << 0;
212 }
213 }
214 while (versionParts.count() < 3) {
215 versionParts << 0;
216 }
217 return Version(versionParts.at(0), versionParts.at(1), versionParts.at(2));
218}
219
220void GLPlatformTest::testDetect()
221{
222 QFETCH(QString, configFile);
223 KConfig config(configFile);
224 const KConfigGroup driverGroup = config.group(QStringLiteral("Driver"));
225 s_gl = new MockGL;
226 s_gl->getString.vendor = driverGroup.readEntry("Vendor").toUtf8();
227 s_gl->getString.renderer = driverGroup.readEntry("Renderer").toUtf8();
228 s_gl->getString.version = driverGroup.readEntry("Version").toUtf8();
229 s_gl->getString.shadingLanguageVersion = driverGroup.readEntry("ShadingLanguageVersion").toUtf8();
230 s_gl->getString.extensions = QList<QByteArray>{QByteArrayLiteral("GL_ARB_shader_objects"),
231 QByteArrayLiteral("GL_ARB_fragment_shader"),
232 QByteArrayLiteral("GL_ARB_vertex_shader"),
233 QByteArrayLiteral("GL_ARB_texture_non_power_of_two")};
234 s_gl->getString.extensionsString = QByteArray();
235
236 auto *gl = GLPlatform::instance();
237 QVERIFY(gl);
238 gl->detect(EglPlatformInterface);
239 QCOMPARE(gl->platformInterface(), EglPlatformInterface);
240
241 const KConfigGroup settingsGroup = config.group(QStringLiteral("Settings"));
242
243 QCOMPARE(gl->supports(GLFeature::LooseBinding), settingsGroup.readEntry("LooseBinding", false));
244
245 QCOMPARE(gl->glVersion(), readVersion(settingsGroup, "GLVersion"));
246 QCOMPARE(gl->glslVersion(), readVersion(settingsGroup, "GLSLVersion"));
247 QCOMPARE(gl->mesaVersion(), readVersion(settingsGroup, "MesaVersion"));
248 QEXPECT_FAIL("amd-catalyst-radeonhd-7700M-3.1.13399", "Detects GL version instead of driver version", Continue);
249 QCOMPARE(gl->driverVersion(), readVersion(settingsGroup, "DriverVersion"));
250
251 QCOMPARE(gl->driver(), Driver(settingsGroup.readEntry("Driver", int(Driver_Unknown))));
252 QCOMPARE(gl->chipClass(), ChipClass(settingsGroup.readEntry("ChipClass", int(UnknownChipClass))));
253
254 QCOMPARE(gl->isMesaDriver(), settingsGroup.readEntry("Mesa", false));
255 QCOMPARE(gl->isRadeon(), settingsGroup.readEntry("Radeon", false));
256 QCOMPARE(gl->isNvidia(), settingsGroup.readEntry("Nvidia", false));
257 QCOMPARE(gl->isIntel(), settingsGroup.readEntry("Intel", false));
258 QCOMPARE(gl->isVirtualBox(), settingsGroup.readEntry("VirtualBox", false));
259 QCOMPARE(gl->isVMware(), settingsGroup.readEntry("VMware", false));
260 QCOMPARE(gl->isAdreno(), settingsGroup.readEntry("Adreno", false));
261 QCOMPARE(gl->isPanfrost(), settingsGroup.readEntry("Panfrost", false));
262 QCOMPARE(gl->isLima(), settingsGroup.readEntry("Lima", false));
263 QCOMPARE(gl->isVideoCore4(), settingsGroup.readEntry("VC4", false));
264 QCOMPARE(gl->isVideoCore3D(), settingsGroup.readEntry("V3D", false));
265 QCOMPARE(gl->isVirgl(), settingsGroup.readEntry("Virgl", false));
266
267 QCOMPARE(gl->isSoftwareEmulation(), settingsGroup.readEntry("SoftwareEmulation", false));
268 QCOMPARE(gl->isVirtualMachine(), settingsGroup.readEntry("VirtualMachine", false));
269
270 QCOMPARE(gl->glVersionString(), s_gl->getString.version);
271 QCOMPARE(gl->glRendererString(), s_gl->getString.renderer);
272 QCOMPARE(gl->glVendorString(), s_gl->getString.vendor);
273 QCOMPARE(gl->glShadingLanguageVersionString(), s_gl->getString.shadingLanguageVersion);
274
275 QCOMPARE(gl->isLooseBinding(), settingsGroup.readEntry("LooseBinding", false));
276 QCOMPARE(gl->isGLES(), settingsGroup.readEntry("GLES", false));
277 QCOMPARE(gl->recommendedCompositor(), CompositingType(settingsGroup.readEntry("Compositor", int(NoCompositing))));
278 QCOMPARE(gl->preferBufferSubData(), settingsGroup.readEntry("PreferBufferSubData", false));
279}
280
281QTEST_GUILESS_MAIN(GLPlatformTest)
282#include "kwinglplatformtest.moc"
static QString chipClassToString(ChipClass chipClass)
static QString driverToString(Driver driver)
static GLPlatform * instance()
Definition glplatform.h:394
Q_DECLARE_METATYPE(KWin::SwitchEvent::State)
MockGL * s_gl
Definition mock_gl.cpp:12
@ Driver_V3D
Definition glplatform.h:67
@ Driver_R300G
Definition glplatform.h:49
@ Driver_Swrast
Definition glplatform.h:56
@ Driver_Qualcomm
Definition glplatform.h:61
@ Driver_VC4
Definition glplatform.h:66
@ Driver_VMware
Definition glplatform.h:60
@ Driver_VirtualBox
Definition glplatform.h:59
@ Driver_NVidia
Definition glplatform.h:54
@ Driver_Llvmpipe
Definition glplatform.h:58
@ Driver_R600G
Definition glplatform.h:51
@ Driver_RadeonSI
Definition glplatform.h:62
@ Driver_R200
Definition glplatform.h:47
@ Driver_Lima
Definition glplatform.h:65
@ Driver_R100
Definition glplatform.h:46
@ Driver_Virgl
Definition glplatform.h:63
@ Driver_Catalyst
Definition glplatform.h:55
@ Driver_R300C
Definition glplatform.h:48
@ Driver_Panfrost
Definition glplatform.h:64
@ Driver_Unknown
Definition glplatform.h:68
@ Driver_Intel
Definition glplatform.h:53
@ Driver_Nouveau
Definition glplatform.h:52
@ Driver_R600C
Definition glplatform.h:50
@ Driver_Softpipe
Definition glplatform.h:57
void KWIN_EXPORT cleanupGL()
Definition glutils.cpp:122
@ EglPlatformInterface
Definition globals.h:45
@ NoOpenGLPlatformInterface
Definition globals.h:43
CompositingType
Definition globals.h:28
@ QPainterCompositing
Definition globals.h:39
@ NoCompositing
Definition globals.h:29
ChipClass
Definition glplatform.h:72
@ NV40
Definition glplatform.h:95
@ NV30
Definition glplatform.h:94
@ UnknownVideoCore3D
Definition glplatform.h:151
@ Adreno5XX
Definition glplatform.h:128
@ UnknownRadeon
Definition glplatform.h:89
@ NV20
Definition glplatform.h:93
@ R300
Definition glplatform.h:76
@ VolcanicIslands
Definition glplatform.h:85
@ UnknownChipClass
Definition glplatform.h:153
@ MaliGXX
Definition glplatform.h:135
@ IvyBridge
Definition glplatform.h:105
@ VC4_2_1
Definition glplatform.h:146
@ R700
Definition glplatform.h:80
@ Adreno3XX
Definition glplatform.h:126
@ R600
Definition glplatform.h:79
@ UnknownPanfrost
Definition glplatform.h:136
@ Evergreen
Definition glplatform.h:81
@ UnknownVideoCore4
Definition glplatform.h:147
@ ArcticIslands
Definition glplatform.h:86
@ NV10
Definition glplatform.h:92
@ SandyBridge
Definition glplatform.h:104
@ G80
Definition glplatform.h:96
@ Adreno4XX
Definition glplatform.h:127
@ UnknownAdreno
Definition glplatform.h:129
@ Adreno2XX
Definition glplatform.h:125
@ Mali450
Definition glplatform.h:141
@ GF100
Definition glplatform.h:97
@ SeaIslands
Definition glplatform.h:84
@ MaliT8XX
Definition glplatform.h:134
@ R400
Definition glplatform.h:77
@ MaliT7XX
Definition glplatform.h:133
@ UnknownIntel
Definition glplatform.h:120
@ Haswell
Definition glplatform.h:106
@ UnknownLima
Definition glplatform.h:143
@ R100
Definition glplatform.h:74
@ Adreno1XX
Definition glplatform.h:124
@ UnknownNVidia
Definition glplatform.h:98
@ R500
Definition glplatform.h:78
@ NorthernIslands
Definition glplatform.h:82
@ SouthernIslands
Definition glplatform.h:83
@ Mali470
Definition glplatform.h:142
@ Mali400
Definition glplatform.h:140
@ Vega
Definition glplatform.h:87
@ R200
Definition glplatform.h:75
@ V3D_4_2
Definition glplatform.h:150
QByteArray version
Definition mock_gl.h:21
QByteArray extensionsString
Definition mock_gl.h:23
struct MockGL::@0 getString
QByteArray renderer
Definition mock_gl.h:20
QList< QByteArray > extensions
Definition mock_gl.h:22
QByteArray vendor
Definition mock_gl.h:19
QByteArray shadingLanguageVersion
Definition mock_gl.h:24