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
|
/*
* 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.WakelockItem;
import com.android.loganalysis.item.WakelockItem.WakeLockCategory;
import junit.framework.TestCase;
import java.util.Arrays;
import java.util.List;
/**
* Unit tests for {@link WakelockParser}
*/
public class WakelockParserTest extends TestCase {
/**
* Test that normal input is parsed.
*/
public void testWakelockParser() {
List<String> inputBlock = Arrays.asList(
" All kernel wake locks:",
" Kernel Wake lock PowerManagerService.WakeLocks: 1h 3m 50s 5ms (8 times) realtime",
" Kernel Wake lock event0-2656 : 3m 49s 268ms (2399 times) realtime",
" Kernel Wake lock wlan_wd_wake: 3m 34s 639ms (1751 times) realtime",
" Kernel Wake lock wlan_rx_wake: 3m 19s 887ms (225 times) realtime",
" Kernel Wake lock wlan_tx_wake: 2m 19s 887ms (225 times) realtime",
" Kernel Wake lock tx_wake: 1m 19s 887ms (225 times) realtime",
" ",
" All partial wake locks:",
" Wake lock u0a7 NlpWakeLock: 8m 13s 203ms (1479 times) realtime",
" Wake lock u0a7 NlpCollectorWakeLock: 6m 29s 18ms (238 times) realtime",
" Wake lock u0a7 GCM_CONN_ALARM: 6m 8s 587ms (239 times) realtime",
" Wake lock 1000 *alarm*: 5m 11s 316ms (1469 times) realtime",
" Wake lock u10 xxx: 4m 11s 316ms (1469 times) realtime",
" Wake lock u30 cst: 2m 11s 316ms (1469 times) realtime");
WakelockItem wakelock = new WakelockParser().parse(inputBlock);
assertEquals(WakelockParser.TOP_WAKELOCK_COUNT,
wakelock.getWakeLocks(WakeLockCategory.KERNEL_WAKELOCK).size());
assertEquals("event0-2656 ",
wakelock.getWakeLocks(WakeLockCategory.KERNEL_WAKELOCK).get(0).getName());
assertEquals(229268, wakelock.getWakeLocks(WakeLockCategory.KERNEL_WAKELOCK).
get(0).getHeldTime());
assertEquals(2399, wakelock.getWakeLocks(WakeLockCategory.KERNEL_WAKELOCK).
get(0).getLockedCount());
assertEquals(WakelockParser.TOP_WAKELOCK_COUNT,
wakelock.getWakeLocks(WakeLockCategory.PARTIAL_WAKELOCK).size());
assertEquals("NlpWakeLock", wakelock.getWakeLocks(WakeLockCategory.PARTIAL_WAKELOCK).
get(0).getName());
assertEquals("u0a7", wakelock.getWakeLocks(WakeLockCategory.PARTIAL_WAKELOCK).
get(0).getProcessUID());
assertEquals(493203, wakelock.getWakeLocks(WakeLockCategory.PARTIAL_WAKELOCK).
get(0).getHeldTime());
assertEquals(1479, wakelock.getWakeLocks(WakeLockCategory.PARTIAL_WAKELOCK).
get(0).getLockedCount());
}
}
|