Skip to content

Commit

Permalink
test_suite: Split out the test setup function
Browse files Browse the repository at this point in the history
Signed-off-by: Alistair Francis <[email protected]>
  • Loading branch information
alistair23 committed Jul 12, 2024
1 parent 04b2be2 commit 3891cfb
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions src/test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::doe_pci_cfg::*;
use crate::request;
use crate::spdm;
use crate::spdm::get_measurement;
use crate::spdm::SpdmSessionInfo;
use crate::tcg_concise_evidence_binding::check_tcg_dice_evidence_binding;
use crate::RequestCode;
#[cfg(libspdm_tests)]
Expand All @@ -37,21 +38,16 @@ pub enum TestBackend {

/// # Summary
///
/// Send SPDM requests to the endpoint and automate the request process, such that
/// any assertions within the requests can be validated. This function does not
/// do any additional testing outside of the what the requests do.
///
/// This will only pass when run against a device that meets the
/// "TCG DICE Concise Evidence Binding for SPDM" specification.
/// Setup a spdm session in preperation for testing
///
/// # Parameter
///
/// * `cntx`: The SPDM context
///
/// # Returns
///
/// Success, or any errors returned by the request.
pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void) -> Result<(), u32> {
/// SpdmSessionInfo on Success, or any errors returned by the request.
pub fn setup_test_backend(cntx: *mut c_void) -> Result<SpdmSessionInfo, u32> {
let slot_id = 0;

// Setup Basic Requester, this is the default config we use for spdm-utils.
Expand Down Expand Up @@ -83,13 +79,35 @@ pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void) -> Result<
)?;
info!(" RequestCode::GetCapabilities ... [OK]");

Ok(session_info)
}

/// # Summary
///
/// Send SPDM requests to the endpoint and automate the request process, such that
/// any assertions within the requests can be validated. This function does not
/// do any additional testing outside of the what the requests do.
///
/// This will only pass when run against a device that meets the
/// "TCG DICE Concise Evidence Binding for SPDM" specification.
///
/// # Parameter
///
/// * `cntx`: The SPDM context
///
/// # Returns
///
/// Success, or any errors returned by the request.
pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void, session_info: &mut SpdmSessionInfo) -> Result<(), u32> {
let slot_id = 0;

info!("[{slot_id}] Start RequestCode::GetDigests");
request::prepare_request(
cntx,
RequestCode::GetDigests {},
slot_id,
None,
&mut session_info,
session_info,
)?;
info!(" RequestCode::GetDigests ... [OK]");

Expand All @@ -101,7 +119,7 @@ pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void) -> Result<
},
slot_id,
None,
&mut session_info,
session_info,
)?;
let cert_usage = check_tcg_dice_evidence_binding(0).unwrap();
info!(" RequestCode::GetCertificate ... [OK]");
Expand All @@ -114,15 +132,17 @@ pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void) -> Result<
},
slot_id,
None,
&mut session_info,
session_info,
)?;
info!(" RequestCode::Challenge ... [OK]");

// Setup a PSK session
let mut session_info_psk;
if cert_usage.sign_responses {
session_info = unsafe { spdm::start_session(cntx, slot_id, true).unwrap() };
session_info_psk = unsafe { spdm::start_session(cntx, slot_id, true).unwrap() };
} else {
error!("[{slot_id}] Unable to sign Responses");
return Err(0);
}

// The DICE specifications describe Evidence as measurements that are to
Expand Down Expand Up @@ -207,7 +227,7 @@ pub fn do_tcg_dice_evidence_binding_request_checks(cntx: *mut c_void) -> Result<
},
slot_id,
None,
&mut session_info,
&mut session_info_psk,
)?;
info!(" RequestCode::Challenge ... [OK]");

Expand Down Expand Up @@ -460,7 +480,8 @@ pub unsafe fn start_tests(cntx: *mut c_void, backend: TestBackend) -> ! {

responder_validator_tests(cntx).unwrap();

if let Err(libpsm_err) = do_tcg_dice_evidence_binding_request_checks(cntx) {
let mut session_info = setup_test_backend(cntx).unwrap();
if let Err(libpsm_err) = do_tcg_dice_evidence_binding_request_checks(cntx, &mut session_info) {
panic!(" request failed with libspdm err: {:x}", libpsm_err);
}
if let Err(e) = request_all_measurements(cntx) {
Expand Down

0 comments on commit 3891cfb

Please sign in to comment.