From 8d92650da9a7ee32c2be676d0aaeb45008090ed2 Mon Sep 17 00:00:00 2001 From: Sudheer Shanka Date: Sun, 21 Mar 2021 05:10:55 -0700 Subject: [PATCH] Shorten the name for the dump file. The file name is getting truncated by tradefed and we are missing the information to actually idenity the test. So, instead shorten the filename to preserve the test name. Test: atest ./tests/cts/hostside/src/com/android/cts/net/HostsideRestrictBackgroundNetworkTests.java Ignore-AOSP-First: Submitting internally first to avoid merge conflicts. Merged-In: Ic0f87b97bb58e115fe81e2d688ce0e633397da42 Change-Id: I6ce3fc662782de82d8cad95414e24204b5f7f130 --- .../cts/net/hostside/DumpOnFailureRule.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DumpOnFailureRule.java b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DumpOnFailureRule.java index 5ecb399da0..66cb935a1c 100644 --- a/tests/cts/hostside/app/src/com/android/cts/net/hostside/DumpOnFailureRule.java +++ b/tests/cts/hostside/app/src/com/android/cts/net/hostside/DumpOnFailureRule.java @@ -24,6 +24,8 @@ import android.os.FileUtils; import android.os.ParcelFileDescriptor; import android.util.Log; +import androidx.test.platform.app.InstrumentationRegistry; + import com.android.compatibility.common.util.OnFailureRule; import org.junit.AssumptionViolatedException; @@ -37,23 +39,20 @@ import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; -import androidx.test.platform.app.InstrumentationRegistry; - public class DumpOnFailureRule extends OnFailureRule { private File mDumpDir = new File(Environment.getExternalStorageDirectory(), "CtsHostsideNetworkTests"); @Override public void onTestFailure(Statement base, Description description, Throwable throwable) { - final String testName = description.getClassName() + "_" + description.getMethodName(); - if (throwable instanceof AssumptionViolatedException) { + final String testName = description.getClassName() + "_" + description.getMethodName(); Log.d(TAG, "Skipping test " + testName + ": " + throwable); return; } prepareDumpRootDir(); - final File dumpFile = new File(mDumpDir, "dump-" + testName); + final File dumpFile = new File(mDumpDir, "dump-" + getShortenedTestName(description)); Log.i(TAG, "Dumping debug info for " + description + ": " + dumpFile.getPath()); try (FileOutputStream out = new FileOutputStream(dumpFile)) { for (String cmd : new String[] { @@ -71,6 +70,17 @@ public class DumpOnFailureRule extends OnFailureRule { } } + private String getShortenedTestName(Description description) { + final String qualifiedClassName = description.getClassName(); + final String className = qualifiedClassName.substring( + qualifiedClassName.lastIndexOf(".") + 1); + final String shortenedClassName = className.chars() + .filter(Character::isUpperCase) + .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) + .toString(); + return shortenedClassName + "_" + description.getMethodName(); + } + void dumpCommandOutput(FileOutputStream out, String cmd) { final ParcelFileDescriptor pfd = InstrumentationRegistry.getInstrumentation() .getUiAutomation().executeShellCommand(cmd);