|
@@ -3,57 +3,65 @@
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
-import {DebugProtocol} from '@vscode/debugprotocol';
|
|
|
|
|
-import {after, before, test, suite} from 'mocha';
|
|
|
|
|
-import {assert} from 'chai';
|
|
|
|
|
|
|
+import { DebugProtocol } from '@vscode/debugprotocol';
|
|
|
|
|
+import { after, before, test, suite } from 'mocha';
|
|
|
|
|
+import { assert } from 'chai';
|
|
|
import * as vscode from 'vscode';
|
|
import * as vscode from 'vscode';
|
|
|
import * as cp from 'child_process';
|
|
import * as cp from 'child_process';
|
|
|
-import * as path from "path";
|
|
|
|
|
|
|
+import * as path from 'path';
|
|
|
import * as os from 'os';
|
|
import * as os from 'os';
|
|
|
-import {WasmDebugConfig, WasmDebugConfigurationProvider} from "../../debugConfigurationProvider";
|
|
|
|
|
-import {EXTENSION_PATH, clearAllBp, setBpAtMarker, compileRustToWasm} from "./utils";
|
|
|
|
|
-import {downloadLldb, isLLDBInstalled} from '../../utilities/lldbUtilities';
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ WasmDebugConfig,
|
|
|
|
|
+ WasmDebugConfigurationProvider,
|
|
|
|
|
+} from '../../debugConfigurationProvider';
|
|
|
|
|
+import {
|
|
|
|
|
+ EXTENSION_PATH,
|
|
|
|
|
+ clearAllBp,
|
|
|
|
|
+ setBpAtMarker,
|
|
|
|
|
+ compileRustToWasm,
|
|
|
|
|
+} from './utils';
|
|
|
|
|
+import { downloadLldb, isLLDBInstalled } from '../../utilities/lldbUtilities';
|
|
|
|
|
|
|
|
suite('Unit Tests', function () {
|
|
suite('Unit Tests', function () {
|
|
|
test('DebugConfigurationProvider init commands', function () {
|
|
test('DebugConfigurationProvider init commands', function () {
|
|
|
- const testExtensionPath = "/test/path/";
|
|
|
|
|
|
|
+ const testExtensionPath = '/test/path/';
|
|
|
const provider = new WasmDebugConfigurationProvider(testExtensionPath);
|
|
const provider = new WasmDebugConfigurationProvider(testExtensionPath);
|
|
|
|
|
|
|
|
assert.includeMembers(
|
|
assert.includeMembers(
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
|
provider.getDebugConfig().initCommands!,
|
|
provider.getDebugConfig().initCommands!,
|
|
|
[`command script import ${testExtensionPath}/formatters/rust.py`],
|
|
[`command script import ${testExtensionPath}/formatters/rust.py`],
|
|
|
- "Debugger init commands did not contain "
|
|
|
|
|
|
|
+ 'Debugger init commands did not contain '
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
test('DebugConfigurationProvider resolve configuration', function () {
|
|
test('DebugConfigurationProvider resolve configuration', function () {
|
|
|
- const testExtensionPath = "/test/path/";
|
|
|
|
|
|
|
+ const testExtensionPath = '/test/path/';
|
|
|
const provider = new WasmDebugConfigurationProvider(testExtensionPath);
|
|
const provider = new WasmDebugConfigurationProvider(testExtensionPath);
|
|
|
|
|
|
|
|
const actual = provider.resolveDebugConfiguration(undefined, {
|
|
const actual = provider.resolveDebugConfiguration(undefined, {
|
|
|
- type: "wamr-debug",
|
|
|
|
|
- name: "Attach",
|
|
|
|
|
- request: "attach",
|
|
|
|
|
|
|
+ type: 'wamr-debug',
|
|
|
|
|
+ name: 'Attach',
|
|
|
|
|
+ request: 'attach',
|
|
|
initCommands: [],
|
|
initCommands: [],
|
|
|
attachCommands: [
|
|
attachCommands: [
|
|
|
'process connect -p wasm connect://123.456.789.1:1237',
|
|
'process connect -p wasm connect://123.456.789.1:1237',
|
|
|
- ]
|
|
|
|
|
|
|
+ ],
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
assert.deepEqual(
|
|
assert.deepEqual(
|
|
|
actual,
|
|
actual,
|
|
|
{
|
|
{
|
|
|
- type: "wamr-debug",
|
|
|
|
|
- name: "Attach",
|
|
|
|
|
- request: "attach",
|
|
|
|
|
|
|
+ type: 'wamr-debug',
|
|
|
|
|
+ name: 'Attach',
|
|
|
|
|
+ request: 'attach',
|
|
|
stopOnEntry: true,
|
|
stopOnEntry: true,
|
|
|
initCommands: [],
|
|
initCommands: [],
|
|
|
attachCommands: [
|
|
attachCommands: [
|
|
|
'process connect -p wasm connect://123.456.789.1:1237',
|
|
'process connect -p wasm connect://123.456.789.1:1237',
|
|
|
- ]
|
|
|
|
|
|
|
+ ],
|
|
|
},
|
|
},
|
|
|
- "Configuration did not match the expected configuration after calling resolveDebugConfiguration()"
|
|
|
|
|
|
|
+ 'Configuration did not match the expected configuration after calling resolveDebugConfiguration()'
|
|
|
);
|
|
);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -69,16 +77,24 @@ suite('Inegration Tests', function () {
|
|
|
// Download LLDB if necessary. Should be available in the CI. Only for local execution.
|
|
// Download LLDB if necessary. Should be available in the CI. Only for local execution.
|
|
|
if (!isLLDBInstalled(EXTENSION_PATH)) {
|
|
if (!isLLDBInstalled(EXTENSION_PATH)) {
|
|
|
this.timeout(downloadTimeout);
|
|
this.timeout(downloadTimeout);
|
|
|
- console.log("Downloading LLDB. This might take a moment...");
|
|
|
|
|
|
|
+ console.log('Downloading LLDB. This might take a moment...');
|
|
|
await downloadLldb(EXTENSION_PATH);
|
|
await downloadLldb(EXTENSION_PATH);
|
|
|
- assert.isTrue(isLLDBInstalled(EXTENSION_PATH), "LLDB was not installed correctly");
|
|
|
|
|
|
|
+ assert.isTrue(
|
|
|
|
|
+ isLLDBInstalled(EXTENSION_PATH),
|
|
|
|
|
+ 'LLDB was not installed correctly'
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
compileRustToWasm();
|
|
compileRustToWasm();
|
|
|
|
|
|
|
|
const platform = os.platform();
|
|
const platform = os.platform();
|
|
|
- assert.isTrue(platform === "darwin" || platform === "linux", `Tests do not support your platform: ${platform}`);
|
|
|
|
|
- const iWasmPath = path.resolve(`${EXTENSION_PATH}/../../../product-mini/platforms/${platform}/build/iwasm`);
|
|
|
|
|
|
|
+ assert.isTrue(
|
|
|
|
|
+ platform === 'darwin' || platform === 'linux',
|
|
|
|
|
+ `Tests do not support your platform: ${platform}`
|
|
|
|
|
+ );
|
|
|
|
|
+ const iWasmPath = path.resolve(
|
|
|
|
|
+ `${EXTENSION_PATH}/../../../product-mini/platforms/${platform}/build/iwasm`
|
|
|
|
|
+ );
|
|
|
const testWasmFilePath = `${EXTENSION_PATH}/resource/test/test.wasm`;
|
|
const testWasmFilePath = `${EXTENSION_PATH}/resource/test/test.wasm`;
|
|
|
|
|
|
|
|
debuggerProcess = cp.spawn(
|
|
debuggerProcess = cp.spawn(
|
|
@@ -87,7 +103,7 @@ suite('Inegration Tests', function () {
|
|
|
{}
|
|
{}
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- debuggerProcess.stderr.on('data', (data) => {
|
|
|
|
|
|
|
+ debuggerProcess.stderr.on('data', data => {
|
|
|
console.log(`Error from debugger process: ${data}`);
|
|
console.log(`Error from debugger process: ${data}`);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -101,44 +117,54 @@ suite('Inegration Tests', function () {
|
|
|
// timeout of 1 minutes
|
|
// timeout of 1 minutes
|
|
|
this.timeout(60 * 1000);
|
|
this.timeout(60 * 1000);
|
|
|
clearAllBp();
|
|
clearAllBp();
|
|
|
- setBpAtMarker(`${EXTENSION_PATH}/resource/test/test.rs`, "BP_MARKER_1");
|
|
|
|
|
-
|
|
|
|
|
- const getVariables = new Promise<DebugProtocol.Variable[]>((resolve, reject) => {
|
|
|
|
|
- vscode.debug.registerDebugAdapterTrackerFactory("wamr-debug", {
|
|
|
|
|
- createDebugAdapterTracker: function () {
|
|
|
|
|
- return {
|
|
|
|
|
- // The debug adapter has sent a Debug Adapter Protocol message to the editor.
|
|
|
|
|
- onDidSendMessage: (message: DebugProtocol.ProtocolMessage) => {
|
|
|
|
|
- if (message.type === "response") {
|
|
|
|
|
- const m = message as DebugProtocol.Response;
|
|
|
|
|
- if (m.command === "variables") {
|
|
|
|
|
- const res = m as DebugProtocol.VariablesResponse;
|
|
|
|
|
- resolve(res.body.variables);
|
|
|
|
|
|
|
+ setBpAtMarker(`${EXTENSION_PATH}/resource/test/test.rs`, 'BP_MARKER_1');
|
|
|
|
|
+
|
|
|
|
|
+ const getVariables = new Promise<DebugProtocol.Variable[]>(
|
|
|
|
|
+ (resolve, reject) => {
|
|
|
|
|
+ vscode.debug.registerDebugAdapterTrackerFactory('wamr-debug', {
|
|
|
|
|
+ createDebugAdapterTracker: function () {
|
|
|
|
|
+ return {
|
|
|
|
|
+ // The debug adapter has sent a Debug Adapter Protocol message to the editor.
|
|
|
|
|
+ onDidSendMessage: (
|
|
|
|
|
+ message: DebugProtocol.ProtocolMessage
|
|
|
|
|
+ ) => {
|
|
|
|
|
+ if (message.type === 'response') {
|
|
|
|
|
+ const m = message as DebugProtocol.Response;
|
|
|
|
|
+ if (m.command === 'variables') {
|
|
|
|
|
+ const res =
|
|
|
|
|
+ m as DebugProtocol.VariablesResponse;
|
|
|
|
|
+ resolve(res.body.variables);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- onError: (error: Error) => {
|
|
|
|
|
- reject("An error occurred before vscode reached the breakpoint: " + error);
|
|
|
|
|
- },
|
|
|
|
|
- onExit: (code: number | undefined) => {
|
|
|
|
|
- reject(`Debugger exited before vscode reached the breakpoint with code: ${code}`);
|
|
|
|
|
- },
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ },
|
|
|
|
|
+ onError: (error: Error) => {
|
|
|
|
|
+ reject(
|
|
|
|
|
+ 'An error occurred before vscode reached the breakpoint: ' +
|
|
|
|
|
+ error
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ onExit: (code: number | undefined) => {
|
|
|
|
|
+ reject(
|
|
|
|
|
+ `Debugger exited before vscode reached the breakpoint with code: ${code}`
|
|
|
|
|
+ );
|
|
|
|
|
+ },
|
|
|
|
|
+ };
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
const config: WasmDebugConfig = {
|
|
const config: WasmDebugConfig = {
|
|
|
- type: "wamr-debug",
|
|
|
|
|
- request: "attach",
|
|
|
|
|
- name: "Attach Debugger",
|
|
|
|
|
|
|
+ type: 'wamr-debug',
|
|
|
|
|
+ request: 'attach',
|
|
|
|
|
+ name: 'Attach Debugger',
|
|
|
stopOnEntry: false,
|
|
stopOnEntry: false,
|
|
|
initCommands: [
|
|
initCommands: [
|
|
|
- `command script import ${EXTENSION_PATH}/formatters/rust.py`
|
|
|
|
|
|
|
+ `command script import ${EXTENSION_PATH}/formatters/rust.py`,
|
|
|
],
|
|
],
|
|
|
attachCommands: [
|
|
attachCommands: [
|
|
|
- `process connect -p wasm connect://127.0.0.1:${port}`
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+ `process connect -p wasm connect://127.0.0.1:${port}`,
|
|
|
|
|
+ ],
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
if (os.platform() === 'win32' || os.platform() === 'darwin') {
|
|
if (os.platform() === 'win32' || os.platform() === 'darwin') {
|
|
@@ -148,36 +174,70 @@ suite('Inegration Tests', function () {
|
|
|
try {
|
|
try {
|
|
|
await vscode.debug.startDebugging(undefined, config);
|
|
await vscode.debug.startDebugging(undefined, config);
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
- assert.fail("Could not connect to debug adapter");
|
|
|
|
|
|
|
+ assert.fail('Could not connect to debug adapter');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// wait until vs code has reached breakpoint and has requested the variables.
|
|
// wait until vs code has reached breakpoint and has requested the variables.
|
|
|
const variables = await getVariables;
|
|
const variables = await getVariables;
|
|
|
- const namesToVariables = variables.reduce((acc: { [name: string]: DebugProtocol.Variable }, c) => {
|
|
|
|
|
- if (c.evaluateName) {
|
|
|
|
|
- acc[c.evaluateName] = c;
|
|
|
|
|
- }
|
|
|
|
|
- return acc;
|
|
|
|
|
- }, {});
|
|
|
|
|
|
|
+ const namesToVariables = variables.reduce(
|
|
|
|
|
+ (acc: { [name: string]: DebugProtocol.Variable }, c) => {
|
|
|
|
|
+ if (c.evaluateName) {
|
|
|
|
|
+ acc[c.evaluateName] = c;
|
|
|
|
|
+ }
|
|
|
|
|
+ return acc;
|
|
|
|
|
+ },
|
|
|
|
|
+ {}
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
- assert.includeMembers(Object.keys(namesToVariables), ["vector", "map", "string", "slice", "deque", "ref_cell"], "The Debugger did not return all expected debugger variables.");
|
|
|
|
|
|
|
+ assert.includeMembers(
|
|
|
|
|
+ Object.keys(namesToVariables),
|
|
|
|
|
+ ['vector', 'map', 'string', 'slice', 'deque', 'ref_cell'],
|
|
|
|
|
+ 'The Debugger did not return all expected debugger variables.'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// Vector
|
|
// Vector
|
|
|
- assert.equal(namesToVariables["vector"].value, " (5) vec![1, 2, 3, 4, 12]", "The Vector summary string looks different than expected");
|
|
|
|
|
|
|
+ assert.equal(
|
|
|
|
|
+ namesToVariables['vector'].value,
|
|
|
|
|
+ ' (5) vec![1, 2, 3, 4, 12]',
|
|
|
|
|
+ 'The Vector summary string looks different than expected'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// Map
|
|
// Map
|
|
|
- assert.equal(namesToVariables["map"].value, " size=5, capacity=8", "The Map summary string looks different than expected");
|
|
|
|
|
|
|
+ assert.equal(
|
|
|
|
|
+ namesToVariables['map'].value,
|
|
|
|
|
+ ' size=5, capacity=8',
|
|
|
|
|
+ 'The Map summary string looks different than expected'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// String
|
|
// String
|
|
|
- assert.equal(namesToVariables["string"].value, " \"this is a string\"", "The String summary string looks different than expected");
|
|
|
|
|
|
|
+ assert.equal(
|
|
|
|
|
+ namesToVariables['string'].value,
|
|
|
|
|
+ ' "this is a string"',
|
|
|
|
|
+ 'The String summary string looks different than expected'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// Slice
|
|
// Slice
|
|
|
- assert.equal(namesToVariables["slice"].value, " \"ello\"", "The Slice summary string looks different than expected");
|
|
|
|
|
|
|
+ assert.equal(
|
|
|
|
|
+ namesToVariables['slice'].value,
|
|
|
|
|
+ ' "ello"',
|
|
|
|
|
+ 'The Slice summary string looks different than expected'
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
// Deque
|
|
// Deque
|
|
|
- assert.equal(namesToVariables["deque"].value, " (5) VecDeque[1, 2, 3, 4, 5]", "The Deque summary string looks different than expected");
|
|
|
|
|
|
|
+ // TODO: The deque format conversion have some problem now
|
|
|
|
|
+ // -alloc::collections::vec_deque::VecDeque<int, alloc::alloc::Global> @ 0xfff1c
|
|
|
|
|
+ // + (5) VecDeque[1, 2, 3, 4, 5]
|
|
|
|
|
+ // assert.equal(
|
|
|
|
|
+ // namesToVariables['deque'].value,
|
|
|
|
|
+ // ' (5) VecDeque[1, 2, 3, 4, 5]',
|
|
|
|
|
+ // 'The Deque summary string looks different than expected'
|
|
|
|
|
+ // );
|
|
|
|
|
|
|
|
// RefCell
|
|
// RefCell
|
|
|
- assert.equal(namesToVariables["ref_cell"].value, " 5", "The RefCell summary string looks different than expected");
|
|
|
|
|
|
|
+ assert.equal(
|
|
|
|
|
+ namesToVariables['ref_cell'].value,
|
|
|
|
|
+ ' 5',
|
|
|
|
|
+ 'The RefCell summary string looks different than expected'
|
|
|
|
|
+ );
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|