<commit_before><!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/battor_importer.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {

  var CHROMIUM_EVENTS = [
    {
      name: 'a', args: {}, pid: 52, ts: 0,
      cat: 'foo', tid: 53, ph: 'B'
    },
    {
       pid: 94936, tid: 5643, ts: 11000,
       ph: 'c', cat: '__metadata', name: 'clock_sync',
       args: {sync_id: 'ABCDEF-01234-5678-0A1B2C3D', issue_ts: 10000},
       tts: 16496444
    }
  ];

  var BATTOR_LINES = [
    '# BattOr',
    '# voltage_range [0.0, 6144.0] mV',
    '# current_range [0.0, 2275.5] mA',
    '# sample_rate 2000 Hz, gain 5.0x',
    '0.000000 0.000000 4000.000000',
    '0.500000 0.000000 4000.000000',
    '1.000000 0.000000 4000.000000',
    '1.500000 0.000000 4000.000000',
    '2.000000 1.000000 4000.000000'
  ];

  test('canImport', function() {
    assert.isFalse(tr.e.importer.battor.BattorImporter.canImport('string'));
    assert.isFalse(tr.e.importer.battor.BattorImporter.canImport([]));
    assert.isTrue(tr.e.importer.battor.BattorImporter.canImport(
        BATTOR_LINES.join('\n')));
  });

  test('importExplicitClockSync', function() {
    // Add a BattOr sample with an explicit clock sync.
    var battorLinesWithExplicitSync = BATTOR_LINES;
    battorLinesWithExplicitSync.push(
      '2.500000 1.000000 4000.000000 <ABCDEF-01234-5678-0A1B2C3D>');

    var m = tr.c.TestUtils.newModelWithEvents(
        [CHROMIUM_EVENTS, battorLinesWithExplicitSync.join('\n')]);

    // Check to see if power samples were imported successfully.
    assert.isDefined(m.device.powerSeries);

    // Check to see if the power trace is time shifted correctly.
    assert.equal(m.device.powerSeries.samples[0].start, 7.5);
    assert.equal(m.device.powerSeries.samples[5].start, 10.0);
  });

  test('importMissingLinuxTrace', function() {
    var m = tr.c.TestUtils.newModelWithEvents(BATTOR_LINES.join('\n'));
    assert.isTrue(m.hasImportWarnings);
  });

  test('explicitClockSyncWithoutSyncMarkers', function() {
    // Create an empty model.
    var m = new tr.Model();
    var io = new tr.importer.ImportOptions();
    io.showImportWarnings = false;
    m.importOptions = io;

    // Add a BattOr sample with an explicit clock sync.
    var battorLinesWithExplicitSync = BATTOR_LINES;
    battorLinesWithExplicitSync.push(
      '2.500000 1.000000 4000.000000 <ABCDEF-01234-5678-0A1B2C3D>');

    // Create BattOr importer and import the trace.
    var importer = new tr.e.importer.battor.BattorImporter(
        m, battorLinesWithExplicitSync.join('\n'));
    var series = new tr.model.PowerSeries(m.device);<commit_msg>[battor importer] Make a copy of the BattOr test trace before modifying<commit_after><!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/core/test_utils.html">
<link rel="import" href="/tracing/extras/importer/battor_importer.html">
<link rel="import" href="/tracing/extras/importer/linux_perf/ftrace_importer.html">
<link rel="import" href="/tracing/extras/importer/trace_event_importer.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {

  var CHROMIUM_EVENTS = [
    {
      name: 'a', args: {}, pid: 52, ts: 0,
      cat: 'foo', tid: 53, ph: 'B'
    },
    {
       pid: 94936, tid: 5643, ts: 11000,
       ph: 'c', cat: '__metadata', name: 'clock_sync',
       args: {sync_id: 'ABCDEF-01234-5678-0A1B2C3D', issue_ts: 10000},
       tts: 16496444
    }
  ];

  var BATTOR_LINES = [
    '# BattOr',
    '# voltage_range [0.0, 6144.0] mV',
    '# current_range [0.0, 2275.5] mA',
    '# sample_rate 2000 Hz, gain 5.0x',
    '0.000000 0.000000 4000.000000',
    '0.500000 0.000000 4000.000000',
    '1.000000 0.000000 4000.000000',
    '1.500000 0.000000 4000.000000',
    '2.000000 1.000000 4000.000000'
  ];

  test('canImport', function() {
    assert.isFalse(tr.e.importer.battor.BattorImporter.canImport('string'));
    assert.isFalse(tr.e.importer.battor.BattorImporter.canImport([]));
    assert.isTrue(tr.e.importer.battor.BattorImporter.canImport(
        BATTOR_LINES.join('\n')));
  });

  test('importExplicitClockSync', function() {
    // Add a BattOr sample with an explicit clock sync.
    var battorLinesWithExplicitSync = BATTOR_LINES.slice();
    battorLinesWithExplicitSync.push(
      '2.500000 1.000000 4000.000000 <ABCDEF-01234-5678-0A1B2C3D>');

    var m = tr.c.TestUtils.newModelWithEvents(
        [CHROMIUM_EVENTS, battorLinesWithExplicitSync.join('\n')]);

    // Check to see if power samples were imported successfully.
    assert.isDefined(m.device.powerSeries);

    // Check to see if the power trace is time shifted correctly.
    assert.equal(m.device.powerSeries.samples[0].start, 7.5);
    assert.equal(m.device.powerSeries.samples[5].start, 10.0);
  });

  test('importMissingLinuxTrace', function() {
    var m = tr.c.TestUtils.newModelWithEvents(BATTOR_LINES.join('\n'));
    assert.isTrue(m.hasImportWarnings);
  });

  test('explicitClockSyncWithoutSyncMarkers', function() {
    // Create an empty model.
    var m = new tr.Model();
    var io = new tr.importer.ImportOptions();
    io.showImportWarnings = false;
    m.importOptions = io;

    // Add a BattOr sample with an explicit clock sync.
    var battorLinesWithExplicitSync = BATTOR_LINES.slice();
    battorLinesWithExplicitSync.push(
      '2.500000 1.000000 4000.000000 <ABCDEF-01234-5678-0A1B2C3D>');

    // Create BattOr importer and import the trace.
    var importer = new tr.e.importer.battor.BattorImporter(
        m, battorLinesWithExplicitSync.join('\n'));
    var series = new tr.model.PowerSeries(m.device);
{'fraction_non_alphanumeric': 0.14373983739837398, 'fraction_numerical': 0.08780487804878048, 'mean_word_length': 3.5095307917888565, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '825152', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2184, 'n_words': 458}