• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.game.qualification.test;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 import static com.google.common.truth.Truth.assertWithMessage;
20 import static com.google.common.truth.Truth.assert_;
21 
22 import com.android.tradefed.device.DeviceNotAvailableException;
23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
25 
26 import com.google.gson.Gson;
27 import com.google.gson.JsonSyntaxException;
28 
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 
33 import java.util.Arrays;
34 import java.util.Collection;
35 import java.util.List;
36 import java.util.stream.Collectors;
37 
38 @RunWith(DeviceJUnit4ClassRunner.class)
39 public class VkJsonTests extends BaseHostJUnit4Test {
40     // *** BEGIN CLASSES FOR GSON ***
41     // Classes to be used with GSON.  The structure follows the output of 'cmd gpu vkjson', which is
42     // format is defined in /frameworks/native/vulkan/vkjson/vkjson.cc
43     private static class VkJson {
44         List<VkJsonDevice> devices;
45     }
46 
47     private static class VkJsonDevice {
48         VkJsonDeviceProperties properties;
49         VkJsonExtDriverProperties VK_KHR_driver_properties;
50         List<VkExtension> extensions;
51     }
52 
53     private static class VkJsonDeviceProperties {
54         Long apiVersion;
55     }
56 
57     private static class VkJsonExtDriverProperties {
58         VkPhysicalDeviceDriverPropertiesKHR driverPropertiesKHR;
59     }
60 
61     private static class VkPhysicalDeviceDriverPropertiesKHR {
62         Long driverID;
63         String driverName;
64         String driverInfo;
65         VkConformanceVersionKHR conformanceVersion;
66     }
67 
68     private static class VkConformanceVersionKHR {
69         Short major;
70         Short minor;
71         Short subminor;
72         Short patch;
73     }
74 
75     private static class VkExtension {
76         String extensionName;
77         Integer specVersion;
78     }
79     // *** END CLASSES FOR GSON ***
80 
81     private VkJson mVkJson;
82 
83     @Before
setUp()84     public void setUp() throws DeviceNotAvailableException {
85         String cmdString = getDevice().executeShellCommand("cmd gpu vkjson");
86         Gson gson = new Gson();
87         try {
88             mVkJson = gson.fromJson(cmdString, VkJson.class);
89         } catch (JsonSyntaxException e) {
90             assert_().fail(
91                     "Error parsing JSON from 'cmd gpu vkjson': %s\nresult: %s",
92                     e.getMessage(),
93                     cmdString);
94         }
95 
96         assertThat(mVkJson.devices).isNotNull();
97         assertThat(mVkJson.devices).isNotEmpty();
98     }
99 
100     /**
101      * Vulkan version must be at least 1.1.
102      */
103     @Test
checkRequiredVersion()104     public void checkRequiredVersion() {
105         final long apiVersion = mVkJson.devices.get(0).properties.apiVersion;
106         final long vulkan11Version = 0x401000;
107         assertWithMessage("Supported Vulkan version must be at least 1.1")
108             .that(apiVersion)
109             .named("supported vulkan version")
110             .isAtLeast(vulkan11Version);
111     }
112 
113     /**
114      * The following Vulkan extensions are required:
115      *     VK_GOOGLE_display_timing
116      *     VK_KHR_driver_properties
117      */
118     @Test
checkRequiredExtensions()119     public void checkRequiredExtensions() {
120         final Collection<String> REQUIRED_EXTENSIONS = Arrays.asList(
121                 "VK_GOOGLE_display_timing",
122                 "VK_KHR_driver_properties");
123 
124         List<String> extensions = mVkJson.devices.get(0).extensions.stream()
125                 .map(it -> it.extensionName)
126                 .collect(Collectors.toList());
127         assertWithMessage("Required Vulkan extensions are not supported")
128                 .that(extensions)
129                 .named("supported extensions")
130                 .containsAllIn(REQUIRED_EXTENSIONS);
131     }
132 
133     /**
134      * Vulkan driver conformance must be at least 1.1.2.
135      */
136     @Test
checkKHRDriverProperties()137     public void checkKHRDriverProperties() {
138         // Check driver conformance version is at least 1.1.2.
139         final short MAJOR = 1;
140         final short MINOR = 1;
141         final short SUBMINOR = 2;
142         final String DRIVER_CONFORMANCE_VERSION = MAJOR + "." + MINOR + "." + SUBMINOR;
143 
144         assertWithMessage("VK_KHR_driver_properties is not supported")
145                 .that(mVkJson.devices.get(0).VK_KHR_driver_properties)
146                 .named("VK_KHR_driver_properties")
147                 .isNotNull();
148 
149         VkPhysicalDeviceDriverPropertiesKHR properties =
150                 mVkJson.devices.get(0).VK_KHR_driver_properties.driverPropertiesKHR;
151         assertWithMessage("VK_KHR_driver_properties is not supported")
152                 .that(properties).named("driverPropertiesKHR").isNotNull();
153 
154         VkConformanceVersionKHR version = properties.conformanceVersion;
155         assertThat(version).named("driverPropertiesKHR.conformanceVersion").isNotNull();
156 
157         String msg = "Driver conformance version must be at least " + DRIVER_CONFORMANCE_VERSION;
158         assertWithMessage(msg).that(version.major).named("major version").isAtLeast(MAJOR);
159         if (version.major == MAJOR) {
160             assertWithMessage(msg).that(version.minor).named("minor version").isAtLeast(MINOR);
161             if (version.minor == MINOR) {
162                 assertWithMessage(msg).that(version.subminor).named("subminor version")
163                         .isAtLeast(SUBMINOR);
164             }
165         }
166     }
167 }
168