diff options
author | Kevin Cheng <kevcheng@google.com> | 2017-06-05 10:17:52 -0700 |
---|---|---|
committer | Kevin Cheng <kevcheng@google.com> | 2017-06-09 09:32:50 -0700 |
commit | 4cb42b00879a35286c59fad16026c29e3a1601fd (patch) | |
tree | 141f37829b281c52b0cda15db77e6c459dff6bed /src | |
parent | 455af25d0aebc3578286af9ebf61733663b6e92c (diff) | |
download | contrib-4cb42b00879a35286c59fad16026c29e3a1601fd.tar.gz |
Add in reboot test to replace existing example test.android-vts-8.0_r2android-vts-8.0_r1oreo-dev
Bug: None
Test: Built and ran test successfully.
> tradefed.sh run commandAndExit example/reboot
Change-Id: Ib1db0b1cefbd958d37eaa8636febcc32d3e484a9
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/example/RebootTest.java | 89 | ||||
-rw-r--r-- | src/com/android/example_test/ExampleTest.java | 32 |
2 files changed, 89 insertions, 32 deletions
diff --git a/src/com/android/example/RebootTest.java b/src/com/android/example/RebootTest.java new file mode 100644 index 0000000..8b4d41d --- /dev/null +++ b/src/com/android/example/RebootTest.java @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.example; + +import com.android.ddmlib.testrunner.TestIdentifier; +import com.android.tradefed.config.Option; +import com.android.tradefed.device.DeviceNotAvailableException; +import com.android.tradefed.device.IManagedTestDevice; +import com.android.tradefed.device.ITestDevice; +import com.android.tradefed.result.ITestInvocationListener; +import com.android.tradefed.testtype.IDeviceTest; +import com.android.tradefed.testtype.IRemoteTest; + +import java.util.Collections; +import java.util.Map; + +/** + * Reboots the device and verifies it comes back online. + * This simple reboot tests acts as an example integration test. + */ +public class RebootTest implements IRemoteTest, IDeviceTest { + private ITestDevice mDevice = null; + + @Option(name = "num-of-reboots", description = "Number of times to reboot the device.") + private int mNumDeviceReboots = 1; + + /** + * {@inheritDoc} + */ + @Override + public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { + long start; + Map<String, String> emptyMap = Collections.emptyMap(); + TestIdentifier testId; + start = System.currentTimeMillis(); + listener.testRunStarted(String.format("#%d device reboots", mNumDeviceReboots), + mNumDeviceReboots); + try { + for (int testCount = 0; testCount < mNumDeviceReboots; testCount++) { + testId = new TestIdentifier("RebootTest", + String.format("RebootLoop #%d", testCount)); + listener.testStarted(testId); + try { + getDevice().nonBlockingReboot(); + if (((IManagedTestDevice)getDevice()).getMonitor().waitForDeviceOnline() == null) { + listener.testFailed(testId, "Reboot failed"); + ((IManagedTestDevice)getDevice()).recoverDevice(); + } + } + finally { + listener.testEnded(testId, emptyMap); + } + } + } + finally { + listener.testRunEnded(System.currentTimeMillis() - start, emptyMap); + } + } + + /** + * {@inheritDoc} + */ + @Override + public void setDevice(ITestDevice device) { + mDevice = device; + } + + /** + * {@inheritDoc} + */ + @Override + public ITestDevice getDevice() { + return mDevice; + } +} diff --git a/src/com/android/example_test/ExampleTest.java b/src/com/android/example_test/ExampleTest.java deleted file mode 100644 index dd73be2..0000000 --- a/src/com/android/example_test/ExampleTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.tradefed; - -import com.android.tradefed.device.DeviceNotAvailableException; -import com.android.tradefed.log.LogUtil.CLog; -import com.android.tradefed.result.ITestInvocationListener; -import com.android.tradefed.testtype.IRemoteTest; - -/** - * Example test to seed Trade Federation Contrib project. - */ -// TODO: Delete when real tests make it here. -public class ExampleTest implements IRemoteTest { - @Override - public void run(ITestInvocationListener listener) throws DeviceNotAvailableException { - CLog.i("AOSP example test says Hello!"); - } -} |