Avoid relogging logs from the subprocess
delegate already logged its own logs, parent in this
case doesn't need to do it again.
Test: unit tests
Bug: 161129053
Change-Id: I2ff0dd80aaecd8df45700fffabddf7ef23ffdadb
diff --git a/src/com/android/tradefed/invoker/DelegatedInvocationExecution.java b/src/com/android/tradefed/invoker/DelegatedInvocationExecution.java
index 9ac84a0..3c45101 100644
--- a/src/com/android/tradefed/invoker/DelegatedInvocationExecution.java
+++ b/src/com/android/tradefed/invoker/DelegatedInvocationExecution.java
@@ -177,7 +177,8 @@
private StreamProtoReceiver createReceiver(
ITestInvocationListener listener, IInvocationContext mainContext) throws IOException {
StreamProtoReceiver receiver =
- new StreamProtoReceiver(listener, mainContext, false, false, "");
+ new StreamProtoReceiver(
+ listener, mainContext, false, false, /* report logs */ false, "");
return receiver;
}
diff --git a/src/com/android/tradefed/result/proto/ProtoResultParser.java b/src/com/android/tradefed/result/proto/ProtoResultParser.java
index a481cc9..32792dd 100644
--- a/src/com/android/tradefed/result/proto/ProtoResultParser.java
+++ b/src/com/android/tradefed/result/proto/ProtoResultParser.java
@@ -69,6 +69,8 @@
* invocation scope we should not report it again.
*/
private boolean mReportInvocation = false;
+ /** In some cases we do not need to forward the logs. */
+ private boolean mReportLogs = true;
/** Prefix that will be added to the files logged through the parser. */
private String mFilePrefix;
/** The context from the invocation in progress, not the proto one. */
@@ -115,6 +117,11 @@
mQuietParsing = quiet;
}
+ /** Sets whether or not we should report the logs. */
+ public void setReportLogs(boolean reportLogs) {
+ mReportLogs = reportLogs;
+ }
+
/**
* Main entry function that takes the finalized completed proto and replay its results.
*
@@ -500,6 +507,9 @@
if (!(mListener instanceof ILogSaverListener)) {
return;
}
+ if (!mReportLogs) {
+ return;
+ }
ILogSaverListener logger = (ILogSaverListener) mListener;
for (Entry<String, Any> entry : proto.getArtifactsMap().entrySet()) {
try {
diff --git a/src/com/android/tradefed/result/proto/StreamProtoReceiver.java b/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
index f674906..ab49396 100644
--- a/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
+++ b/src/com/android/tradefed/result/proto/StreamProtoReceiver.java
@@ -83,7 +83,7 @@
boolean reportInvocation,
boolean quietParsing)
throws IOException {
- this(listener, mainContext, reportInvocation, quietParsing, "subprocess-");
+ this(listener, mainContext, reportInvocation, quietParsing, true, "subprocess-");
}
/**
@@ -102,8 +102,30 @@
boolean quietParsing,
String logNamePrefix)
throws IOException {
+ this(listener, mainContext, reportInvocation, quietParsing, true, logNamePrefix);
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param listener the {@link ITestInvocationListener} where to report the results.
+ * @param reportInvocation Whether or not to report the invocation level events.
+ * @param quietParsing Whether or not to let the parser log debug information.
+ * @param reportLogs Whether or not to report the logs
+ * @param logNamePrefix The prefix for file logged through the parser.
+ * @throws IOException
+ */
+ public StreamProtoReceiver(
+ ITestInvocationListener listener,
+ IInvocationContext mainContext,
+ boolean reportInvocation,
+ boolean quietParsing,
+ boolean reportLogs,
+ String logNamePrefix)
+ throws IOException {
mListener = listener;
mParser = new ProtoResultParser(mListener, mainContext, reportInvocation, logNamePrefix);
+ mParser.setReportLogs(reportLogs);
mParser.setQuiet(quietParsing);
mEventReceiver = new EventReceiverThread();
mEventReceiver.start();