From 887376945639002d648c274fb262ba3800c522bb Mon Sep 17 00:00:00 2001 From: Daniel Rosenberg Date: Wed, 30 Oct 2024 18:37:30 -0700 Subject: [PATCH] Reland "Add detailed error log to efs test" Corrected order of Assert Equals, and moved awk parsing into the java code. executeShellV2Command does not handle single quoted awk strings well. Flag: TEST_ONLY Bug: 376164007 Test: atest CopyEfsTest Change-Id: Idea19467ec2f08b1365a2389a1dd3b1db8d429e4 --- .../src/com/android/test/CopyEfsTest.java | 73 +++++++++++++------ 1 file changed, 49 insertions(+), 24 deletions(-) diff --git a/CopyEfsTest/src/com/android/test/CopyEfsTest.java b/CopyEfsTest/src/com/android/test/CopyEfsTest.java index 9314174d..cd22457b 100644 --- a/CopyEfsTest/src/com/android/test/CopyEfsTest.java +++ b/CopyEfsTest/src/com/android/test/CopyEfsTest.java @@ -24,6 +24,7 @@ import org.junit.After; import android.platform.test.annotations.AppModeFull; +import com.android.tradefed.device.DeviceNotAvailableException; import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test; import com.android.tradefed.testtype.junit4.DeviceTestRunOptions; @@ -59,38 +60,62 @@ public class CopyEfsTest extends BaseHostJUnit4Test { testDumpF2FS("persist"); } + private CommandResult RunAndCheckAdbCmd(String cmd) throws DeviceNotAvailableException { + CommandResult r = getDevice().executeShellV2Command(cmd); + assertEquals("Failed to run " + cmd, Integer.valueOf(0), r.getExitCode()); + return r; + } + + // Remove timestamps because ls on device does not support --time-style. + // Format is [permissions] [links] [uid] [gid] [size] time [name/symlink] + // time may vary greatly in formatting + // symlinks will be of the form a -> b + // So we can check for -> in the second to last spot to determine what position the timestamp ends at + // Remove totals because on disk block usage may change depending on filesystem + private String removeTimestamps(String input) { + StringBuilder output = new StringBuilder(); + for (String line : input.split("\n")) { + String[] tokens = line.split("(?")) + name_offset = 3; + for (int i=0; i= 5 && i < tokens.length - name_offset) + continue; + if (i != 0) + output.append(" "); + output.append(tokens[i]); + } + output.append("\n"); + } + return output.toString(); + } + private void testDumpF2FS(String name) throws Exception { - getDevice().executeShellCommand(String.format("cp /dev/block/by-name/%s /data/local/tmp/efs_test/%s.img", name, name)); + RunAndCheckAdbCmd(String.format("cp /dev/block/by-name/%s /data/local/tmp/efs_test/%s.img", name, name)); // The device was mounted r/w. To get a clean image, we run fsck, and then mount to allow mount time fixes to happen. // We can then dump and mount read only to ensure the contents should be the same. - getDevice().executeShellCommand(String.format("fsck.f2fs -f /data/local/tmp/efs_test/%s.img", name, name)); - CommandResult r = getDevice().executeShellV2Command(String.format("mount /data/local/tmp/efs_test/%s.img /data/local/tmp/efs_test/mnt", name)); - assertEquals(r.getExitCode().intValue(), 0); - r = getDevice().executeShellV2Command("umount /data/local/tmp/efs_test/mnt"); - assertEquals(r.getExitCode().intValue(), 0); + RunAndCheckAdbCmd(String.format("fsck.f2fs -f /data/local/tmp/efs_test/%s.img", name)); + RunAndCheckAdbCmd(String.format("mount /data/local/tmp/efs_test/%s.img /data/local/tmp/efs_test/mnt", name)); + RunAndCheckAdbCmd("umount /data/local/tmp/efs_test/mnt"); - r = getDevice().executeShellV2Command(String.format("dump.f2fs -rfPLo /data/local/tmp/efs_test/dump /data/local/tmp/efs_test/%s.img", name)); - assertEquals(r.getExitCode().intValue(), 0); - r = getDevice().executeShellV2Command(String.format("mount -r /data/local/tmp/efs_test/%s.img /data/local/tmp/efs_test/mnt", name)); - assertEquals(r.getExitCode().intValue(), 0); + RunAndCheckAdbCmd(String.format("dump.f2fs -rfPLo /data/local/tmp/efs_test/dump /data/local/tmp/efs_test/%s.img", name)); + RunAndCheckAdbCmd(String.format("mount -r /data/local/tmp/efs_test/%s.img /data/local/tmp/efs_test/mnt", name)); - r = getDevice().executeShellV2Command("diff -rq --no-dereference /data/local/tmp/efs_test/mnt /data/local/tmp/efs_test/dump"); - assertEquals(r.getExitCode().intValue(), 0); + CommandResult r = RunAndCheckAdbCmd("diff -rq --no-dereference /data/local/tmp/efs_test/mnt /data/local/tmp/efs_test/dump"); assertEquals(r.getStdout(), ""); - // Remove timestamps because ls on device does not support --time-style. This is AWKward. - // Format is [permissions] [links] [uid] [gid] [size] time [name/symlink] - // time may have different numbers of blocks - // symlinks will be of the form a -> b - // So we can check for -> in the second to last spot to determine what position the timestamp ends at - // Remove totals because on disk block usage may change depending on filesystem - String ls_cmd = "cd /data/local/tmp/efs_test/%s;ls -AlnR . | awk {'if (NF>3 && $(NF-1) == \"->\") end=3; else end=1; for(i=6;i<=NF-end && i>0;i++)$i=\"\";if ($1 != \"total\"){print $0}'}"; - String mnt_ls = getDevice().executeShellCommand(String.format(ls_cmd, "mnt")); - assertEquals(getDevice().executeShellCommand("echo $?"), "0\n"); - String dump_ls = getDevice().executeShellCommand(String.format(ls_cmd, "dump")); - assertEquals(getDevice().executeShellCommand("echo $?"), "0\n"); - assertEquals(mnt_ls, dump_ls); + String ls_cmd = "cd /data/local/tmp/efs_test/%s;ls -AlnR ."; + CommandResult mnt_ls = RunAndCheckAdbCmd(String.format(ls_cmd, "mnt")); + CommandResult dump_ls = RunAndCheckAdbCmd(String.format(ls_cmd, "dump")); + assertEquals(removeTimestamps(mnt_ls.getStdout()), removeTimestamps(dump_ls.getStdout())); getDevice().executeShellCommand("umount /data/local/tmp/efs_test/mnt"); getDevice().executeShellCommand("rm -rf /data/local/tmp/efs_test/dump/*");