From 951b2f98ddc4a22511164a2d6497d1247b7ba300 Mon Sep 17 00:00:00 2001 From: Jianfeng Jiang Date: Tue, 12 Mar 2024 09:28:09 +0000 Subject: [PATCH] Run OSDK tests in host environment --- .github/workflows/osdk_test.yml | 18 +++++++++++++- docs/src/osdk/guide/README.md | 5 ++-- osdk/src/commands/new/mod.rs | 6 +---- osdk/tests/integration/mod.rs | 4 ++-- osdk/tools/Dockerfile.ubuntu22.04 | 40 +++++++++++++++++++++++++++++++ osdk/tools/build_image.sh | 18 ++++++++++++++ osdk/tools/run_container.sh | 12 ++++++++++ 7 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 osdk/tools/Dockerfile.ubuntu22.04 create mode 100755 osdk/tools/build_image.sh create mode 100755 osdk/tools/run_container.sh diff --git a/.github/workflows/osdk_test.yml b/.github/workflows/osdk_test.yml index 3d79de64a..7c00439d1 100644 --- a/.github/workflows/osdk_test.yml +++ b/.github/workflows/osdk_test.yml @@ -14,7 +14,7 @@ on: jobs: osdk-test: runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 15 container: asterinas/asterinas:0.4.1 steps: - run: echo "Running in asterinas/asterinas:0.4.1" @@ -31,3 +31,19 @@ jobs: - name: Unit test id: unit_test run: cd osdk && cargo build && RUSTUP_HOME=/root/.rustup cargo test + + # Test OSDK in the same environment as described in the OSDK User Guide in the Asterinas Book. + osdk_doc_env_test: + runs-on: ubuntu-latest + timeout-minutes: 15 + container: asterinas/osdk:0.4.0 + steps: + - run: echo "Running in asterinas/osdk:0.4.0" + + - uses: actions/checkout@v4 + + - name: Unit test + id: unit_test + run: cd osdk && cargo build && RUSTUP_HOME=/root/.rustup cargo test + + # TODO: test the demos in Asterinas Book diff --git a/docs/src/osdk/guide/README.md b/docs/src/osdk/guide/README.md index 1be2e99ad..68678f42e 100644 --- a/docs/src/osdk/guide/README.md +++ b/docs/src/osdk/guide/README.md @@ -27,7 +27,7 @@ the following tools need to be installed: - cargo-binutils - gcc - qemu-system-x86_64 -- grub-mkrescue +- grub - ovmf - xorriso @@ -42,7 +42,8 @@ cargo install cargo-binutils Other tools can be installed by ```bash -apt install build-essential grub2-common qemu-system-x86 ovmf xorriso +apt install build-essential grub-efi-amd64 grub2-common \ + libpixman-1-dev mtools qemu-system-x86 ovmf xorriso ``` ### Install diff --git a/osdk/src/commands/new/mod.rs b/osdk/src/commands/new/mod.rs index c23a9e6d7..7a6160aae 100644 --- a/osdk/src/commands/new/mod.rs +++ b/osdk/src/commands/new/mod.rs @@ -43,11 +43,7 @@ fn add_manifest_dependencies(cargo_metadata: &serde_json::Value, crate_name: &st dependencies.as_table_mut().unwrap().extend(aster_frame_dep); let ktest_dep = toml::Table::from_str(&aster_crate_dep("ktest")).unwrap(); dependencies.as_table_mut().unwrap().extend(ktest_dep); - - // If we created a workspace by `osdk new`, we should exclude the `base` crate from the workspace. - // let exclude = toml::Table::from_str(r#"exclude = ["target/osdk/base"]"#).unwrap(); - // manifest.insert("workspace".to_string(), toml::Value::Table(exclude)); - + let content = toml::to_string(&manifest).unwrap(); fs::write(mainfest_path, content).unwrap(); } diff --git a/osdk/tests/integration/mod.rs b/osdk/tests/integration/mod.rs index 9abee3256..40018629d 100644 --- a/osdk/tests/integration/mod.rs +++ b/osdk/tests/integration/mod.rs @@ -9,7 +9,7 @@ use std::{ use crate::util::{assert_success, cargo_osdk, create_workspace}; -// #[test] +#[test] fn build_with_default_manifest() { let workspace = "/tmp/workspace_foo"; if Path::new(workspace).exists() { @@ -24,7 +24,7 @@ fn build_with_default_manifest() { fs::remove_dir_all(workspace).unwrap(); } -// #[test] +#[test] fn build_with_conditional_manifest() { let workspace = "/tmp/workspace_bar"; if Path::new(workspace).exists() { diff --git a/osdk/tools/Dockerfile.ubuntu22.04 b/osdk/tools/Dockerfile.ubuntu22.04 new file mode 100644 index 000000000..ba7306b5d --- /dev/null +++ b/osdk/tools/Dockerfile.ubuntu22.04 @@ -0,0 +1,40 @@ +# SPDX-License-Identifier: MPL-2.0 + +# This image is for the OSDK GitHub CI. +# The environment is consistent with the one +# described in the OSDK User Guide section of the Asterinas Book. + +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt update \ + && apt install -y \ + build-essential \ + curl \ + grub-efi-amd64 \ + grub2-common \ + libpixman-1-dev `# running dependency for QEMU` \ + mtools `# used by grub-mkrescue` \ + ovmf \ + qemu-system-x86 \ + xorriso \ + && apt clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Rust of both nightly and stable channel +ENV PATH="/root/.cargo/bin:${PATH}" +ARG ASTER_RUST_VERSION +RUN curl https://sh.rustup.rs -sSf | \ + sh -s -- --default-toolchain ${ASTER_RUST_VERSION} -y \ + && rustup toolchain install stable \ + && rm -rf /root/.cargo/registry && rm -rf /root/.cargo/git \ + && cargo -V \ + && rustup component add rust-src rustc-dev llvm-tools-preview + +# Install cargo-binutils +RUN cargo install cargo-binutils + +VOLUME [ "/root/asterinas" ] + +WORKDIR /root/asterinas diff --git a/osdk/tools/build_image.sh b/osdk/tools/build_image.sh new file mode 100755 index 000000000..259f12220 --- /dev/null +++ b/osdk/tools/build_image.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +ASTER_ROOT_DIR=${SCRIPT_DIR}/../.. +ASTER_RUST_VERSION=$( grep -m1 -o 'nightly-[0-9]\+-[0-9]\+-[0-9]\+' ${ASTER_ROOT_DIR}/rust-toolchain.toml ) +VERSION=$( cat ${ASTER_ROOT_DIR}/VERSION ) +IMAGE_NAME=asterinas/osdk:${VERSION} +DOCKERFILE=${SCRIPT_DIR}/Dockerfile.ubuntu22.04 + +docker build \ + -t ${IMAGE_NAME} \ + --build-arg ASTER_RUST_VERSION=${ASTER_RUST_VERSION} \ + -f ${DOCKERFILE} \ + ${SCRIPT_DIR} diff --git a/osdk/tools/run_container.sh b/osdk/tools/run_container.sh new file mode 100755 index 000000000..c2f2ad0be --- /dev/null +++ b/osdk/tools/run_container.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# SPDX-License-Identifier: MPL-2.0 + +set -e + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +ASTER_ROOT_DIR=${SCRIPT_DIR}/../.. +VERSION=$( cat ${ASTER_ROOT_DIR}/VERSION ) +IMAGE_NAME=asterinas/osdk:${VERSION} + +docker run -it -v ${ASTER_ROOT_DIR}:/root/asterinas ${IMAGE_NAME}