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 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 18 | import static org.mockito.Mockito.doReturn; |
| 19 | |
| 20 | import com.android.ddmlib.IDevice; |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 21 | import com.android.tradefed.build.BuildInfo; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 22 | import com.android.tradefed.build.BuildRetrievalError; |
| 23 | import com.android.tradefed.build.IBuildInfo; |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 24 | import com.android.tradefed.build.IBuildInfo.BuildInfoProperties; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 25 | import com.android.tradefed.build.IBuildProvider; |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 26 | import com.android.tradefed.build.IDeviceBuildInfo; |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 27 | import com.android.tradefed.build.IDeviceBuildProvider; |
| 28 | import com.android.tradefed.command.CommandOptions; |
Julien Desprez | 75fbb80 | 2016-11-15 12:35:58 +0000 | [diff] [blame] | 29 | import com.android.tradefed.command.CommandRunner.ExitCode; |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 30 | import com.android.tradefed.command.FatalHostError; |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 31 | import com.android.tradefed.command.ICommandOptions; |
Julien Desprez | 07fe153 | 2016-08-12 11:48:32 +0100 | [diff] [blame] | 32 | import com.android.tradefed.command.remote.DeviceDescriptor; |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 33 | import com.android.tradefed.config.Configuration; |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 34 | import com.android.tradefed.config.ConfigurationDef; |
| 35 | import com.android.tradefed.config.DeviceConfigurationHolder; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 36 | import com.android.tradefed.config.IConfiguration; |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 37 | import com.android.tradefed.config.IConfigurationFactory; |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 38 | import com.android.tradefed.config.IDeviceConfiguration; |
jdesprez | 839825d | 2018-01-31 12:14:23 -0800 | [diff] [blame] | 39 | import com.android.tradefed.config.Option; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 40 | import com.android.tradefed.config.OptionSetter; |
Julien Desprez | 07fe153 | 2016-08-12 11:48:32 +0100 | [diff] [blame] | 41 | import com.android.tradefed.device.DeviceAllocationState; |
Brett Chabot | 5e4bc50 | 2010-06-10 20:10:30 -0700 | [diff] [blame] | 42 | import com.android.tradefed.device.DeviceNotAvailableException; |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 43 | import com.android.tradefed.device.IDeviceRecovery; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 44 | import com.android.tradefed.device.INativeDevice; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 45 | import com.android.tradefed.device.ITestDevice; |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 46 | import com.android.tradefed.device.ITestDevice.RecoveryMode; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 47 | import com.android.tradefed.device.StubDevice; |
Julien Desprez | 0750c38 | 2016-05-23 10:40:26 +0100 | [diff] [blame] | 48 | import com.android.tradefed.device.TestDeviceOptions; |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 49 | import com.android.tradefed.device.metric.BaseDeviceMetricCollector; |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 50 | import com.android.tradefed.device.metric.DeviceMetricData; |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 51 | import com.android.tradefed.device.metric.IMetricCollector; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 52 | import com.android.tradefed.invoker.shard.IShardHelper; |
| 53 | import com.android.tradefed.invoker.shard.ShardHelper; |
| 54 | import com.android.tradefed.invoker.shard.StrictShardHelper; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 55 | import com.android.tradefed.log.ILeveledLogOutput; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 56 | import com.android.tradefed.log.ILogRegistry; |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 57 | import com.android.tradefed.result.ByteArrayInputStreamSource; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 58 | import com.android.tradefed.result.ILogSaver; |
| 59 | import com.android.tradefed.result.ILogSaverListener; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 60 | import com.android.tradefed.result.ITestInvocationListener; |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 61 | import com.android.tradefed.result.ITestSummaryListener; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 62 | import com.android.tradefed.result.InputStreamSource; |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 63 | import com.android.tradefed.result.InvocationStatus; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 64 | import com.android.tradefed.result.LogDataType; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 65 | import com.android.tradefed.result.LogFile; |
jdesprez | 821a005 | 2018-01-16 03:37:16 -0800 | [diff] [blame] | 66 | import com.android.tradefed.result.TestDescription; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 67 | import com.android.tradefed.result.TestSummary; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 68 | import com.android.tradefed.targetprep.BuildError; |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 69 | import com.android.tradefed.targetprep.ITargetCleaner; |
Brett Chabot | beaebb0 | 2011-02-07 16:16:06 -0800 | [diff] [blame] | 70 | import com.android.tradefed.targetprep.ITargetPreparer; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 71 | import com.android.tradefed.testtype.IDeviceTest; |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 72 | import com.android.tradefed.testtype.IInvocationContextReceiver; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 73 | import com.android.tradefed.testtype.IRemoteTest; |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 74 | import com.android.tradefed.testtype.IResumableTest; |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 75 | import com.android.tradefed.testtype.IRetriableTest; |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 76 | import com.android.tradefed.testtype.IShardableTest; |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 77 | import com.android.tradefed.testtype.IStrictShardableTest; |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 78 | import com.android.tradefed.testtype.StubTest; |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 79 | import com.android.tradefed.util.FileUtil; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 80 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 81 | import com.google.common.util.concurrent.SettableFuture; |
| 82 | |
Brett Chabot | 0eabebe | 2011-09-12 16:15:42 -0700 | [diff] [blame] | 83 | import junit.framework.Test; |
| 84 | import junit.framework.TestCase; |
| 85 | |
Jed Estep | a97349e | 2016-11-02 20:44:09 -0700 | [diff] [blame] | 86 | import org.easymock.Capture; |
| 87 | import org.easymock.EasyMock; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 88 | import org.mockito.Mockito; |
Jed Estep | a97349e | 2016-11-02 20:44:09 -0700 | [diff] [blame] | 89 | |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 90 | import java.io.File; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 91 | import java.io.IOException; |
| 92 | import java.io.InputStream; |
Brett Chabot | 664b893 | 2010-08-06 17:17:33 -0700 | [diff] [blame] | 93 | import java.util.ArrayList; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 94 | import java.util.Collections; |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 95 | import java.util.HashSet; |
Brett Chabot | 664b893 | 2010-08-06 17:17:33 -0700 | [diff] [blame] | 96 | import java.util.List; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 97 | import java.util.Map; |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 98 | import java.util.Set; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 99 | |
jdesprez | d0e00da | 2017-09-07 18:54:49 -0700 | [diff] [blame] | 100 | /** Unit tests for {@link TestInvocation}. */ |
| 101 | @SuppressWarnings("MustBeClosedChecker") |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 102 | public class TestInvocationTest extends TestCase { |
| 103 | |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 104 | private static final String SERIAL = "serial"; |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 105 | private static final Map<String, String> EMPTY_MAP = Collections.emptyMap(); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 106 | private static final String PATH = "path"; |
| 107 | private static final String URL = "url"; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 108 | private static final TestSummary mSummary = new TestSummary("http://www.url.com/report.txt"); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 109 | private static final InputStreamSource EMPTY_STREAM_SOURCE = |
| 110 | new ByteArrayInputStreamSource(new byte[0]); |
| 111 | private static final String LOGCAT_NAME_ERROR = |
Michael Rosenfeld | b0f58d2 | 2017-01-26 14:38:32 -0800 | [diff] [blame] | 112 | TestInvocation.getDeviceLogName(TestInvocation.Stage.ERROR); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 113 | private static final String LOGCAT_NAME_SETUP = |
Michael Rosenfeld | b0f58d2 | 2017-01-26 14:38:32 -0800 | [diff] [blame] | 114 | TestInvocation.getDeviceLogName(TestInvocation.Stage.SETUP); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 115 | private static final String LOGCAT_NAME_TEST = |
Michael Rosenfeld | b0f58d2 | 2017-01-26 14:38:32 -0800 | [diff] [blame] | 116 | TestInvocation.getDeviceLogName(TestInvocation.Stage.TEST); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 117 | private static final String LOGCAT_NAME_TEARDOWN = |
Michael Rosenfeld | b0f58d2 | 2017-01-26 14:38:32 -0800 | [diff] [blame] | 118 | TestInvocation.getDeviceLogName(TestInvocation.Stage.TEARDOWN); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 119 | /** The {@link TestInvocation} under test, with all dependencies mocked out */ |
| 120 | private TestInvocation mTestInvocation; |
| 121 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 122 | private IConfiguration mStubConfiguration; |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 123 | private IConfiguration mStubMultiConfiguration; |
| 124 | |
| 125 | private IInvocationContext mStubInvocationMetadata; |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 126 | |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 127 | // The mock objects. |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 128 | private ITestDevice mMockDevice; |
| 129 | private ITargetPreparer mMockPreparer; |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 130 | private IBuildProvider mMockBuildProvider; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 131 | private IBuildInfo mMockBuildInfo; |
| 132 | private ITestInvocationListener mMockTestListener; |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 133 | private ITestSummaryListener mMockSummaryListener; |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 134 | private ILeveledLogOutput mMockLogger; |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 135 | private ILogSaver mMockLogSaver; |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 136 | private IDeviceRecovery mMockRecovery; |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 137 | private Capture<List<TestSummary>> mUriCapture; |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 138 | private ILogRegistry mMockLogRegistry; |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 139 | private IConfigurationFactory mMockConfigFactory; |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 140 | private IRescheduler mockRescheduler; |
Julien Desprez | 07fe153 | 2016-08-12 11:48:32 +0100 | [diff] [blame] | 141 | private DeviceDescriptor mFakeDescriptor; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 142 | |
| 143 | @Override |
| 144 | protected void setUp() throws Exception { |
| 145 | super.setUp(); |
| 146 | |
Brett Chabot | e7e335e | 2011-02-16 14:51:03 -0800 | [diff] [blame] | 147 | mStubConfiguration = new Configuration("foo", "bar"); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 148 | mStubMultiConfiguration = new Configuration("foo", "bar"); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 149 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 150 | mMockDevice = EasyMock.createMock(ITestDevice.class); |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 151 | mMockRecovery = EasyMock.createMock(IDeviceRecovery.class); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 152 | mMockPreparer = EasyMock.createMock(ITargetPreparer.class); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 153 | mMockBuildProvider = EasyMock.createMock(IBuildProvider.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 154 | |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 155 | // Use strict mocks here since the order of Listener calls is important |
| 156 | mMockTestListener = EasyMock.createStrictMock(ITestInvocationListener.class); |
| 157 | mMockSummaryListener = EasyMock.createStrictMock(ITestSummaryListener.class); |
Brett Chabot | 5dae872 | 2010-09-17 20:05:51 -0700 | [diff] [blame] | 158 | mMockBuildInfo = EasyMock.createMock(IBuildInfo.class); |
Brett Chabot | 35d50c6 | 2011-03-07 10:39:23 -0800 | [diff] [blame] | 159 | mMockLogger = EasyMock.createMock(ILeveledLogOutput.class); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 160 | mMockLogRegistry = EasyMock.createMock(ILogRegistry.class); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 161 | mMockLogSaver = EasyMock.createMock(ILogSaver.class); |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 162 | mMockConfigFactory = EasyMock.createMock(IConfigurationFactory.class); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 163 | mockRescheduler = EasyMock.createMock(IRescheduler.class); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 164 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 165 | mStubConfiguration.setDeviceRecovery(mMockRecovery); |
| 166 | mStubConfiguration.setTargetPreparer(mMockPreparer); |
| 167 | mStubConfiguration.setBuildProvider(mMockBuildProvider); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 168 | |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 169 | EasyMock.expect(mMockPreparer.isDisabled()).andStubReturn(false); |
| 170 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 171 | List<IDeviceConfiguration> deviceConfigs = new ArrayList<IDeviceConfiguration>(); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 172 | IDeviceConfiguration device1 = |
| 173 | new DeviceConfigurationHolder(ConfigurationDef.DEFAULT_DEVICE_NAME); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 174 | device1.addSpecificConfig(mMockRecovery); |
| 175 | device1.addSpecificConfig(mMockPreparer); |
| 176 | device1.addSpecificConfig(mMockBuildProvider); |
| 177 | deviceConfigs.add(device1); |
| 178 | mStubMultiConfiguration.setDeviceConfigList(deviceConfigs); |
| 179 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 180 | mStubConfiguration.setLogSaver(mMockLogSaver); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 181 | mStubMultiConfiguration.setLogSaver(mMockLogSaver); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 182 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 183 | List<ITestInvocationListener> listenerList = new ArrayList<ITestInvocationListener>(1); |
| 184 | listenerList.add(mMockTestListener); |
| 185 | listenerList.add(mMockSummaryListener); |
| 186 | mStubConfiguration.setTestInvocationListeners(listenerList); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 187 | mStubMultiConfiguration.setTestInvocationListeners(listenerList); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 188 | |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 189 | mStubConfiguration.setLogOutput(mMockLogger); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 190 | mStubMultiConfiguration.setLogOutput(mMockLogger); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 191 | EasyMock.expect(mMockDevice.getSerialNumber()).andStubReturn(SERIAL); |
Guang Zhu | 789a52b | 2014-01-17 14:27:01 -0800 | [diff] [blame] | 192 | EasyMock.expect(mMockDevice.getIDevice()).andStubReturn(null); |
Brett Chabot | f7ad156 | 2010-07-27 11:58:58 -0700 | [diff] [blame] | 193 | mMockDevice.setRecovery(mMockRecovery); |
Julien Desprez | 26bee8d | 2016-03-29 12:09:48 +0100 | [diff] [blame] | 194 | mMockDevice.preInvocationSetup((IBuildInfo)EasyMock.anyObject()); |
| 195 | EasyMock.expectLastCall().anyTimes(); |
| 196 | mMockDevice.postInvocationTearDown(); |
| 197 | EasyMock.expectLastCall().anyTimes(); |
Julien Desprez | 07fe153 | 2016-08-12 11:48:32 +0100 | [diff] [blame] | 198 | mFakeDescriptor = new DeviceDescriptor(SERIAL, false, DeviceAllocationState.Available, |
| 199 | "unknown", "unknown", "unknown", "unknown", "unknown"); |
| 200 | EasyMock.expect(mMockDevice.getDeviceDescriptor()).andStubReturn(mFakeDescriptor); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 201 | |
Jorge Gonzalez | 3777e32 | 2011-05-11 18:04:29 -0700 | [diff] [blame] | 202 | EasyMock.expect(mMockBuildInfo.getBuildId()).andStubReturn("1"); |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 203 | EasyMock.expect(mMockBuildInfo.getBuildAttributes()).andStubReturn(EMPTY_MAP); |
Brett Chabot | 2b79e0f | 2013-03-18 16:50:16 -0700 | [diff] [blame] | 204 | EasyMock.expect(mMockBuildInfo.getBuildBranch()).andStubReturn("branch"); |
| 205 | EasyMock.expect(mMockBuildInfo.getBuildFlavor()).andStubReturn("flavor"); |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 206 | EasyMock.expect(mMockBuildInfo.getProperties()).andStubReturn(new HashSet<>()); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 207 | |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 208 | // always expect logger initialization and cleanup calls |
| 209 | mMockLogRegistry.registerLogger(mMockLogger); |
| 210 | mMockLogger.init(); |
| 211 | mMockLogger.closeLog(); |
| 212 | mMockLogRegistry.unregisterLogger(); |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 213 | mUriCapture = new Capture<List<TestSummary>>(); |
Brett Chabot | bcb497c | 2010-08-07 17:07:36 -0700 | [diff] [blame] | 214 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 215 | mStubInvocationMetadata = new InvocationContext(); |
| 216 | mStubInvocationMetadata.addAllocatedDevice(ConfigurationDef.DEFAULT_DEVICE_NAME, |
| 217 | mMockDevice); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 218 | mStubInvocationMetadata.addDeviceBuildInfo(ConfigurationDef.DEFAULT_DEVICE_NAME, |
| 219 | mMockBuildInfo); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 220 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 221 | // create the BaseTestInvocation to test |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 222 | mTestInvocation = |
| 223 | new TestInvocation() { |
| 224 | @Override |
| 225 | ILogRegistry getLogRegistry() { |
| 226 | return mMockLogRegistry; |
| 227 | } |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 228 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 229 | @Override |
jdesprez | 85129dd | 2017-11-13 06:05:57 -0800 | [diff] [blame] | 230 | public IInvocationExecution createInvocationExec() { |
| 231 | return new InvocationExecution() { |
| 232 | @Override |
| 233 | protected IShardHelper createShardHelper() { |
| 234 | return new ShardHelper(); |
| 235 | } |
| 236 | }; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | @Override |
| 240 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 241 | // empty on purpose |
| 242 | } |
| 243 | }; |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Neal Nguyen | 2ceabaa | 2010-05-26 14:42:14 -0700 | [diff] [blame] | 246 | @Override |
| 247 | protected void tearDown() throws Exception { |
| 248 | super.tearDown(); |
| 249 | |
| 250 | } |
| 251 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 252 | /** |
| 253 | * Test the normal case invoke scenario with a {@link IRemoteTest}. |
| 254 | * <p/> |
| 255 | * Verifies that all external interfaces get notified as expected. |
| 256 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 257 | public void testInvoke_RemoteTest() throws Throwable { |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 258 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 259 | setupMockSuccessListeners(); |
Julien Desprez | 26bee8d | 2016-03-29 12:09:48 +0100 | [diff] [blame] | 260 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 261 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 262 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 263 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 264 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 265 | verifyMocks(test, mockRescheduler); |
| 266 | verifySummaryListener(); |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Test the normal case for multi invoke scenario with a {@link IRemoteTest}. |
| 271 | * <p/> |
| 272 | * Verifies that all external interfaces get notified as expected. |
| 273 | */ |
| 274 | public void testInvokeMulti_RemoteTest() throws Throwable { |
| 275 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 276 | setupMockSuccessListeners(); |
| 277 | |
| 278 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 279 | setupNormalInvoke(test); |
| 280 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 281 | mTestInvocation.invoke(mStubInvocationMetadata, mStubMultiConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 282 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 283 | verifySummaryListener(); |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * Test the normal case invoke scenario with an {@link ITestSummaryListener} masquerading as |
| 288 | * an {@link ITestInvocationListener}. |
| 289 | * <p/> |
| 290 | * Verifies that all external interfaces get notified as expected. |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 291 | */ |
Julien Desprez | 78fcda2 | 2016-06-16 17:35:11 +0100 | [diff] [blame] | 292 | public void testInvoke_twoSummary() throws Throwable { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 293 | |
| 294 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 295 | setupMockSuccessListeners(); |
| 296 | |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 297 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 298 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 299 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 300 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 301 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 302 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | /** |
| 306 | * Test the invoke scenario where build retrieve fails. |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 307 | * <p/> |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 308 | * An invocation will be started in this scenario. |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 309 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 310 | public void testInvoke_buildFailed() throws Throwable { |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 311 | BuildRetrievalError exception = new BuildRetrievalError("error", null, mMockBuildInfo); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 312 | EasyMock.expect(mMockBuildProvider.getBuild()).andThrow(exception); |
Julien Desprez | 949ba3a | 2016-11-28 15:18:32 +0000 | [diff] [blame] | 313 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(null); |
Brett Chabot | c992430 | 2011-06-30 16:48:01 -0700 | [diff] [blame] | 314 | setupMockFailureListeners(exception); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 315 | setupInvoke(); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 316 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Julien Desprez | 949ba3a | 2016-11-28 15:18:32 +0000 | [diff] [blame] | 317 | CommandOptions cmdOptions = new CommandOptions(); |
| 318 | final String expectedTestTag = "TEST_TAG"; |
| 319 | cmdOptions.setTestTag(expectedTestTag); |
| 320 | mStubConfiguration.setCommandOptions(cmdOptions); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 321 | mStubConfiguration.setTest(test); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 322 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
| 323 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(2); |
| 324 | mMockDevice.clearLogcat(); |
| 325 | EasyMock.expectLastCall().times(2); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 326 | mMockLogRegistry.unregisterLogger(); |
| 327 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 328 | mMockLogger.closeLog(); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 329 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 330 | replayMocks(test, mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 331 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 332 | verifyMocks(test, mockRescheduler); |
Julien Desprez | 949ba3a | 2016-11-28 15:18:32 +0000 | [diff] [blame] | 333 | // invocation test tag was updated. |
| 334 | assertEquals(expectedTestTag, mStubInvocationMetadata.getTestTag()); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /** |
Brett Chabot | dd21ddf | 2010-06-07 14:16:19 -0700 | [diff] [blame] | 338 | * Test the invoke scenario where there is no build to test. |
| 339 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 340 | public void testInvoke_noBuild() throws Throwable { |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 341 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(null); |
Brett Chabot | ccfda2e | 2011-02-09 14:39:59 -0800 | [diff] [blame] | 342 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 343 | mStubConfiguration.setTest(test); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 344 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 345 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 346 | setupInvoke(); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 347 | replayMocks(test, mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 348 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 349 | verifyMocks(test); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 352 | /** |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 353 | * Test the invoke scenario where there is no build to test for a {@link IRetriableTest}. |
| 354 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 355 | public void testInvoke_noBuildRetry() throws Throwable { |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 356 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(null); |
| 357 | |
| 358 | IRetriableTest test = EasyMock.createMock(IRetriableTest.class); |
| 359 | EasyMock.expect(test.isRetriable()).andReturn(Boolean.TRUE); |
| 360 | |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 361 | EasyMock.expect(mockRescheduler.rescheduleCommand()).andReturn(EasyMock.anyBoolean()); |
| 362 | |
| 363 | mStubConfiguration.setTest(test); |
| 364 | mStubConfiguration.getCommandOptions().setLoopMode(false); |
| 365 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 366 | EasyMock.expectLastCall().times(1); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 367 | setupInvoke(); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 368 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 369 | replayMocks(test); |
| 370 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 371 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Eric Rowe | f85ffac | 2012-10-03 12:56:12 -0700 | [diff] [blame] | 372 | EasyMock.verify(mockRescheduler); |
| 373 | verifyMocks(test); |
| 374 | } |
| 375 | |
| 376 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 377 | * Test the{@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 378 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 379 | * where the test is a {@link IDeviceTest} |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 380 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 381 | public void testInvoke_deviceTest() throws Throwable { |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 382 | DeviceConfigTest mockDeviceTest = EasyMock.createMock(DeviceConfigTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 383 | mStubConfiguration.setTest(mockDeviceTest); |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 384 | mockDeviceTest.setDevice(mMockDevice); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 385 | mockDeviceTest.run((ITestInvocationListener)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 386 | setupMockSuccessListeners(); |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 387 | setupNormalInvoke(mockDeviceTest); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 388 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 389 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 390 | verifyMocks(mockDeviceTest, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 391 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Test the invoke scenario where test run throws {@link IllegalArgumentException} |
| 396 | * |
| 397 | * @throws Exception if unexpected error occurs |
| 398 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 399 | public void testInvoke_testFail() throws Throwable { |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 400 | IllegalArgumentException exception = new IllegalArgumentException(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 401 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 402 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 403 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 404 | setupMockFailureListeners(exception); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 405 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | 7e5f8ac | 2010-05-17 12:27:56 -0700 | [diff] [blame] | 406 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 407 | EasyMock.replay(mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 408 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 409 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 410 | fail("IllegalArgumentException was not rethrown"); |
| 411 | } catch (IllegalArgumentException e) { |
| 412 | // expected |
| 413 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 414 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 415 | verifySummaryListener(); |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /** |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 419 | * Test the invoke scenario where test run throws {@link FatalHostError} |
| 420 | * |
| 421 | * @throws Exception if unexpected error occurs |
| 422 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 423 | public void testInvoke_fatalError() throws Throwable { |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 424 | FatalHostError exception = new FatalHostError("error"); |
| 425 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 426 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 427 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 428 | setupMockFailureListeners(exception); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 429 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 430 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 431 | EasyMock.replay(mockRescheduler); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 432 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 433 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 434 | fail("FatalHostError was not rethrown"); |
| 435 | } catch (FatalHostError e) { |
| 436 | // expected |
| 437 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 438 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 439 | verifySummaryListener(); |
Brett Chabot | a17af5d | 2010-08-23 13:51:17 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 443 | * Test the invoke scenario where test run throws {@link DeviceNotAvailableException} |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 444 | * |
| 445 | * @throws Exception if unexpected error occurs |
| 446 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 447 | public void testInvoke_deviceNotAvail() throws Throwable { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 448 | DeviceNotAvailableException exception = new DeviceNotAvailableException("ERROR", SERIAL); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 449 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 450 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 451 | EasyMock.expectLastCall().andThrow(exception); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 452 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 453 | EasyMock.expectLastCall(); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 454 | setupMockFailureListeners(exception); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 455 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 456 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 457 | EasyMock.replay(mockRescheduler); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 458 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 459 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 460 | fail("DeviceNotAvailableException not thrown"); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 461 | } catch (DeviceNotAvailableException e) { |
| 462 | // expected |
| 463 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 464 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 465 | verifySummaryListener(); |
Brett Chabot | 3759c85 | 2010-07-13 17:36:31 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 469 | * Test the invoke scenario where preparer throws {@link BuildError} |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 470 | * |
| 471 | * @throws Exception if unexpected error occurs |
| 472 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 473 | public void testInvoke_buildError() throws Throwable { |
Julien Desprez | 07fe153 | 2016-08-12 11:48:32 +0100 | [diff] [blame] | 474 | BuildError exception = new BuildError("error", mFakeDescriptor); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 475 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 476 | mStubConfiguration.setTest(test); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 477 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 478 | |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 479 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 480 | EasyMock.expectLastCall().andThrow(exception); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 481 | setupMockFailureListeners(exception); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 482 | EasyMock.expect(mMockDevice.getBugreport()).andReturn(EMPTY_STREAM_SOURCE); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 483 | setupInvokeWithBuild(); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 484 | replayMocks(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 485 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 486 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 487 | verifyMocks(test, mockRescheduler); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 488 | verifySummaryListener(); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 491 | /** |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 492 | * Test the invoke scenario for a {@link IResumableTest}. |
| 493 | * |
| 494 | * @throws Exception if unexpected error occurs |
| 495 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 496 | public void testInvoke_resume() throws Throwable { |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 497 | IResumableTest resumableTest = EasyMock.createMock(IResumableTest.class); |
| 498 | mStubConfiguration.setTest(resumableTest); |
| 499 | ITestInvocationListener resumeListener = EasyMock.createStrictMock( |
| 500 | ITestInvocationListener.class); |
| 501 | mStubConfiguration.setTestInvocationListener(resumeListener); |
| 502 | |
| 503 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 504 | resumeListener.invocationStarted(mStubInvocationMetadata); |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 505 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 506 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 507 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 508 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(""); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 509 | mMockDevice.startLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 510 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 511 | |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 512 | resumableTest.run((ITestInvocationListener) EasyMock.anyObject()); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 513 | EasyMock.expectLastCall().andThrow(new DeviceNotAvailableException("ERROR", SERIAL)); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 514 | EasyMock.expect(resumableTest.isResumable()).andReturn(Boolean.TRUE); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 515 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 516 | EasyMock.expectLastCall(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 517 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 518 | mMockDevice.clearLogcat(); |
| 519 | EasyMock.expectLastCall().times(3); |
| 520 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
| 521 | EasyMock.expect( |
| 522 | mMockLogSaver.saveLogData( |
| 523 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 524 | EasyMock.eq(LogDataType.LOGCAT), |
| 525 | (InputStream) EasyMock.anyObject())) |
| 526 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 527 | EasyMock.expect( |
| 528 | mMockLogSaver.saveLogData( |
| 529 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 530 | EasyMock.eq(LogDataType.LOGCAT), |
| 531 | (InputStream) EasyMock.anyObject())) |
| 532 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 533 | EasyMock.expect( |
| 534 | mMockLogSaver.saveLogData( |
| 535 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 536 | EasyMock.eq(LogDataType.LOGCAT), |
| 537 | (InputStream) EasyMock.anyObject())) |
| 538 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 539 | EasyMock.expect( |
| 540 | mMockLogSaver.saveLogData( |
| 541 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 542 | EasyMock.eq(LogDataType.TEXT), |
| 543 | (InputStream) EasyMock.anyObject())) |
| 544 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 545 | resumeListener.testLog( |
| 546 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 547 | EasyMock.eq(LogDataType.LOGCAT), |
| 548 | (InputStreamSource) EasyMock.anyObject()); |
| 549 | resumeListener.testLog( |
| 550 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 551 | EasyMock.eq(LogDataType.LOGCAT), |
| 552 | (InputStreamSource) EasyMock.anyObject()); |
| 553 | resumeListener.testLog( |
| 554 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 555 | EasyMock.eq(LogDataType.LOGCAT), |
| 556 | (InputStreamSource) EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 557 | resumeListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 558 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 559 | |
| 560 | // just return same build and logger for simplicity |
| 561 | EasyMock.expect(mMockBuildInfo.clone()).andReturn(mMockBuildInfo); |
| 562 | EasyMock.expect(mMockLogger.clone()).andReturn(mMockLogger); |
| 563 | IRescheduler mockRescheduler = EasyMock.createMock(IRescheduler.class); |
| 564 | Capture<IConfiguration> capturedConfig = new Capture<IConfiguration>(); |
| 565 | EasyMock.expect(mockRescheduler.scheduleConfig(EasyMock.capture(capturedConfig))) |
| 566 | .andReturn(Boolean.TRUE); |
jdesprez | 58e413e | 2018-03-09 10:30:17 -0800 | [diff] [blame^] | 567 | // When resuming the original build provider is still going to handle the clean up. |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 568 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
jdesprez | 58e413e | 2018-03-09 10:30:17 -0800 | [diff] [blame^] | 569 | EasyMock.expectLastCall().times(4); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 570 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 571 | mMockDevice.stopLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 572 | |
Brett Chabot | 35d50c6 | 2011-03-07 10:39:23 -0800 | [diff] [blame] | 573 | mMockLogger.init(); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 574 | mMockLogSaver.invocationStarted(mStubInvocationMetadata); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 575 | // now set resumed invocation expectations |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 576 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 577 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
Brett Chabot | eba1fd6 | 2011-09-13 17:17:45 -0700 | [diff] [blame] | 578 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 579 | mMockBuildInfo.setTestTag(EasyMock.eq("stub")); |
| 580 | EasyMock.expectLastCall().times(2); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 581 | mMockDevice.startLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 582 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 583 | mMockLogSaver.invocationStarted(mStubInvocationMetadata); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 584 | mMockDevice.setRecovery(mMockRecovery); |
Brett Chabot | ad12358 | 2011-02-09 18:26:40 -0800 | [diff] [blame] | 585 | resumableTest.run((ITestInvocationListener)EasyMock.anyObject()); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 586 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 587 | mMockDevice.clearLogcat(); |
| 588 | EasyMock.expectLastCall().times(3); |
| 589 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
| 590 | EasyMock.expect( |
| 591 | mMockLogSaver.saveLogData( |
| 592 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 593 | EasyMock.eq(LogDataType.LOGCAT), |
| 594 | (InputStream) EasyMock.anyObject())) |
| 595 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 596 | EasyMock.expect( |
| 597 | mMockLogSaver.saveLogData( |
| 598 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 599 | EasyMock.eq(LogDataType.LOGCAT), |
| 600 | (InputStream) EasyMock.anyObject())) |
| 601 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 602 | EasyMock.expect( |
| 603 | mMockLogSaver.saveLogData( |
| 604 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 605 | EasyMock.eq(LogDataType.LOGCAT), |
| 606 | (InputStream) EasyMock.anyObject())) |
| 607 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 608 | EasyMock.expect( |
| 609 | mMockLogSaver.saveLogData( |
| 610 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 611 | EasyMock.eq(LogDataType.TEXT), |
| 612 | (InputStream) EasyMock.anyObject())) |
| 613 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 614 | resumeListener.testLog( |
| 615 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 616 | EasyMock.eq(LogDataType.LOGCAT), |
| 617 | (InputStreamSource) EasyMock.anyObject()); |
| 618 | resumeListener.testLog( |
| 619 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 620 | EasyMock.eq(LogDataType.LOGCAT), |
| 621 | (InputStreamSource) EasyMock.anyObject()); |
| 622 | resumeListener.testLog( |
| 623 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 624 | EasyMock.eq(LogDataType.LOGCAT), |
| 625 | (InputStreamSource) EasyMock.anyObject()); |
| 626 | resumeListener.testLog( |
| 627 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 628 | EasyMock.eq(LogDataType.TEXT), |
| 629 | (InputStreamSource) EasyMock.anyObject()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 630 | resumeListener.invocationEnded(EasyMock.anyLong()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 631 | mMockLogSaver.invocationEnded(EasyMock.anyLong()); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 632 | EasyMock.expect(resumeListener.getSummary()).andReturn(null); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 633 | mMockLogger.closeLog(); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 634 | EasyMock.expectLastCall().times(3); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 635 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 636 | mMockDevice.stopLogcat(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 637 | EasyMock.replay(mockRescheduler, resumeListener, resumableTest, mMockPreparer, |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 638 | mMockBuildProvider, mMockLogger, mMockLogSaver, mMockDevice, mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 639 | |
| 640 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 641 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 642 | fail("DeviceNotAvailableException not thrown"); |
| 643 | } catch (DeviceNotAvailableException e) { |
| 644 | // expect |
| 645 | } |
| 646 | // now call again, and expect invocation to be resumed properly |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 647 | mTestInvocation.invoke(mStubInvocationMetadata, capturedConfig.getValue(), mockRescheduler); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 648 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 649 | EasyMock.verify(mockRescheduler, resumeListener, resumableTest, mMockPreparer, |
| 650 | mMockBuildProvider, mMockLogger, mMockLogSaver, mMockDevice, mMockBuildInfo); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | /** |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 654 | * Test the invoke scenario for a {@link IRetriableTest}. |
| 655 | * |
| 656 | * @throws Exception if unexpected error occurs |
| 657 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 658 | public void testInvoke_retry() throws Throwable { |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 659 | AssertionError exception = new AssertionError(); |
| 660 | IRetriableTest test = EasyMock.createMock(IRetriableTest.class); |
| 661 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 662 | EasyMock.expectLastCall().andThrow(exception); |
| 663 | EasyMock.expect(test.isRetriable()).andReturn(Boolean.TRUE); |
| 664 | mStubConfiguration.getCommandOptions().setLoopMode(false); |
| 665 | IRescheduler mockRescheduler = EasyMock.createMock(IRescheduler.class); |
| 666 | EasyMock.expect(mockRescheduler.rescheduleCommand()).andReturn(EasyMock.anyBoolean()); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 667 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 668 | setupMockFailureListeners(exception); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 669 | setupNormalInvoke(test); |
| 670 | EasyMock.replay(mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 671 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 672 | verifyMocks(test, mockRescheduler); |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 673 | verifySummaryListener(); |
| 674 | } |
| 675 | |
| 676 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 677 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 678 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 679 | * when a {@link ITargetCleaner} is part of the config. |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 680 | */ |
| 681 | public void testInvoke_tearDown() throws Throwable { |
| 682 | IRemoteTest test = EasyMock.createNiceMock(IRemoteTest.class); |
| 683 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 684 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 685 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 686 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, null); |
| 687 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 688 | setupMockSuccessListeners(); |
| 689 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 690 | EasyMock.replay(mockCleaner, mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 691 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 692 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 693 | verifySummaryListener(); |
| 694 | } |
| 695 | |
| 696 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 697 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 698 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 699 | * 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] | 700 | * {@link DeviceNotAvailableException}. |
| 701 | */ |
| 702 | public void testInvoke_tearDown_deviceNotAvail() throws Throwable { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 703 | DeviceNotAvailableException exception = new DeviceNotAvailableException("ERROR", SERIAL); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 704 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 705 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 706 | EasyMock.expectLastCall().andThrow(exception); |
| 707 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 708 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 709 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
Guang Zhu | 36c56a2 | 2014-12-30 19:56:00 -0800 | [diff] [blame] | 710 | EasyMock.expectLastCall(); |
| 711 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, exception); |
| 712 | EasyMock.expectLastCall(); |
Julien Desprez | 70488e8 | 2016-02-05 11:28:34 +0000 | [diff] [blame] | 713 | mMockDevice.setRecoveryMode(RecoveryMode.NONE); |
| 714 | EasyMock.expectLastCall(); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 715 | EasyMock.replay(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 716 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 717 | setupMockFailureListeners(exception); |
| 718 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
| 719 | setupNormalInvoke(test); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 720 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 721 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 722 | fail("DeviceNotAvailableException not thrown"); |
| 723 | } catch (DeviceNotAvailableException e) { |
| 724 | // expected |
| 725 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 726 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 727 | verifySummaryListener(); |
| 728 | } |
| 729 | |
| 730 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 731 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 732 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 733 | * 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] | 734 | * {@link RuntimeException}. |
| 735 | */ |
| 736 | public void testInvoke_tearDown_runtime() throws Throwable { |
| 737 | RuntimeException exception = new RuntimeException(); |
| 738 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 739 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 740 | EasyMock.expectLastCall().andThrow(exception); |
| 741 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 742 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 743 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 744 | // tearDown should be called |
| 745 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, exception); |
| 746 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 747 | setupMockFailureListeners(exception); |
| 748 | mMockBuildProvider.buildNotTested(mMockBuildInfo); |
| 749 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 750 | EasyMock.replay(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 751 | try { |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 752 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 753 | fail("RuntimeException not thrown"); |
| 754 | } catch (RuntimeException e) { |
| 755 | // expected |
| 756 | } |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 757 | verifyMocks(mockCleaner, mockRescheduler); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 758 | verifySummaryListener(); |
| 759 | } |
| 760 | |
| 761 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 762 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 763 | * ITestInvocationListener[])} scenario |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 764 | * when there is {@link ITestInvocationListener} which implements the {@link ILogSaverListener} |
| 765 | * interface. |
| 766 | */ |
| 767 | public void testInvoke_logFileSaved() throws Throwable { |
| 768 | List<ITestInvocationListener> listenerList = |
| 769 | mStubConfiguration.getTestInvocationListeners(); |
| 770 | ILogSaverListener logSaverListener = EasyMock.createMock(ILogSaverListener.class); |
| 771 | listenerList.add(logSaverListener); |
| 772 | mStubConfiguration.setTestInvocationListeners(listenerList); |
| 773 | |
| 774 | logSaverListener.setLogSaver(mMockLogSaver); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 775 | logSaverListener.invocationStarted(mStubInvocationMetadata); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 776 | logSaverListener.testLog( |
| 777 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 778 | EasyMock.eq(LogDataType.LOGCAT), |
| 779 | (InputStreamSource) EasyMock.anyObject()); |
| 780 | logSaverListener.testLogSaved( |
| 781 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 782 | EasyMock.eq(LogDataType.LOGCAT), |
| 783 | (InputStreamSource) EasyMock.anyObject(), |
| 784 | (LogFile) EasyMock.anyObject()); |
| 785 | logSaverListener.testLog( |
| 786 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 787 | EasyMock.eq(LogDataType.LOGCAT), |
| 788 | (InputStreamSource) EasyMock.anyObject()); |
| 789 | logSaverListener.testLogSaved( |
| 790 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 791 | EasyMock.eq(LogDataType.LOGCAT), |
| 792 | (InputStreamSource) EasyMock.anyObject(), |
| 793 | (LogFile) EasyMock.anyObject()); |
| 794 | logSaverListener.testLog( |
| 795 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 796 | EasyMock.eq(LogDataType.LOGCAT), |
| 797 | (InputStreamSource) EasyMock.anyObject()); |
| 798 | logSaverListener.testLogSaved( |
| 799 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 800 | EasyMock.eq(LogDataType.LOGCAT), |
| 801 | (InputStreamSource) EasyMock.anyObject(), |
| 802 | (LogFile) EasyMock.anyObject()); |
| 803 | logSaverListener.testLog( |
| 804 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 805 | EasyMock.eq(LogDataType.TEXT), |
| 806 | (InputStreamSource) EasyMock.anyObject()); |
| 807 | logSaverListener.testLogSaved( |
| 808 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 809 | EasyMock.eq(LogDataType.TEXT), |
| 810 | (InputStreamSource) EasyMock.anyObject(), |
| 811 | (LogFile) EasyMock.anyObject()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 812 | logSaverListener.invocationEnded(EasyMock.anyLong()); |
| 813 | EasyMock.expect(logSaverListener.getSummary()).andReturn(mSummary); |
| 814 | |
| 815 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 816 | setupMockSuccessListeners(); |
| 817 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 818 | setupNormalInvoke(test); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 819 | EasyMock.replay(logSaverListener, mockRescheduler); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 820 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | 2040ac0 | 2016-03-21 18:05:30 +0000 | [diff] [blame] | 821 | verifyMocks(test, logSaverListener, mockRescheduler); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 822 | assertEquals(2, mUriCapture.getValue().size()); |
| 823 | } |
| 824 | |
| 825 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 826 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
| 827 | * ITestInvocationListener[])} |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 828 | * scenario with {@link IStrictShardableTest} when a shard index is given. |
| 829 | */ |
| 830 | public void testInvoke_strictShardableTest_withShardIndex() throws Throwable { |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 831 | mTestInvocation = |
| 832 | new TestInvocation() { |
| 833 | @Override |
| 834 | ILogRegistry getLogRegistry() { |
| 835 | return mMockLogRegistry; |
| 836 | } |
| 837 | |
| 838 | @Override |
jdesprez | 85129dd | 2017-11-13 06:05:57 -0800 | [diff] [blame] | 839 | public IInvocationExecution createInvocationExec() { |
| 840 | return new InvocationExecution() { |
| 841 | @Override |
| 842 | protected IShardHelper createShardHelper() { |
| 843 | return new StrictShardHelper(); |
| 844 | } |
| 845 | }; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | @Override |
| 849 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 850 | // empty on purpose |
| 851 | } |
| 852 | }; |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 853 | String[] commandLine = {"config", "arg"}; |
| 854 | int shardCount = 10; |
| 855 | int shardIndex = 5; |
| 856 | IStrictShardableTest test = EasyMock.createMock(IStrictShardableTest.class); |
| 857 | IRemoteTest testShard = EasyMock.createMock(IRemoteTest.class); |
| 858 | mStubConfiguration.setTest(test); |
| 859 | mStubConfiguration.setCommandLine(commandLine); |
| 860 | mStubConfiguration.getCommandOptions().setShardCount(shardCount); |
| 861 | mStubConfiguration.getCommandOptions().setShardIndex(shardIndex); |
| 862 | |
| 863 | setupInvokeWithBuild(); |
| 864 | setupMockSuccessListeners(); |
| 865 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 866 | mMockBuildInfo.addBuildAttribute("command_line_args", "config arg"); |
| 867 | mMockBuildInfo.addBuildAttribute("shard_count", "10"); |
| 868 | mMockBuildInfo.addBuildAttribute("shard_index", "5"); |
| 869 | EasyMock.expect(test.getTestShard(shardCount, shardIndex)).andReturn(testShard); |
Julien Desprez | 8427fc2 | 2016-05-31 15:56:01 +0100 | [diff] [blame] | 870 | testShard.run((ITestInvocationListener)EasyMock.anyObject()); |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 871 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 872 | replayMocks(test, testShard); |
| 873 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 874 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 875 | |
| 876 | verifyMocks(test, testShard); |
| 877 | } |
| 878 | |
| 879 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 880 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
| 881 | * ITestInvocationListener[])} |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 882 | * scenario with non-{@link IStrictShardableTest} when shard index 0 is given. |
| 883 | */ |
| 884 | public void testInvoke_nonStrictShardableTest_withShardIndexZero() throws Throwable { |
| 885 | String[] commandLine = {"config", "arg"}; |
| 886 | int shardCount = 10; |
| 887 | int shardIndex = 0; |
| 888 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
| 889 | mStubConfiguration.setTest(test); |
| 890 | mStubConfiguration.setCommandLine(commandLine); |
| 891 | mStubConfiguration.getCommandOptions().setShardCount(shardCount); |
| 892 | mStubConfiguration.getCommandOptions().setShardIndex(shardIndex); |
| 893 | |
| 894 | setupInvokeWithBuild(); |
| 895 | setupMockSuccessListeners(); |
| 896 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 897 | mMockBuildInfo.addBuildAttribute("command_line_args", "config arg"); |
| 898 | mMockBuildInfo.addBuildAttribute("shard_count", "10"); |
| 899 | mMockBuildInfo.addBuildAttribute("shard_index", "0"); |
| 900 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 901 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 902 | replayMocks(test); |
| 903 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 904 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 905 | |
| 906 | verifyMocks(test); |
| 907 | } |
| 908 | |
| 909 | /** |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 910 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
| 911 | * ITestInvocationListener[])} |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 912 | * scenario with non-{@link IStrictShardableTest} when a shard index non-0 is given. |
| 913 | */ |
| 914 | public void testInvoke_nonStrictShardableTest_withShardIndexNonZero() throws Throwable { |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 915 | mTestInvocation = |
| 916 | new TestInvocation() { |
| 917 | @Override |
| 918 | ILogRegistry getLogRegistry() { |
| 919 | return mMockLogRegistry; |
| 920 | } |
| 921 | |
| 922 | @Override |
jdesprez | 85129dd | 2017-11-13 06:05:57 -0800 | [diff] [blame] | 923 | public IInvocationExecution createInvocationExec() { |
| 924 | return new InvocationExecution() { |
| 925 | @Override |
| 926 | protected IShardHelper createShardHelper() { |
| 927 | return new StrictShardHelper(); |
| 928 | } |
| 929 | }; |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 930 | } |
| 931 | |
| 932 | @Override |
| 933 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 934 | // empty on purpose |
| 935 | } |
| 936 | }; |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 937 | String[] commandLine = {"config", "arg"}; |
| 938 | int shardCount = 10; |
| 939 | int shardIndex = 1; |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 940 | IStrictShardableTest shardableTest = EasyMock.createMock(IStrictShardableTest.class); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 941 | IRemoteTest test = EasyMock.createMock(IRemoteTest.class); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 942 | EasyMock.expect(shardableTest.getTestShard(10, 1)).andReturn(test); |
| 943 | test.run((ITestInvocationListener)EasyMock.anyObject()); |
| 944 | EasyMock.expectLastCall(); |
| 945 | mStubConfiguration.setTest(shardableTest); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 946 | mStubConfiguration.setCommandLine(commandLine); |
| 947 | mStubConfiguration.getCommandOptions().setShardCount(shardCount); |
| 948 | mStubConfiguration.getCommandOptions().setShardIndex(shardIndex); |
| 949 | |
| 950 | setupInvokeWithBuild(); |
| 951 | setupMockSuccessListeners(); |
| 952 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 953 | mMockBuildInfo.addBuildAttribute("command_line_args", "config arg"); |
| 954 | mMockBuildInfo.addBuildAttribute("shard_count", "10"); |
| 955 | mMockBuildInfo.addBuildAttribute("shard_index", "1"); |
| 956 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 957 | replayMocks(shardableTest, test); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 958 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 959 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 960 | |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 961 | verifyMocks(shardableTest, test); |
Moon Kim | 7bc070b | 2016-07-14 12:29:42 -0700 | [diff] [blame] | 962 | } |
| 963 | |
| 964 | /** |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 965 | * Test the test-tag is set when the IBuildInfo's test-tag is not. |
| 966 | */ |
| 967 | public void testInvoke_testtag() throws Throwable { |
| 968 | String[] commandLine = {"run", "empty"}; |
| 969 | mStubConfiguration.setCommandLine(commandLine); |
| 970 | mStubConfiguration.getCommandOptions().setTestTag("not-default"); |
| 971 | |
| 972 | setupInvoke(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 973 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 974 | mMockDevice.clearLogcat(); |
| 975 | EasyMock.expectLastCall().times(3); |
| 976 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 977 | mMockBuildInfo.setDeviceSerial(SERIAL); |
| 978 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 979 | EasyMock.expectLastCall().times(2); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 980 | setupMockSuccessListeners(); |
| 981 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 982 | mMockBuildInfo.addBuildAttribute("command_line_args", "run empty"); |
| 983 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 984 | // Default build is "stub" so we set the test-tag |
| 985 | mMockBuildInfo.setTestTag(EasyMock.eq("not-default")); |
| 986 | EasyMock.expectLastCall(); |
| 987 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn("stub"); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 988 | mMockLogRegistry.unregisterLogger(); |
| 989 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 990 | mMockLogger.closeLog(); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 991 | replayMocks(); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 992 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 993 | verifyMocks(); |
| 994 | } |
| 995 | |
| 996 | /** |
| 997 | * Test the test-tag of the IBuildInfo is not modified when the CommandOption default test-tag |
| 998 | * is not modified. |
| 999 | */ |
| 1000 | public void testInvoke_testtag_notset() throws Throwable { |
| 1001 | String[] commandLine = {"run", "empty"}; |
| 1002 | mStubConfiguration.setCommandLine(commandLine); |
| 1003 | setupInvoke(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1004 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 1005 | mMockDevice.clearLogcat(); |
| 1006 | EasyMock.expectLastCall().times(3); |
| 1007 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1008 | mMockBuildInfo.setDeviceSerial(SERIAL); |
| 1009 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 1010 | EasyMock.expectLastCall().times(2); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1011 | setupMockSuccessListeners(); |
| 1012 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 1013 | mMockBuildInfo.addBuildAttribute("command_line_args", "run empty"); |
| 1014 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 1015 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn("buildprovidertesttag"); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 1016 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 1017 | mMockLogRegistry.unregisterLogger(); |
| 1018 | mMockLogger.closeLog(); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1019 | replayMocks(); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 1020 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1021 | verifyMocks(); |
| 1022 | } |
| 1023 | |
| 1024 | /** |
| 1025 | * Test the test-tag of the IBuildInfo is not set and Command Option is not set either. |
| 1026 | * A default 'stub' test-tag is set to ensure reporting is done. |
| 1027 | */ |
| 1028 | public void testInvoke_notesttag() throws Throwable { |
| 1029 | String[] commandLine = {"run", "empty"}; |
| 1030 | mStubConfiguration.setCommandLine(commandLine); |
| 1031 | setupInvoke(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1032 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 1033 | mMockDevice.clearLogcat(); |
| 1034 | EasyMock.expectLastCall().times(3); |
| 1035 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1036 | mMockBuildInfo.setDeviceSerial(SERIAL); |
| 1037 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 1038 | EasyMock.expectLastCall().times(2); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1039 | setupMockSuccessListeners(); |
| 1040 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 1041 | mMockBuildInfo.addBuildAttribute("command_line_args", "run empty"); |
| 1042 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 1043 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(null); |
| 1044 | mMockBuildInfo.setTestTag(EasyMock.eq("stub")); |
| 1045 | EasyMock.expectLastCall(); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 1046 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 1047 | mMockLogRegistry.unregisterLogger(); |
| 1048 | mMockLogger.closeLog(); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1049 | replayMocks(); |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 1050 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1051 | verifyMocks(); |
| 1052 | } |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 1053 | |
| 1054 | /** |
| 1055 | * Helper tests class to expose all the interfaces needed for the tests. |
| 1056 | */ |
| 1057 | private interface IFakeBuildProvider extends IDeviceBuildProvider, IInvocationContextReceiver { |
| 1058 | } |
| 1059 | |
| 1060 | /** |
| 1061 | * Test the injection of test-tag from TestInvocation to the build provider via the |
| 1062 | * {@link IInvocationContextReceiver}. |
| 1063 | */ |
| 1064 | public void testInvoke_buildProviderNeedTestTag() throws Throwable { |
| 1065 | final String testTag = "THISISTHETAG"; |
| 1066 | String[] commandLine = {"run", "empty"}; |
| 1067 | mStubConfiguration.setCommandLine(commandLine); |
| 1068 | ICommandOptions commandOption = new CommandOptions(); |
| 1069 | commandOption.setTestTag(testTag); |
| 1070 | IFakeBuildProvider mockProvider = EasyMock.createMock(IFakeBuildProvider.class); |
| 1071 | mStubConfiguration.setBuildProvider(mockProvider); |
| 1072 | mStubConfiguration.setCommandOptions(commandOption); |
| 1073 | setupInvoke(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1074 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 1075 | mMockDevice.clearLogcat(); |
| 1076 | EasyMock.expectLastCall().times(3); |
| 1077 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 1078 | mMockBuildInfo.setDeviceSerial(SERIAL); |
| 1079 | setupMockSuccessListeners(); |
| 1080 | mMockBuildInfo.addBuildAttribute("command_line_args", "run empty"); |
| 1081 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
| 1082 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(null); |
| 1083 | // Validate proper tag is set on the build. |
| 1084 | mMockBuildInfo.setTestTag(EasyMock.eq(testTag)); |
| 1085 | mockProvider.setInvocationContext((IInvocationContext)EasyMock.anyObject()); |
| 1086 | EasyMock.expect(mockProvider.getBuild(mMockDevice)).andReturn(mMockBuildInfo); |
| 1087 | mockProvider.cleanUp(mMockBuildInfo); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 1088 | EasyMock.expectLastCall().times(2); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 1089 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 1090 | mMockLogRegistry.unregisterLogger(); |
| 1091 | mMockLogger.closeLog(); |
| 1092 | |
Julien Desprez | aa9ea85 | 2016-11-25 10:56:35 +0000 | [diff] [blame] | 1093 | replayMocks(mockProvider); |
| 1094 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 1095 | verifyMocks(mockProvider); |
| 1096 | } |
| 1097 | |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1098 | /** |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 1099 | * Set up expected conditions for normal run up to the part where tests are run. |
| 1100 | * |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1101 | * @param test the {@link Test} to use. |
| 1102 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1103 | private void setupNormalInvoke(IRemoteTest test) throws Throwable { |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 1104 | setupInvokeWithBuild(); |
Brett Chabot | b1052c2 | 2011-01-12 19:44:23 -0800 | [diff] [blame] | 1105 | mStubConfiguration.setTest(test); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 1106 | mStubMultiConfiguration.setTest(test); |
Brett Chabot | fe88a15 | 2010-08-02 17:52:59 -0700 | [diff] [blame] | 1107 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
Brett Chabot | c8b709f | 2011-09-02 09:04:22 -0700 | [diff] [blame] | 1108 | |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1109 | mMockPreparer.setUp(mMockDevice, mMockBuildInfo); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 1110 | replayMocks(test); |
| 1111 | } |
| 1112 | |
| 1113 | /** |
| 1114 | * Set up expected calls that occur on every invoke, regardless of result |
| 1115 | */ |
| 1116 | private void setupInvoke() { |
Moon Kim | 80553c5 | 2014-09-15 13:45:40 -0700 | [diff] [blame] | 1117 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 1118 | mMockDevice.setOptions((TestDeviceOptions)EasyMock.anyObject()); |
| 1119 | mMockDevice.startLogcat(); |
Guang Zhu | 0a1c63d | 2015-01-02 11:03:38 -0800 | [diff] [blame] | 1120 | mMockDevice.clearLastConnectedWifiNetwork(); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 1121 | mMockDevice.stopLogcat(); |
| 1122 | } |
| 1123 | |
| 1124 | /** |
| 1125 | * Set up expected calls that occur on every invoke that gets a valid build |
| 1126 | */ |
| 1127 | private void setupInvokeWithBuild() { |
| 1128 | setupInvoke(); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1129 | EasyMock.expect(mMockDevice.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(3); |
| 1130 | mMockDevice.clearLogcat(); |
| 1131 | EasyMock.expectLastCall().times(3); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1132 | |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1133 | EasyMock.expect(mMockLogger.getLog()).andReturn(EMPTY_STREAM_SOURCE); |
Brett Chabot | 4455637 | 2014-03-19 19:07:15 -0700 | [diff] [blame] | 1134 | mMockBuildInfo.setDeviceSerial(SERIAL); |
Brett Chabot | 66d8757 | 2010-11-01 19:54:59 -0700 | [diff] [blame] | 1135 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 1136 | EasyMock.expectLastCall().anyTimes(); |
Julien Desprez | f7f32c9 | 2016-07-27 10:07:50 +0100 | [diff] [blame] | 1137 | mMockBuildInfo.setTestTag(EasyMock.eq("stub")); |
| 1138 | EasyMock.expectLastCall(); |
| 1139 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(""); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 1140 | |
| 1141 | mMockLogRegistry.unregisterLogger(); |
| 1142 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
| 1143 | mMockLogger.closeLog(); |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /** |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1147 | * Set up expected conditions for the test InvocationListener and SummaryListener |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1148 | * |
| 1149 | * <p>The order of calls for a single listener should be: |
| 1150 | * |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1151 | * <ol> |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1152 | * <li>invocationStarted |
| 1153 | * <li>testLog(LOGCAT_NAME_SETUP, ...) (if no build or retrieval error) |
| 1154 | * <li>invocationFailed (if run failed) |
| 1155 | * <li>testLog(LOGCAT_NAME_ERROR, ...) (if build retrieval error) |
| 1156 | * <li>testLog(LOGCAT_NAME_TEST, ...) (otherwise) |
| 1157 | * <li>testLog(build error bugreport, ...) (otherwise and if build error) |
| 1158 | * <li>testLog(LOGCAT_NAME_TEARDOWN, ...) (otherwise) |
| 1159 | * <li>testLog(TRADEFED_LOG_NAME, ...) |
| 1160 | * <li>putSummary (for an ITestSummaryListener) |
| 1161 | * <li>invocationEnded |
| 1162 | * <li>getSummary (for an ITestInvocationListener) |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1163 | * </ol> |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1164 | * |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1165 | * However note that, across all listeners, any getSummary call will precede all putSummary |
| 1166 | * calls. |
| 1167 | */ |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1168 | private void setupMockListeners(InvocationStatus status, Throwable throwable) |
| 1169 | throws IOException { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1170 | // invocationStarted |
Julien Desprez | 53353e6 | 2016-08-12 15:24:33 +0100 | [diff] [blame] | 1171 | mMockLogSaver.invocationStarted(mStubInvocationMetadata); |
| 1172 | mMockTestListener.invocationStarted(mStubInvocationMetadata); |
| 1173 | mMockSummaryListener.invocationStarted(mStubInvocationMetadata); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1174 | |
Michael Rosenfeld | d7d700b | 2017-10-18 10:09:13 -0700 | [diff] [blame] | 1175 | if (!(throwable instanceof BuildRetrievalError)) { |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1176 | EasyMock.expect( |
| 1177 | mMockLogSaver.saveLogData( |
| 1178 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 1179 | EasyMock.eq(LogDataType.LOGCAT), |
| 1180 | (InputStream) EasyMock.anyObject())) |
| 1181 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 1182 | mMockTestListener.testLog( |
| 1183 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 1184 | EasyMock.eq(LogDataType.LOGCAT), |
| 1185 | (InputStreamSource) EasyMock.anyObject()); |
| 1186 | mMockSummaryListener.testLog( |
| 1187 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 1188 | EasyMock.eq(LogDataType.LOGCAT), |
| 1189 | (InputStreamSource) EasyMock.anyObject()); |
| 1190 | } |
| 1191 | |
Guang Zhu | 36c56a2 | 2014-12-30 19:56:00 -0800 | [diff] [blame] | 1192 | // invocationFailed |
| 1193 | if (!status.equals(InvocationStatus.SUCCESS)) { |
| 1194 | mMockTestListener.invocationFailed(EasyMock.eq(throwable)); |
| 1195 | mMockSummaryListener.invocationFailed(EasyMock.eq(throwable)); |
| 1196 | } |
| 1197 | |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1198 | if (throwable instanceof BuildRetrievalError) { |
| 1199 | // Handle logcat error listeners |
| 1200 | EasyMock.expect( |
| 1201 | mMockLogSaver.saveLogData( |
| 1202 | EasyMock.eq(LOGCAT_NAME_ERROR), |
| 1203 | EasyMock.eq(LogDataType.LOGCAT), |
| 1204 | (InputStream) EasyMock.anyObject())) |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 1205 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 1206 | mMockTestListener.testLog( |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1207 | EasyMock.eq(LOGCAT_NAME_ERROR), |
| 1208 | EasyMock.eq(LogDataType.LOGCAT), |
| 1209 | (InputStreamSource) EasyMock.anyObject()); |
Julien Desprez | 47c287f | 2016-07-14 12:16:57 +0100 | [diff] [blame] | 1210 | mMockSummaryListener.testLog( |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1211 | EasyMock.eq(LOGCAT_NAME_ERROR), |
| 1212 | EasyMock.eq(LogDataType.LOGCAT), |
| 1213 | (InputStreamSource) EasyMock.anyObject()); |
| 1214 | } else { |
| 1215 | // Handle test logcat listeners |
| 1216 | EasyMock.expect( |
| 1217 | mMockLogSaver.saveLogData( |
| 1218 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 1219 | EasyMock.eq(LogDataType.LOGCAT), |
| 1220 | (InputStream) EasyMock.anyObject())) |
| 1221 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 1222 | mMockTestListener.testLog( |
| 1223 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 1224 | EasyMock.eq(LogDataType.LOGCAT), |
| 1225 | (InputStreamSource) EasyMock.anyObject()); |
| 1226 | mMockSummaryListener.testLog( |
| 1227 | EasyMock.eq(LOGCAT_NAME_TEST), |
| 1228 | EasyMock.eq(LogDataType.LOGCAT), |
| 1229 | (InputStreamSource) EasyMock.anyObject()); |
| 1230 | // Handle build error bugreport listeners |
| 1231 | if (throwable instanceof BuildError) { |
| 1232 | EasyMock.expect( |
jdesprez | c3537f7 | 2017-09-05 17:27:14 -0700 | [diff] [blame] | 1233 | mMockDevice.logBugreport( |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1234 | EasyMock.eq( |
| 1235 | TestInvocation.BUILD_ERROR_BUGREPORT_NAME |
| 1236 | + "_" |
| 1237 | + SERIAL), |
jdesprez | c3537f7 | 2017-09-05 17:27:14 -0700 | [diff] [blame] | 1238 | EasyMock.anyObject())) |
| 1239 | .andReturn(true); |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1240 | } |
| 1241 | // Handle teardown logcat listeners |
| 1242 | EasyMock.expect( |
| 1243 | mMockLogSaver.saveLogData( |
| 1244 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 1245 | EasyMock.eq(LogDataType.LOGCAT), |
| 1246 | (InputStream) EasyMock.anyObject())) |
| 1247 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
| 1248 | mMockTestListener.testLog( |
| 1249 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 1250 | EasyMock.eq(LogDataType.LOGCAT), |
| 1251 | (InputStreamSource) EasyMock.anyObject()); |
| 1252 | mMockSummaryListener.testLog( |
| 1253 | EasyMock.eq(LOGCAT_NAME_TEARDOWN), |
| 1254 | EasyMock.eq(LogDataType.LOGCAT), |
| 1255 | (InputStreamSource) EasyMock.anyObject()); |
Eric Rowe | 4a3369d | 2011-11-23 12:12:16 -0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Michael Rosenfeld | 5501225 | 2017-01-12 15:45:19 -0800 | [diff] [blame] | 1258 | EasyMock.expect( |
| 1259 | mMockLogSaver.saveLogData( |
| 1260 | EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
| 1261 | EasyMock.eq(LogDataType.TEXT), |
| 1262 | (InputStream) EasyMock.anyObject())) |
| 1263 | .andReturn(new LogFile(PATH, URL, false /* compressed */, true /* text */)); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1264 | mMockTestListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 1265 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1266 | mMockSummaryListener.testLog(EasyMock.eq(TestInvocation.TRADEFED_LOG_NAME), |
Omari Stephens | 41978ee | 2011-02-23 19:03:05 -0800 | [diff] [blame] | 1267 | EasyMock.eq(LogDataType.TEXT), (InputStreamSource)EasyMock.anyObject()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1268 | |
| 1269 | // invocationEnded, getSummary (mMockTestListener) |
| 1270 | mMockTestListener.invocationEnded(EasyMock.anyLong()); |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 1271 | EasyMock.expect(mMockTestListener.getSummary()).andReturn(mSummary); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1272 | |
| 1273 | // putSummary, invocationEnded (mMockSummaryListener) |
| 1274 | mMockSummaryListener.putSummary(EasyMock.capture(mUriCapture)); |
| 1275 | mMockSummaryListener.invocationEnded(EasyMock.anyLong()); |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1276 | mMockLogSaver.invocationEnded(EasyMock.anyLong()); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1277 | } |
| 1278 | |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1279 | /** |
| 1280 | * Test the {@link TestInvocation#invoke(IInvocationContext, IConfiguration, IRescheduler, |
| 1281 | * ITestInvocationListener[])} scenario with {@link IShardableTest}. |
| 1282 | */ |
| 1283 | public void testInvoke_shardableTest_legacy() throws Throwable { |
jdesprez | 8ba3346 | 2017-04-05 16:51:13 -0700 | [diff] [blame] | 1284 | String command = "empty --test-tag t"; |
| 1285 | String[] commandLine = {"empty", "--test-tag", "t"}; |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1286 | int shardCount = 2; |
| 1287 | IShardableTest test = EasyMock.createMock(IShardableTest.class); |
| 1288 | List<IRemoteTest> shards = new ArrayList<>(); |
| 1289 | IRemoteTest shard1 = EasyMock.createMock(IRemoteTest.class); |
| 1290 | IRemoteTest shard2 = EasyMock.createMock(IRemoteTest.class); |
| 1291 | shards.add(shard1); |
| 1292 | shards.add(shard2); |
| 1293 | EasyMock.expect(test.split()).andReturn(shards); |
| 1294 | mStubConfiguration.setTest(test); |
| 1295 | mStubConfiguration.setCommandLine(commandLine); |
jdesprez | a90f972 | 2017-08-11 16:48:24 -0700 | [diff] [blame] | 1296 | mMockBuildProvider.cleanUp(mMockBuildInfo); |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1297 | setupInvoke(); |
jdesprez | 8ba3346 | 2017-04-05 16:51:13 -0700 | [diff] [blame] | 1298 | setupNShardInvocation(shardCount, command); |
jdesprez | 3dff70b | 2017-04-18 10:39:13 -0700 | [diff] [blame] | 1299 | mMockLogRegistry.dumpToGlobalLog(mMockLogger); |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1300 | replayMocks(test, mockRescheduler, shard1, shard2); |
| 1301 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 1302 | verifyMocks(test, mockRescheduler, shard1, shard2); |
| 1303 | } |
| 1304 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1305 | /** |
| 1306 | * Test that {@link TestInvocation#logDeviceBatteryLevel(IInvocationContext, String)} is not |
| 1307 | * adding battery information for placeholder device. |
| 1308 | */ |
| 1309 | public void testLogDeviceBatteryLevel_placeholderDevice() { |
| 1310 | final String fakeEvent = "event"; |
| 1311 | IInvocationContext context = new InvocationContext(); |
| 1312 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1313 | EasyMock.expect(device1.getIDevice()).andReturn(new StubDevice("serial1")); |
| 1314 | context.addAllocatedDevice("device1", device1); |
| 1315 | EasyMock.replay(device1); |
| 1316 | mTestInvocation.logDeviceBatteryLevel(context, fakeEvent); |
| 1317 | EasyMock.verify(device1); |
| 1318 | assertEquals(0, context.getAttributes().size()); |
| 1319 | } |
| 1320 | |
| 1321 | /** |
| 1322 | * Test that {@link TestInvocation#logDeviceBatteryLevel(IInvocationContext, String)} is adding |
| 1323 | * battery information for physical real device. |
| 1324 | */ |
| 1325 | public void testLogDeviceBatteryLevel_physicalDevice() { |
| 1326 | final String fakeEvent = "event"; |
| 1327 | IInvocationContext context = new InvocationContext(); |
| 1328 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1329 | IDevice idevice = Mockito.mock(IDevice.class); |
| 1330 | EasyMock.expect(device1.getIDevice()).andReturn(idevice); |
| 1331 | SettableFuture<Integer> future = SettableFuture.create(); |
| 1332 | future.set(50); |
| 1333 | doReturn(future).when(idevice).getBattery(Mockito.anyLong(), Mockito.any()); |
| 1334 | EasyMock.expect(device1.getSerialNumber()).andReturn("serial1"); |
| 1335 | context.addAllocatedDevice("device1", device1); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1336 | context.addDeviceBuildInfo("device1", new BuildInfo()); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1337 | EasyMock.replay(device1); |
| 1338 | mTestInvocation.logDeviceBatteryLevel(context, fakeEvent); |
| 1339 | EasyMock.verify(device1); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1340 | assertEquals(1, context.getBuildInfo("device1").getBuildAttributes().size()); |
| 1341 | assertEquals( |
| 1342 | "50", |
| 1343 | context.getBuildInfo("device1") |
| 1344 | .getBuildAttributes() |
| 1345 | .get("serial1-battery-" + fakeEvent)); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | /** |
| 1349 | * Test that {@link TestInvocation#logDeviceBatteryLevel(IInvocationContext, String)} is adding |
| 1350 | * battery information for multiple physical real device. |
| 1351 | */ |
| 1352 | public void testLogDeviceBatteryLevel_physicalDevice_multi() { |
| 1353 | final String fakeEvent = "event"; |
| 1354 | IInvocationContext context = new InvocationContext(); |
| 1355 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1356 | IDevice idevice = Mockito.mock(IDevice.class); |
| 1357 | EasyMock.expect(device1.getSerialNumber()).andReturn("serial1"); |
| 1358 | EasyMock.expect(device1.getIDevice()).andReturn(idevice); |
| 1359 | SettableFuture<Integer> future = SettableFuture.create(); |
| 1360 | future.set(50); |
| 1361 | doReturn(future).when(idevice).getBattery(Mockito.anyLong(), Mockito.any()); |
| 1362 | ITestDevice device2 = EasyMock.createMock(ITestDevice.class); |
| 1363 | EasyMock.expect(device2.getIDevice()).andReturn(idevice); |
| 1364 | EasyMock.expect(device2.getSerialNumber()).andReturn("serial2"); |
| 1365 | context.addAllocatedDevice("device1", device1); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1366 | context.addDeviceBuildInfo("device1", new BuildInfo()); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1367 | context.addAllocatedDevice("device2", device2); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1368 | context.addDeviceBuildInfo("device2", new BuildInfo()); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1369 | EasyMock.replay(device1, device2); |
| 1370 | mTestInvocation.logDeviceBatteryLevel(context, fakeEvent); |
| 1371 | EasyMock.verify(device1, device2); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1372 | assertEquals(1, context.getBuildInfo("device1").getBuildAttributes().size()); |
| 1373 | assertEquals(1, context.getBuildInfo("device2").getBuildAttributes().size()); |
| 1374 | assertEquals( |
| 1375 | "50", |
| 1376 | context.getBuildInfo("device1") |
| 1377 | .getBuildAttributes() |
| 1378 | .get("serial1-battery-" + fakeEvent)); |
| 1379 | assertEquals( |
| 1380 | "50", |
| 1381 | context.getBuildInfo("device2") |
| 1382 | .getBuildAttributes() |
| 1383 | .get("serial2-battery-" + fakeEvent)); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | /** |
| 1387 | * Test that {@link TestInvocation#logDeviceBatteryLevel(IInvocationContext, String)} is adding |
| 1388 | * battery information for multiple physical real device, and ignore stub device if any. |
| 1389 | */ |
| 1390 | public void testLogDeviceBatteryLevel_physicalDevice_stub_multi() { |
| 1391 | final String fakeEvent = "event"; |
| 1392 | IInvocationContext context = new InvocationContext(); |
| 1393 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1394 | IDevice idevice = Mockito.mock(IDevice.class); |
| 1395 | EasyMock.expect(device1.getSerialNumber()).andReturn("serial1"); |
| 1396 | EasyMock.expect(device1.getIDevice()).andReturn(idevice); |
| 1397 | SettableFuture<Integer> future = SettableFuture.create(); |
| 1398 | future.set(50); |
| 1399 | doReturn(future).when(idevice).getBattery(Mockito.anyLong(), Mockito.any()); |
| 1400 | ITestDevice device2 = EasyMock.createMock(ITestDevice.class); |
| 1401 | EasyMock.expect(device2.getIDevice()).andReturn(idevice); |
| 1402 | EasyMock.expect(device2.getSerialNumber()).andReturn("serial2"); |
| 1403 | ITestDevice device3 = EasyMock.createMock(ITestDevice.class); |
| 1404 | EasyMock.expect(device1.getIDevice()).andStubReturn(new StubDevice("stub1")); |
| 1405 | ITestDevice device4 = EasyMock.createMock(ITestDevice.class); |
| 1406 | EasyMock.expect(device1.getIDevice()).andStubReturn(new StubDevice("stub2")); |
| 1407 | context.addAllocatedDevice("device1", device1); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1408 | context.addDeviceBuildInfo("device1", new BuildInfo()); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1409 | context.addAllocatedDevice("device2", device2); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1410 | context.addDeviceBuildInfo("device2", new BuildInfo()); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1411 | context.addAllocatedDevice("device3", device3); |
| 1412 | context.addAllocatedDevice("device4", device4); |
| 1413 | EasyMock.replay(device1, device2); |
| 1414 | mTestInvocation.logDeviceBatteryLevel(context, fakeEvent); |
| 1415 | EasyMock.verify(device1, device2); |
jdesprez | cf54555 | 2017-07-12 02:08:08 -0700 | [diff] [blame] | 1416 | assertEquals(1, context.getBuildInfo("device1").getBuildAttributes().size()); |
| 1417 | assertEquals(1, context.getBuildInfo("device2").getBuildAttributes().size()); |
| 1418 | assertEquals( |
| 1419 | "50", |
| 1420 | context.getBuildInfo("device1") |
| 1421 | .getBuildAttributes() |
| 1422 | .get("serial1-battery-" + fakeEvent)); |
| 1423 | assertEquals( |
| 1424 | "50", |
| 1425 | context.getBuildInfo("device2") |
| 1426 | .getBuildAttributes() |
| 1427 | .get("serial2-battery-" + fakeEvent)); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1428 | } |
| 1429 | |
jdesprez | 8ba3346 | 2017-04-05 16:51:13 -0700 | [diff] [blame] | 1430 | /** Helper to set the expectation for N number of shards. */ |
| 1431 | private void setupNShardInvocation(int numShard, String commandLine) throws Exception { |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1432 | mMockBuildInfo.setTestTag(EasyMock.eq("stub")); |
| 1433 | EasyMock.expectLastCall(); |
| 1434 | EasyMock.expect(mMockBuildProvider.getBuild()).andReturn(mMockBuildInfo); |
| 1435 | EasyMock.expect(mMockBuildInfo.getTestTag()).andStubReturn(""); |
jdesprez | 8ba3346 | 2017-04-05 16:51:13 -0700 | [diff] [blame] | 1436 | mMockBuildInfo.addBuildAttribute("command_line_args", commandLine); |
Julien Desprez | 2763ca0 | 2016-12-06 14:39:33 +0000 | [diff] [blame] | 1437 | mMockLogSaver.invocationStarted((IInvocationContext)EasyMock.anyObject()); |
| 1438 | EasyMock.expectLastCall(); |
| 1439 | mMockTestListener.invocationStarted((IInvocationContext)EasyMock.anyObject()); |
| 1440 | EasyMock.expectLastCall(); |
| 1441 | mMockSummaryListener.invocationStarted((IInvocationContext)EasyMock.anyObject()); |
| 1442 | EasyMock.expectLastCall(); |
| 1443 | EasyMock.expect(mMockLogger.clone()).andReturn(mMockLogger).times(numShard); |
| 1444 | EasyMock.expect(mMockBuildInfo.clone()).andReturn(mMockBuildInfo).times(numShard); |
| 1445 | EasyMock.expect(mockRescheduler.scheduleConfig(EasyMock.anyObject())) |
| 1446 | .andReturn(true).times(numShard); |
| 1447 | mMockBuildInfo.setDeviceSerial(SERIAL); |
| 1448 | EasyMock.expectLastCall(); |
| 1449 | mMockBuildProvider.cleanUp(EasyMock.anyObject()); |
| 1450 | EasyMock.expectLastCall(); |
| 1451 | } |
| 1452 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1453 | private void setupMockSuccessListeners() throws IOException { |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1454 | setupMockListeners(InvocationStatus.SUCCESS, null); |
| 1455 | } |
| 1456 | |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1457 | private void setupMockFailureListeners(Throwable throwable) throws IOException { |
Eric Rowe | a3b8585 | 2012-07-16 15:07:49 -0700 | [diff] [blame] | 1458 | setupMockListeners(InvocationStatus.FAILED, throwable); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | private void verifySummaryListener() { |
| 1462 | // Check that we captured the expected uris List |
Omari Stephens | a01abfe | 2010-09-07 15:48:44 -0700 | [diff] [blame] | 1463 | List<TestSummary> summaries = mUriCapture.getValue(); |
| 1464 | assertEquals(1, summaries.size()); |
| 1465 | assertEquals(mSummary, summaries.get(0)); |
Omari Stephens | 203296c | 2010-09-02 18:20:45 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /** |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 1469 | * Verify all mock objects received expected calls |
| 1470 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1471 | private void verifyMocks(Object... mocks) { |
Brett Chabot | 1d35e66 | 2011-05-25 19:48:24 -0700 | [diff] [blame] | 1472 | // note: intentionally exclude configuration from verification - don't care |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 1473 | // what methods are called |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1474 | EasyMock.verify(mMockTestListener, mMockSummaryListener, mMockPreparer, |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1475 | mMockBuildProvider, mMockLogger, mMockBuildInfo, mMockLogRegistry, |
| 1476 | mMockLogSaver); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1477 | if (mocks.length > 0) { |
| 1478 | EasyMock.verify(mocks); |
| 1479 | } |
Brett Chabot | 057e16e | 2010-06-27 21:53:48 -0700 | [diff] [blame] | 1480 | } |
| 1481 | |
| 1482 | /** |
| 1483 | * Switch all mock objects into replay mode. |
| 1484 | */ |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1485 | private void replayMocks(Object... mocks) { |
Eric Rowe | 0b44511 | 2013-07-12 09:29:47 -0700 | [diff] [blame] | 1486 | EasyMock.replay(mMockTestListener, mMockSummaryListener, mMockPreparer, |
| 1487 | mMockBuildProvider, mMockLogger, mMockBuildInfo, mMockLogRegistry, |
Moon Kim | b78076b | 2016-07-06 15:12:07 -0700 | [diff] [blame] | 1488 | mMockLogSaver, mMockDevice, mMockConfigFactory); |
Brett Chabot | 87803df | 2013-03-01 16:01:50 -0800 | [diff] [blame] | 1489 | if (mocks.length > 0) { |
| 1490 | EasyMock.replay(mocks); |
| 1491 | } |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /** |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1495 | * Interface for testing device config pass through. |
| 1496 | */ |
Brett Chabot | 2e441bd | 2010-09-16 18:25:11 -0700 | [diff] [blame] | 1497 | private interface DeviceConfigTest extends IRemoteTest, IDeviceTest { |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1498 | |
| 1499 | } |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1500 | |
| 1501 | /** |
| 1502 | * Test {@link INativeDevice#preInvocationSetup(IBuildInfo info)} is called when command option |
| 1503 | * skip-pre-device-setup is not set. |
| 1504 | */ |
| 1505 | public void testNotSkipPreDeviceSetup() throws Throwable { |
| 1506 | IInvocationContext context = new InvocationContext(); |
| 1507 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1508 | IDevice idevice = Mockito.mock(IDevice.class); |
| 1509 | context.addAllocatedDevice("DEFAULT_DEVICE", device1); |
| 1510 | EasyMock.expect(device1.getSerialNumber()).andReturn("serial1").anyTimes(); |
| 1511 | EasyMock.expect(device1.getIDevice()).andReturn(idevice).anyTimes(); |
| 1512 | EasyMock.expect(device1.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(1); |
| 1513 | device1.clearLogcat(); |
| 1514 | EasyMock.expectLastCall().once(); |
| 1515 | device1.preInvocationSetup((IBuildInfo) EasyMock.anyObject()); |
| 1516 | EasyMock.expectLastCall().once(); |
| 1517 | |
| 1518 | CommandOptions commandOption = new CommandOptions(); |
| 1519 | OptionSetter setter = new OptionSetter(commandOption); |
| 1520 | setter.setOptionValue("skip-pre-device-setup", "false"); |
| 1521 | mStubConfiguration.setCommandOptions(commandOption); |
| 1522 | |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1523 | EasyMock.expect(mMockPreparer.isDisabled()).andReturn(true); |
| 1524 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1525 | ITestInvocationListener listener = EasyMock.createStrictMock(ITestInvocationListener.class); |
| 1526 | listener.testLog( |
| 1527 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 1528 | EasyMock.eq(LogDataType.LOGCAT), |
| 1529 | (InputStreamSource) EasyMock.anyObject()); |
| 1530 | |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1531 | EasyMock.replay(device1, listener, mMockPreparer); |
jdesprez | 94cdfeb | 2017-09-18 10:49:24 -0700 | [diff] [blame] | 1532 | new InvocationExecution().doSetup(context, mStubConfiguration, listener); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1533 | EasyMock.verify(device1, listener, mMockPreparer); |
jdesprez | 94cdfeb | 2017-09-18 10:49:24 -0700 | [diff] [blame] | 1534 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | /** |
| 1538 | * Test {@link INativeDevice#preInvocationSetup(IBuildInfo info)} is not called when command |
| 1539 | * option skip-pre-device-setup is set. |
| 1540 | */ |
| 1541 | public void testSkipPreDeviceSetup() throws Throwable { |
| 1542 | IInvocationContext context = new InvocationContext(); |
| 1543 | ITestDevice device1 = EasyMock.createMock(ITestDevice.class); |
| 1544 | IDevice idevice = Mockito.mock(IDevice.class); |
| 1545 | context.addAllocatedDevice("DEFAULT_DEVICE", device1); |
| 1546 | EasyMock.expect(device1.getSerialNumber()).andReturn("serial1").anyTimes(); |
| 1547 | EasyMock.expect(device1.getIDevice()).andReturn(idevice).anyTimes(); |
| 1548 | EasyMock.expect(device1.getLogcat()).andReturn(EMPTY_STREAM_SOURCE).times(1); |
| 1549 | device1.clearLogcat(); |
| 1550 | EasyMock.expectLastCall().once(); |
| 1551 | |
| 1552 | CommandOptions commandOption = new CommandOptions(); |
| 1553 | OptionSetter setter = new OptionSetter(commandOption); |
| 1554 | setter.setOptionValue("skip-pre-device-setup", "true"); |
| 1555 | mStubConfiguration.setCommandOptions(commandOption); |
| 1556 | |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1557 | EasyMock.expect(mMockPreparer.isDisabled()).andReturn(true); |
| 1558 | |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1559 | ITestInvocationListener listener = EasyMock.createStrictMock(ITestInvocationListener.class); |
| 1560 | listener.testLog( |
| 1561 | EasyMock.eq(LOGCAT_NAME_SETUP), |
| 1562 | EasyMock.eq(LogDataType.LOGCAT), |
| 1563 | (InputStreamSource) EasyMock.anyObject()); |
| 1564 | |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1565 | EasyMock.replay(device1, listener, mMockPreparer); |
jdesprez | 94cdfeb | 2017-09-18 10:49:24 -0700 | [diff] [blame] | 1566 | new InvocationExecution().doSetup(context, mStubConfiguration, listener); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1567 | EasyMock.verify(device1, listener, mMockPreparer); |
jdesprez | bc580f9 | 2017-06-02 11:41:40 -0700 | [diff] [blame] | 1568 | } |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1569 | |
| 1570 | /** |
| 1571 | * Test when a {@link IDeviceBuildInfo} is passing through we do not attempt to add any external |
| 1572 | * directories when there is none coming from environment. |
| 1573 | */ |
| 1574 | public void testInvoke_deviceInfoBuild_noEnv() throws Throwable { |
jdesprez | a04c03e | 2017-12-19 05:53:37 -0800 | [diff] [blame] | 1575 | mTestInvocation = |
| 1576 | new TestInvocation() { |
| 1577 | @Override |
| 1578 | ILogRegistry getLogRegistry() { |
| 1579 | return mMockLogRegistry; |
| 1580 | } |
| 1581 | |
| 1582 | @Override |
| 1583 | public IInvocationExecution createInvocationExec() { |
| 1584 | return new InvocationExecution() { |
| 1585 | @Override |
| 1586 | protected IShardHelper createShardHelper() { |
| 1587 | return new ShardHelper(); |
| 1588 | } |
| 1589 | |
| 1590 | @Override |
| 1591 | List<File> getExternalTestCasesDirs() { |
| 1592 | // Return empty list to ensure we do not have any environment loaded |
| 1593 | return new ArrayList<>(); |
| 1594 | } |
| 1595 | }; |
| 1596 | } |
| 1597 | |
| 1598 | @Override |
| 1599 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 1600 | // empty on purpose |
| 1601 | } |
| 1602 | }; |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1603 | mMockBuildInfo = EasyMock.createMock(IDeviceBuildInfo.class); |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 1604 | EasyMock.expect(mMockBuildInfo.getProperties()).andStubReturn(new HashSet<>()); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1605 | IRemoteTest test = EasyMock.createNiceMock(IRemoteTest.class); |
| 1606 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1607 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1608 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 1609 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, null); |
| 1610 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 1611 | |
| 1612 | File tmpTestsDir = FileUtil.createTempDir("invocation-tests-dir"); |
| 1613 | try { |
| 1614 | EasyMock.expect(((IDeviceBuildInfo) mMockBuildInfo).getTestsDir()) |
| 1615 | .andReturn(tmpTestsDir); |
| 1616 | setupMockSuccessListeners(); |
| 1617 | setupNormalInvoke(test); |
| 1618 | EasyMock.replay(mockCleaner, mockRescheduler); |
| 1619 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 1620 | verifyMocks(mockCleaner, mockRescheduler); |
| 1621 | verifySummaryListener(); |
| 1622 | } finally { |
| 1623 | FileUtil.recursiveDelete(tmpTestsDir); |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | /** |
| 1628 | * Test when a {@link IDeviceBuildInfo} is passing through we attempt to add the external |
| 1629 | * directories to it when they are available. |
| 1630 | */ |
| 1631 | public void testInvoke_deviceInfoBuild_withEnv() throws Throwable { |
| 1632 | File tmpTestsDir = FileUtil.createTempDir("invocation-tests-dir"); |
| 1633 | File tmpExternalTestsDir = FileUtil.createTempDir("external-tf-dir"); |
| 1634 | File tmpTestsFile = FileUtil.createTempFile("testsfile", "txt", tmpExternalTestsDir); |
| 1635 | try { |
| 1636 | mTestInvocation = |
| 1637 | new TestInvocation() { |
| 1638 | @Override |
| 1639 | ILogRegistry getLogRegistry() { |
| 1640 | return mMockLogRegistry; |
| 1641 | } |
| 1642 | |
| 1643 | @Override |
jdesprez | 85129dd | 2017-11-13 06:05:57 -0800 | [diff] [blame] | 1644 | public IInvocationExecution createInvocationExec() { |
| 1645 | return new InvocationExecution() { |
| 1646 | @Override |
| 1647 | protected IShardHelper createShardHelper() { |
| 1648 | return new ShardHelper(); |
| 1649 | } |
jdesprez | a1731b2 | 2017-12-06 06:05:52 -0800 | [diff] [blame] | 1650 | |
| 1651 | @Override |
| 1652 | List<File> getExternalTestCasesDirs() { |
| 1653 | List<File> list = new ArrayList<>(); |
| 1654 | list.add(tmpExternalTestsDir); |
| 1655 | return list; |
| 1656 | } |
jdesprez | 85129dd | 2017-11-13 06:05:57 -0800 | [diff] [blame] | 1657 | }; |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | @Override |
| 1661 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 1662 | // empty on purpose |
| 1663 | } |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1664 | }; |
| 1665 | mMockBuildInfo = EasyMock.createMock(IDeviceBuildInfo.class); |
| 1666 | IRemoteTest test = EasyMock.createNiceMock(IRemoteTest.class); |
| 1667 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
jdesprez | 5ae744c | 2017-10-27 10:36:53 -0700 | [diff] [blame] | 1668 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1669 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 1670 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, null); |
| 1671 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 1672 | |
jdesprez | a04c03e | 2017-12-19 05:53:37 -0800 | [diff] [blame] | 1673 | mMockBuildInfo.setFile( |
| 1674 | EasyMock.contains(tmpExternalTestsDir.getName()), |
| 1675 | EasyMock.anyObject(), |
| 1676 | EasyMock.eq("v1")); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1677 | EasyMock.expect(((IDeviceBuildInfo) mMockBuildInfo).getTestsDir()) |
| 1678 | .andReturn(tmpTestsDir); |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 1679 | EasyMock.expect(mMockBuildInfo.getProperties()).andStubReturn(new HashSet<>()); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1680 | |
| 1681 | setupMockSuccessListeners(); |
| 1682 | setupNormalInvoke(test); |
| 1683 | EasyMock.replay(mockCleaner, mockRescheduler); |
| 1684 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 1685 | verifyMocks(mockCleaner, mockRescheduler); |
| 1686 | verifySummaryListener(); |
| 1687 | // Check that the external directory was copied in the testsDir. |
| 1688 | assertTrue(tmpTestsDir.listFiles().length == 1); |
jdesprez | e509334 | 2017-11-16 06:16:06 -0800 | [diff] [blame] | 1689 | // external-tf-dir - the symlink is the original file name + randomized sequence |
| 1690 | assertTrue( |
| 1691 | tmpTestsDir.listFiles()[0].getName().startsWith(tmpExternalTestsDir.getName())); |
jdesprez | da087c0 | 2017-06-26 14:23:07 -0700 | [diff] [blame] | 1692 | // testsfile.txt |
| 1693 | assertTrue(tmpTestsDir.listFiles()[0].listFiles().length == 1); |
| 1694 | assertEquals( |
| 1695 | tmpTestsFile.getName(), tmpTestsDir.listFiles()[0].listFiles()[0].getName()); |
| 1696 | } finally { |
| 1697 | FileUtil.recursiveDelete(tmpTestsDir); |
| 1698 | FileUtil.recursiveDelete(tmpExternalTestsDir); |
| 1699 | } |
| 1700 | } |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1701 | |
jdesprez | 5338768 | 2018-02-27 14:10:46 -0800 | [diff] [blame] | 1702 | /** |
| 1703 | * Test when a {@link IDeviceBuildInfo} is passing through we do not attempt to add the external |
| 1704 | * directories to it, since {@link BuildInfoProperties} is set to skip the linking. |
| 1705 | */ |
| 1706 | public void testInvoke_deviceInfoBuild_withEnv_andSkipProperty() throws Throwable { |
| 1707 | File tmpTestsDir = FileUtil.createTempDir("invocation-tests-dir"); |
| 1708 | File tmpExternalTestsDir = FileUtil.createTempDir("external-tf-dir"); |
| 1709 | FileUtil.createTempFile("testsfile", "txt", tmpExternalTestsDir); |
| 1710 | try { |
| 1711 | mTestInvocation = |
| 1712 | new TestInvocation() { |
| 1713 | @Override |
| 1714 | ILogRegistry getLogRegistry() { |
| 1715 | return mMockLogRegistry; |
| 1716 | } |
| 1717 | |
| 1718 | @Override |
| 1719 | public IInvocationExecution createInvocationExec() { |
| 1720 | return new InvocationExecution() { |
| 1721 | @Override |
| 1722 | protected IShardHelper createShardHelper() { |
| 1723 | return new ShardHelper(); |
| 1724 | } |
| 1725 | |
| 1726 | @Override |
| 1727 | List<File> getExternalTestCasesDirs() { |
| 1728 | List<File> list = new ArrayList<>(); |
| 1729 | list.add(tmpExternalTestsDir); |
| 1730 | return list; |
| 1731 | } |
| 1732 | }; |
| 1733 | } |
| 1734 | |
| 1735 | @Override |
| 1736 | protected void setExitCode(ExitCode code, Throwable stack) { |
| 1737 | // empty on purpose |
| 1738 | } |
| 1739 | }; |
| 1740 | mMockBuildInfo = EasyMock.createMock(IDeviceBuildInfo.class); |
| 1741 | IRemoteTest test = EasyMock.createNiceMock(IRemoteTest.class); |
| 1742 | ITargetCleaner mockCleaner = EasyMock.createMock(ITargetCleaner.class); |
| 1743 | EasyMock.expect(mockCleaner.isDisabled()).andReturn(false).times(2); |
| 1744 | mockCleaner.setUp(mMockDevice, mMockBuildInfo); |
| 1745 | mockCleaner.tearDown(mMockDevice, mMockBuildInfo, null); |
| 1746 | mStubConfiguration.getTargetPreparers().add(mockCleaner); |
| 1747 | |
| 1748 | Set<BuildInfoProperties> prop = new HashSet<>(); |
| 1749 | prop.add(BuildInfoProperties.DO_NOT_LINK_TESTS_DIR); |
| 1750 | EasyMock.expect(mMockBuildInfo.getProperties()).andStubReturn(prop); |
| 1751 | |
| 1752 | setupMockSuccessListeners(); |
| 1753 | setupNormalInvoke(test); |
| 1754 | EasyMock.replay(mockCleaner, mockRescheduler); |
| 1755 | mTestInvocation.invoke(mStubInvocationMetadata, mStubConfiguration, mockRescheduler); |
| 1756 | verifyMocks(mockCleaner, mockRescheduler); |
| 1757 | verifySummaryListener(); |
| 1758 | // Check that the external directory was NOT copied in the testsDir. |
| 1759 | assertTrue(tmpTestsDir.listFiles().length == 0); |
| 1760 | } finally { |
| 1761 | FileUtil.recursiveDelete(tmpTestsDir); |
| 1762 | FileUtil.recursiveDelete(tmpExternalTestsDir); |
| 1763 | } |
| 1764 | } |
| 1765 | |
jdesprez | 839825d | 2018-01-31 12:14:23 -0800 | [diff] [blame] | 1766 | public static class TestableCollector extends BaseDeviceMetricCollector { |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1767 | |
jdesprez | 839825d | 2018-01-31 12:14:23 -0800 | [diff] [blame] | 1768 | @Option(name = "name") |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1769 | private String mName; |
| 1770 | |
jdesprez | 839825d | 2018-01-31 12:14:23 -0800 | [diff] [blame] | 1771 | public TestableCollector() {} |
| 1772 | |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1773 | public TestableCollector(String name) { |
| 1774 | mName = name; |
| 1775 | } |
| 1776 | |
| 1777 | @Override |
jdesprez | 7154090 | 2017-10-16 12:53:36 -0700 | [diff] [blame] | 1778 | public void onTestRunEnd( |
| 1779 | DeviceMetricData runData, final Map<String, String> currentRunMetrics) { |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1780 | runData.addStringMetric(mName, mName); |
| 1781 | } |
| 1782 | } |
| 1783 | |
| 1784 | /** |
| 1785 | * Test that when {@link IMetricCollector} are used, they wrap and call in sequence the listener |
| 1786 | * so all metrics end up on the final receiver. |
| 1787 | */ |
| 1788 | public void testMetricCollectionChain() throws Exception { |
| 1789 | IConfiguration configuration = new Configuration("test", "description"); |
| 1790 | StubTest test = new StubTest(); |
| 1791 | OptionSetter setter = new OptionSetter(test); |
| 1792 | setter.setOptionValue("run-a-test", "true"); |
| 1793 | configuration.setTest(test); |
| 1794 | |
| 1795 | List<IMetricCollector> collectors = new ArrayList<>(); |
| 1796 | collectors.add(new TestableCollector("collector1")); |
| 1797 | collectors.add(new TestableCollector("collector2")); |
| 1798 | collectors.add(new TestableCollector("collector3")); |
| 1799 | collectors.add(new TestableCollector("collector4")); |
| 1800 | configuration.setDeviceMetricCollectors(collectors); |
| 1801 | |
| 1802 | mMockTestListener.testRunStarted("TestStub", 1); |
jdesprez | 821a005 | 2018-01-16 03:37:16 -0800 | [diff] [blame] | 1803 | TestDescription testId = new TestDescription("StubTest", "StubMethod"); |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1804 | mMockTestListener.testStarted(EasyMock.eq(testId), EasyMock.anyLong()); |
| 1805 | mMockTestListener.testEnded( |
| 1806 | EasyMock.eq(testId), EasyMock.anyLong(), EasyMock.eq(Collections.emptyMap())); |
| 1807 | Capture<Map<String, String>> captured = new Capture<>(); |
| 1808 | mMockTestListener.testRunEnded(EasyMock.anyLong(), EasyMock.capture(captured)); |
| 1809 | EasyMock.replay(mMockTestListener); |
jdesprez | 94cdfeb | 2017-09-18 10:49:24 -0700 | [diff] [blame] | 1810 | new InvocationExecution() |
| 1811 | .runTests(mStubInvocationMetadata, configuration, mMockTestListener); |
jdesprez | 267ab89 | 2017-09-08 15:30:06 -0700 | [diff] [blame] | 1812 | EasyMock.verify(mMockTestListener); |
| 1813 | // The collectors are called in sequence |
| 1814 | List<String> listKeys = new ArrayList<>(captured.getValue().keySet()); |
| 1815 | assertEquals("collector4", listKeys.get(0)); |
| 1816 | assertEquals("collector3", listKeys.get(1)); |
| 1817 | assertEquals("collector2", listKeys.get(2)); |
| 1818 | assertEquals("collector1", listKeys.get(3)); |
| 1819 | } |
Brett Chabot | 74121d8 | 2010-01-28 20:14:27 -0800 | [diff] [blame] | 1820 | } |