summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMaxim Siniavine <siniavine@google.com>2015-02-23 18:24:43 -0800
committerMaxim Siniavine <siniavine@google.com>2015-02-25 16:49:05 -0800
commit3c61512f540ec74f0ebda2567725b445f7c873f5 (patch)
tree773aeb250befbda56703847d4454c0ff59038571 /tests
parentc2f8ca20c05a22b5438c2fdbdceb32070321b243 (diff)
downloadloganalysis-3c61512f540ec74f0ebda2567725b445f7c873f5.tar.gz
Add memory health parser
Change-Id: I5508f0c24cfff566db167e8e7dba772a8b17950f
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/loganalysis/parser/MemHealthParserTest.java120
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/src/com/android/loganalysis/parser/MemHealthParserTest.java b/tests/src/com/android/loganalysis/parser/MemHealthParserTest.java
new file mode 100644
index 0000000..f071929
--- /dev/null
+++ b/tests/src/com/android/loganalysis/parser/MemHealthParserTest.java
@@ -0,0 +1,120 @@
+/*
+ * Copyright (C) 2015 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 com.android.loganalysis.parser;
+
+import com.android.loganalysis.item.MemoryHealthItem;
+
+import junit.framework.TestCase;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for memory health parser.
+ */
+public class MemHealthParserTest extends TestCase {
+ public void testOneForegroundProc() {
+ List<String> lines = Arrays.asList("Foreground",
+ "com.google.android.gm",
+ "Average Native Heap: 10910",
+ "Average Dalvik Heap: 8011",
+ "Average PSS: 90454",
+ "Peak Native Heap: 11136",
+ "Peak Dalvik Heap: 9812",
+ "Peak PSS: 95161",
+ "Count 528"
+ );
+
+ MemoryHealthItem item = new MemoryHealthParser().parse(lines);
+ Map<String, Map<String, Long>> processes = item.getForeground();
+ assertNotNull(processes);
+ assertNotNull(processes.get("com.google.android.gm"));
+ Map<String, Long> process = processes.get("com.google.android.gm");
+ assertEquals(10910, process.get("native_avg").longValue());
+ assertEquals(8011, process.get("dalvik_avg").longValue());
+ assertEquals(90454, process.get("pss_avg").longValue());
+ assertEquals(11136, process.get("native_peak").longValue());
+ assertEquals(9812, process.get("dalvik_peak").longValue());
+ assertEquals(95161, process.get("pss_peak").longValue());
+ }
+
+ public void testTwoForegroundProc() {
+ List<String> lines = Arrays.asList("Foreground",
+ "com.google.android.gm",
+ "Average Native Heap: 10910",
+ "Average Dalvik Heap: 8011",
+ "Average PSS: 90454",
+ "Peak Native Heap: 11136",
+ "Peak Dalvik Heap: 9812",
+ "Peak PSS: 95161",
+ "Count 528",
+ "com.google.android.music",
+ "Average Native Heap: 1",
+ "Average Dalvik Heap: 2",
+ "Average PSS: 3",
+ "Peak Native Heap: 4",
+ "Peak Dalvik Heap: 5",
+ "Peak PSS: 6",
+ "Count 7"
+ );
+
+ MemoryHealthItem item = new MemoryHealthParser().parse(lines);
+ Map<String, Map<String, Long>> processes = item.getForeground();
+ assertEquals(2, processes.size());
+ Map<String, Long> process = processes.get("com.google.android.music");
+ assertEquals(1, process.get("native_avg").longValue());
+ assertEquals(2, process.get("dalvik_avg").longValue());
+ assertEquals(3, process.get("pss_avg").longValue());
+ assertEquals(4, process.get("native_peak").longValue());
+ assertEquals(5, process.get("dalvik_peak").longValue());
+ assertEquals(6, process.get("pss_peak").longValue());
+ }
+
+ public void testForegroundBackgroundProc() {
+ List<String> lines = Arrays.asList("Foreground",
+ "com.google.android.gm",
+ "Average Native Heap: 10910",
+ "Average Dalvik Heap: 8011",
+ "Average PSS: 90454",
+ "Peak Native Heap: 11136",
+ "Peak Dalvik Heap: 9812",
+ "Peak PSS: 95161",
+ "Count 528",
+ "Background",
+ "com.google.android.music",
+ "Average Native Heap: 1",
+ "Average Dalvik Heap: 2",
+ "Average PSS: 3",
+ "Peak Native Heap: 4",
+ "Peak Dalvik Heap: 5",
+ "Peak PSS: 6",
+ "Count 7"
+ );
+
+ MemoryHealthItem item = new MemoryHealthParser().parse(lines);
+ Map<String, Map<String, Long>> processes = item.getForeground();
+ assertEquals(1, processes.size());
+ assertEquals(1, item.getBackground().size());
+ Map<String, Long> process = item.getBackground().get("com.google.android.music");
+ assertEquals(1, process.get("native_avg").longValue());
+ assertEquals(2, process.get("dalvik_avg").longValue());
+ assertEquals(3, process.get("pss_avg").longValue());
+ assertEquals(4, process.get("native_peak").longValue());
+ assertEquals(5, process.get("dalvik_peak").longValue());
+ assertEquals(6, process.get("pss_peak").longValue());
+ }
+}