#![cfg(any(feature = "signing", feature = "encryption"))]
#![allow(clippy::unwrap_used)]
#![allow(clippy::panic)]
#![allow(clippy::print_stderr)]
use std::process::Command;
fn run_example_with_env(name: &str, extra_env: &[(&str, &str)]) -> bool {
let mut cmd = Command::new(env!("CARGO"));
cmd.args([
"run",
"--example",
name,
"--quiet",
"--features",
"signing,encryption,mock",
])
.env("RUST_LOG", "warn")
.env_remove("ENCLAVE_INTERACTIVE")
.current_dir(env!("CARGO_MANIFEST_DIR"));
for (k, v) in extra_env {
cmd.env(k, v);
}
let output = cmd
.output()
.unwrap_or_else(|e| panic!("failed to spawn cargo run --example {name}: {e}"));
if !output.status.success() {
eprintln!(
"example '{name}' failed (exit {:?}):\nstdout:\n{}\nstderr:\n{}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}
output.status.success()
}
#[test]
fn example_memory_protection() {
assert!(
run_example_with_env("memory_protection", &[]),
"memory_protection example failed"
);
}
#[test]
fn example_integrity_ephemeral() {
assert!(
run_example_with_env("integrity", &[]),
"integrity example (ephemeral mode) failed"
);
}
#[test]
#[cfg(target_os = "linux")] fn example_signing_mock() {
assert!(
run_example_with_env("signing", &[("ENCLAVE_MOCK", "1")]),
"signing example (mock mode) failed"
);
}
#[test]
#[cfg(target_os = "linux")] fn example_encryption_mock() {
assert!(
run_example_with_env("encryption", &[("ENCLAVE_MOCK", "1")]),
"encryption example (mock mode) failed"
);
}
#[test]
#[ignore = "requires real hardware and interactive prompts (ENCLAVE_INTERACTIVE=1)"]
fn example_integrity_interactive() {
assert!(
run_example_with_env("integrity", &[("ENCLAVE_INTERACTIVE", "1")]),
"integrity example (interactive mode) failed"
);
}
#[test]
#[ignore = "requires real hardware and interactive prompts (ENCLAVE_INTERACTIVE=1)"]
fn example_signing_real_hardware() {
assert!(
run_example_with_env("signing", &[]),
"signing example (real hardware) failed"
);
}
#[test]
#[ignore = "requires real hardware and interactive prompts (ENCLAVE_INTERACTIVE=1)"]
fn example_encryption_real_hardware() {
assert!(
run_example_with_env("encryption", &[]),
"encryption example (real hardware) failed"
);
}