Skip to content

Commit

Permalink
wamr-ide: Add vscode extension tests (#2292)
Browse files Browse the repository at this point in the history
This PR adds tests for #2219 by changing the `compilation_on_android_ubuntu.yml` workflow.
The first run will take about two hours, since LLDB is built from scratch. Later, the build is
cached and the whole job should not take more than three minutes.

Core of the PR is an integration test that boots up vscode and lets it debug a test WASM file.
  • Loading branch information
MrSarius committed Jun 20, 2023
1 parent 85981b7 commit 72fc872
Show file tree
Hide file tree
Showing 15 changed files with 511 additions and 22 deletions.
116 changes: 116 additions & 0 deletions .github/workflows/compilation_on_android_ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
- "test-tools/wamr-ide/**"
# will be triggered on push events
push:
branches:
Expand All @@ -38,6 +39,7 @@ on:
- "tests/wamr-test-suites/**"
- "wamr-compiler/**"
- "wamr-sdk/**"
- "test-tools/wamr-ide/**"
# allow to be triggered manually
workflow_dispatch:

Expand Down Expand Up @@ -545,3 +547,117 @@ jobs:
if: env.TEST_ON_X86_32 == 'true'
run: ./test_wamr.sh ${{ env.X86_32_TARGET_TEST_OPTIONS }} ${{ matrix.test_option }} -t ${{ matrix.running_mode }}
working-directory: ./tests/wamr-test-suites

test-wamr-ide:
needs:
[
build_iwasm
]
runs-on: ubuntu-22.04
env:
PYTHON_VERSION: '3.10'
PYTHON_UBUNTU_STANDALONE_BUILD: https://github.com/indygreg/python-build-standalone/releases/download/20230507/cpython-3.10.11+20230507-x86_64-unknown-linux-gnu-install_only.tar.gz

steps:
- name: checkout
uses: actions/checkout@v3

- name: install dependencies
run: |
rustup target add wasm32-wasi
sudo apt update && sudo apt-get install -y lld ninja-build
npm install
working-directory: test-tools/wamr-ide/VSCode-Extension

- name: build iwasm with source debugging feature
run: |
mkdir build
cd build
cmake .. -DWAMR_BUILD_DEBUG_INTERP=1
make
working-directory: product-mini/platforms/linux

- name: Cache LLDB
id: cache-lldb
uses: actions/cache@v3
env:
cache-name: cache-lldb-vscode
with:
path: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux
key: ${{ env.cache-name }}-${{ hashFiles('build-scripts/lldb-wasm.patch') }}-${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }}

- if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
name: get stand-alone python ubuntu
run: |
wget ${{ env.PYTHON_UBUNTU_STANDALONE_BUILD }} -O python.tar.gz
tar -xvf python.tar.gz
working-directory: core/deps

- if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
name: download llvm
run: |
wget https://github.com/llvm/llvm-project/archive/1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip
unzip -q 1f27fe6128769f00197925c3b8f6abb9d0e5cd2e.zip
mv llvm-project-1f27fe6128769f00197925c3b8f6abb9d0e5cd2e llvm-project
working-directory: core/deps

- if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
name: apply wamr patch
run: |
git init
git config user.email "action@github.com"
git config user.name "github action"
git apply ../../../build-scripts/lldb-wasm.patch
working-directory: core/deps/llvm-project

- if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
name: build lldb ubuntu
run: |
echo "start to build lldb..."
mkdir -p wamr-lldb
cmake -S ./llvm -B build \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=../wamr-lldb \
-DCMAKE_BUILD_TYPE:STRING="Release" \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DLLVM_ENABLE_PROJECTS="clang;lldb" \
-DLLVM_TARGETS_TO_BUILD:STRING="X86;WebAssembly" \
-DLLVM_BUILD_BENCHMARKS:BOOL=OFF \
-DLLVM_BUILD_DOCS:BOOL=OFF \
-DLLVM_BUILD_EXAMPLES:BOOL=OFF \
-DLLVM_BUILD_LLVM_DYLIB:BOOL=OFF \
-DLLVM_BUILD_TESTS:BOOL=OFF \
-DLLVM_INCLUDE_BENCHMARKS:BOOL=OFF \
-DLLVM_INCLUDE_DOCS:BOOL=OFF \
-DLLVM_INCLUDE_EXAMPLES:BOOL=OFF \
-DLLVM_INCLUDE_TESTS:BOOL=OFF \
-DLLVM_ENABLE_BINDINGS:BOOL=OFF \
-DLLVM_ENABLE_LIBXML2:BOOL=ON \
-DLLVM_ENABLE_LLD:BOOL=ON \
-DLLDB_ENABLE_PYTHON:BOOL=ON \
-DLLDB_EMBED_PYTHON_HOME=ON \
-DLLDB_PYTHON_HOME=.. \
-DLLDB_PYTHON_RELATIVE_PATH=lib/lldb-python \
-DPython3_EXECUTABLE="$(pwd)/../python/bin/python${{ env.PYTHON_VERSION }}"
cmake --build build --target lldb install --parallel $(nproc)
working-directory: core/deps/llvm-project

- if: ${{ steps.cache-lldb.outputs.cache-hit != 'true' }}
name: copy lldb to extension folder
run: |
mkdir -p bin
mkdir -p lib
cp ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/package.json ./
cp -r ../../../../../../core/deps/llvm-project/lldb/tools/lldb-vscode/syntaxes/ ./
cp ../../../../../../core/deps/llvm-project/build/bin/lldb* bin
cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so lib
cp ../../../../../../core/deps/llvm-project/build/lib/liblldb*.so.* lib
cp -R ../../../../../../core/deps/llvm-project/build/lib/lldb-python lib
cp -R ../../../../../../core/deps/python/lib/python* lib
cp ../../../../../../core/deps/python/lib/libpython${{ env.PYTHON_VERSION }}.so.1.0 lib
working-directory: test-tools/wamr-ide/VSCode-Extension/resource/debug/linux

- name: run tests
timeout-minutes: 5
run: xvfb-run npm run test
working-directory: test-tools/wamr-ide/VSCode-Extension
7 changes: 6 additions & 1 deletion test-tools/wamr-ide/VSCode-Extension/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ node_modules
.vscode-test/
*.vsix
package-lock.json
src/test
.vscode
resource/debug/**
!resource/debug/darwin/.placeholder
!resource/debug/linux/.placeholder
!resource/debug/windows/.placeholder
resource/test/test.wasm
1 change: 1 addition & 0 deletions test-tools/wamr-ide/VSCode-Extension/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
11 changes: 11 additions & 0 deletions test-tools/wamr-ide/VSCode-Extension/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Launch Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": ["${workspaceFolder}/out/test/**/*.js"]
}
]
}
8 changes: 8 additions & 0 deletions test-tools/wamr-ide/VSCode-Extension/.vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ out/test/**
**/.eslintrc.json
**/*.map
**/*.ts

src

resource/test
resource/debug/**
!resource/debug/darwin/.placeholder
!resource/debug/linux/.placeholder
!resource/debug/windows/.placeholder
13 changes: 9 additions & 4 deletions test-tools/wamr-ide/VSCode-Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"description": "An Integrated Development Environment for WASM",
"version": "1.2.2",
"engines": {
"vscode": "^1.59.0"
"vscode": "^1.59.0",
"node": ">=16.0.0"
},
"engineStrict": true,
"categories": [
"Other"
],
Expand Down Expand Up @@ -235,6 +237,7 @@
"prettier-format-apply": "prettier --config .prettierrc.json 'src/**/*.ts' --write"
},
"devDependencies": {
"@types/chai": "^4.3.5",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "14.x",
Expand All @@ -243,12 +246,14 @@
"@types/yauzl": "^2.10.0",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.0",
"@vscode/debugprotocol": "^1.61.0",
"@vscode/test-electron": "^2.3.3",
"chai": "^4.3.7",
"eslint": "^7.32.0",
"glob": "^7.1.7",
"mocha": "^8.4.0",
"mocha": "^10.2.0",
"prettier": "2.5.1",
"typescript": "^4.3.2",
"vscode-test": "^1.5.2"
"typescript": "^4.3.2"
},
"dependencies": {
"@vscode/webview-ui-toolkit": "^0.8.4",
Expand Down
2 changes: 2 additions & 0 deletions test-tools/wamr-ide/VSCode-Extension/resource/test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# compile with debug symbols and no optimization
rustc --target wasm32-wasi ./test.rs -g -C opt-level=0
35 changes: 35 additions & 0 deletions test-tools/wamr-ide/VSCode-Extension/resource/test/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

use std::collections::HashMap;
use std::collections::VecDeque;
use std::cell::RefCell;

fn main() {
let mut vector = Vec::from([1, 2, 3, 4]);
vector.push(12);

let mut map: HashMap<&str, f64> = HashMap::from([
("Mercury", 0.4),
("Venus", 0.7),
("Earth", 1.0),
("Mars", 1.5),
]);
map.insert("Venus", 2.5);
map.insert("Sun", 312.2);

let string = "this is a string";

let tmp = String::from("hello world");
let slice = &tmp[1..5];

let mut deque = VecDeque::from([1, 2, 3]);
deque.push_back(4);
deque.push_back(5);

let ref_cell = RefCell::new(5);

println!("Hello, world!"); // BP_MARKER_1
}
10 changes: 5 additions & 5 deletions test-tools/wamr-ide/VSCode-Extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ let isWasmProject = false;
export async function activate(context: vscode.ExtensionContext) {
const extensionPath = context.extensionPath;
const osPlatform = os.platform();
const wamrVersion = getWAMRExtensionVersion(context);
const wamrVersion = getWAMRExtensionVersion(context.extensionPath);
const typeMap = new Map<string, string>();
const scriptMap = new Map<string, string>();
/* set relative path of build.bat|sh script */
Expand Down Expand Up @@ -409,13 +409,13 @@ export async function activate(context: vscode.ExtensionContext) {

/* we should check again whether the user installed lldb, as this can be skipped during activation */
try {
if (!isLLDBInstalled(context)) {
if (!isLLDBInstalled(context.extensionPath)) {
/**NOTE - if users select to skip install,
* we should return rather than continue
* the execution
*/
if (
(await promptInstallLLDB(context)) ===
(await promptInstallLLDB(context.extensionPath)) ===
SelectionOfPrompt.skip
) {
return;
Expand Down Expand Up @@ -772,8 +772,8 @@ export async function activate(context: vscode.ExtensionContext) {
);

try {
if (!isLLDBInstalled(context)) {
await promptInstallLLDB(context);
if (!isLLDBInstalled(context.extensionPath)) {
await promptInstallLLDB(context.extensionPath);
}

if (
Expand Down
33 changes: 33 additions & 0 deletions test-tools/wamr-ide/VSCode-Extension/src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (C) 2019 Intel Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/

import * as path from 'path';
import * as os from 'os';

import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--user-data-dir', `${os.tmpdir()}`]
});
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
Loading

0 comments on commit 72fc872

Please sign in to comment.