Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
add feature to control async runtime.
Browse files Browse the repository at this point in the history
fix #152

Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang authored and jyao1 committed Dec 1, 2023
1 parent d516783 commit 0189b3c
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 65 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ jobs:
RUSTFLAGS: "-C instrument-coverage"
CC_x86_64_unknown_none: clang
AR_x86_64_unknown_none: llvm-ar
RUN_REQUESTER_FEATURES: "spdm-ring,hashed-transcript-data"
RUN_RESPONDER_FEATURES: "spdm-ring,hashed-transcript-data"
RUN_REQUESTER_FEATURES: "spdm-ring,hashed-transcript-data,async-executor"
RUN_RESPONDER_FEATURES: "spdm-ring,hashed-transcript-data,async-executor"
run: |
./sh_script/build.sh -r
Expand All @@ -101,8 +101,8 @@ jobs:
RUSTFLAGS: "-C instrument-coverage"
CC_x86_64_unknown_none: clang
AR_x86_64_unknown_none: llvm-ar
RUN_REQUESTER_FEATURES: "spdm-mbedtls"
RUN_RESPONDER_FEATURES: "spdm-mbedtls"
RUN_REQUESTER_FEATURES: "spdm-mbedtls,async-executor"
RUN_RESPONDER_FEATURES: "spdm-mbedtls,async-executor"
run: |
./sh_script/build.sh -r
Expand All @@ -112,8 +112,8 @@ jobs:
RUSTFLAGS: "-C instrument-coverage"
CC_x86_64_unknown_none: clang
AR_x86_64_unknown_none: llvm-ar
RUN_REQUESTER_FEATURES: "spdm-mbedtls,hashed-transcript-data"
RUN_RESPONDER_FEATURES: "spdm-mbedtls,hashed-transcript-data"
RUN_REQUESTER_FEATURES: "spdm-mbedtls,hashed-transcript-data,async-executor"
RUN_RESPONDER_FEATURES: "spdm-mbedtls,hashed-transcript-data,async-executor"
run: |
./sh_script/build.sh -r
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ jobs:
runs-on: [ubuntu-latest]
run_requester_features:
[
"spdm-ring",
"spdm-ring,hashed-transcript-data",
"spdm-mbedtls",
"spdm-mbedtls,hashed-transcript-data",
"spdm-ring,async-executor",
"spdm-ring,hashed-transcript-data,async-executor",
"spdm-mbedtls,async-executor",
"spdm-mbedtls,hashed-transcript-data,async-executor",
]
run_responder_features:
[
"spdm-ring",
"spdm-ring,hashed-transcript-data",
"spdm-mbedtls",
"spdm-mbedtls,hashed-transcript-data",
"spdm-ring,async-executor",
"spdm-ring,hashed-transcript-data,async-executor",
"spdm-mbedtls,async-executor",
"spdm-mbedtls,hashed-transcript-data,async-executor",
]
include:
- runs-on: windows-latest
run_requester_features: "spdm-ring,hashed-transcript-data"
run_responder_features: "spdm-ring,hashed-transcript-data"
run_requester_features: "spdm-ring,hashed-transcript-data,async-executor"
run_responder_features: "spdm-ring,hashed-transcript-data,async-executor"
# The type of runner that the job will run on
runs-on: ${{ matrix.runs-on }}

Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 18 additions & 16 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,38 @@ cargo build -Z build-std=core,alloc,compiler_builtins --target x86_64-unknown-no

Open one command windows and run:
```
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring,hashed-transcript-data"
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring,hashed-transcript-data,async-executor"
```

Open another command windows and run:
```
cargo run -p spdm-requester-emu --no-default-features --features "spdm-ring,hashed-transcript-data"
cargo run -p spdm-requester-emu --no-default-features --features "spdm-ring,hashed-transcript-data,async-executor"
```

### Run emulator with selected feature

The following list shows the supported combinations for both spdm-requester-emu and spdm-responder-emu


| Features | CryptoLibrary | Hashed transcript data support | Notes |
| ----------------------------------------------------------------------- | ------------- | ------------------------------ | ------------------------------------------------------------------ |
| spdm-ring | ring | No | use ring as crypto library with hashed-transcript-data disabled |
| spdm-ring,hashed-transcript-data | ring | Yes | use ring as crypto library with hashed-transcript-data enabled |
| spdm-mbedtls | mbedtls | No | use mbedtls as crypto library with hashed-transcript-data disabled |
| spdm-mbedtls,hashed-transcript-data | mbedtls | Yes | use mbedtls as crypto library with hashed-transcript-data |
| Features | CryptoLibrary | Hashed transcript data support | async runtime | notes |
|-------------------------------------------------|---------------|--------------------------------|---------------|---------------------------------------------------------------------------------------------------|
| spdm-ring,async-executor | ring | No | executor | use ring as crypto library with hashed-transcript-data disabled, use executor as async runtime |
| spdm-ring,hashed-transcript-data,async-executor | ring | Yes | executor | use ring as crypto library with hashed-transcript-data enabled, use executor as async runtime |
| spdm-ring,hashed-transcript-data,async-tokio | ring | Yes | tokio | use ring as crypto library with hashed-transcript-data enabled, use tokio as async runtime |
| spdm-mbedtls,async-executor | mbedtls | No | executor | use mbedtls as crypto library with hashed-transcript-data disabled, use executor as async runtime |
| spdm-mbedtls,hashed-transcript-data,async-executor | mbedtls | Yes | executor | use mbedtls as crypto library with hashed-transcript-data enabled, use executor as async runtime |
| spdm-mbedtls,hashed-transcript-data,async-tokio | mbedtls | Yes | tokio | use mbedtls as crypto library with hashed-transcript-data enabled, use tokio as async runtime |

For example, run the emulator with spdm-ring enabled and without hashed-transcript-data enabled.
For example, run the emulator with spdm-ring enabled and without hashed-transcript-data enabled, and use executor as async runtime.
Open one command windows and run:
```
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring"
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring,async-executor "
```

run the emulator with spdm-mbedtls enabled and with hashed-transcript-data enabled.
run the emulator with spdm-mbedtls enabled and with hashed-transcript-data enabled, and use tokio as async runtime.
Open another command windows and run:
```
cargo run -p spdm-requester-emu --no-default-features --features "spdm-mbedtls,hashed-transcript-data"
cargo run -p spdm-requester-emu --no-default-features --features "spdm-mbedtls,hashed-transcript-data,async-tokio"
```

NOTE: In order to run the emu without hashed-transcript-data, please change `max_cert_chain_data_size` in `spdmlib/etc/config.json` from `4096` to `3500`.
Expand Down Expand Up @@ -192,14 +194,14 @@ spdm_responder_emu.exe --trans PCI_DOE

2. run rust-spdm-emu as requester:
```
cargo run -p spdm-requester-emu --no-default-features --features "spdm-ring,hashed-transcript-data"
cargo run -p spdm-requester-emu --no-default-features --features "spdm-ring,hashed-transcript-data,async-executor "
```

Test rust-spdm as responder:

1. run rust-spdm-emu as Test rust-spdm as responder:
```
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring,hashed-transcript-data"
cargo run -p spdm-responder-emu --no-default-features --features "spdm-ring,hashed-transcript-data,async-executor "
```

2. run libspdm in spdm-emu as requester:
Expand All @@ -218,12 +220,12 @@ export RUST_MIN_STACK=10485760

Test with hashed-transcript-data:
```
cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring,spdmlib/hashed-transcript-data" -- --test-threads=1
cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring,spdmlib/hashed-transcript-data,async-executor" -- --test-threads=1
```

Test without hashed-transcript-data:
```
cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring" -- --test-threads=1
cargo test --no-default-features --features "spdmlib/std,spdmlib/spdm-ring,async-executor" -- --test-threads=1
```

To run a specific test, use `cargo test <test_func_name>`
Expand Down
4 changes: 2 additions & 2 deletions sh_script/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ build() {
echo_command cargo build -p spdm-responder-emu
}

RUN_REQUESTER_FEATURES=${RUN_REQUESTER_FEATURES:-spdm-ring,hashed-transcript-data}
RUN_RESPONDER_FEATURES=${RUN_RESPONDER_FEATURES:-spdm-ring,hashed-transcript-data}
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"
Expand Down
6 changes: 5 additions & 1 deletion test/spdm-emu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ futures = { version = "0.3", default-features = false }
async-trait = "0.1.71"
async-recursion = "1.0.4"
spin = { version = "0.9.8" }
tokio = { version = "1.30.0", features = ["full"] }
executor = { path = "../../executor" }

spdmlib_crypto_mbedtls = { path = "../../spdmlib_crypto_mbedtls", default-features = false, optional = true }

[features]
default = ["spdm-ring", "spdmlib/hashed-transcript-data"]
default = ["spdm-ring", "spdmlib/hashed-transcript-data", "async-executor"]
mut-auth = ["spdmlib/mut-auth"]
mandatory-mut-auth = ["mut-auth", "spdmlib/mandatory-mut-auth"]
spdm-ring = ["spdmlib/spdm-ring", "spdmlib/std"]
spdm-mbedtls = ["spdmlib_crypto_mbedtls"]
hashed-transcript-data = ["spdmlib/hashed-transcript-data", "spdmlib_crypto_mbedtls?/hashed-transcript-data"]
async-executor = []
async-tokio = []
26 changes: 26 additions & 0 deletions test/spdm-emu/src/async_runtime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

extern crate alloc;
use alloc::boxed::Box;
use core::{future::Future, pin::Pin};

// Run async task
pub fn block_on<T>(future: Pin<Box<dyn Future<Output = T> + 'static + Send>>) -> T
where
T: Send + 'static,
{
#[cfg(all(feature = "async-executor", feature = "async-tokio"))]
compile_error!("features `async-executor` and `async-tokio` are mutually exclusive");

if cfg!(feature = "async-executor") {
executor::block_on(future)
} else if cfg!(feature = "async-tokio") {
let rt = tokio::runtime::Runtime::new().unwrap();

rt.block_on(future)
} else {
panic!("Calling block_on require one of `async-executor` or `async-tokio` is enabled!");
}
}
1 change: 1 addition & 0 deletions test/spdm-emu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#![forbid(unsafe_code)]

pub mod async_runtime;
pub mod crypto;
pub mod crypto_callback;
pub mod secret_impl_sample;
Expand Down
5 changes: 4 additions & 1 deletion test/spdm-requester-emu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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" }

[features]
default = ["spdm-emu/default"]
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"]
24 changes: 12 additions & 12 deletions test/spdm-requester-emu/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use log::LevelFilter;
use log::*;
use simple_logger::SimpleLogger;

use spdm_emu::async_runtime::block_on;
use spdm_emu::crypto_callback::SECRET_ASYM_IMPL_INSTANCE;
use spdm_emu::secret_impl_sample::SECRET_PSK_IMPL_INSTANCE;
use spdm_emu::EMU_STACK_SIZE;
Expand Down Expand Up @@ -56,8 +57,6 @@ use tdisp::pci_tdisp_requester::pci_tdisp_req_lock_interface_request;
use tdisp::pci_tdisp_requester::pci_tdisp_req_start_interface_request;
use tdisp::pci_tdisp_requester::pci_tdisp_req_stop_interface_request;

use tokio::runtime::Runtime;

use spin::Mutex;
extern crate alloc;
use alloc::sync::Arc;
Expand Down Expand Up @@ -1294,30 +1293,31 @@ fn emu_main() {
SOCKET_TRANSPORT_TYPE_MCTP
};

// Create the runtime
let rt = Runtime::new().unwrap();

rt.block_on(send_receive_hello(
block_on(Box::pin(send_receive_hello(
socket.clone(),
transport_encap.clone(),
transport_type,
));
)));

let socket_io_transport = SocketIoTransport::new(socket.clone());
let socket_io_transport: Arc<Mutex<dyn SpdmDeviceIo + Send + Sync>> =
Arc::new(Mutex::new(socket_io_transport));

rt.block_on(test_spdm(
block_on(Box::pin(test_spdm(
socket_io_transport.clone(),
transport_encap.clone(),
));
)));

rt.block_on(test_idekm_tdisp(
block_on(Box::pin(test_idekm_tdisp(
socket_io_transport.clone(),
transport_encap.clone(),
));
)));

rt.block_on(send_receive_stop(socket, transport_encap, transport_type));
block_on(Box::pin(send_receive_stop(
socket,
transport_encap,
transport_type,
)));
}

fn main() {
Expand Down
5 changes: 4 additions & 1 deletion test/spdm-responder-emu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ log = "0.4.13"
futures = { version = "0.3", default-features = false }
spin = { version = "0.9.8" }
tokio = { version = "1.30.0", features = ["full"] }
executor = { path = "../../executor" }
zeroize = { version = "1.5.0", features = ["zeroize_derive"]}

[features]
mut-auth = ["spdm-emu/mut-auth"]
mut-auth = ["spdm-emu/mut-auth", "async-executor"]
mandatory-mut-auth = ["mut-auth", "spdm-emu/mandatory-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"]
Loading

0 comments on commit 0189b3c

Please sign in to comment.