Merge "Add a skeleton for userspace reboot CTS tests" am: b3d565321d am: e4210443b3

Change-Id: I00e88d3208b35ed3ec8b414e4df28ddf460ea2fb
diff --git a/hostsidetests/userspacereboot/Android.bp b/hostsidetests/userspacereboot/Android.bp
new file mode 100644
index 0000000..51ed05a
--- /dev/null
+++ b/hostsidetests/userspacereboot/Android.bp
@@ -0,0 +1,33 @@
+// Copyright (C) 2019 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.
+
+java_test_host {
+    name: "CtsUserspaceRebootHostSideTestCases",
+    defaults: ["cts_defaults"],
+
+    srcs:  ["src/**/*.java"],
+
+    libs: [
+        "cts-tradefed",
+        "tradefed",
+        "truth-prebuilt",
+        "hamcrest",
+        "hamcrest-library",
+    ],
+
+    test_suites: [
+        "cts",
+        "general-tests",
+    ],
+}
diff --git a/hostsidetests/userspacereboot/AndroidTest.xml b/hostsidetests/userspacereboot/AndroidTest.xml
new file mode 100644
index 0000000..d3692fc
--- /dev/null
+++ b/hostsidetests/userspacereboot/AndroidTest.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2019 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.
+  -->
+<configuration description="Runs userspace reboot CTS tests">
+    <option name="test-suite-tag" value="cts" />
+    <option name="config-descriptor:metadata" key="component" value="framework" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
+    <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
+    <test class="com.android.tradefed.testtype.HostTest" >
+        <option name="class" value="com.android.cts.userspacereboot.host.UserspaceRebootHostTest" />
+    </test>
+</configuration>
diff --git a/hostsidetests/userspacereboot/OWNERS b/hostsidetests/userspacereboot/OWNERS
new file mode 100644
index 0000000..8b2fa8c
--- /dev/null
+++ b/hostsidetests/userspacereboot/OWNERS
@@ -0,0 +1,2 @@
+ioffe@google.com
+tomcherry@google.com
\ No newline at end of file
diff --git a/hostsidetests/userspacereboot/src/com/android/cts/userspacereboot/host/UserspaceRebootHostTest.java b/hostsidetests/userspacereboot/src/com/android/cts/userspacereboot/host/UserspaceRebootHostTest.java
new file mode 100644
index 0000000..3dc02b8
--- /dev/null
+++ b/hostsidetests/userspacereboot/src/com/android/cts/userspacereboot/host/UserspaceRebootHostTest.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 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.cts.userspacereboot.host;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.junit.Assume.assumeTrue;
+
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class UserspaceRebootHostTest extends BaseHostJUnit4Test  {
+
+    @Test
+    public void testOnlyFbeDevicesSupportUserspaceReboot() throws Exception {
+        assumeTrue("Userspace reboot not supported on the device", isUserspaceRebootSupported());
+        assertThat(getDevice().getProperty("ro.crypto.state")).isEqualTo("encrypted");
+        assertThat(getDevice().getProperty("ro.crypto.type")).isEqualTo("file");
+    }
+
+    private boolean isUserspaceRebootSupported() throws Exception {
+        final String value = getDevice().getProperty("ro.init.userspace_reboot.is_supported");
+        return "1".equals(value) || "true".equals(value);
+    }
+}