1 /* 2 * Copyright (C) 2025 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 17 package com.android.cuttlefish.tests; 18 19 import static com.google.common.truth.Truth.assertThat; 20 21 import com.android.cuttlefish.tests.utils.CuttlefishHostTest; 22 import com.android.cuttlefish.tests.utils.UnlockScreenRule; 23 import com.android.tradefed.log.LogUtil.CLog; 24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 25 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner.TestLogData; 26 import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; 27 import java.awt.Color; 28 import java.util.Arrays; 29 import java.util.List; 30 import org.junit.After; 31 import org.junit.Assert; 32 import org.junit.Before; 33 import org.junit.Rule; 34 import org.junit.Test; 35 import org.junit.rules.TestRule; 36 import org.junit.runner.RunWith; 37 38 /** 39 * Tests that exercises HWC operations. By using `simply_red` binary, test that the HWC is showing a 40 * red color on the screen by taking a screenshot through Cuttlefish to verify the HWC output. 41 */ 42 @RunWith(DeviceJUnit4ClassRunner.class) 43 public class CuttlefishHwcRedSmokeTest extends CuttlefishHostTest { 44 @Rule public TestLogData mLogs = new TestLogData(); 45 46 private static final String HWC_TEST_BINARY = "simply_red"; 47 private static final String DEVICE_TEST_DIR = 48 "/data/cf_display_tests/" + CuttlefishHwcRedSmokeTest.class.getSimpleName(); 49 private Thread binaryRunThread; 50 51 @Before setUp()52 public void setUp() throws Exception { 53 // The binary runs indefinitely to maintain the color on the screen. 54 // Host test doesn't allow commands to run in the background using `&`, so we start the 55 // binary in a separate thread here. 56 binaryRunThread = new Thread(() -> { 57 try { 58 getDevice().executeShellCommand(DEVICE_TEST_DIR + "/" + HWC_TEST_BINARY); 59 } catch (Exception e) { 60 CLog.e("Error running HWC_TEST_BINARY: " + e.toString()); 61 } 62 }); 63 binaryRunThread.start(); 64 } 65 66 @After tearDown()67 public void tearDown() throws Exception { 68 getDevice().executeShellCommand("pkill " + HWC_TEST_BINARY); 69 binaryRunThread.interrupt(); 70 } 71 72 @Test testHwcRedDisplay()73 public void testHwcRedDisplay() throws Exception { 74 final WaitForColorsResult result = 75 waitForColors(Arrays.asList(ExpectedColor.create(0.5f, 0.5f, Color.RED))); 76 77 if (!result.succeeded()) { 78 saveScreenshotToTestResults("screenshot", result.failureImage(), mLogs); 79 } 80 81 assertThat(result.succeeded()).isTrue(); 82 } 83 } 84