Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the output formation of ToString method of Uuid #152

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
export OPTEE_DIR=$HOME
source environment

# Run unit tests
(cd optee-utee && SYS_BUILD_TYPE=unit_test cargo test --lib --features no_panic_handler -vv)
(cd optee-teec && SYS_BUILD_TYPE=unit_test cargo test --lib -vv)

# Build Rust optee-utee and optee-teec
(cd optee-utee && cargo build --target aarch64-unknown-linux-gnu -vv)
(cd optee-teec && cargo build --target aarch64-unknown-linux-gnu -vv)
Expand Down
15 changes: 15 additions & 0 deletions optee-teec/optee-teec-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ use std::env;
use std::path::Path;

fn main() {
const ENV_SYS_BUILD_TYPE: &str = "SYS_BUILD_TYPE";
println!("cargo:rerun-if-env-changed={}", ENV_SYS_BUILD_TYPE);

let build_type = env::var(ENV_SYS_BUILD_TYPE).unwrap_or(String::from("")).to_lowercase();
match build_type.as_str() {
"unit_test" => unit_test_build(),
_ => production_build(),
}
}

// this allow developers to run unit tests in host machine(even x86)
fn unit_test_build() {
}

fn production_build() {
let optee_client_dir = env::var("OPTEE_CLIENT_EXPORT").expect("OPTEE_CLIENT_EXPORT is not set");
let search_path = Path::new(&optee_client_dir).join("usr/lib");
println!("cargo:rustc-link-search={}", search_path.display());
Expand Down
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);
}
}
}
16 changes: 16 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,22 @@ use std::env;
use std::path::Path;

fn main() {
const ENV_SYS_BUILD_TYPE: &str = "SYS_BUILD_TYPE";
println!("cargo:rerun-if-env-changed={}", ENV_SYS_BUILD_TYPE);

let build_type = env::var(ENV_SYS_BUILD_TYPE).unwrap_or(String::from("")).to_lowercase();
match build_type.as_str() {
"unit_test" => unit_test_build(),
_ => production_build(),
}
}

// this allow developers to run unit tests in host machine by
// SYS_BUILD_TYPE=unit_test cargo test --lib --features no_panic_handler
fn unit_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);
}
}
}