-
Notifications
You must be signed in to change notification settings - Fork 318
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trim and truncate test failure stack traces for both orchestrator and…
… classic/non-orchestrator modes. This change should clean up test failure reporting by: - Remove test runner framework related stack frames - Truncate stack traces to a 64KB size when running under orchestrator to attempt to avoid binder transaction limits. This limit is already enforced when running in classic/non-orchestrator mode JUnit 4.13 has a really nice getTrimmedStackTrace feature, but androidx.test is fixed to 4.12 for the time being. So as a temporary workaround, copy the relevant JUnit change junit-team/junit4#1028 into this project. Fixes #729, and hopefully #269 PiperOrigin-RevId: 329797783
- Loading branch information
1 parent
4bd7957
commit 7c9cce7
Showing
9 changed files
with
356 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
services/events/java/androidx/test/services/events/internal/StackTrimmer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (C) 2020 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package androidx.test.services.events.internal; | ||
|
||
import androidx.annotation.VisibleForTesting; | ||
import android.util.Log; | ||
import org.junit.runner.notification.Failure; | ||
|
||
/** A utility for JUnit failure stack traces */ | ||
public final class StackTrimmer { | ||
|
||
private static final String TAG = "StackTrimmer"; | ||
|
||
@VisibleForTesting static final int MAX_TRACE_SIZE = 64 * 1024; | ||
|
||
private StackTrimmer() {} | ||
|
||
/** | ||
* Returns the stack trace, trimming to remove frames from the test runner, and truncating if its | ||
* too large. | ||
*/ | ||
public static String getTrimmedStackTrace(Failure failure) { | ||
// TODO(b/128614857): switch to JUnit 4.13 Failure.getTrimmedTrace once its available | ||
String trace = Throwables.getTrimmedStackTrace(failure.getException()); | ||
if (trace.length() > MAX_TRACE_SIZE) { | ||
// Since AJUR needs to report failures back to AM via a binder IPC, we need to make sure that | ||
// we don't exceed the Binder transaction limit - which is 1MB per process. | ||
Log.w( | ||
TAG, | ||
String.format("Stack trace too long, trimmed to first %s characters.", MAX_TRACE_SIZE)); | ||
trace = trace.substring(0, MAX_TRACE_SIZE) + "\n"; | ||
} | ||
return trace; | ||
} | ||
} |
Oops, something went wrong.