Skip to content

Commit

Permalink
Add rollback test for spdm-rs and spdm-emu
Browse files Browse the repository at this point in the history
Signed-off-by: OuyangHang33 <[email protected]>
  • Loading branch information
OuyangHang33 committed Apr 28, 2024
1 parent fae2ec6 commit 2771829
Show file tree
Hide file tree
Showing 3 changed files with 1,665 additions and 0 deletions.
104 changes: 104 additions & 0 deletions sh_script/rollbacktest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

set -euo pipefail

export RUST_MIN_STACK=10485760
RUSTFLAGS=${RUSTFLAGS:-}

usage() {
cat <<EOM
Usage: $(basename "$0") [OPTION]...
-e EMU test
-r Rust test
-a Run all roll back test
-h Show help info
EOM
}

trap cleanup exit

echo_command() {
set -x
"$@"
set +x
}

cleanup() {
kill -9 $(ps aux | grep spdm-responder | grep emu | awk '{print $2}') || true
kill -9 $(ps aux | grep spdm_responder_emu | grep emu | awk '{print $2}') || true
}

RUN_REQUESTER_FEATURES=${RUN_REQUESTER_FEATURES:-spdm-ring,hashed-transcript-data,async-executor}
RUN_RESPONDER_FEATURES=${RUN_RESPONDER_FEATURES:-spdm-ring,hashed-transcript-data,async-executor}
RUN_REQUESTER_MUTAUTH_FEATURES="${RUN_REQUESTER_FEATURES},mut-auth"
RUN_RESPONDER_MUTAUTH_FEATURES="${RUN_RESPONDER_FEATURES},mut-auth"
RUN_RESPONDER_MANDATORY_MUTAUTH_FEATURES="${RUN_RESPONDER_FEATURES},mandatory-mut-auth"


run_with_spdm_emu_rsp_rust_req() {
echo "Running spdm-rs requester to test spdm-emu responder..."
pushd test_key
chmod +x ./spdm_responder_emu
echo_command ./spdm_responder_emu --trans PCI_DOE &
popd
sleep 5
echo_command cargo run -p spdm-requester-emu-rollback --no-default-features --features="$RUN_REQUESTER_FEATURES"
cleanup
popd
}

run_rust_spdm_emu_test_rsp() {
echo "Running spdm-rs requester to test spdm-rs responder..."
echo_command cargo run -p spdm-responder-emu --no-default-features --features="$RUN_RESPONDER_FEATURES" &
sleep 5
echo_command cargo run -p spdm-requester-emu-rollback --no-default-features --features="$RUN_REQUESTER_FEATURES"
cleanup
}


EMU_OPTION=false
RUST_OPTION=false
ALL_OPTION=false


process_args() {
while getopts ":erah" option; do
case "${option}" in
e)
EMU_OPTION=true
;;
r)
RUST_OPTION=true
;;
a)
ALL_OPTION=true
;;
h)
usage
exit 0
;;
*)
echo "Invalid option '-$OPTARG'"
usage
exit 1
;;
esac
done
}


main() {
if [[ ${EMU_OPTION} == true ]]; then
run_with_spdm_emu_rsp_rust_req
fi
if [[ ${RUST_OPTION} == true ]]; then
run_rust_spdm_emu_test_rsp
fi
if [[ ${ALL_OPTION} == true ]]; then
run_with_spdm_emu_rsp_rust_req
run_rust_spdm_emu_test_rsp
fi
}

process_args "$@"
main
38 changes: 38 additions & 0 deletions test/spdm-requester-emu-rollback/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
cargo-features = ["edition2024"]
[package]
name = "spdm-requester-emu-rollback"
version = "0.1.0"
authors = ["Hank Ouyang <[email protected]>"]
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
spdm-emu = { path = "../spdm-emu", default-features = false }
spdmlib = { path = "../../spdmlib", default-features = false }
idekm = { path = "../../idekm", default-features = false }
tdisp = { path = "../../tdisp", default-features = false }
codec = { path = "../../codec" }
mctp_transport = { path = "../../mctp_transport" }
pcidoe_transport = { path = "../../pcidoe_transport" }
log = "0.4.13"
simple_logger = "4.2.0"
futures = { version = "0.3", default-features = false }
spin = { version = "0.9.8" }
tokio = { version = "1.30.0", features = ["full"] }
executor = { path = "../../executor" }
maybe-async = "0.2.7"
td-benchmark = { git = "https://github.com/confidential-containers/td-shim.git", default-features = false, optional = true }
dhat = { version = "0.3.2", optional = true }

[features]
default = ["spdm-emu/default", "async-executor"]
mut-auth = ["spdm-emu/mut-auth"]
spdm-ring = ["spdm-emu/spdm-ring"]
spdm-mbedtls = ["spdm-emu/spdm-mbedtls"]
hashed-transcript-data = ["spdm-emu/hashed-transcript-data"]
async-executor = ["spdm-emu/async-executor"]
async-tokio = ["spdm-emu/async-tokio"]
is_sync = ["spdm-emu/is_sync", "spdmlib/is_sync", "maybe-async/is_sync", "idekm/is_sync", "tdisp/is_sync", "mctp_transport/is_sync", "pcidoe_transport/is_sync"]
test_stack_size = ["td-benchmark"]
test_heap_size = ["dhat"]
Loading

0 comments on commit 2771829

Please sign in to comment.