Skip to content

Commit

Permalink
Change the output formation of ToString method of Uuid
Browse files Browse the repository at this point in the history
1) change the realization of Display trait of Uuid, make its formation
   const of 36 bytes.
2) introduce an env(RUN_TEST_IN_REE) in optee-utee-sys crate so that
   we can run library tests of optee-utee
  • Loading branch information
ivila authored and zehui committed Nov 29, 2024
1 parent eb1ea70 commit 31d2b2c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
25 changes: 23 additions & 2 deletions optee-teec/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
17 changes: 17 additions & 0 deletions optee-utee/optee-utee-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
27 changes: 25 additions & 2 deletions optee-utee/src/uuid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

0 comments on commit 31d2b2c

Please sign in to comment.