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 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 23 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 24 25 import com.google.gson.Gson; 26 import com.google.gson.JsonSyntaxException; 27 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 import java.util.Arrays; 33 import java.util.Collection; 34 import java.util.List; 35 import java.util.stream.Collectors; 36 37 @RunWith(DeviceJUnit4ClassRunner.class) 38 public class VkJsonTests extends BaseHostJUnit4Test { 39 // *** BEGIN CLASSES FOR GSON *** 40 // Classes to be used with GSON. The structure follows the output of 'cmd gpu vkjson', which is 41 // format is defined in /frameworks/native/vulkan/vkjson/vkjson.cc 42 private static class VkJson { 43 List<VkJsonDevice> devices; 44 } 45 46 private static class VkJsonDevice { 47 VkJsonDeviceProperties properties; 48 VkJsonExtDriverProperties VK_KHR_driver_properties; 49 List<VkExtension> extensions; 50 } 51 52 private static class VkJsonDeviceProperties { 53 Long apiVersion; 54 } 55 56 private static class VkJsonExtDriverProperties { 57 VkPhysicalDeviceDriverPropertiesKHR driverPropertiesKHR; 58 } 59 60 private static class VkPhysicalDeviceDriverPropertiesKHR { 61 Long driverID; 62 String driverName; 63 String driverInfo; 64 VkConformanceVersionKHR conformanceVersion; 65 } 66 67 private static class VkConformanceVersionKHR { 68 Short major; 69 Short minor; 70 Short subminor; 71 Short patch; 72 } 73 74 private static class VkExtension { 75 String extensionName; 76 Integer specVersion; 77 } 78 // *** END CLASSES FOR GSON *** 79 80 private VkJson mVkJson; 81 82 @Before setUp()83 public void setUp() throws DeviceNotAvailableException { 84 TestUtils.assumeGameCoreCertified(getDevice()); 85 86 String cmdString = getDevice().executeShellCommand("cmd gpu vkjson"); 87 Gson gson = new Gson(); 88 try { 89 mVkJson = gson.fromJson(cmdString, VkJson.class); 90 } catch (JsonSyntaxException e) { 91 assertWithMessage( 92 "Error parsing JSON from 'cmd gpu vkjson': %s\nresult: %s", 93 e.getMessage(), 94 cmdString) 95 .fail(); 96 } 97 98 assertThat(mVkJson.devices).isNotNull(); 99 assertThat(mVkJson.devices).isNotEmpty(); 100 } 101 102 /** 103 * Vulkan version must be at least 1.1. 104 */ 105 @Test checkRequiredVersion()106 public void checkRequiredVersion() { 107 final long apiVersion = mVkJson.devices.get(0).properties.apiVersion; 108 final long vulkan11Version = 0x401000; 109 assertWithMessage("supported vulkan version: Supported Vulkan version must be at least 1.1") 110 .that(apiVersion) 111 .isAtLeast(vulkan11Version); 112 } 113 114 /** 115 * The following Vulkan extensions are required: 116 * VK_GOOGLE_display_timing 117 * VK_KHR_driver_properties 118 */ 119 @Test checkRequiredExtensions()120 public void checkRequiredExtensions() { 121 final Collection<String> REQUIRED_EXTENSIONS = Arrays.asList( 122 "VK_GOOGLE_display_timing", 123 "VK_KHR_driver_properties"); 124 125 List<String> extensions = mVkJson.devices.get(0).extensions.stream() 126 .map(it -> it.extensionName) 127 .collect(Collectors.toList()); 128 assertWithMessage("supported extensions: Required Vulkan extensions are not supported") 129 .that(extensions) 130 .containsAtLeastElementsIn(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: VK_KHR_driver_properties is not supported") 145 .that(mVkJson.devices.get(0).VK_KHR_driver_properties) 146 .isNotNull(); 147 148 VkPhysicalDeviceDriverPropertiesKHR properties = 149 mVkJson.devices.get(0).VK_KHR_driver_properties.driverPropertiesKHR; 150 assertWithMessage("driverPropertiesKHR: VK_KHR_driver_properties is not supported") 151 .that(properties).isNotNull(); 152 153 VkConformanceVersionKHR version = properties.conformanceVersion; 154 assertWithMessage("driverPropertiesKHR.conformanceVersion").that(version).isNotNull(); 155 156 String msg = "Driver conformance version must be at least " + DRIVER_CONFORMANCE_VERSION; 157 assertWithMessage("major version: " + msg).that(version.major).isAtLeast(MAJOR); 158 if (version.major == MAJOR) { 159 assertWithMessage("minor version: " + msg).that(version.minor).isAtLeast(MINOR); 160 if (version.minor == MINOR) { 161 assertWithMessage("subminor version: " + msg).that(version.subminor) 162 .isAtLeast(SUBMINOR); 163 } 164 } 165 } 166 } 167