1 /*
2  * Copyright (C) 2021 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.cuttlefish.tests;
17 
18 import static com.google.common.truth.Truth.assertThat;
19 
20 import com.android.tradefed.config.Option;
21 import com.android.tradefed.device.ITestDevice;
22 import com.android.tradefed.log.LogUtil.CLog;
23 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
24 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
25 
26 import org.junit.Assert;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 
30 /**
31  * Tests that Cuttlefish is using a specified EGL and VK implementation.
32  */
33 @RunWith(DeviceJUnit4ClassRunner.class)
34 public class CuttlefishGraphicsConfigurationTest extends BaseHostJUnit4Test {
35 
36     private static final String EGL_SYSPROP = "ro.hardware.egl";
37 
38     private static final String VULKAN_SYSPROP = "ro.hardware.vulkan";
39 
40     @Option(name="expected-egl",
41             description="The expected EGL implementation enabled on the device.")
42     private String mExpectedEgl = "";
43 
44     @Option(name="expected-vulkan",
45             description="The expected Vulkan implementation enabled on the device.")
46     private String mExpectedVulkan = "";
47 
48     @Test
testGraphicsConfiguration()49     public void testGraphicsConfiguration() throws Exception {
50         final ITestDevice device = getDevice();
51 
52         final String deviceEgl = device.getProperty(EGL_SYSPROP);
53         CLog.i("Device's %s is \"%s\"", EGL_SYSPROP, deviceEgl);
54         if (!mExpectedEgl.isEmpty()) {
55             assertThat(deviceEgl).isEqualTo(mExpectedEgl);
56         }
57 
58         final String deviceVulkan = device.getProperty(VULKAN_SYSPROP);
59         CLog.i("Device's %s is \"%s\"", VULKAN_SYSPROP, deviceVulkan);
60         if (!mExpectedVulkan.isEmpty()) {
61             assertThat(deviceVulkan).isEqualTo(mExpectedVulkan);
62         }
63     }
64 }