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.tradefed.device.metric; 17 18 import static org.mockito.ArgumentMatchers.any; 19 import static org.mockito.ArgumentMatchers.anyString; 20 import static org.mockito.ArgumentMatchers.eq; 21 import static org.mockito.Mockito.doNothing; 22 import static org.mockito.Mockito.doReturn; 23 import static org.mockito.Mockito.verify; 24 25 import com.android.tradefed.device.ITestDevice; 26 import com.android.tradefed.invoker.IInvocationContext; 27 import com.android.tradefed.result.ITestInvocationListener; 28 import com.android.tradefed.result.InputStreamSource; 29 import com.android.tradefed.result.LogDataType; 30 31 import org.junit.Before; 32 import org.junit.Rule; 33 import org.junit.Test; 34 import org.junit.rules.TemporaryFolder; 35 import org.junit.runner.RunWith; 36 import org.junit.runners.JUnit4; 37 import org.mockito.Mock; 38 import org.mockito.MockitoAnnotations; 39 import org.mockito.Spy; 40 41 import java.io.File; 42 43 /** Unit tests for {@link GraphicsStatsMetricCollector}. */ 44 //TODO(b/71868090): Consolidate all the individual metric collector tests into one common tests. 45 @RunWith(JUnit4.class) 46 public class GraphicsStatsMetricCollectorTest { 47 @Mock IInvocationContext mContext; 48 49 @Mock ITestInvocationListener mListener; 50 51 @Mock ITestDevice mDevice; 52 53 @Spy GraphicsStatsMetricCollector mGfxInfoMetricCollector; 54 55 @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); 56 57 @Before 58 public void setup() throws Exception { 59 MockitoAnnotations.initMocks(this); 60 61 mGfxInfoMetricCollector.init(mContext, mListener); 62 63 doNothing() 64 .when(mListener) 65 .testLog(anyString(), eq(LogDataType.GFX_INFO), any(InputStreamSource.class)); 66 67 doReturn(new File("graphics-1")) 68 .when(mGfxInfoMetricCollector) 69 .saveProcessOutput(any(ITestDevice.class), anyString(), anyString()); 70 71 doReturn(tempFolder.newFolder()).when(mGfxInfoMetricCollector).createTempDir(); 72 } 73 74 @Test 75 public void testCollect() throws Exception { 76 DeviceMetricData runData = new DeviceMetricData(mContext); 77 78 mGfxInfoMetricCollector.collect(mDevice, runData); 79 80 // Verify that we logged the metric file. 81 verify(mListener).testLog(eq("graphics-1"), eq(LogDataType.GFX_INFO), any()); 82 } 83 } 84