1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.loganalysis.parser;
17 
18 import com.android.loganalysis.item.DumpsysItem;
19 
20 import junit.framework.TestCase;
21 
22 import java.util.Arrays;
23 import java.util.List;
24 
25 /**
26  * Unit tests for {@link DumpsysParser}
27  */
28 public class DumpsysParserTest extends TestCase {
29 
30     /**
31      * Test that normal input is parsed.
32      */
testDumpsysParser()33     public void testDumpsysParser() {
34         List<String> inputBlock =
35                 Arrays.asList(
36                         "DUMP OF SERVICE batterystats:",
37                         "Battery History (37% used, 95KB used of 256KB, 166 strings using 15KB):",
38                         "     0 (9) RESET:TIME: 2014-12-09-11-33-29",
39                         "     +1s067ms (1) 100 c0500020 -wifi_full_lock -wifi_scan",
40                         "     +3s297ms (2) 100 80400020 -wake_lock -screen",
41                         "     +30m02s075ms (1) 100 c0500020 wifi_signal_strength=4 wifi_suppl=completed",
42                         "     +30m03s012ms (2) 099 c0500020 temp=306 volt=4217",
43                         "     +33m48s967ms (1) 099 f8400020 +wifi_scan",
44                         "     +33m49s335ms (2) 098 f0400020 temp=324 -wifi_scan",
45                         "Statistics since last charge:",
46                         " Time on battery: 2h 21m 5s 622ms (12.0%) realtime, 7m 54s 146ms (0.7%) uptime",
47                         " Time on battery screen off: 2h 5m 55s 3ms (1%) realtime, 7m 4s 5ms (7%) uptime",
48                         " Total run time: 19h 38m 43s 650ms realtime, 17h 25m 32s 175ms uptime",
49                         " All kernel wake locks:",
50                         " Kernel Wake lock PowerManagerService.WakeLocks: 1h 3m 50s 5ms (8 times) realtime",
51                         " Kernel Wake lock event0-2656 : 3m 49s 268ms (2399 times) realtime",
52                         " Kernel Wake lock wlan_wd_wake: 3m 34s 639ms (1751 times) realtime",
53                         " Kernel Wake lock wlan_rx_wake: 3m 19s 887ms (225 times) realtime",
54                         " Kernel Wake lock wlan_tx_wake: 2m 19s 887ms (225 times) realtime",
55                         " Kernel Wake lock tx_wake: 1m 19s 887ms (225 times) realtime",
56                         " ",
57                         " All partial wake locks:",
58                         " Wake lock u0a7 NlpWakeLock: 8m 13s 203ms (1479 times) realtime",
59                         " Wake lock u0a7 NlpCollectorWakeLock: 6m 29s 18ms (238 times) realtime",
60                         " Wake lock u0a7 GCM_CONN_ALARM: 6m 8s 587ms (239 times) realtime",
61                         " Wake lock 1000 *alarm*: 5m 11s 316ms (1469 times) realtime",
62                         " Wake lock u10 xxx: 4m 11s 316ms (1469 times) realtime",
63                         " Wake lock u30 cst: 2m 11s 316ms (1469 times) realtime",
64                         " ",
65                         " All wakeup reasons:",
66                         " Wakeup reason 200:qcom,smd-rpm:222:fc4: 11m 49s 332ms (0 times) realtime",
67                         " Wakeup reason 200:qcom,smd-rpm: 48s 45ms (0 times) realtime",
68                         " Wakeup reason 2:qcom,smd-rpm:2:f0.qm,mm:22:fc4mi: 3s 417ms (0 times) realtime",
69                         " Wakeup reason 188:qcom,smd-adsp:200:qcom,smd-rpm: 1s 656ms (0 times) realtime",
70                         " Wakeup reason 58:qcom,smsm-modem:2:qcom,smd-rpm: 6m 16s 1ms (5 times) realtime",
71                         " Wakeup reason 57:qcom,smd-modem:200:qcom,smd-rpm: 40s 995ms (0 times) realtime",
72                         " Wakeup reason unknown: 8s 455ms (0 times) realtime",
73                         " Wakeup reason 9:bcmsdh_sdmmc:2:qcomd-rpm:240:mso: 8m 5s 9ms (0 times) realtime",
74                         " ",
75                         " 0:",
76                         "    User activity: 2 other",
77                         "    Wake lock SCREEN_FROZEN realtime",
78                         "    Sensor 0: 9s 908ms realtime (1 times)",
79                         "    Sensor 1: 9s 997ms realtime (1 times)",
80                         "    Foreground for: 2h 21m 5s 622ms",
81                         "    Apk android:",
82                         "      24 wakeup alarms",
83                         " u0a9:",
84                         "    Mobile network: 8.1KB received, 1.6KB sent (packets 291 received, 342 sent)",
85                         "    Mobile radio active: 3m 43s 890ms (34.2%) 39x @ 354 mspp",
86                         "    Sensor 2: 12m 13s 15ms realtime (5 times)",
87                         "    Sensor 32: (not used)",
88                         "    Sensor 35: (not used)",
89                         "DUMP OF SERVICE package:",
90                         "Package [com.google.android.calculator] (e075c9d):",
91                         "  userId=10071",
92                         "  secondaryCpuAbi=null",
93                         "  versionCode=73000302 minSdk=10000 targetSdk=10000",
94                         "  versionName=7.3 (3821978)",
95                         "  splits=[base]",
96                         "Package [com.google.android.googlequicksearchbox] (607929e):",
97                         "  userId=10037",
98                         "  pkg=Package{af43294 com.google.android.googlequicksearchbox}",
99                         "  versionCode=300734793 minSdk=10000 targetSdk=10000",
100                         "  versionName=6.16.35.26.arm64",
101                         "  apkSigningVersion=2",
102                         "DUMP OF SERVICE procstats:",
103                         "COMMITTED STATS FROM 2015-03-20-02-01-02 (checked in):",
104                         "  * com.android.systemui / u0a22 / v22:",
105                         "           TOTAL: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)",
106                         "      Persistent: 100% (159MB-160MB-161MB/153MB-153MB-154MB over 13)",
107                         "  * com.google.process.gapps / u0a9 / v22:",
108                         "           TOTAL: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)",
109                         "          Imp Fg: 100% (22MB-24MB-25MB/18MB-19MB-20MB over 13)",
110                         "DUMP OF SERVICE wifi:",
111                         "Wi-Fi is enabled",
112                         "rec[0]: time=10-09 00:25:16.737 processed=DefaultState org=DeviceActiveState "
113                                 + "dest=<null> what=155654(0x26006)",
114                         "mScreenOff true",
115                         " rec[0]: time=10-08 16:49:55.034 processed=WatchdogEnabledState org=OnlineState "
116                                 + "dest=OnlineWatchState what=135170(0x21002)",
117                         "rec[30]: time=10-08 13:06:50.379 processed=DriverStartedState org=ConnectedState "
118                                 + "dest=<null> what=131143(0x20047) (1)CMD_START_SCAN  rt=4720806/7884852 10013 51 "
119                                 + "ic=0 proc(ms):14 onGoing full started:1444334810368,11 cnt=24 rssi=-127 f=-1 "
120                                 + "sc=0 link=-1 tx=1.5, 1.7, 0.0  rx=8.4 fiv=20000 [on:3266 tx:65 rx:556 "
121                                 + "period:1268] from screen [on:266962 period:266959]",
122                         "rec[357]: time=10-08 13:10:13.199 processed=DriverStartedState org=ConnectedState "
123                                 + "dest=<null> what=131143(0x20047) (-2)CMD_START_SCAN  rt=4923625/8087671 10013 "
124                                 + "175 ic=0 proc(ms):2 onGoing full started:1444335011199,1999 cnt=24 rssi=-127 "
125                                 + "f=-1 sc=0 link=-1 tx=8.4, 1.7, 0.0  rx=6.7 fiv=20000 [on:0 tx:0 rx:0 period:990]"
126                                 + "from screen [on:467747 period:469779]",
127                         "WifiConfigStore - Log Begin ----",
128                         "10-08 11:09:14.653 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
129                         "10-08 13:06:29.489 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED "
130                                 + "bssid=9c:1c:12:c3:d0:72 reason=0]",
131                         "10-08 13:06:22.280 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
132                         "10-08 13:06:25.363 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
133                         "10-08 13:08:15.018 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED "
134                                 + "bssid=9c:1c:12:e8:72:d2 reason=3 locally_generated=1]",
135                         "10-08 13:08:15.324 - wlan0: 442:IFNAME=wlan0 ENABLE_NETWORK 0 -> true");
136 
137         DumpsysItem dumpsys = new DumpsysParser().parse(inputBlock);
138         assertNotNull(dumpsys.getBatteryStats());
139         assertNotNull(dumpsys.getPackageStats());
140         assertNotNull(dumpsys.getProcStats());
141         assertNotNull(dumpsys.getWifiStats());
142     }
143 }
144