| // Copyright 2016 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| /** |
| * @fileoverview Jasmine test file for androidlog_summary.js. |
| */ |
| |
| describe('AndroidlogSummary', function() { |
| var logSummary; |
| var basicLog; |
| var time1; |
| var time2; |
| var time3; |
| |
| beforeEach(function() { |
| logSummary = new LogSummary(); |
| time1 = '01-04 14:45:37.720'; |
| time2 = '01-04 14:45:37.721'; |
| time3 = '01-04 14:45:37.722'; |
| time4 = '01-04 14:45:37.723'; |
| }); |
| |
| it('should properly match the Android log time format', function() { |
| var regexMatchTime = time1.match(logHelper.ANDROID_TIME_FORMAT)[0]; |
| expect(regexMatchTime).toEqual(time1); |
| }); |
| |
| it('WifiStateMachine tracking should be initialized properly', function() { |
| expect(logSummary.wifiStateMachines.length).toBe(0); |
| }); |
| |
| it('should detect wpa_supplicant disconnects and add to notes', function() { |
| var log = [ |
| time1 + ' wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED' + |
| ' bssid=24:de:c6:e0:89:51 reason=3 locally_generated=1', |
| ]; |
| |
| androidlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.wifiStateMachines.length).toBe(1); |
| expect(logSummary.wifiStateMachines[0].notes.length).toBe(1); |
| }); |
| |
| it('should skip a log line without a valid timestamp', function() { |
| var log = [' wpa_supplicant: Deauthentication frame IE(s)' + |
| ' - hexdump(len=0): [NULL]']; |
| androidlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.wifiStateMachines.length).toBe(0); |
| expect(logSummary.logStartTime).toBe(-1); |
| }); |
| |
| it('should detect and store wpa_supplicant state changes', function() { |
| var log = [ |
| time1 + ' wpa_supplicant: wlan0: State: SCANNING -> ASSOCIATING', |
| time2 + ' wpa_supplicant: wlan0: State: ASSOCIATING -> ASSOCIATED', |
| time3 + ' wpa_supplicant: wlan0: State: ASSOCIATED -> COMPLETED' |
| ]; |
| |
| androidlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.wifiStateMachines.length).toBe(1); |
| // We have 3 state changes in the log used for the test. We expect 7 |
| // entries in the state array since all but the last state will have a start |
| // and stop point. The last state will get the endpoint in post processing |
| // once the end of the log is found. |
| expect(logSummary.wifiStateMachines[0].supplicantStates.length).toBe(7); |
| expect( |
| logSummary.wifiStateMachines[0].networkDetailedStates.length).toBe(0); |
| expect(logSummary.wifiStateMachines[0].notes.length).toBe(3); |
| }); |
| |
| it('should detect and store WifiStateMachine state changes', function() { |
| var log = [ |
| time1 + ' WifiStateMachine: setDetailed state, old =OBTAINING_IPADDR ' + |
| 'and new state=DISCONNECTED', |
| time2 + ' WifiStateMachine: setDetailed state, old =DISCONNECTED ' + |
| 'and new state=SCANNING', |
| time3 + ' WifiStateMachine: setDetailed state, old =SCANNING and ' + |
| 'new state=CONNECTING', |
| ]; |
| |
| androidlogSummary.processLogLines(log, logSummary); |
| expect(logSummary.wifiStateMachines.length).toBe(1); |
| expect(logSummary.wifiStateMachines[0].supplicantStates.length).toBe(0); |
| // We have 3 state changes in the log used for the test. We expect 7 |
| // entries in the state array since all but the last state will have a start |
| // and stop point. The last state will get the endpoint in post processing |
| // once the end of the log is found. |
| expect( |
| logSummary.wifiStateMachines[0].networkDetailedStates.length).toBe(7); |
| expect(logSummary.wifiStateMachines[0].notes.length).toBe(3); |
| }); |
| |
| it('should properly detect and track a mix of log lines', function() { |
| var mixedLog = [ |
| time1 + ' wpa_supplicant: Deauthentication frame IE(s)' + |
| ' - hexdump(len=0): [NULL]', |
| time2 + ' wpa_supplicant: wlan0: CTRL-EVENT-DISCONNECTED' + |
| ' bssid=24:de:c6:e0:89:51 reason=3 locally_generated=1', |
| time3 + ' WifiStateMachine: setDetailed state, old =OBTAINING_IPADDR' + |
| ' and new state=DISCONNECTED hidden=false', |
| time4 + ' wpa_supplicant: wlan0: State: ASSOCIATED -> COMPLETED', |
| time4 + ' LowiWifiHal: ivmh: event ignored!!' |
| |
| ]; |
| |
| androidlogSummary.processLogLines(mixedLog, logSummary); |
| expect(logSummary.wifiStateMachines.length).toBe(1); |
| // supplicant states should have 3 entries: 2 entries for the old state and |
| // 1 entry for the new state. The final state entry will be done in post |
| // processing. |
| expect(logSummary.wifiStateMachines[0].supplicantStates.length).toBe(3); |
| // WSM states should have 3 entries: 2 for old state, 1 for new state |
| expect( |
| logSummary.wifiStateMachines[0].networkDetailedStates.length).toBe(3); |
| // Notes should have 3 entries: |
| // 1 - supplicant disconnect |
| // 2 - WSM state change |
| // 3 - supplicant state change. |
| expect(logSummary.wifiStateMachines[0].notes.length).toBe(3); |
| }); |
| }); |