1 /*
2  * Copyright (C) 2016 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.DumpsysWifiStatsItem;
19 
20 import junit.framework.TestCase;
21 
22 import java.util.Arrays;
23 import java.util.List;
24 
25 /**
26  * Unit tests for {@link DumpsysWifiStatsParser}
27  */
28 public class DumpsysWifiStatsParserTest extends TestCase {
29 
30     /**
31      * Test that normal input is parsed.
32      */
testDumpsysWifiStatsParser()33     public void testDumpsysWifiStatsParser() {
34         List<String> inputBlock = Arrays.asList(
35                 "Wi-Fi is enabled",
36                 "rec[0]: time=10-09 00:25:16.737 processed=DefaultState org=DeviceActiveState "
37                 + "dest=<null> what=155654(0x26006)",
38                 "mScreenOff true",
39                 " rec[0]: time=10-08 16:49:55.034 processed=WatchdogEnabledState org=OnlineState "
40                 + "dest=OnlineWatchState what=135170(0x21002)",
41                 "rec[30]: time=10-08 13:06:50.379 processed=DriverStartedState org=ConnectedState "
42                 + "dest=<null> what=131143(0x20047) (1)CMD_START_SCAN  rt=4720806/7884852 10013 51 "
43                 + "ic=0 proc(ms):14 onGoing full started:1444334810368,11 cnt=24 rssi=-127 f=-1 "
44                 + "sc=0 link=-1 tx=1.5, 1.7, 0.0  rx=8.4 fiv=20000 [on:3266 tx:65 rx:556 "
45                 + "period:1268] from screen [on:266962 period:266959]",
46                 "rec[357]: time=10-08 13:10:13.199 processed=DriverStartedState org=ConnectedState "
47                 + "dest=<null> what=131143(0x20047) (-2)CMD_START_SCAN  rt=4923625/8087671 10013 "
48                 + "175 ic=0 proc(ms):2 onGoing full started:1444335011199,1999 cnt=24 rssi=-127 "
49                 + "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] "
50                 + "from screen [on:467747 period:469779]",
51                 "WifiConfigStore - Log Begin ----",
52                 "10-08 11:09:14.653 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
53                 "10-08 13:06:29.489 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED "
54                 + "bssid=9c:1c:12:c3:d0:72 reason=0]",
55                 "10-08 13:06:22.280 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
56                 "10-08 13:06:25.363 - Event [IFNAME=wlan0 CTRL-EVENT-SCAN-STARTED ]",
57                 "10-08 13:08:15.018 - Event [IFNAME=wlan0 CTRL-EVENT-DISCONNECTED "
58                 + "bssid=9c:1c:12:e8:72:d2 reason=3 locally_generated=1]",
59                 "10-08 13:08:15.324 - wlan0: 442:IFNAME=wlan0 ENABLE_NETWORK 0 -> true",
60                 "01-21 13:17:23.1 - Event [IFNAME=wlan0 Trying to associate with SSID 'WL-power']",
61                 "01-21 13:18:23.1 - Event [IFNAME=wlan0 Trying to associate with SSID 'WL-power']",
62                 "01-21 13:18:23.1 - Event [IFNAME=wlan0 Trying to associate with SSID 'WL-power']");
63 
64         DumpsysWifiStatsItem wifiStats = new DumpsysWifiStatsParser().parse(inputBlock);
65         assertEquals(2, wifiStats.getNumWifiDisconnects());
66         assertEquals(3, wifiStats.getNumWifiScans());
67         assertEquals(3, wifiStats.getNumWifiAssociations());
68     }
69 
70     /**
71      * Test that input with no wifi disconnect and wifi scans.
72      */
testDumpsysWifiStatsParser_no_wifi_scan_disconnect()73     public void testDumpsysWifiStatsParser_no_wifi_scan_disconnect() {
74         List<String> inputBlock = Arrays.asList(
75                 "Wi-Fi is enabled",
76                 "rec[0]: time=10-09 00:25:16.737 processed=DefaultState org=DeviceActiveState "
77                 + "dest=<null> what=155654(0x26006)",
78                 "mScreenOff true",
79                 " rec[0]: time=10-08 16:49:55.034 processed=WatchdogEnabledState org=OnlineState "
80                 + "dest=OnlineWatchState what=135170(0x21002)",
81                 "rec[30]: time=10-08 13:06:50.379 processed=DriverStartedState org=ConnectedState "
82                 + "dest=<null> what=131143(0x20047) (1)CMD_START_SCAN  rt=4720806/7884852 10013 51 "
83                 + "ic=0 proc(ms):14 onGoing full started:1444334810368,11 cnt=24 rssi=-127 f=-1 "
84                 + "sc=0 link=-1 tx=1.5, 1.7, 0.0  rx=8.4 fiv=20000 [on:3266 tx:65 rx:556 "
85                 + "period:1268] from screen [on:266962 period:266959]",
86                 "rec[357]: time=10-08 13:10:13.199 processed=DriverStartedState org=ConnectedState "
87                 + "dest=<null> what=131143(0x20047) (-2)CMD_START_SCAN  rt=4923625/8087671 10013 "
88                 + "175 ic=0 proc(ms):2 onGoing full started:1444335011199,1999 cnt=24 rssi=-127 "
89                 + "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]"
90                 + "from screen [on:467747 period:469779]",
91                 "WifiConfigStore - Log Begin ----",
92                 "10-08 13:07:37.777 - wlan0: 384:IFNAME=wlan0 ENABLE_NETWORK 4 -> true",
93                 "10-08 13:07:37.789 - wlan0: 388:IFNAME=wlan0 SAVE_CONFIG -> true",
94                 "10-08 13:08:15.065 - wlan0: 427:IFNAME=wlan0 SET ps 1 -> true",
95                 "10-08 13:08:15.179 - wlan0: 432:IFNAME=wlan0 SET pno 1 -> true");
96 
97         DumpsysWifiStatsItem wifiStats = new DumpsysWifiStatsParser().parse(inputBlock);
98         assertEquals(0, wifiStats.getNumWifiDisconnects());
99         assertEquals(0, wifiStats.getNumWifiScans());
100         assertEquals(0, wifiStats.getNumWifiAssociations());
101     }
102 }
103 
104