diff options
author | Alain Michaud <alainmichaud@google.com> | 2022-01-24 00:06:11 +0000 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2022-05-02 20:29:33 +0000 |
commit | c884df81578078d9fdadb54b63c5e1971307d272 (patch) | |
tree | 29e4504a2ef35ff406766e76214e56dd9ad1aa25 | |
parent | b38eb2dc32721b75cd63a064e9a31ea0c1805f53 (diff) | |
download | uwb-c884df81578078d9fdadb54b63c5e1971307d272.tar.gz |
uwb(native): Adding host tests for libuwb_uci_rust, libuwb_uci_packet
A specific device only configuration is not needed since all existing
tests can be ran on the host.
Bug: 216784920
Test: atest --host libuwb_uci_packet_tests
Test: atest --host libuwb_uci_rust_tests
Change-Id: Ia58586c984abe1523ac786de6d59a86544e219d6
-rwxr-xr-x | src/Android.bp | 64 | ||||
-rw-r--r-- | src/rust/adaptation/mod.rs | 36 | ||||
-rw-r--r-- | src/rust/lib.rs | 1 |
3 files changed, 73 insertions, 28 deletions
diff --git a/src/Android.bp b/src/Android.bp index d6cfa15..5fca6f6 100755 --- a/src/Android.bp +++ b/src/Android.bp @@ -21,12 +21,18 @@ rust_defaults { "liblog_rust", "liblogger", "libnum_traits", - "librustutils", "libthiserror", "libtokio", "libuwb_uci_packets", - "libbinder_tokio_rs", + "libbinder_tokio_rs", ], + target: { + android: { + rustlibs: [ + "librustutils", + ], + }, + }, rlibs: [ "libarbitrary", ], @@ -37,6 +43,7 @@ rust_defaults { "com.android.uwb", ], min_sdk_version: "Tiramisu", + host_supported: true, } rust_library { @@ -47,11 +54,29 @@ rust_library { rust_test { name: "libuwb_uci_rust_tests", defaults: ["libuwb_uci_defaults"], - test_suites: [ - "general-tests", - "mts-uwb" - ], - test_config_template: "uwb_rust_test_config_template.xml", + target: { + android: { + test_suites: [ + "general-tests", + "mts-uwb" + ], + test_config_template: "uwb_rust_test_config_template.xml", + }, + host: { + test_suites: [ + "general-tests", + ], + data_libs: [ + "libandroid_runtime_lazy", + "libbase", + "libbinder", + "libbinder_ndk", + "libcutils", + "liblog", + "libutils", + ], + }, + }, // Support multilib variants (using different suffix per sub-architecture), which is needed on // build targets with secondary architectures, as the MTS test suite packaging logic flattens // all test artifacts into a single `testcases` directory. @@ -80,16 +105,26 @@ rust_defaults { "libnum_traits", "libthiserror", ], + host_supported: true, } rust_test { name: "libuwb_uci_packet_tests", defaults: ["libuwb_uci_packet_defaults"], - test_suites: [ - "general-tests", - "mts-uwb" - ], - test_config_template: "uwb_rust_test_config_template.xml", + target: { + android: { + test_suites: [ + "general-tests", + "mts-uwb" + ], + test_config_template: "uwb_rust_test_config_template.xml", + }, + host: { + test_suites: [ + "general-tests", + ], + }, + }, // Support multilib variants (using different suffix per sub-architecture), which is needed on // build targets with secondary architectures, as the MTS test suite packaging logic flattens // all test artifacts into a single `testcases` directory. @@ -103,11 +138,6 @@ rust_test { }, }, auto_gen_config: true, - rustlibs:[ - "android.hardware.uwb-V1-rust", - "liblog_rust", - "libuwb_uci_rust", - ], } rust_library { diff --git a/src/rust/adaptation/mod.rs b/src/rust/adaptation/mod.rs index 4f017fd..a650810 100644 --- a/src/rust/adaptation/mod.rs +++ b/src/rust/adaptation/mod.rs @@ -17,7 +17,8 @@ use android_hardware_uwb::binder::{ use async_trait::async_trait; use binder::IBinder; use binder_tokio::{Tokio, TokioRuntime}; -use log::{error, warn}; +use log::error; +#[cfg(target_os = "android")] use rustutils::system_properties; use std::sync::Arc; use tokio::runtime::Handle; @@ -112,18 +113,15 @@ pub struct UwbAdaptationImpl { } impl UwbAdaptationImpl { - async fn new_with_args( - rsp_sender: mpsc::UnboundedSender<HalCallback>, - hal: Strong<dyn IUwbChipAsync<Tokio>>, - hal_death_recipient: Arc<Mutex<DeathRecipient>>, - ) -> Result<Self> { - let mode = match system_properties::read("persist.uwb.uci_logger_mode") { + #[cfg(target_os = "android")] + fn get_uci_log_mode() -> UciLogMode { + match system_properties::read("persist.uwb.uci_logger_mode") { Ok(Some(logger_mode)) => match logger_mode.as_str() { "disabled" => UciLogMode::Disabled, "filtered" => UciLogMode::Filtered, "enabled" => UciLogMode::Enabled, str => { - warn!("Logger mode not recognized! Value: {:?}", str); + error!("Logger mode not recognized! Value: {:?}", str); UCI_LOG_DEFAULT } }, @@ -132,9 +130,25 @@ impl UwbAdaptationImpl { error!("Failed to get uci_logger_mode {:?}", e); UCI_LOG_DEFAULT } - }; - let logger = - UciLoggerImpl::new(mode, Arc::new(Mutex::new(RealFileFactory::default()))).await; + } + } + + #[cfg(not(target_os = "android"))] + fn get_uci_log_mode() -> UciLogMode { + // system_properties is not supported on host builds. + UCI_LOG_DEFAULT + } + + async fn new_with_args( + rsp_sender: mpsc::UnboundedSender<HalCallback>, + hal: Strong<dyn IUwbChipAsync<Tokio>>, + hal_death_recipient: Arc<Mutex<DeathRecipient>>, + ) -> Result<Self> { + let logger = UciLoggerImpl::new( + UwbAdaptationImpl::get_uci_log_mode(), + Arc::new(Mutex::new(RealFileFactory::default())), + ) + .await; Ok(UwbAdaptationImpl { hal, rsp_sender, logger: Arc::new(logger), hal_death_recipient }) } diff --git a/src/rust/lib.rs b/src/rust/lib.rs index d42e060..e9f3dbe 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -16,6 +16,7 @@ // TODO remove this and add appropriate documentation once it is decided whether this stays here or // moves into packages/modules/Uwb #![allow(missing_docs)] +#![feature(rustc_private)] pub mod adaptation; pub mod error; |