diff --git a/optee-teec/src/uuid.rs b/optee-teec/src/uuid.rs index 4d21b035..2939fc64 100644 --- a/optee-teec/src/uuid.rs +++ b/optee-teec/src/uuid.rs @@ -106,11 +106,32 @@ impl fmt::Display for Uuid { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{:x}-{:x}-{:x}-{}", + "{:08x}-{:04x}-{:04x}-{}-{}", self.raw.timeLow, self.raw.timeMid, self.raw.timeHiAndVersion, - hex::encode(self.raw.clockSeqAndNode) + hex::encode(&self.raw.clockSeqAndNode[0..2]), + hex::encode(&self.raw.clockSeqAndNode[2..8]), ) } } + +#[cfg(test)] +mod tests { + use super::Uuid; + + #[test] + fn test_to_string() { + let uuids = [ + "00173366-2aca-49bc-beb7-10c975e6131e", // uuid with timeLow leading zeros + "11173366-0aca-49bc-beb7-10c975e6131e", // uuid with timeMid leading zeros + "11173366-2aca-09bc-beb7-10c975e6131e", // uuid with timeHiAndVersion leading zeros + "11173366-2aca-19bc-beb7-10c975e6131e", // random uuid + ]; + for origin in uuids.iter() { + let uuid = Uuid::parse_str(origin).unwrap(); + let formatted = uuid.to_string(); + assert_eq!(origin, &formatted); + } + } +} diff --git a/optee-utee/optee-utee-sys/build.rs b/optee-utee/optee-utee-sys/build.rs index a59da9a5..d9c832f6 100644 --- a/optee-utee/optee-utee-sys/build.rs +++ b/optee-utee/optee-utee-sys/build.rs @@ -19,6 +19,23 @@ use std::env; use std::path::Path; fn main() { + const ENV_RUN_TEST_IN_REE: &str = "RUN_TEST_IN_REE"; + println!("cargo:rerun-if-env-changed={}", ENV_RUN_TEST_IN_REE); + + let run_test_in_ree = env::var(ENV_RUN_TEST_IN_REE).unwrap_or(String::from("false")); + match run_test_in_ree.eq_ignore_ascii_case("true") { + true => test_build(), + false => production_build(), + } +} + +// this allow developers to run library tests in REE by +// RUN_TEST_IN_REE=true cargo test --lib --features no_panic_handler +fn test_build() { +} + +fn production_build() { + let optee_os_dir = env::var("TA_DEV_KIT_DIR").unwrap(); let search_path = Path::new(&optee_os_dir).join("lib"); diff --git a/optee-utee/src/uuid.rs b/optee-utee/src/uuid.rs index c629a988..64527f7a 100644 --- a/optee-utee/src/uuid.rs +++ b/optee-utee/src/uuid.rs @@ -105,11 +105,34 @@ impl fmt::Display for Uuid { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "{:x}-{:x}-{:x}-{}", + "{:08x}-{:04x}-{:04x}-{}-{}", self.raw.timeLow, self.raw.timeMid, self.raw.timeHiAndVersion, - hex::encode(self.raw.clockSeqAndNode) + hex::encode(&self.raw.clockSeqAndNode[0..2]), + hex::encode(&self.raw.clockSeqAndNode[2..8]), ) } } + +#[cfg(test)] +mod tests { + extern crate alloc; + use super::*; + use alloc::string::ToString; + + #[test] + fn test_to_string() { + let uuids = [ + "00173366-2aca-49bc-beb7-10c975e6131e", // uuid with timeLow leading zeros + "11173366-0aca-49bc-beb7-10c975e6131e", // uuid with timeMid leading zeros + "11173366-2aca-09bc-beb7-10c975e6131e", // uuid with timeHiAndVersion leading zeros + "11173366-2aca-19bc-beb7-10c975e6131e", // random uuid + ]; + for origin in uuids.iter() { + let uuid = Uuid::parse_str(origin).unwrap(); + let formatted = uuid.to_string(); + assert_eq!(origin, &formatted); + } + } +}