Merge "Shorten the name for the dump file."

This commit is contained in:
Treehugger Robot
2021-03-22 21:34:02 +00:00
committed by Gerrit Code Review

View File

@@ -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);