From 449af6f2295e0bfc7db751e32bfe42f7a3110179 Mon Sep 17 00:00:00 2001 From: clemensh Date: Thu, 21 Apr 2016 01:35:21 -0700 Subject: [PATCH] [wasm] Also test structured stack trace This extends the wasm test case which only checks the "simple" string-variant of the stack trace. It checks the return values of the getFunctionName, getLineNumber, getFileName and toString methods. R=machenbach@chromium.org, jfb@chromium.org, titzer@chromium.org Review URL: https://codereview.chromium.org/1875153002 Cr-Commit-Position: refs/heads/master@{#35687} --- test/mjsunit/mjsunit.js | 9 +++++ test/mjsunit/mjsunit.status | 3 -- test/mjsunit/wasm/stack.js | 66 ++++++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 18 deletions(-) diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js index 9b07953c8a..6a7c2da9e4 100644 --- a/test/mjsunit/mjsunit.js +++ b/test/mjsunit/mjsunit.js @@ -114,6 +114,9 @@ var assertUnreachable; var assertOptimized; var assertUnoptimized; +// Assert that a string contains another expected substring. +var assertContains; + (function () { // Scope for utility functions. @@ -416,6 +419,12 @@ var assertUnoptimized; throw new MjsUnitAssertionError(message); }; + assertContains = function(sub, value, name_opt) { + if (value == null ? (sub != null) : value.indexOf(sub) == -1) { + fail("contains '" + String(sub) + "'", value, name_opt); + } + }; + var OptimizationStatusImpl = undefined; var OptimizationStatus = function(fun, sync_opt) { diff --git a/test/mjsunit/mjsunit.status b/test/mjsunit/mjsunit.status index f0ae82bc64..2b9032e6cf 100644 --- a/test/mjsunit/mjsunit.status +++ b/test/mjsunit/mjsunit.status @@ -283,9 +283,6 @@ 'harmony/unicode-regexp-ignore-case-noi18n': [FAIL, ['no_i18n == True', PASS]], # desugaring regexp property class relies on ICU. 'harmony/regexp-property-*': [PASS, ['no_i18n == True', FAIL]], - - # TODO(clemensh): Figure out why this test is failing on 'V8 Linux64 - custom snapshot - debug' - 'wasm/stack': [PASS, FAIL], }], # ALWAYS ['novfp3 == True', { diff --git a/test/mjsunit/wasm/stack.js b/test/mjsunit/wasm/stack.js index ed05517ae5..11f5f84703 100644 --- a/test/mjsunit/wasm/stack.js +++ b/test/mjsunit/wasm/stack.js @@ -2,39 +2,75 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// clang-format off // Flags: --expose-wasm load("test/mjsunit/wasm/wasm-constants.js"); load("test/mjsunit/wasm/wasm-module-builder.js"); -var expected = "Error\n" + - // The line numbers below will change as this test gains / loses lines.. - " at STACK (stack.js:24:11)\n" + // -- - " at ()\n" + // TODO(jfb): wasm stack here. - " at testStack (stack.js:38:18)\n" + // -- - " at stack.js:40:3"; // -- - // The stack trace contains file path, only keep "stack.js". function stripPath(s) { return s.replace(/[^ (]*stack\.js/g, "stack.js"); } +function verifyStack(frames, expected) { + assertEquals(expected.length, frames.length, "number of frames mismatch"); + expected.forEach(function(exp, i) { + assertEquals(exp[0], frames[i].getFunctionName(), + "["+i+"].getFunctionName()"); + assertEquals(exp[1], frames[i].getLineNumber(), + "["+i+"].getLineNumber()"); + assertContains(exp[2], frames[i].getFileName(), + "["+i+"].getFileName()"); + assertContains(exp[3], frames[i].toString(), + "["+i+"].toString()"); + }); +} + + var stack; function STACK() { var e = new Error(); stack = e.stack; } -(function testStack() { - var builder = new WasmModuleBuilder(); +var builder = new WasmModuleBuilder(); - builder.addImport("func", [kAstStmt]); +builder.addImport("func", [kAstStmt]); - builder.addFunction(undefined, [kAstStmt]) - .addBody([kExprCallImport, 0]) - .exportAs("main"); +builder.addFunction("main", [kAstStmt]) + .addBody([kExprCallImport, 0]) + .exportAs("main"); + +var module = builder.instantiate({func: STACK}); + +(function testSimpleStack() { + var expected_string = "Error\n" + + // The line numbers below will change as this test gains / loses lines.. + " at STACK (stack.js:33:11)\n" + // -- + " at ()\n" + // TODO(jfb): wasm stack here. + " at testSimpleStack (stack.js:55:18)\n" + // -- + " at stack.js:57:3"; // -- - var module = builder.instantiate({func: STACK}); module.exports.main(); - assertEquals(expected, stripPath(stack)); + assertEquals(expected_string, stripPath(stack)); +})(); + +// For the remaining tests, collect the Callsite objects instead of just a +// string: +Error.prepareStackTrace = function(error, frames) { + return frames; +}; + +(function testStackFrames() { + module.exports.main(); + + // TODO(clemensh): add a isWasm() method or similar, and test it + verifyStack(stack, [ + // function line file toString + [ "STACK", 33, "stack.js", "stack.js:33:11"], + [ "", null, null, ""], + ["testStackFrames", 66, "stack.js", "stack.js:66:18"], + [ null, 76, "stack.js", "stack.js:76:3"] + ]); })();