v8_log_importer_test.js revision 66a37686207944273ced825e0e8b6b6375f8c3de
1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7base.require('tracing.test_utils');
8base.require('tracing.importer.v8_log_importer');
9
10base.unittest.testSuite('tracing.importer.v8_log_importer', function() {
11  var V8LogImporter = tracing.importer.V8LogImporter;
12
13  test('tickEventInSharedLibrary', function() {
14    var lines = [
15      'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
16      'tick,0x99d8aae4,0xbff02f08,12158,0,0x0,5'];
17    var m = new tracing.TraceModel(lines.join('\n'));
18    var p = m.processes[-32];
19    var threads = p.findAllThreadsNamed('V8 PC');
20    var t = threads[0];
21    assertEquals(1, t.samples.length);
22    assertEquals('/usr/lib/libc++.1.dylib', t.samples[0].title);
23  });
24
25  test('tickEventInGeneratedCode', function() {
26    var lines = [
27      'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
28      'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
29      'tick,0x5b60ce84,0xbff02f08,12158,0,0x0,5'];
30    var m = new tracing.TraceModel(lines.join('\n'));
31    var p = m.processes[-32];
32    var threads = p.findAllThreadsNamed('V8 PC');
33    var t = threads[0];
34    assertEquals(1, t.samples.length);
35    assertEquals('StringAddStub', t.samples[0].title);
36  });
37
38  test('tickEventInUknownCode', function() {
39    var lines = [
40      'shared-library,"/usr/lib/libc++.1.dylib",0x99d8aae0,0x99dce729',
41      'code-creation,Stub,2,0x5b60ce80,1259,"StringAddStub"',
42      'tick,0x4,0xbff02f08,12158,0,0x0,5'];
43    var m = new tracing.TraceModel(lines.join('\n'));
44    var p = m.processes[-32];
45    var threads = p.findAllThreadsNamed('V8 PC');
46    var t = threads[0];
47    assertEquals(1, t.samples.length);
48    assertEquals('UnknownCode', t.samples[0].title);
49  });
50
51  test('timerEventSliceCreation', function() {
52    var lines = ['timer-event,"V8.External",38189483,3'];
53    var m = new tracing.TraceModel(lines.join('\n'));
54    var p = m.processes[-32];
55    var threads = p.findAllThreadsNamed('V8 Timers');
56    assertNotUndefined(threads);
57    assertEquals(threads.length, 1);
58    var t = threads[0];
59    assertEquals(t.sliceGroup.length, 1);
60  });
61
62  test('processThreadCreation', function() {
63    var lines = ['timer-event,"V8.External",38189483,3'];
64    var m = new tracing.TraceModel(lines.join('\n'));
65    assertNotUndefined(m);
66    var p = m.processes[-32];
67    assertNotUndefined(p);
68    var threads = p.findAllThreadsNamed('V8 Timers');
69    assertNotUndefined(threads);
70    assertEquals(threads.length, 1);
71    var t = threads[0];
72    assertEquals(t.name, 'V8 Timers');
73  });
74
75  test('canImport', function() {
76    assertTrue(V8LogImporter.canImport(
77        'timer-event,"V8.External",38189483,3'));
78    assertFalse(V8LogImporter.canImport(''));
79    assertFalse(V8LogImporter.canImport([]));
80  });
81});
82