Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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.invoker; |
| 17 | |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 18 | import com.android.tradefed.build.BuildRetrievalError; |
| 19 | import com.android.tradefed.build.IBuildInfo; |
| 20 | import com.android.tradefed.build.IBuildProvider; |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 21 | import com.android.tradefed.command.FatalHostError; |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 22 | import com.android.tradefed.config.Configuration; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 23 | import com.android.tradefed.config.IConfiguration; |
Brett Chabot | 5e4bc50 | 2010-06-10 20:10:30 -0700 | [diff] [blame] | 24 | import com.android.tradefed.device.DeviceNotAvailableException; |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 25 | import com.android.tradefed.device.IDeviceRecovery; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 26 | import com.android.tradefed.device.ITestDevice; |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 27 | import com.android.tradefed.device.ITestDevice.RecoveryMode; |
Julien Desprez | 0750c38 | 2016-05-23 10:40:26 +0100 | [diff] [blame] | 28 | import com.android.tradefed.device.TestDeviceOptions; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 29 | import com.android.tradefed.log.ILeveledLogOutput; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 30 | import com.android.tradefed.log.ILogRegistry; |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 31 | import com.android.tradefed.result.ByteArrayInputStreamSource; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 32 | import com.android.tradefed.result.ILogSaver; |
| 33 | import com.android.tradefed.result.ILogSaverListener; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 34 | import com.android.tradefed.result.ITestInvocationListener; |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 35 | import com.android.tradefed.result.ITestSummaryListener; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 36 | import com.android.tradefed.result.InputStreamSource; |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 37 | import com.android.tradefed.result.InvocationStatus; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 38 | import com.android.tradefed.result.LogDataType; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 39 | import com.android.tradefed.result.LogFile; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 40 | import com.android.tradefed.result.TestSummary; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 41 | import com.android.tradefed.targetprep.BuildError; |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 42 | import com.android.tradefed.targetprep.ITargetCleaner; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 43 | import com.android.tradefed.targetprep.ITargetPreparer; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 44 | import com.android.tradefed.testtype.IDeviceTest; |
| 45 | import com.android.tradefed.testtype.IRemoteTest; |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 46 | import com.android.tradefed.testtype.IResumableTest; |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 47 | import com.android.tradefed.testtype.IRetriableTest; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 48 | |
Brett Chabot | 0eabebe | 2011-09-12 16:15:42 -0700 | [diff] [blame] | 49 | import junit.framework.Test; |
| 50 | import junit.framework.TestCase; |
| 51 | |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 52 | import org.easymock.Capture; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 53 | import org.easymock.EasyMock; |
| 54 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 55 | import java.io.IOException; |
| 56 | import java.io.InputStream; |
Brett Chabot | 664b893 | 2010-08-06 17:17:33 -0700 | [diff] [blame] | 57 | import java.util.ArrayList; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 58 | import java.util.Collections; |
Brett Chabot | 664b893 | 2010-08-06 17:17:33 -0700 | [diff] [blame] | 59 | import java.util.List; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 60 | import java.util.Map; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 61 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Unit tests for {@link TestInvocation}. |
| 64 | */ |
| 65 | public class TestInvocationTest extends TestCase { |
| 66 | |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 67 | private static final String SERIAL = "serial"; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 68 | private static final Map<String, String> EMPTY_MAP = Collections.emptyMap(); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 69 | private static final String PATH = "path"; |
| 70 | private static final String URL = "url"; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 71 | private static final TestSummary mSummary = new TestSummary("http://www.url.com/report.txt"); |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 72 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 73 | /** The {@link TestInvocation} under test, with all dependencies mocked out */ |
| 74 | private TestInvocation mTestInvocation; |
| 75 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 76 | private IConfiguration mStubConfiguration; |
| 77 | |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 78 | // The mock objects. |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 79 | private ITestDevice mMockDevice; |
| 80 | private ITargetPreparer mMockPreparer; |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 81 | private IBuildProvider mMockBuildProvider; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 82 | private IBuildInfo mMockBuildInfo; |
| 83 | private ITestInvocationListener mMockTestListener; |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 84 | private ITestSummaryListener mMockSummaryListener; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 85 | private ILeveledLogOutput mMockLogger; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 86 | private ILogSaver mMockLogSaver; |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 87 | private IDeviceRecovery mMockRecovery; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 88 | private Capture<List<TestSummary>> mUriCapture; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 89 | private ILogRegistry mMockLogRegistry; |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 90 | private IRescheduler mockRescheduler; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | protected void setUp() throws Exception { |
| 94 | super.setUp(); |
| 95 | |
Brett Chabot | e7e335e | 2011-02-16 14:51:03 -0800 | [diff] [blame] | 96 | mStubConfiguration = new Configuration("foo", "bar"); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 97 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 98 | mMockDevice = EasyMock.createMock(ITestDevice.class); |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 99 | mMockRecovery = EasyMock.createMock(IDeviceRecovery.class); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 100 | mMockPreparer = EasyMock.createMock(ITargetPreparer.class); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 101 | mMockBuildProvider = EasyMock.createMock(IBuildProvider.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 102 | |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 103 | // Use strict mocks here since the order of Listener calls is important |
| 104 | mMockTestListener = EasyMock.createStrictMock(ITestInvocationListener.class); |
| 105 | mMockSummaryListener = EasyMock.createStrictMock(ITestSummaryListener.class); |
Brett Chabot | 5dae872 | 2010-09-17 20:05:51 -0700 | [diff] [blame] | 106 | mMockBuildInfo = EasyMock.createMock(IBuildInfo.class); |
Brett Chabot | 35d50c6 | 2011-03-07 10:39:23 -0800 | [diff] [blame] | 107 | mMockLogger = EasyMock.createMock(ILeveledLogOutput.class); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 108 | mMockLogRegistry = EasyMock.createMock(ILogRegistry.class); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 109 | mMockLogSaver = EasyMock.createMock(ILogSaver.class); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 110 | mockRescheduler = EasyMock.createMock(IRescheduler.class); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 111 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 112 | mStubConfiguration.setDeviceRecovery(mMockRecovery); |
| 113 | mStubConfiguration.setTargetPreparer(mMockPreparer); |
| 114 | mStubConfiguration.setBuildProvider(mMockBuildProvider); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 115 | mStubConfiguration.setLogSaver(mMockLogSaver); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 116 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 117 | List<ITestInvocationListener> listenerList = new ArrayList<ITestInvocationListener>(1); |
| 118 | listenerList.add(mMockTestListener); |
| 119 | listenerList.add(mMockSummaryListener); |
| 120 | mStubConfiguration.setTestInvocationListeners(listenerList); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 121 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 122 | mStubConfiguration.setLogOutput(mMockLogger); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 123 | EasyMock.expect(mMockDevice.getSerialNumber()).andStubReturn(SERIAL); |
Guang Zhu | 789a52b | 2014-01-17 14:27:01 -0800 | [diff] [blame] | 124 | EasyMock.expect(mMockDevice.getIDevice()).andStubReturn(null); |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 125 | mMockDevice.setRecovery(mMockRecovery); |
Julien Desprez | 26bee8d | 2016-03-29 12:09:48 +0100 | [diff] [blame] | 126 | mMockDevice.preInvocationSetup((IBuildInfo)EasyMock.anyObject()); |
| 127 | EasyMock.expectLastCall().anyTimes(); |
| 128 | mMockDevice.postInvocationTearDown(); |
| 129 | EasyMock.expectLastCall().anyTimes(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 130 | |
Jorge Gonzalez | 3777e32 | 2011-05-11 18:04:29 -0700 | [diff] [blame] | 131 | EasyMock.expect(mMockBuildInfo.getBuildId()).andStubReturn("1"); |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 132 | EasyMock.expect(mMockBuildInfo.getBuildAttributes()).andStubReturn(EMPTY_MAP); |
Brett Chabot | 2b79e0f | 2013-03-18 16:50:16 -0700 | [diff] [blame] | 133 | EasyMock.expect(mMockBuildInfo.getBuildBranch()).andStubReturn("branch"); |
| 134 | EasyMock.expect(mMockBuildInfo.getBuildFlavor()).andStubReturn("flavor"); |
Brett Chabot | 9d88543 | 2011-07-29 16:25:31 -0700 | [diff] [blame] | 135 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(""); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 136 | // always expect logger initialization and cleanup calls |
| 137 | mMockLogRegistry.registerLogger(mMockLogger); |
| 138 | mMockLogger.init(); |
| 139 | mMockLogger.closeLog(); |
| 140 | mMockLogRegistry.unregisterLogger(); |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 141 | mUriCapture = new Capture<List<TestSummary>>(); |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 142 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 143 | // create the BaseTestInvocation to test |
Brett Chabot | 5e4bc50 | 2010-06-10 20:10:30 -0700 | [diff] [blame] | 144 | mTestInvocation = new TestInvocation() { |
| 145 | @Override |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 146 | ILogRegistry getLogRegistry() { |
| 147 | return mMockLogRegistry; |
Brett Chabot | 5e4bc50 | 2010-06-10 20:10:30 -0700 | [diff] [blame] | 148 | } |
| 149 | }; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Neal Nguyen | 2ceabaa | 2010-05-26 14:42:14 -0700 | [diff] [blame] | 152 | @Override |
| 153 | protected void tearDown() throws Exception { |
| 154 | super.tearDown(); |
| 155 | |
| 156 | } |
| 157 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 158 | /** |
| 159 | * Test the normal case invoke scenario with a {@link IRemoteTest}. |
| 160 | * <p/> |
| 161 | * Verifies that all external interfaces get notified as expected. |
| 162 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 163 | public void testInvoke_RemoteTest() throws Throwable { |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 164 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 165 | setupMockSuccessListeners(); |
Julien Desprez | 26bee8d | 2016-03-29 12:09:48 +0100 | [diff] [blame] | 166 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 167 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 168 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 169 | EasyMock.replay(mockRescheduler); |
| 170 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 171 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 172 | verifySummaryListener(); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Test the normal case invoke scenario with an {@link ITestSummaryListener} masquerading as |
| 177 | * an {@link ITestInvocationListener}. |
| 178 | * <p/> |
| 179 | * Verifies that all external interfaces get notified as expected. |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 180 | */ |
Julien Desprez | 78fcda2 | 2016-06-16 17:35:11 +0100 | [diff] [blame^] | 181 | public void testInvoke_twoSummary() throws Throwable { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 182 | |
| 183 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 184 | setupMockSuccessListeners(); |
| 185 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 186 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 187 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 188 | EasyMock.replay(mockRescheduler); |
| 189 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 190 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 191 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Test the invoke scenario where build retrieve fails. |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 196 | * <p/> |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 197 | * An invocation will be started in this scenario. |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 198 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 199 | public void testInvoke_buildFailed() throws Throwable { |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 200 | BuildRetrievalError exception = new BuildRetrievalError("error", null, mMockBuildInfo); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 201 | EasyMock.expect(mMockBuildProvider.getBuild()).andThrow(exception); |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 202 | setupMockFailureListeners(exception); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 203 | setupInvoke(); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 204 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 205 | mStubConfiguration.setTest(test); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 206 | EasyMock.expect(mMockLogger.getLog()) |
| 207 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
| 208 | EasyMock.expect(mMockDevice.getLogcat()) |
| 209 | .andReturn(new ByteArrayInputStreamSource(new byte[0])).times(2); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 210 | replayMocks(test, mockRescheduler); |
| 211 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 212 | verifyMocks(test, mockRescheduler); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
Brett Chabot | dd21ddf | 2010-06-07 14:16:19 -0700 | [diff] [blame] | 216 | * Test the invoke scenario where there is no build to test. |
| 217 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 218 | public void testInvoke_noBuild() throws Throwable { |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 219 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(null); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 220 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 221 | mStubConfiguration.setTest(test); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 222 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 223 | setupInvoke(); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 224 | replayMocks(test, mockRescheduler); |
| 225 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 226 | verifyMocks(test); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 227 | } |
| 228 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 229 | /** |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 230 | * Test the invoke scenario where there is no build to test for a {@link IRetriableTest}. |
| 231 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 232 | public void testInvoke_noBuildRetry() throws Throwable { |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 233 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(null); |
| 234 | |
| 235 | IRetriableTest test = EasyMock.createMock(IRetriableTest.class); |
| 236 | EasyMock.expect(test.isRetriable()).andReturn(Boolean.TRUE); |
| 237 | |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 238 | EasyMock.expect(mockRescheduler.rescheduleCommand()).andReturn(EasyMock.anyBoolean()); |
| 239 | |
| 240 | mStubConfiguration.setTest(test); |
| 241 | mStubConfiguration.getCommandOptions().setLoopMode(false); |
| 242 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 243 | setupInvoke(); |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 244 | replayMocks(test); |
| 245 | EasyMock.replay(mockRescheduler); |
| 246 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 247 | EasyMock.verify(mockRescheduler); |
| 248 | verifyMocks(test); |
| 249 | } |
| 250 | |
| 251 | /** |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 252 | * Test the{@link TestInvocation#invoke(ITestDevice, IConfiguration, IRescheduler, |
| 253 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 254 | * where the test is a {@link IDeviceTest} |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 255 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 256 | public void testInvoke_deviceTest() throws Throwable { |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 257 | DeviceConfigTest mockDeviceTest = EasyMock.createMock(DeviceConfigTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 258 | mStubConfiguration.setTest(mockDeviceTest); |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 259 | mockDeviceTest.setDevice(mMockDevice); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 260 | mockDeviceTest.run((ITestInvocationListener)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 261 | setupMockSuccessListeners(); |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 262 | setupNormalInvoke(mockDeviceTest); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 263 | EasyMock.replay(mockRescheduler); |
| 264 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 265 | verifyMocks(mockDeviceTest, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 266 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Test the invoke scenario where test run throws {@link IllegalArgumentException} |
| 271 | * |
| 272 | * @throws Exception if unexpected error occurs |
| 273 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 274 | public void testInvoke_testFail() throws Throwable { |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 275 | IllegalArgumentException exception = new IllegalArgumentException(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 276 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 277 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 278 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 279 | setupMockFailureListeners(exception); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 280 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 281 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 282 | EasyMock.replay(mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 283 | try { |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 284 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 285 | fail("IllegalArgumentException was not rethrown"); |
| 286 | } catch (IllegalArgumentException e) { |
| 287 | // expected |
| 288 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 289 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 290 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 294 | * Test the invoke scenario where test run throws {@link FatalHostError} |
| 295 | * |
| 296 | * @throws Exception if unexpected error occurs |
| 297 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 298 | public void testInvoke_fatalError() throws Throwable { |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 299 | FatalHostError exception = new FatalHostError("error"); |
| 300 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 301 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 302 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 303 | setupMockFailureListeners(exception); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 304 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 305 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 306 | EasyMock.replay(mockRescheduler); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 307 | try { |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 308 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 309 | fail("FatalHostError was not rethrown"); |
| 310 | } catch (FatalHostError e) { |
| 311 | // expected |
| 312 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 313 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 314 | verifySummaryListener(); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /** |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 318 | * Test the invoke scenario where test run throws {@link DeviceNotAvailableException} |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 319 | * |
| 320 | * @throws Exception if unexpected error occurs |
| 321 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 322 | public void testInvoke_deviceNotAvail() throws Throwable { |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 323 | DeviceNotAvailableException exception = new DeviceNotAvailableException(); |
| 324 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 325 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 326 | EasyMock.expectLastCall().andThrow(exception); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 327 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 328 | EasyMock.expectLastCall(); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 329 | setupMockFailureListeners(exception); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 330 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 331 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 332 | EasyMock.replay(mockRescheduler); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 333 | try { |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 334 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 335 | fail("DeviceNotAvailableException not thrown"); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 336 | } catch (DeviceNotAvailableException e) { |
| 337 | // expected |
| 338 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 339 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 340 | verifySummaryListener(); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 344 | * Test the invoke scenario where preparer throws {@link BuildError} |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 345 | * |
| 346 | * @throws Exception if unexpected error occurs |
| 347 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 348 | public void testInvoke_buildError() throws Throwable { |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 349 | BuildError exception = new BuildError("error"); |
| 350 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 351 | mStubConfiguration.setTest(test); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 352 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 353 | |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 354 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 355 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 356 | setupMockFailureListeners(exception); |
Eric Rowe | 4a3369d | 2011-11-23 12:12:16 -0800 | [diff] [blame] | 357 | EasyMock.expect(mMockDevice.getBugreport()) |
Guang Zhu | 36c56a2 | 2014-12-30 19:56:00 -0800 | [diff] [blame] | 358 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 359 | setupInvokeWithBuild(); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 360 | replayMocks(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 361 | EasyMock.replay(mockRescheduler); |
| 362 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 363 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 364 | verifySummaryListener(); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 367 | /** |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 368 | * Test the invoke scenario for a {@link IResumableTest}. |
| 369 | * |
| 370 | * @throws Exception if unexpected error occurs |
| 371 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 372 | public void testInvoke_resume() throws Throwable { |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 373 | IResumableTest resumableTest = EasyMock.createMock(IResumableTest.class); |
| 374 | mStubConfiguration.setTest(resumableTest); |
| 375 | ITestInvocationListener resumeListener = EasyMock.createStrictMock( |
| 376 | ITestInvocationListener.class); |
| 377 | mStubConfiguration.setTestInvocationListener(resumeListener); |
| 378 | |
| 379 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 380 | resumeListener.invocationStarted(mMockBuildInfo); |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 381 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 382 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 383 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 384 | mMockDevice.startLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 385 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 386 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 387 | resumableTest.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 388 | EasyMock.expectLastCall().andThrow(new DeviceNotAvailableException()); |
| 389 | EasyMock.expect(resumableTest.isResumable()).andReturn(Boolean.TRUE); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 390 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 391 | EasyMock.expectLastCall(); |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 392 | EasyMock.expect(mMockDevice.getLogcat()) |
| 393 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
| 394 | EasyMock.expect(mMockLogger.getLog()) |
| 395 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 396 | EasyMock.expect(mMockLogSaver.saveLogData(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
| 397 | EasyMock.eq(LogDataType.LOGCAT), (InputStream)EasyMock.anyObject()) |
| 398 | ).andReturn(new LogFile(PATH, URL)); |
| 399 | EasyMock.expect(mMockLogSaver.saveLogData(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 400 | EasyMock.eq(LogDataType.TEXT), (InputStream)EasyMock.anyObject()) |
| 401 | ).andReturn(new LogFile(PATH, URL)); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 402 | resumeListener.testLog(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 403 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 404 | resumeListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 405 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 406 | |
| 407 | // just return same build and logger for simplicity |
| 408 | EasyMock.expect(mMockBuildInfo.clone()).andReturn(mMockBuildInfo); |
| 409 | EasyMock.expect(mMockLogger.clone()).andReturn(mMockLogger); |
| 410 | IRescheduler mockRescheduler = EasyMock.createMock(IRescheduler.class); |
| 411 | Capture<IConfiguration> capturedConfig = new Capture<IConfiguration>(); |
| 412 | EasyMock.expect(mockRescheduler.scheduleConfig(EasyMock.capture(capturedConfig))) |
| 413 | .andReturn(Boolean.TRUE); |
| 414 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 415 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 416 | mMockDevice.stopLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 417 | |
Brett Chabot | 35d50c6 | 2011-03-07 10:39:23 -0800 | [diff] [blame] | 418 | mMockLogger.init(); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 419 | mMockLogSaver.invocationStarted(mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 420 | // now set resumed invocation expectations |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 421 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 422 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 423 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 424 | mMockDevice.startLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 425 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 426 | mMockLogSaver.invocationStarted(mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 427 | mMockDevice.setRecovery(mMockRecovery); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 428 | resumableTest.run((ITestInvocationListener)EasyMock.anyObject()); |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 429 | EasyMock.expect(mMockDevice.getLogcat()) |
| 430 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
| 431 | EasyMock.expect(mMockLogger.getLog()) |
| 432 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 433 | EasyMock.expect(mMockLogSaver.saveLogData(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
| 434 | EasyMock.eq(LogDataType.LOGCAT), (InputStream)EasyMock.anyObject()) |
| 435 | ).andReturn(new LogFile(PATH, URL)); |
| 436 | EasyMock.expect(mMockLogSaver.saveLogData(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 437 | EasyMock.eq(LogDataType.TEXT), (InputStream)EasyMock.anyObject()) |
| 438 | ).andReturn(new LogFile(PATH, URL)); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 439 | resumeListener.testLog(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 440 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 441 | resumeListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 442 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 443 | resumeListener.invocationEnded(EasyMock.anyLong()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 444 | mMockLogSaver.invocationEnded(EasyMock.anyLong()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 445 | EasyMock.expect(resumeListener.getSummary()).andReturn(null); |
| 446 | mMockBuildInfo.cleanUp(); |
| 447 | mMockLogger.closeLog(); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 448 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 449 | mMockDevice.stopLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 450 | |
| 451 | EasyMock.replay(mockRescheduler, resumeListener, resumableTest, mMockPreparer, |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 452 | mMockBuildProvider, mMockLogger, mMockLogSaver, mMockDevice, mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 453 | |
| 454 | try { |
| 455 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 456 | fail("DeviceNotAvailableException not thrown"); |
| 457 | } catch (DeviceNotAvailableException e) { |
| 458 | // expect |
| 459 | } |
| 460 | // now call again, and expect invocation to be resumed properly |
| 461 | mTestInvocation.invoke(mMockDevice, capturedConfig.getValue(), mockRescheduler); |
| 462 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 463 | EasyMock.verify(mockRescheduler, resumeListener, resumableTest, mMockPreparer, |
| 464 | mMockBuildProvider, mMockLogger, mMockLogSaver, mMockDevice, mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /** |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 468 | * Test the invoke scenario for a {@link IRetriableTest}. |
| 469 | * |
| 470 | * @throws Exception if unexpected error occurs |
| 471 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 472 | public void testInvoke_retry() throws Throwable { |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 473 | AssertionError exception = new AssertionError(); |
| 474 | IRetriableTest test = EasyMock.createMock(IRetriableTest.class); |
| 475 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 476 | EasyMock.expectLastCall().andThrow(exception); |
| 477 | EasyMock.expect(test.isRetriable()).andReturn(Boolean.TRUE); |
| 478 | mStubConfiguration.getCommandOptions().setLoopMode(false); |
| 479 | IRescheduler mockRescheduler = EasyMock.createMock(IRescheduler.class); |
| 480 | EasyMock.expect(mockRescheduler.rescheduleCommand()).andReturn(EasyMock.anyBoolean()); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 481 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 482 | setupMockFailureListeners(exception); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 483 | setupNormalInvoke(test); |
| 484 | EasyMock.replay(mockRescheduler); |
| 485 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 486 | verifyMocks(test, mockRescheduler); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 487 | verifySummaryListener(); |
| 488 | } |
| 489 | |
| 490 | /** |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 491 | * Test the {@link TestInvocation#invoke(ITestDevice, IConfiguration, IRescheduler, |
| 492 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 493 | * when a {@link ITargetCleaner} is part of the config. |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 494 | */ |
| 495 | public void testInvoke_tearDown() throws Throwable { |
| 496 | IRemoteTest test = EasyMock.createNiceMock(IRemoteTest.class); |
| 497 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
| 498 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 499 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, null); |
| 500 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 501 | setupMockSuccessListeners(); |
| 502 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 503 | EasyMock.replay(mockCleaner, mockRescheduler); |
| 504 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 505 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 506 | verifySummaryListener(); |
| 507 | } |
| 508 | |
| 509 | /** |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 510 | * Test the {@link TestInvocation#invoke(ITestDevice, IConfiguration, IRescheduler, |
| 511 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 512 | * when a {@link ITargetCleaner} is part of the config, and the test throws a |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 513 | * {@link DeviceNotAvailableException}. |
| 514 | */ |
| 515 | public void testInvoke_tearDown_deviceNotAvail() throws Throwable { |
| 516 | DeviceNotAvailableException exception = new DeviceNotAvailableException(); |
| 517 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 518 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 519 | EasyMock.expectLastCall().andThrow(exception); |
| 520 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
| 521 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
Guang Zhu | 36c56a2 | 2014-12-30 19:56:00 -0800 | [diff] [blame] | 522 | EasyMock.expectLastCall(); |
| 523 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, exception); |
| 524 | EasyMock.expectLastCall(); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 525 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 526 | EasyMock.expectLastCall(); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 527 | EasyMock.replay(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 528 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 529 | setupMockFailureListeners(exception); |
| 530 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
| 531 | setupNormalInvoke(test); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 532 | try { |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 533 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 534 | fail("DeviceNotAvailableException not thrown"); |
| 535 | } catch (DeviceNotAvailableException e) { |
| 536 | // expected |
| 537 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 538 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 539 | verifySummaryListener(); |
| 540 | } |
| 541 | |
| 542 | /** |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 543 | * Test the {@link TestInvocation#invoke(ITestDevice, IConfiguration, IRescheduler, |
| 544 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 545 | * when a {@link ITargetCleaner} is part of the config, and the test throws a |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 546 | * {@link RuntimeException}. |
| 547 | */ |
| 548 | public void testInvoke_tearDown_runtime() throws Throwable { |
| 549 | RuntimeException exception = new RuntimeException(); |
| 550 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 551 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 552 | EasyMock.expectLastCall().andThrow(exception); |
| 553 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
| 554 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 555 | // tearDown should be called |
| 556 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, exception); |
| 557 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 558 | setupMockFailureListeners(exception); |
| 559 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
| 560 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 561 | EasyMock.replay(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 562 | try { |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 563 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 564 | fail("RuntimeException not thrown"); |
| 565 | } catch (RuntimeException e) { |
| 566 | // expected |
| 567 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 568 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 569 | verifySummaryListener(); |
| 570 | } |
| 571 | |
| 572 | /** |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 573 | * Test the {@link TestInvocation#invoke(ITestDevice, IConfiguration, IRescheduler, |
| 574 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 575 | * when there is {@link ITestInvocationListener} which implements the {@link ILogSaverListener} |
| 576 | * interface. |
| 577 | */ |
| 578 | public void testInvoke_logFileSaved() throws Throwable { |
| 579 | List<ITestInvocationListener> listenerList = |
| 580 | mStubConfiguration.getTestInvocationListeners(); |
| 581 | ILogSaverListener logSaverListener = EasyMock.createMock(ILogSaverListener.class); |
| 582 | listenerList.add(logSaverListener); |
| 583 | mStubConfiguration.setTestInvocationListeners(listenerList); |
| 584 | |
| 585 | logSaverListener.setLogSaver(mMockLogSaver); |
| 586 | logSaverListener.invocationStarted(mMockBuildInfo); |
| 587 | logSaverListener.testLog(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
| 588 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject()); |
| 589 | logSaverListener.testLogSaved(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
| 590 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject(), |
| 591 | (LogFile)EasyMock.anyObject()); |
| 592 | logSaverListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 593 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
| 594 | logSaverListener.testLogSaved(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 595 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject(), |
| 596 | (LogFile)EasyMock.anyObject()); |
| 597 | logSaverListener.invocationEnded(EasyMock.anyLong()); |
| 598 | EasyMock.expect(logSaverListener.getSummary()).andReturn(mSummary); |
| 599 | |
| 600 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 601 | setupMockSuccessListeners(); |
| 602 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 603 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 604 | EasyMock.replay(logSaverListener, mockRescheduler); |
| 605 | mTestInvocation.invoke(mMockDevice, mStubConfiguration, mockRescheduler); |
| 606 | verifyMocks(test, logSaverListener, mockRescheduler); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 607 | assertEquals(2, mUriCapture.getValue().size()); |
| 608 | } |
| 609 | |
| 610 | /** |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 611 | * @param test the {@link Test} to use. |
| 612 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 613 | private void setupNormalInvoke(IRemoteTest test) throws Throwable { |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 614 | setupInvokeWithBuild(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 615 | mStubConfiguration.setTest(test); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 616 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 617 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 618 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 619 | |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 620 | replayMocks(test); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Set up expected calls that occur on every invoke, regardless of result |
| 625 | */ |
| 626 | private void setupInvoke() { |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 627 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 628 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
| 629 | mMockDevice.startLogcat(); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 630 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 631 | mMockDevice.stopLogcat(); |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * Set up expected calls that occur on every invoke that gets a valid build |
| 636 | */ |
| 637 | private void setupInvokeWithBuild() { |
| 638 | setupInvoke(); |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 639 | EasyMock.expect(mMockDevice.getLogcat()) |
| 640 | .andReturn(new ByteArrayInputStreamSource(new byte[0])).times(2); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 641 | |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 642 | EasyMock.expect(mMockLogger.getLog()) |
| 643 | .andReturn(new ByteArrayInputStreamSource(new byte[0])); |
| 644 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Brett Chabot | 66d8757 | 2010-11-01 19:54:59 -0700 | [diff] [blame] | 645 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 649 | * Set up expected conditions for the test InvocationListener and SummaryListener |
| 650 | * <p/> |
| 651 | * The order of calls for a single listener should be: |
| 652 | * <ol> |
| 653 | * <li>invocationStarted</li> |
| 654 | * <li>invocationFailed (if run failed)</li> |
| 655 | * <li>testLog(DEVICE_LOG_NAME, ...)</li> |
| 656 | * <li>testLog(TRADEFED_LOG_NAME, ...)</li> |
| 657 | * <li>putSummary (for an ITestSummaryListener)</li> |
| 658 | * <li>invocationEnded</li> |
| 659 | * <li>getSummary (for an ITestInvocationListener)</li> |
| 660 | * </ol> |
| 661 | * However note that, across all listeners, any getSummary call will precede all putSummary |
| 662 | * calls. |
| 663 | */ |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 664 | private void setupMockListeners(InvocationStatus status, Throwable throwable) |
| 665 | throws IOException { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 666 | // invocationStarted |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 667 | mMockLogSaver.invocationStarted(mMockBuildInfo); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 668 | mMockTestListener.invocationStarted(mMockBuildInfo); |
| 669 | mMockSummaryListener.invocationStarted(mMockBuildInfo); |
| 670 | |
Guang Zhu | 36c56a2 | 2014-12-30 19:56:00 -0800 | [diff] [blame] | 671 | // invocationFailed |
| 672 | if (!status.equals(InvocationStatus.SUCCESS)) { |
| 673 | mMockTestListener.invocationFailed(EasyMock.eq(throwable)); |
| 674 | mMockSummaryListener.invocationFailed(EasyMock.eq(throwable)); |
| 675 | } |
| 676 | |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 677 | if (throwable instanceof BuildError) { |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 678 | EasyMock.expect(mMockLogSaver.saveLogData( |
| 679 | EasyMock.eq(TestInvocation.BUILD_ERROR_BUGREPORT_NAME), |
| 680 | EasyMock.eq(LogDataType.BUGREPORT), (InputStream)EasyMock.anyObject()) |
| 681 | ).andReturn(new LogFile(PATH, URL)); |
Eric Rowe | 4a3369d | 2011-11-23 12:12:16 -0800 | [diff] [blame] | 682 | mMockTestListener.testLog(EasyMock.eq(TestInvocation.BUILD_ERROR_BUGREPORT_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 683 | EasyMock.eq(LogDataType.BUGREPORT), (InputStreamSource)EasyMock.anyObject()); |
Eric Rowe | 4a3369d | 2011-11-23 12:12:16 -0800 | [diff] [blame] | 684 | mMockSummaryListener.testLog(EasyMock.eq(TestInvocation.BUILD_ERROR_BUGREPORT_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 685 | EasyMock.eq(LogDataType.BUGREPORT), (InputStreamSource)EasyMock.anyObject()); |
Eric Rowe | 4a3369d | 2011-11-23 12:12:16 -0800 | [diff] [blame] | 686 | } |
| 687 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 688 | // saveAndZipLogData (mMockLogFileSaver) |
| 689 | EasyMock.expect(mMockLogSaver.saveLogData( EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
| 690 | EasyMock.eq(LogDataType.LOGCAT), (InputStream)EasyMock.anyObject()) |
| 691 | ).andReturn(new LogFile(PATH, URL)); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 692 | // testLog (mMockTestListener) |
| 693 | mMockTestListener.testLog(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 694 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 695 | // testLog (mMockSummaryListener) |
| 696 | mMockSummaryListener.testLog(EasyMock.eq(TestInvocation.DEVICE_LOG_NAME), |
Eric Rowe | cc35ac2 | 2013-07-09 12:22:36 -0700 | [diff] [blame] | 697 | EasyMock.eq(LogDataType.LOGCAT), (InputStreamSource)EasyMock.anyObject()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 698 | |
| 699 | EasyMock.expect(mMockLogSaver.saveLogData(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 700 | EasyMock.eq(LogDataType.TEXT), (InputStream)EasyMock.anyObject()) |
| 701 | ).andReturn(new LogFile(PATH, URL)); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 702 | mMockTestListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 703 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 704 | mMockSummaryListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 705 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 706 | |
| 707 | // invocationEnded, getSummary (mMockTestListener) |
| 708 | mMockTestListener.invocationEnded(EasyMock.anyLong()); |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 709 | EasyMock.expect(mMockTestListener.getSummary()).andReturn(mSummary); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 710 | |
| 711 | // putSummary, invocationEnded (mMockSummaryListener) |
| 712 | mMockSummaryListener.putSummary(EasyMock.capture(mUriCapture)); |
| 713 | mMockSummaryListener.invocationEnded(EasyMock.anyLong()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 714 | mMockLogSaver.invocationEnded(EasyMock.anyLong()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 715 | } |
| 716 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 717 | private void setupMockSuccessListeners() throws IOException { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 718 | setupMockListeners(InvocationStatus.SUCCESS, null); |
| 719 | } |
| 720 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 721 | private void setupMockFailureListeners(Throwable throwable) throws IOException { |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 722 | setupMockListeners(InvocationStatus.FAILED, throwable); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | private void verifySummaryListener() { |
| 726 | // Check that we captured the expected uris List |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 727 | List<TestSummary> summaries = mUriCapture.getValue(); |
| 728 | assertEquals(1, summaries.size()); |
| 729 | assertEquals(mSummary, summaries.get(0)); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /** |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 733 | * Verify all mock objects received expected calls |
| 734 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 735 | private void verifyMocks(Object... mocks) { |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 736 | // note: intentionally exclude configuration from verification - don't care |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 737 | // what methods are called |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 738 | EasyMock.verify(mMockTestListener, mMockSummaryListener, mMockPreparer, |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 739 | mMockBuildProvider, mMockLogger, mMockBuildInfo, mMockLogRegistry, |
| 740 | mMockLogSaver); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 741 | if (mocks.length > 0) { |
| 742 | EasyMock.verify(mocks); |
| 743 | } |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | /** |
| 747 | * Switch all mock objects into replay mode. |
| 748 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 749 | private void replayMocks(Object... mocks) { |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 750 | EasyMock.replay(mMockTestListener, mMockSummaryListener, mMockPreparer, |
| 751 | mMockBuildProvider, mMockLogger, mMockBuildInfo, mMockLogRegistry, |
Moon Kim | 0995f44 | 2016-05-25 13:13:40 -0700 | [diff] [blame] | 752 | mMockLogSaver, mMockDevice); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 753 | if (mocks.length > 0) { |
| 754 | EasyMock.replay(mocks); |
| 755 | } |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | /** |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 759 | * Interface for testing device config pass through. |
| 760 | */ |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 761 | private interface DeviceConfigTest extends IRemoteTest, IDeviceTest { |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 762 | |
| 763 | } |
| 764 | } |