test work

This commit is contained in:
John Smith
2022-12-01 10:46:52 -05:00
parent b6c446cd39
commit 9a4ab59ed6
10 changed files with 248 additions and 150 deletions

View File

@@ -15,7 +15,7 @@ rt-async-std = [ "async-std", "async_executors/async_std", ]
rt-tokio = [ "tokio", "tokio-util", "async_executors/tokio_tp", "async_executors/tokio_io", "async_executors/tokio_timer", ]
veilid_tools_android_tests = [ "dep:tracing-android" ]
veilid_tools_ios_tests = []
veilid_tools_ios_tests = [ "dep:oslog", "dep:tracing-oslog" ]
tracing = [ "dep:tracing", "dep:tracing-subscriber" ]
[dependencies]
@@ -72,7 +72,8 @@ android-logd-logger = "0.2.1"
# Dependencies for iOS
[target.'cfg(target_os = "ios")'.dependencies]
simplelog = { version = "^0.12", features = [ "test" ] }
oslog = { version = "^0", optional = true }
tracing-oslog = { version = "^0", optional = true }
### DEV DEPENDENCIES

View File

@@ -15,8 +15,10 @@ pub extern "system" fn Java_com_veilid_veilid_1tools_1android_1tests_MainActivit
_class: JClass,
_ctx: JObject,
) {
crate::tests::android::veilid_tools_setup_android_tests();
run_all_tests();
veilid_tools_setup_android_tests();
block_on(async {
run_all_tests().await;
})
}
pub fn veilid_tools_setup_android_tests() {

View File

@@ -6,38 +6,55 @@ use std::panic;
#[no_mangle]
pub extern "C" fn run_veilid_tools_tests() {
crate::tests::ios::veilid_tools_setup_ios_tests();
run_all_tests();
veilid_tools_setup_ios_tests();
block_on(async {
run_all_tests().await;
})
}
pub fn veilid_tools_setup_ios_tests() {
cfg_if! {
if #[cfg(feature = "tracing")] {
use tracing_subscriber::{filter, fmt, prelude::*};
// use tracing_subscriber::{filter, fmt, prelude::*};
// let mut filters = filter::Targets::new();
// for ig in DEFAULT_LOG_IGNORE_LIST {
// filters = filters.with_target(ig, filter::LevelFilter::OFF);
// }
// let fmt_layer = fmt::layer();
// tracing_subscriber::registry()
// .with(filters)
// .with(filter::LevelFilter::TRACE)
// .with(fmt_layer)
// .init();
let mut filters = filter::Targets::new();
for ig in DEFAULT_LOG_IGNORE_LIST {
filters = filters.with_target(ig, filter::LevelFilter::OFF);
}
let fmt_layer = fmt::layer();
tracing_subscriber::registry()
.with(filters)
.with(filter::LevelFilter::TRACE)
.with(fmt_layer)
.with(OsLogger::new("com.veilid.veilidtools-tests", "default"))
.init();
} else {
use simplelog::*;
let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
let mut cb = ConfigBuilder::new();
for ig in DEFAULT_LOG_IGNORE_LIST {
cb.add_filter_ignore_str(ig);
}
logs.push(TermLogger::new(
LevelFilter::Trace,
cb.build(),
TerminalMode::Mixed,
ColorChoice::Auto,
));
CombinedLogger::init(logs).expect("logger init error");
// use simplelog::*;
// let mut logs: Vec<Box<dyn SharedLogger>> = Vec::new();
// let mut cb = ConfigBuilder::new();
// for ig in DEFAULT_LOG_IGNORE_LIST {
// cb.add_filter_ignore_str(ig);
// }
// logs.push(TermLogger::new(
// LevelFilter::Trace,
// cb.build(),
// TerminalMode::Mixed,
// ColorChoice::Auto,
// ));
// CombinedLogger::init(logs).expect("logger init error");
OsLogger::new("com.veilid.veilidtools-tests", "default")
.level_filter(LevelFilter::Trace)
.init()
.unwrap();
}
}

View File

@@ -9,42 +9,28 @@ use super::*;
// Allow access to tests from non cfg(test), as required for android and ios tests
#[allow(dead_code)]
pub fn run_all_tests() {
pub async fn run_all_tests() {
info!("TEST: exec_test_host_interface");
exec_test_host_interface();
test_host_interface::test_all().await;
info!("TEST: exec_test_async_peek_stream");
exec_test_async_peek_stream();
test_async_peek_stream::test_all().await;
info!("TEST: exec_test_async_tag_lock");
exec_test_async_tag_lock();
test_async_tag_lock::test_all().await;
info!("Finished unit tests");
}
#[cfg(feature = "rt-tokio")]
fn block_on<F: Future<Output = T>, T>(f: F) -> T {
#[allow(dead_code)]
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
let rt = tokio::runtime::Runtime::new().unwrap();
let local = tokio::task::LocalSet::new();
local.block_on(&rt, f)
}
#[cfg(feature = "rt-async-std")]
fn block_on<F: Future<Output = T>, T>(f: F) -> T {
async_std::task::block_on(f)
rt.block_on(f)
}
fn exec_test_host_interface() {
block_on(async {
test_host_interface::test_all().await;
});
}
fn exec_test_async_peek_stream() {
block_on(async {
test_async_peek_stream::test_all().await;
})
}
fn exec_test_async_tag_lock() {
block_on(async {
test_async_tag_lock::test_all().await;
})
#[cfg(feature = "rt-async-std")]
#[allow(dead_code)]
pub fn block_on<F: Future<Output = T>, T>(f: F) -> T {
async_std::task::block_on(f)
}
///////////////////////////////////////////////////////////////////////////
@@ -88,21 +74,27 @@ cfg_if! {
#[serial]
fn run_test_host_interface() {
setup();
exec_test_host_interface();
block_on(async {
test_host_interface::test_all().await;
});
}
#[test]
#[serial]
fn run_test_async_peek_stream() {
setup();
exec_test_async_peek_stream();
block_on(async {
test_async_peek_stream::test_all().await;
});
}
#[test]
#[serial]
fn run_test_async_tag_lock() {
setup();
exec_test_async_tag_lock();
block_on(async {
test_async_tag_lock::test_all().await;
});
}
}
}