Merge "Change CopyEfsTest to test contents" into main
This commit is contained in:
commit
c42244bfb6
1 changed files with 35 additions and 48 deletions
|
@ -19,12 +19,15 @@ package com.android.test;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assume.assumeTrue;
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.After;
|
||||||
|
|
||||||
import android.platform.test.annotations.AppModeFull;
|
import android.platform.test.annotations.AppModeFull;
|
||||||
|
|
||||||
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
|
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
|
||||||
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
|
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
|
||||||
import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
|
import com.android.tradefed.testtype.junit4.DeviceTestRunOptions;
|
||||||
|
import com.android.tradefed.util.CommandResult;
|
||||||
import com.android.tradefed.util.RunUtil;
|
import com.android.tradefed.util.RunUtil;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -36,62 +39,46 @@ import java.io.StringReader;
|
||||||
@RunWith(DeviceJUnit4ClassRunner.class)
|
@RunWith(DeviceJUnit4ClassRunner.class)
|
||||||
public class CopyEfsTest extends BaseHostJUnit4Test {
|
public class CopyEfsTest extends BaseHostJUnit4Test {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
getDevice().enableAdbRoot();
|
||||||
|
|
||||||
|
getDevice().executeShellCommand("rm -rf /data/local/tmp/efs_test");
|
||||||
|
getDevice().executeShellCommand("mkdir -p /data/local/tmp/efs_test/mnt");
|
||||||
|
getDevice().executeShellCommand("mkdir -p /data/local/tmp/efs_test/dump");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@AppModeFull
|
@AppModeFull
|
||||||
public void copyEfsTest() throws Exception {
|
public void copyEfsTest() throws Exception {
|
||||||
|
assumeTrue(getDevice().executeShellCommand("getconf PAGESIZE").trim().equals("4096"));
|
||||||
|
|
||||||
getDevice().enableAdbRoot();
|
testDumpF2FS("efs");
|
||||||
|
testDumpF2FS("efs_backup");
|
||||||
// This test can be run on OEM unlocked device only as unlocking bootloader requires
|
testDumpF2FS("modem_userdata");
|
||||||
// manual intervention.
|
|
||||||
String result = getDevice().getProperty("ro.boot.flash.locked");
|
|
||||||
assumeTrue("0".equals(result));
|
|
||||||
final String dataFstype = getFsTypeFor("/data");
|
|
||||||
assertTrue(!dataFstype.isEmpty());
|
|
||||||
if (!dataFstype.equals("ext4")) {
|
|
||||||
getDevice().executeShellCommand("cmd recovery wipe ext4");
|
|
||||||
RunUtil.getDefault().sleep(10000);
|
|
||||||
// Wait for 2 mins device to be online againg
|
|
||||||
getDevice().waitForDeviceOnline(120000);
|
|
||||||
getDevice().enableAdbRoot();
|
|
||||||
}
|
|
||||||
assertEquals("ext4", getFsTypeFor("/data"));
|
|
||||||
String dataBlockDev = getBlockDevFor("/data");
|
|
||||||
assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/efs"));
|
|
||||||
assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/efs_backup"));
|
|
||||||
assertEquals(dataBlockDev, getBlockDevFor("/mnt/vendor/modem_userdata"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String[] getMountInfo(String mountPoint) throws Exception {
|
private void testDumpF2FS(String name) throws Exception {
|
||||||
String result = getDevice().executeShellCommand("cat /proc/mounts");
|
getDevice().executeShellV2Command(String.format("cp /dev/block/by-name/%s /data/local/tmp/efs_test/%s.img", name, name));
|
||||||
BufferedReader br = new BufferedReader(new StringReader(result));
|
CommandResult r = getDevice().executeShellV2Command(String.format("dump.f2fs -rfPo /data/local/tmp/efs_test/dump /data/local/tmp/efs_test/%s.img", name));
|
||||||
String line;
|
assertEquals(r.getExitCode().intValue(), 0);
|
||||||
while ((line = br.readLine()) != null) {
|
r = getDevice().executeShellV2Command(String.format("mount -r /data/local/tmp/efs_test/%s.img /data/local/tmp/efs_test/mnt", name));
|
||||||
final String[] fields = line.split(" ");
|
assertEquals(r.getExitCode().intValue(), 0);
|
||||||
final String device = fields[0];
|
assertEquals("", getDevice().executeShellCommand("diff -rq /data/local/tmp/efs_test/mnt /data/local/tmp/efs_test/dump"));
|
||||||
final String partition = fields[1];
|
// Remove timestamps at positions 6 and 7, because ls on device does not support --time-style
|
||||||
final String fsType = fields[2];
|
// Remove totals because on disk block usage may change depending on filesystem
|
||||||
if (partition.equals(mountPoint)) {
|
String ls_cmd = "ls -alLnR /data/local/tmp/efs_test/%s | awk {\'$6=\"\";$7=\"\";if ($1 != \"total\"){print $0'}";
|
||||||
return fields;
|
String mnt_ls = getDevice().executeShellCommand(String.format(ls_cmd, "mnt"));
|
||||||
}
|
String dump_ls = getDevice().executeShellCommand(String.format(ls_cmd, "dump"));
|
||||||
}
|
assertEquals(mnt_ls, dump_ls);
|
||||||
return null;
|
getDevice().executeShellCommand("umount -r /data/local/tmp/efs_test/mnt");
|
||||||
|
getDevice().executeShellCommand("rm -rf /data/local/tmp/efs_test/dump/*");
|
||||||
|
getDevice().executeShellCommand("rm /data/local/tmp/efs_test/" + name + ".img");
|
||||||
}
|
}
|
||||||
private String getFsTypeFor(String mountPoint) throws Exception {
|
|
||||||
String[] result = getMountInfo(mountPoint);
|
@After
|
||||||
if (result == null) {
|
public void tearDown() throws Exception {
|
||||||
return "";
|
getDevice().executeShellCommand("umount -r /data/local/tmp/efs_test/mnt");
|
||||||
}
|
getDevice().executeShellCommand("rm -rf /data/local/tmp/efs_test");
|
||||||
return result[2];
|
|
||||||
}
|
|
||||||
private String getBlockDevFor(String mountPoint) throws Exception {
|
|
||||||
String[] result = getMountInfo(mountPoint);
|
|
||||||
if (result == null) {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return result[0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue