More robust parsing of /proc/meminfo
The test assumed that an entry (ex: foo: 100 kB) in /proc/meminfo
doesn't have a tab character. That assumption was broken when the kernel
starts to emit an entry with a tab chracter. Specifically, the following
entry was added with a tab character(s) in front of the number.
SecPageTables: 0 kB
Fixing this by matching a line with a regex.
Bug: N/A
Test: run com.android.microdroid.test.MicrodroidHostTests#testMicrodroidRamUsage
with the updated kernel
Change-Id: I6061c0adb382e2513bf2abbfea5c9219800f55f8
diff --git a/tests/helper/src/java/com/android/microdroid/test/common/ProcessUtil.java b/tests/helper/src/java/com/android/microdroid/test/common/ProcessUtil.java
index d85929d..940ec9c 100644
--- a/tests/helper/src/java/com/android/microdroid/test/common/ProcessUtil.java
+++ b/tests/helper/src/java/com/android/microdroid/test/common/ProcessUtil.java
@@ -99,12 +99,14 @@
if (line.length() == 0) {
continue;
}
- if (line.contains(": ")) {
+ // Each line is '<metrics>: <number> kB'.
+ // EX : Pss_Anon: 70712 kB
+ // EX : Active(file): 5792 kB
+ // EX : ProtectionKey: 0
+ if (line.matches("[\\w()]+:\\s+.*")) {
if (entries.size() == 0) {
throw new RuntimeException("unexpected line: " + line);
}
- // Each line is '<metrics>: <number> kB'.
- // EX : Pss_Anon: 70712 kB
if (line.endsWith(" kB")) line = line.substring(0, line.length() - 3);
String[] elems = line.split(":");
String name = elems[0].trim();