v8/test/inspector/runtime-call-stats/enable-disable.js
Peter Marshall 5eb5015ea8 [tests] Filter out non-existent methods in inspector tests
Previously these would silently fail unless the caller checked the
.error property of the return value. There are no tests that check
iteractions with non-existent methods so this should always be an
error at the test runner level, rather than relying on clients to
check the error.

1. Fix the tests that accidentally call methods that don't exist.
2. Change the test runner so that it prints an error and ends the test.
3. Add a test that the test runner does #2.

Bug: v8:10134
Change-Id: Idd619950a057290c565d58fba6db3ddbcaf2c5eb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2006093
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65835}
2020-01-17 12:21:29 +00:00

52 lines
1.8 KiB
JavaScript

// Copyright 2019 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.
let {session, contextGroup, Protocol} = InspectorTest.start(
'Test RunTimeCallStats collection enabling and disabling.');
var source =
`
function fib(x) {
if (x < 2) return 1;
return fib(x-1) + fib(x-2);
}
fib(5);
`;
function logErrorMessage(result) {
InspectorTest.log('Expected error: "' + result.error.message + '"');
}
(async function test() {
await Protocol.Runtime.enable();
// This should fail with "not enabled" error.
logErrorMessage(await Protocol.Profiler.getRuntimeCallStats());
// This should fail with "already enabled" error.
await Protocol.Profiler.enableRuntimeCallStats();
logErrorMessage(await Protocol.Profiler.enableRuntimeCallStats());
// The result should not be empty.
await Protocol.Runtime.evaluate({ expression: source, sourceURL: arguments.callee.name, persistScript: true });
const counters = (await Protocol.Profiler.getRuntimeCallStats()).result.result;
if (counters.length > 0)
InspectorTest.log('Some counters reported');
await Protocol.Profiler.disableRuntimeCallStats();
// This should fail with "not enabled" error too.
logErrorMessage(await Protocol.Profiler.getRuntimeCallStats());
// The result should not be empty and have smaller amount of counters than
// the first result.
await Protocol.Profiler.enableRuntimeCallStats();
const counters2 = (await Protocol.Profiler.getRuntimeCallStats()).result.result;
if (counters2.length > 0 && counters2.length < counters.length)
InspectorTest.log('Less counters reported');
await Protocol.Profiler.disableRuntimeCallStats();
await Protocol.Runtime.disable();
InspectorTest.completeTest();
})().catch(e => InspectorTest.log('caught: ' + e));