summaryrefslogtreecommitdiff
path: root/tests/src/com/android/loganalysis/parser/MemHealthParserTest.java
blob: f0719296bc69669e2254884ba899aff72a477adf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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());
    }
}