blob: e966aac102681dc8fc683e62ca890f7a509ed60e [file] [log] [blame]
// Copyright 2015 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 log_helper.js.
*/
describe('LogHelper', function() {
it('should convert elapsed ms to a wall time', function() {
expect(logHelper.formatElapsedMS('1')).toEqual('00:00:00.001');
expect(logHelper.formatElapsedMS('10')).toEqual('00:00:00.010');
expect(logHelper.formatElapsedMS('100')).toEqual('00:00:00.100');
expect(logHelper.formatElapsedMS('1000')).toEqual('00:00:01.000');
expect(logHelper.formatElapsedMS('10000')).toEqual('00:00:10.000');
expect(logHelper.formatElapsedMS('100000')).toEqual('00:01:40.000');
expect(logHelper.formatElapsedMS('1000000')).toEqual('00:16:40.000');
expect(logHelper.formatElapsedMS('10000000')).toEqual('02:46:40.000');
});
it('should detect syslogs', function() {
var time1 = '2015-01-06T23:33:03.478905-08:00';
var time2 = '2015-01-06T23:33:06.680764-08:00';
var time3 = '2015-01-06T23:33:06.681832-08:00';
var basicLog = [
time1 + ' wpa_supplicant[863]: nl80211: Scan trigger',
time2 + ' wpa_supplicant[863]: nl80211: Event message available',
time3 + ' wpa_supplicant[863]: nl80211: New scan results available'
];
var log;
var logLines = [
'---------- END ----------',
'',
'netlog=<multiline>',
'---------- START ----------'
];
log = logLines.concat(basicLog);
log.push('---------- END ----------');
var logHolder = logHelper.detectFileType(log);
expect(logHolder.fileType).toEqual('system_log');
});
it('should detect netlogs', function() {
var time1 = '2015-01-06T23:33:03.478905-08:00';
var time2 = '2015-01-06T23:33:06.680764-08:00';
var time3 = '2015-01-06T23:33:06.681832-08:00';
var basicLog = [
time1 + ' Service 0 updated; state: Associating failure Unknown',
time2 + ' Service 0: state Idle -> Associating',
time3 + ' wpa_supplicant[863]: nl80211: New scan results available'
];
var logHolder = logHelper.detectFileType(basicLog);
expect(logHolder.fileType).toEqual('netlog');
});
it('should detect an unknown file type', function() {
var randomFile = [
'This is not a real log',
'It should not be processed',
' wpa_supplicant[863]: nl80211: New scan results available'
];
var logHolder = logHelper.detectFileType(randomFile);
expect(logHolder.fileType).toEqual('unknown');
});
});