Skip to content
Snippets Groups Projects
Commit 8d92650d authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

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
parent 60b26ee4
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment