Skip to content

Commit 67e816e

Browse files
committed
test(runtime): count only this process's dispatch warnings
The log outlives the app, so a second run on the same device counted the warnings of the first. Lines are now matched to android.os.Process.myPid(); logcat's --pid filter needs API 24.
1 parent b8dfe7c commit 67e816e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎test-app/app/src/main/java/com/tns/tests/LogcatUtil.java‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@ public static boolean logcatContainsString(String str) throws Exception {
2222
return output.contains(str);
2323
}
2424

25-
// Lines this app logged under the JS tag at warning level or above that contain both
26-
// strings. Leaves the log in place, so earlier lines count too.
25+
// Lines this process logged under the JS tag at warning level or above that contain
26+
// both strings. Leaves the log in place, so earlier lines of this process count too.
2727
public static int countJsWarnings(String needle, String otherNeedle) throws Exception {
28-
Process process = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "-v", "raw", "-s", "JS:W"});
28+
// -v brief prefixes each line with "W/JS ( 1234): "; --pid needs API 24.
29+
String pidTag = "(" + android.os.Process.myPid() + "):";
30+
Process process = Runtime.getRuntime().exec(new String[]{"logcat", "-d", "-v", "brief", "-s", "JS:W"});
2931
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
3032
int count = 0;
3133
String line;
3234
while ((line = bufferedReader.readLine()) != null) {
35+
int prefixEnd = line.indexOf("):");
36+
if (prefixEnd < 0 || !line.substring(0, prefixEnd + 2).replace(" ", "").endsWith(pidTag)) {
37+
continue;
38+
}
3339
if (line.contains(needle) && line.contains(otherNeedle)) {
3440
count++;
3541
}

0 commit comments

Comments
 (0)