-
Notifications
You must be signed in to change notification settings - Fork 0
Add integration test scripts and CI workflows (Lint, Build, and Integration Tests) #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Build | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/build.yml' | ||
| push: | ||
| paths: | ||
| - 'src/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/build.yml' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| build: | ||
| runs-on: ${{ matrix.runner }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| toolchain: | ||
| - "1.90" | ||
| - stable | ||
| os: | ||
| - ubuntu-x64 | ||
| - ubuntu-arm64 | ||
| include: | ||
| - os: ubuntu-x64 | ||
| runner: ubuntu-24.04 | ||
| target: x86_64-unknown-linux-gnu | ||
| - os: ubuntu-arm64 | ||
| runner: ubuntu-24.04-arm | ||
| target: aarch64-unknown-linux-gnu | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
| with: | ||
| toolchain: ${{ matrix.toolchain }} | ||
| target: ${{ matrix.target }} | ||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libtss2-dev pkg-config | ||
| - run: cargo build --workspace --all-targets --all-features --target ${{ matrix.target }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| name: Lint (Rust) | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - 'src/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/lint.yml' | ||
| push: | ||
| paths: | ||
| - 'src/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/lint.yml' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| rustfmt: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
| with: | ||
| toolchain: stable | ||
| components: rustfmt | ||
| - run: cargo fmt --all -- --check | ||
|
|
||
| clippy: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
| with: | ||
| toolchain: stable | ||
| components: clippy | ||
| - name: Install dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libtss2-dev pkg-config | ||
| - run: cargo clippy --workspace --all-targets --all-features -- -D warnings |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| name: Integration Tests | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - 'src/**' | ||
| - 'tests/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/test.yml' | ||
| pull_request: | ||
| paths: | ||
| - 'src/**' | ||
| - 'tests/**' | ||
| - 'Cargo.toml' | ||
| - 'Cargo.lock' | ||
| - '.github/workflows/test.yml' | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| CARGO_TERM_COLOR: always | ||
|
|
||
| jobs: | ||
| integration-test: | ||
| runs-on: ${{ matrix.runner }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| toolchain: | ||
| - "1.90" | ||
| - stable | ||
| os: | ||
| - ubuntu-x64 | ||
| - ubuntu-arm64 | ||
| include: | ||
| - os: ubuntu-x64 | ||
| runner: ubuntu-24.04 | ||
| target: x86_64-unknown-linux-gnu | ||
| - os: ubuntu-arm64 | ||
| runner: ubuntu-24.04-arm | ||
| target: aarch64-unknown-linux-gnu | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions-rust-lang/setup-rust-toolchain@v1 | ||
| with: | ||
| toolchain: ${{ matrix.toolchain }} | ||
| target: ${{ matrix.target }} | ||
| - name: Install dependencies and swtpm | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y libtss2-dev pkg-config swtpm | ||
| - name: Run integration tests | ||
| run: bash ./tests/run_all.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # Common test helpers for tpm2-cli integration tests. | ||
| # Source this file from individual test scripts. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | ||
| export TPM2_BIN="${REPO_ROOT}/target/release/tpm2" | ||
| SWTPM_PID="" | ||
| SWTPM_PORT="" | ||
| SWTPM_CTRL_PORT="" | ||
| export TEST_TMPDIR="" | ||
|
|
||
| # Colours for output (disabled if not a terminal and not in CI). | ||
| if [ -t 1 ] || [ "${CI:-}" = "true" ]; then | ||
| GREEN=$'\033[32m' | ||
| RED=$'\033[31m' | ||
| YELLOW=$'\033[33m' | ||
| RESET=$'\033[0m' | ||
| else | ||
| GREEN="" RED="" YELLOW="" RESET="" | ||
| fi | ||
|
|
||
| PASS_COUNT=0 | ||
| FAIL_COUNT=0 | ||
| SKIP_COUNT=0 | ||
|
|
||
| pass() { | ||
| PASS_COUNT=$((PASS_COUNT + 1)) | ||
| echo "${GREEN} PASS${RESET}: $1" | ||
| } | ||
|
|
||
| fail() { | ||
| FAIL_COUNT=$((FAIL_COUNT + 1)) | ||
| echo "${RED} FAIL${RESET}: $1" | ||
| if [ -n "${2:-}" ]; then | ||
| echo " $2" | ||
| fi | ||
| if [ "${GITHUB_ACTIONS:-}" = "true" ]; then | ||
| echo "::error::FAIL: $1" | ||
| fi | ||
| } | ||
|
|
||
| skip() { | ||
| SKIP_COUNT=$((SKIP_COUNT + 1)) | ||
| echo "${YELLOW} SKIP${RESET}: $1" | ||
| if [ "${GITHUB_ACTIONS:-}" = "true" ]; then | ||
| echo "::warning::SKIP: $1" | ||
| fi | ||
| } | ||
|
|
||
| summary() { | ||
| echo "" | ||
| echo "Results: ${GREEN}${PASS_COUNT} passed${RESET}, ${RED}${FAIL_COUNT} failed${RESET}, ${YELLOW}${SKIP_COUNT} skipped${RESET}" | ||
| if [ "$FAIL_COUNT" -gt 0 ]; then | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| } | ||
|
|
||
| # Start an swtpm simulator and set TPM2TOOLS_TCTI. | ||
| start_swtpm() { | ||
| TEST_TMPDIR="$(mktemp -d)" | ||
| export TEST_TMPDIR | ||
|
|
||
| # Pick a random port range to avoid collisions. | ||
| SWTPM_PORT=$((20000 + RANDOM % 10000)) | ||
| SWTPM_CTRL_PORT=$((SWTPM_PORT + 1)) | ||
|
|
||
| swtpm socket \ | ||
| --tpmstate dir="$TEST_TMPDIR" \ | ||
| --tpm2 \ | ||
| --server type=tcp,port="$SWTPM_PORT" \ | ||
| --ctrl type=tcp,port="$SWTPM_CTRL_PORT" \ | ||
| --flags startup-clear & | ||
| SWTPM_PID=$! | ||
|
|
||
| # Wait for swtpm to be ready. | ||
| for _ in $(seq 1 20); do | ||
| if bash -c "echo >/dev/tcp/localhost/$SWTPM_PORT" 2>/dev/null; then | ||
| break | ||
| fi | ||
| sleep 0.1 | ||
| done | ||
|
|
||
| export TPM2TOOLS_TCTI="swtpm:host=localhost,port=${SWTPM_PORT}" | ||
| } | ||
|
|
||
| # Stop swtpm and clean up. | ||
| stop_swtpm() { | ||
| if [ -n "$SWTPM_PID" ]; then | ||
| kill "$SWTPM_PID" 2>/dev/null || true | ||
| wait "$SWTPM_PID" 2>/dev/null || true | ||
| SWTPM_PID="" | ||
| fi | ||
| if [ -n "$TEST_TMPDIR" ]; then | ||
| rm -rf "$TEST_TMPDIR" | ||
| TEST_TMPDIR="" | ||
| fi | ||
| } | ||
|
|
||
| trap stop_swtpm EXIT | ||
|
|
||
| # Run the tpm2 binary. Suppress INFO log output. | ||
| tpm2() { | ||
| "$TPM2_BIN" -v Off "$@" | ||
| } | ||
| export -f tpm2 | ||
|
|
||
| # Run a test case. Usage: run_test "description" command [args...] | ||
| # Captures stdout+stderr; on failure prints them. | ||
| run_test() { | ||
| local desc="$1" | ||
| shift | ||
| local output | ||
| if output=$("$@" 2>&1); then | ||
| pass "$desc" | ||
| else | ||
| fail "$desc" "$(echo "$output" | head -5)" | ||
| fi | ||
| } | ||
|
|
||
| # Build the binary if needed. | ||
| ensure_built() { | ||
| if [ ! -x "$TPM2_BIN" ]; then | ||
| echo "Building tpm2 binary..." | ||
| (cd "$REPO_ROOT" && cargo build --release --quiet) | ||
| fi | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wait loop for
swtpmhas a fixed timeout of 2 seconds (20 * 0.1s). On a heavily loaded CI machine,swtpmmight take longer to start up, which could lead to flaky tests when the script fails to connect to the socket. Consider increasing the timeout to make the tests more robust.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will leave the code as-is until the identified issue actually occurs.