release-request-276f9f52-87fd-4915-bd79-9a2f0ee77433-for-git_oc-release-4090213 snap-temp-L31600000073091223

Change-Id: I92b5ade2fff68e748da11c580dda07fdca5a41ee
diff --git a/res/config/example/example.xml b/res/config/example/reboot.xml
similarity index 60%
rename from res/config/example/example.xml
rename to res/config/example/reboot.xml
index 14d3378..a2cc8d4 100644
--- a/res/config/example/example.xml
+++ b/res/config/example/reboot.xml
@@ -13,16 +13,7 @@
      See the License for the specific language governing permissions and
      limitations under the License.
 -->
-<!-- TODO: Delete when real configs make it here. -->
-<configuration description="Example test config.">
-    <!-- Some option for the whole configuration. -->
-    <option name="test-tag" value="example-test" />
-
-    <!-- Example test that will be ran. -->
-    <test class="com.android.tradefed.ExampleTest" />
-
-    <!-- Example target preparer used. -->
-    <target_preparer class="com.android.tradefed.targetprep.ExampleTargetPreparer" />
-
+<configuration description="Config for reboot test.">
+    <test class="com.android.example.RebootTest"/>
+    <option name="num-of-reboots" value="2"/>
 </configuration>
-
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!");
-    }
-}