Skip to content

Commit 4546f6a

Browse files
committed
Add end to end test for mtectrl.
Bug: 255628885 Change-Id: Ie03b40b8702fa45ea9f8ba2d022975d5cc9024dd
1 parent 427b7d5 commit 4546f6a

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

Diff for: mtectrl/Android.bp

+8
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,11 @@ cc_test {
4040
"libgmock",
4141
]
4242
}
43+
44+
java_test_host {
45+
name: "mtectrl_end_to_end_test",
46+
libs: ["tradefed"],
47+
static_libs: ["frameworks-base-hostutils", "cts-install-lib-host"],
48+
srcs: ["src/com/android/tests/mtectrl/MtectrlEndToEndTest.java"],
49+
test_suites: ["general-tests"],
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright (C) 2022 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+
17+
package com.android.tests.mtectrl;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import static org.hamcrest.CoreMatchers.equalTo;
22+
import static org.junit.Assume.assumeThat;
23+
24+
import com.android.tradefed.invoker.TestInformation;
25+
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
26+
import com.android.tradefed.testtype.junit4.AfterClassWithInfo;
27+
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
28+
import com.android.tradefed.testtype.junit4.BeforeClassWithInfo;
29+
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
33+
// Test the protocol described in
34+
// https://source.android.com/docs/security/test/memory-safety/bootloader-support.
35+
// This will reboot the device multiple times, which is perfectly normal.
36+
37+
@RunWith(DeviceJUnit4ClassRunner.class)
38+
public class MtectrlEndToEndTest extends BaseHostJUnit4Test {
39+
private static String mPreviousState = null;
40+
41+
@BeforeClassWithInfo
42+
public static void setUp(TestInformation testInfo) throws Exception {
43+
assumeThat(
44+
testInfo.getDevice().getProperty("ro.arm64.memtag.bootctl_supported"),
45+
equalTo("1"));
46+
mPreviousState = testInfo.getDevice().getProperty("arm64.memtag.bootctl");
47+
if (mPreviousState == null) {
48+
mPreviousState = "";
49+
}
50+
}
51+
52+
@AfterClassWithInfo
53+
public static void tearDown(TestInformation testInfo) throws Exception {
54+
if (mPreviousState != null) {
55+
testInfo.getDevice().setProperty("arm64.memtag.bootctl", mPreviousState);
56+
testInfo.getDevice().reboot();
57+
}
58+
}
59+
60+
@Test
61+
public void testMemtagOnce() throws Exception {
62+
getDevice().setProperty("arm64.memtag.bootctl", "memtag-once");
63+
getDevice().reboot();
64+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isAnyOf("", "none", null);
65+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
66+
getDevice().reboot();
67+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isAnyOf("", "none", null);
68+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).doesNotContain("mte");
69+
}
70+
71+
@Test
72+
public void testMemtag() throws Exception {
73+
getDevice().setProperty("arm64.memtag.bootctl", "memtag");
74+
getDevice().reboot();
75+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
76+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
77+
getDevice().reboot();
78+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
79+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
80+
}
81+
82+
@Test
83+
public void testBoth() throws Exception {
84+
getDevice().setProperty("arm64.memtag.bootctl", "memtag,memtag-once");
85+
getDevice().reboot();
86+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
87+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
88+
getDevice().reboot();
89+
assertThat(getDevice().getProperty("arm64.memtag.bootctl")).isEqualTo("memtag");
90+
assertThat(getDevice().pullFileContents("/proc/cpuinfo")).contains("mte");
91+
}
92+
}

0 commit comments

Comments
 (0)