summaryrefslogtreecommitdiff
path: root/mtectrl
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2022-10-26 16:13:54 -0700
committerFlorian Mayer <fmayer@google.com>2022-11-07 14:49:46 -0800
commit4546f6ab90a54e37198886e8a3ad8636fa00d086 (patch)
tree4c9308979507ac532dca04e2de11c8001abea732 /mtectrl
parent427b7d5b5e6d455ce092dfab484d0381139df8ea (diff)
downloadextras-4546f6ab90a54e37198886e8a3ad8636fa00d086.tar.gz
Add end to end test for mtectrl.
Bug: 255628885 Change-Id: Ie03b40b8702fa45ea9f8ba2d022975d5cc9024dd
Diffstat (limited to 'mtectrl')
-rw-r--r--mtectrl/Android.bp8
-rw-r--r--mtectrl/src/com/android/tests/mtectrl/MtectrlEndToEndTest.java92
2 files changed, 100 insertions, 0 deletions
diff --git a/mtectrl/Android.bp b/mtectrl/Android.bp
index 688ca7dd..423eec27 100644
--- a/mtectrl/Android.bp
+++ b/mtectrl/Android.bp
@@ -40,3 +40,11 @@ cc_test {
"libgmock",
]
}
+
+java_test_host {
+ name: "mtectrl_end_to_end_test",
+ libs: ["tradefed"],
+ static_libs: ["frameworks-base-hostutils", "cts-install-lib-host"],
+ srcs: ["src/com/android/tests/mtectrl/MtectrlEndToEndTest.java"],
+ test_suites: ["general-tests"],
+}
diff --git a/mtectrl/src/com/android/tests/mtectrl/MtectrlEndToEndTest.java b/mtectrl/src/com/android/tests/mtectrl/MtectrlEndToEndTest.java
new file mode 100644
index 00000000..fd3d4401
--- /dev/null
+++ b/mtectrl/src/com/android/tests/mtectrl/MtectrlEndToEndTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2022 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.tests.mtectrl;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.junit.Assume.assumeThat;
+
+import com.android.tradefed.invoker.TestInformation;
+import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
+import com.android.tradefed.testtype.junit4.AfterClassWithInfo;
+import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
+import com.android.tradefed.testtype.junit4.BeforeClassWithInfo;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+// Test the protocol described in
+// https://source.android.com/docs/security/test/memory-safety/bootloader-support.
+// This will reboot the device multiple times, which is perfectly normal.
+
+@RunWith(DeviceJUnit4ClassRunner.class)
+public class MtectrlEndToEndTest extends BaseHostJUnit4Test {
+ private static String mPreviousState = null;
+
+ @BeforeClassWithInfo
+ public static void setUp(TestInformation testInfo) throws Exception {
+ assumeThat(
+ testInfo.getDevice().getProperty("ro.arm64.memtag.bootctl_supported"),
+ equalTo("1"));
+ mPreviousState = testInfo.getDevice().getProperty("arm64.memtag.bootctl");
+ if (mPreviousState == null) {
+ mPreviousState = "";
+ }
+ }
+
+ @AfterClassWithInfo
+ public static void tearDown(TestInformation testInfo) throws Exception {
+ if (mPreviousState != null) {
+ testInfo.getDevice().setProperty("arm64.memtag.bootctl", mPreviousState);
+ testInfo.getDevice().reboot();
+ }
+ }
+
+ @Test
+ public void testMemtagOnce() throws Exception {
+ getDevice().setProperty("arm64.memtag.bootctl", "memtag-once");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isAnyOf("", "none", null);
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isAnyOf("", "none", null);
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).doesNotContain("mte");
+ }
+
+ @Test
+ public void testMemtag() throws Exception {
+ getDevice().setProperty("arm64.memtag.bootctl", "memtag");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
+ }
+
+ @Test
+ public void testBoth() throws Exception {
+ getDevice().setProperty("arm64.memtag.bootctl", "memtag,memtag-once");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
+ getDevice().reboot();
+ assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
+ assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
+ }
+}