Skip to content

Commit

Permalink
Adds strum as a integration test requirement.
Browse files Browse the repository at this point in the history
-Adds integration-test feature in order to conditionally add
 dependencies.

-Updates the TpmFormatZeroWarning so it is possible to iterate over all
 the items when creating integration tests.

Signed-off-by: Jesper Brynolf <jesper.brynolf@gmail.com>
  • Loading branch information
Superhepper committed Jul 28, 2023
1 parent fdb394a commit a360ec9
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 41 deletions.
3 changes: 3 additions & 0 deletions tss-esapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ oid = { version = "0.2.1", optional = true }
picky-asn1 = { version = "0.3.0", optional = true }
picky-asn1-x509 = { version = "0.6.1", optional = true }
cfg-if = "1.0.0"
strum = { version = "0.25.0", optional = true }
strum_macros = { version = "0.25.0", optional = true }

[dev-dependencies]
env_logger = "0.9.0"
Expand All @@ -39,3 +41,4 @@ semver = "1.0.7"
default = ["abstraction"]
generate-bindings = ["tss-esapi-sys/generate-bindings"]
abstraction = ["oid", "picky-asn1", "picky-asn1-x509"]
integration-tests = ["strum", "strum_macros"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use std::convert::TryFrom;
/// These are the values from the specification without
/// the indicator that indicates that it is a TPM format
/// zero warning (i.e. [TPM2_RC_WARN]).
#[cfg_attr(feature = "integration-tests", derive(strum_macros::EnumIter))]
#[derive(FromPrimitive, ToPrimitive, Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum TpmFormatZeroWarning {
Expand Down
4 changes: 2 additions & 2 deletions tss-esapi/tests/all-fedora.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ cargo clippy --all-targets --all-features -- -D clippy::all -D clippy::cargo
###################
# Build the crate #
###################
RUST_BACKTRACE=1 cargo build --features generate-bindings
RUST_BACKTRACE=1 cargo build --features "generate-bindings integration-tests"

#################
# Run the tests #
#################
TEST_TCTI=tabrmd:bus_type=session RUST_BACKTRACE=1 RUST_LOG=info cargo test --features generate-bindings -- --test-threads=1 --nocapture
TEST_TCTI=tabrmd:bus_type=session RUST_BACKTRACE=1 RUST_LOG=info cargo test --features "generate-bindings integration-tests" -- --test-threads=1 --nocapture
4 changes: 2 additions & 2 deletions tss-esapi/tests/all-ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ fi
# Generate bindings for non-"standard" versions #
#################################################
if [[ "$TPM2_TSS_VERSION" != "2.3.3" ]]; then
FEATURES="--features=generate-bindings"
FEATURES="--features=\"generate-bindings integration-tests\""
else
FEATURES=""
FEATURES="--features=integration-tests"
fi

#################################
Expand Down
2 changes: 1 addition & 1 deletion tss-esapi/tests/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ tpm2_startup -c -T mssim
# Install and run tarpaulin #
#############################
cargo install cargo-tarpaulin
cargo tarpaulin --tests --out Xml --exclude-files="tests/*,../*" -- --test-threads=1 --nocapture
cargo tarpaulin --features integration-tests --tests --out Xml --exclude-files="tests/*,../*" -- --test-threads=1 --nocapture
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2022 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.
use std::convert::TryFrom;
use strum::IntoEnumIterator;
use tss_esapi::{
constants::{
return_code::TpmFormatZeroWarning,
Expand Down Expand Up @@ -231,43 +232,14 @@ fn test_display_implementation() {
);
}

macro_rules! test_error_number_method {
(TpmFormatZeroWarning::$zero_warning:ident) => {
let zero_warning_rc = TpmFormatZeroWarningResponseCode::from(TpmFormatZeroWarning::$zero_warning);
#[test]
fn test_error_number() {
TpmFormatZeroWarning::iter().for_each(|item| {
let zero_warning_rc = TpmFormatZeroWarningResponseCode::from(item);
assert_eq!(
TpmFormatZeroWarning::$zero_warning,
item,
zero_warning_rc.error_number(),
"The TpmFormatZeroWarningResponseCode `error_number()` method did not return the expected TpmFormatZeroWarning"
);
};
}

#[test]
fn test_error_number() {
test_error_number_method!(TpmFormatZeroWarning::ContextGap);
test_error_number_method!(TpmFormatZeroWarning::ObjectMemory);
test_error_number_method!(TpmFormatZeroWarning::SessionMemory);
test_error_number_method!(TpmFormatZeroWarning::ObjectHandles);
test_error_number_method!(TpmFormatZeroWarning::Locality);
test_error_number_method!(TpmFormatZeroWarning::Yielded);
test_error_number_method!(TpmFormatZeroWarning::Canceled);
test_error_number_method!(TpmFormatZeroWarning::Testing);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH0);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH1);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH2);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH3);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH4);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH5);
test_error_number_method!(TpmFormatZeroWarning::ReferenceH6);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS0);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS1);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS2);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS3);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS4);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS5);
test_error_number_method!(TpmFormatZeroWarning::ReferenceS6);
test_error_number_method!(TpmFormatZeroWarning::NvRate);
test_error_number_method!(TpmFormatZeroWarning::Lockout);
test_error_number_method!(TpmFormatZeroWarning::Retry);
test_error_number_method!(TpmFormatZeroWarning::NvUnavailable);
});
}
2 changes: 1 addition & 1 deletion tss-esapi/tests/valgrind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ cargo install cargo-valgrind
#################
# Run the tests #
#################
TEST_TCTI=mssim: RUST_BACKTRACE=1 RUST_LOG=info cargo valgrind test -- --test-threads=1 --nocapture
TEST_TCTI=mssim: RUST_BACKTRACE=1 RUST_LOG=info cargo valgrind --features integration-tests test -- --test-threads=1 --nocapture

0 comments on commit a360ec9

Please sign in to comment.