[test][tools] Add test for timline.mjs

Bug: v8:10668
Change-Id: I51f81a66408a4b262f9ac7e6421609c5e485f779
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2435107
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Sathya Gunasekaran  <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70174}
This commit is contained in:
Camillo Bruni 2020-09-28 17:31:52 +02:00 committed by Commit Bot
parent 677920320c
commit 12cd035911
3 changed files with 36 additions and 2 deletions

View File

@ -12,6 +12,7 @@ group("v8_mjsunit") {
data = [ data = [
"./", "./",
"../../tools/arguments.js",
"../../tools/clusterfuzz/v8_mock.js", "../../tools/clusterfuzz/v8_mock.js",
"../../tools/clusterfuzz/v8_mock_archs.js", "../../tools/clusterfuzz/v8_mock_archs.js",
"../../tools/clusterfuzz/v8_mock_webassembly.js", "../../tools/clusterfuzz/v8_mock_webassembly.js",
@ -24,6 +25,8 @@ group("v8_mjsunit") {
"../../tools/profile_view.mjs", "../../tools/profile_view.mjs",
"../../tools/splaytree.mjs", "../../tools/splaytree.mjs",
"../../tools/tickprocessor.mjs", "../../tools/tickprocessor.mjs",
"../../tools/system-analyzer/log/log.mjs",
"../../tools/system-analyzer/timeline.mjs",
"../../tools/dumpcpp.mjs", "../../tools/dumpcpp.mjs",
] ]
} }

View File

@ -0,0 +1,31 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import { Timeline } from "../../../tools/system-analyzer/timeline.mjs";
import { Event } from "../../../tools/system-analyzer/log/log.mjs";
(function testTimeline() {
let timeline = new Timeline();
let id1 = "0x3e7e082470cd";
let id2 = "0x3e7e082470ad";
let time = 12;
let event1 = new Event(id1, time);
let event2 = new Event(id1, time + 1);
let event3 = new Event(id1, time + 2);
let event4 = new Event(id1, time + 3);
let event5 = new Event(id2, time + 3);
timeline.push(event1);
timeline.push(event2);
timeline.push(event3);
timeline.push(event4);
timeline.push(event5);
let startTime = time;
let endTime = time + 2;
timeline.selectTimeRange(startTime, endTime);
assertArrayEquals(timeline.selection, [event1, event2, event3]);
let entryIdx = timeline.find(time + 1);
let entry = timeline.at(entryIdx);
assertEquals(entry.time, time + 1);
})();

View File

@ -76,11 +76,11 @@ class Timeline {
} }
first() { first() {
return this.#values.first(); return this.#values[0];
} }
last() { last() {
return this.#values.last(); return this.#values[this.#values.length - 1];
} }
duration() { duration() {