1 /* 2 * Copyright (C) 2019 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.tests.apex; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertTrue; 21 22 import com.android.tradefed.device.DeviceNotAvailableException; 23 import com.android.tradefed.log.LogUtil.CLog; 24 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 25 import com.android.tradefed.util.CommandResult; 26 27 import org.junit.runner.RunWith; 28 29 import java.util.Scanner; 30 import java.util.regex.Matcher; 31 import java.util.regex.Pattern; 32 33 /** 34 * Test to check if Apex can be staged, activated and uninstalled successfully. 35 */ 36 @RunWith(DeviceJUnit4ClassRunner.class) 37 public class MediaSwCodecHostTest extends ApexE2EBaseHostTest { 38 private static final String CMD_LSHAL_CODECS = 39 "lshal debug android.hardware.media.c2@1.0::IComponentStore/software"; 40 private static final Pattern CODEC_NAME_REGEX = 41 Pattern.compile("\\s+name: (.+)"); 42 43 @Override additionalCheck()44 public void additionalCheck() { 45 checkCodecs(); 46 } 47 checkCodecs()48 private void checkCodecs() { 49 try { 50 CommandResult commandResult = getDevice().executeShellV2Command(CMD_LSHAL_CODECS); 51 assertEquals("Couldn't list software codecs on device", 52 0, (int) commandResult.getExitCode()); 53 54 String outputString = commandResult.getStdout(); 55 Scanner in = new Scanner(outputString); 56 int codecCount = 0; 57 while (in.hasNextLine()) { 58 String line = in.nextLine(); 59 Matcher m = CODEC_NAME_REGEX.matcher(line); 60 if (m.matches()) { 61 codecCount++; 62 } 63 } 64 CLog.i("Found " + codecCount + " codecs"); 65 assertTrue("Failed to load software codecs. ", codecCount > 0); 66 } catch (DeviceNotAvailableException e) { 67 throw new AssertionError("Unable to run lshal", e); 68 } 69 } 70 } 71