From 89dd5da52221f10a6befa1237dc93c3186f228ab Mon Sep 17 00:00:00 2001 From: John Smith Date: Wed, 30 Nov 2022 21:32:41 -0500 Subject: [PATCH] more test work --- veilid-core/run_tests.sh | 2 +- veilid-core/src/intf/native/android/mod.rs | 64 +------------ veilid-core/src/intf/native/ios/mod.rs | 87 ------------------ veilid-core/src/intf/native/mod.rs | 2 - veilid-core/src/lib.rs | 2 +- veilid-core/src/tests/android/mod.rs | 58 ++++++++++++ .../.gitignore | 0 .../.idea/.gitignore | 0 .../.idea/.name | 0 .../.idea/compiler.xml | 0 .../.idea/gradle.xml | 0 .../.idea/jarRepositories.xml | 0 .../.idea/misc.xml | 0 .../.idea/vcs.xml | 0 .../{ => veilid_core_android_tests}/.project | 0 .../org.eclipse.buildship.core.prefs | 0 .../{ => veilid_core_android_tests}/adb+.sh | 0 .../app/.classpath | 0 .../app/.gitignore | 0 .../app/.project | 0 .../org.eclipse.buildship.core.prefs | 0 .../app/CMakeLists.txt | 0 .../app/build.gradle | 4 +- .../app/cpplink.cpp | 0 .../app/proguard-rules.pro | 0 .../app/src/main/AndroidManifest.xml | 0 .../MainActivity.java | 0 .../drawable-v24/ic_launcher_foreground.xml | 0 .../res/drawable/ic_launcher_background.xml | 0 .../app/src/main/res/layout/activity_main.xml | 0 .../res/mipmap-anydpi-v26/ic_launcher.xml | 0 .../mipmap-anydpi-v26/ic_launcher_round.xml | 0 .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin .../res/mipmap-hdpi/ic_launcher_round.png | Bin .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin .../res/mipmap-mdpi/ic_launcher_round.png | Bin .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin .../res/mipmap-xhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin .../app/src/main/res/values-night/themes.xml | 0 .../app/src/main/res/values/colors.xml | 0 .../app/src/main/res/values/strings.xml | 0 .../app/src/main/res/values/themes.xml | 0 .../build.gradle | 0 .../gradle.properties | 0 .../gradle/wrapper/gradle-wrapper.jar | Bin .../gradle/wrapper/gradle-wrapper.properties | 0 .../{ => veilid_core_android_tests}/gradlew | 0 .../gradlew.bat | 0 .../install_on_all_devices.sh | 0 .../remove_from_all_devices.sh | 0 .../settings.gradle | 0 veilid-core/src/tests/ios/mod.rs | 45 +++++++++ veilid-core/src/tests/mod.rs | 4 +- veilid-core/src/tests/native/mod.rs | 56 +++-------- veilid-core/webdriver.json | 15 +++ veilid-tools/run_tests.sh | 10 +- veilid-tools/src/tests/android/mod.rs | 59 +++--------- veilid-tools/src/tests/ios/mod.rs | 13 ++- veilid-tools/src/tests/mod.rs | 4 +- veilid-tools/src/tests/native/mod.rs | 32 +------ veilid-tools/tests/web.rs | 1 + 65 files changed, 175 insertions(+), 283 deletions(-) delete mode 100644 veilid-core/src/intf/native/ios/mod.rs create mode 100644 veilid-core/src/tests/android/mod.rs rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.gitignore (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/.gitignore (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/.name (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/compiler.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/gradle.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/jarRepositories.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/misc.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.idea/vcs.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.project (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/.settings/org.eclipse.buildship.core.prefs (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/adb+.sh (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/.classpath (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/.gitignore (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/.project (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/.settings/org.eclipse.buildship.core.prefs (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/CMakeLists.txt (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/build.gradle (96%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/cpplink.cpp (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/proguard-rules.pro (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/AndroidManifest.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/java/com/veilid/veilid_core_android_tests/MainActivity.java (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/drawable-v24/ic_launcher_foreground.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/drawable/ic_launcher_background.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/layout/activity_main.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-hdpi/ic_launcher.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-hdpi/ic_launcher_round.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-mdpi/ic_launcher.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-mdpi/ic_launcher_round.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xhdpi/ic_launcher.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xxhdpi/ic_launcher.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/values-night/themes.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/values/colors.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/values/strings.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/app/src/main/res/values/themes.xml (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/build.gradle (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/gradle.properties (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/gradle/wrapper/gradle-wrapper.jar (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/gradle/wrapper/gradle-wrapper.properties (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/gradlew (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/gradlew.bat (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/install_on_all_devices.sh (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/remove_from_all_devices.sh (100%) rename veilid-core/src/tests/android/{ => veilid_core_android_tests}/settings.gradle (100%) create mode 100644 veilid-core/src/tests/ios/mod.rs create mode 100644 veilid-core/webdriver.json diff --git a/veilid-core/run_tests.sh b/veilid-core/run_tests.sh index deed7641..7334bec4 100755 --- a/veilid-core/run_tests.sh +++ b/veilid-core/run_tests.sh @@ -3,7 +3,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" pushd $SCRIPTDIR 2>/dev/null if [[ "$1" == "wasm" ]]; then - WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --chrome --headless + WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --firefox --headless elif [[ "$1" == "ios" ]]; then SYMROOT=/tmp/testout APPNAME=veilidcore-tests diff --git a/veilid-core/src/intf/native/android/mod.rs b/veilid-core/src/intf/native/android/mod.rs index 424efe7f..c6991235 100644 --- a/veilid-core/src/intf/native/android/mod.rs +++ b/veilid-core/src/intf/native/android/mod.rs @@ -1,20 +1,10 @@ -// xxx : support for android older than API 24, if we need it someday -//mod android_get_if_addrs; -//pub use android_get_if_addrs::*; - mod get_directories; pub use get_directories::*; -use crate::veilid_config::VeilidConfigLogLevel; use crate::*; -use backtrace::Backtrace; use jni::errors::Result as JniResult; -use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM}; +use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM}; use lazy_static::*; -use std::panic; -use tracing::*; -use tracing_subscriber::prelude::*; -use tracing_subscriber::*; pub struct AndroidGlobals { pub vm: JavaVM, @@ -32,63 +22,13 @@ lazy_static! { pub static ref ANDROID_GLOBALS: Arc>> = Arc::new(Mutex::new(None)); } -pub fn veilid_core_setup_android_no_log<'a>(env: JNIEnv<'a>, ctx: JObject<'a>) { +pub fn veilid_core_setup_android(env: JNIEnv, ctx: JObject) { *ANDROID_GLOBALS.lock() = Some(AndroidGlobals { vm: env.get_java_vm().unwrap(), ctx: env.new_global_ref(ctx).unwrap(), }); } -pub fn veilid_core_setup_android<'a>( - env: JNIEnv<'a>, - ctx: JObject<'a>, - log_tag: &'a str, - log_level: VeilidConfigLogLevel, -) { - cfg_if! { - if #[cfg(feature = "tracing")] { - // Set up subscriber and layers - let subscriber = Registry::default(); - let mut layers = Vec::new(); - let filter = VeilidLayerFilter::new(log_level, None); - let layer = tracing_android::layer(log_tag) - .expect("failed to set up android logging") - .with_filter(filter.clone()); - layers.push(layer.boxed()); - - let subscriber = subscriber.with(layers); - subscriber - .try_init() - .expect("failed to init android tracing"); - } - } - // Set up panic hook for backtraces - panic::set_hook(Box::new(|panic_info| { - let bt = Backtrace::new(); - if let Some(location) = panic_info.location() { - error!( - "panic occurred in file '{}' at line {}", - location.file(), - location.line(), - ); - } else { - error!("panic occurred but can't get location information..."); - } - if let Some(s) = panic_info.payload().downcast_ref::<&str>() { - error!("panic payload: {:?}", s); - } else if let Some(s) = panic_info.payload().downcast_ref::() { - error!("panic payload: {:?}", s); - } else if let Some(a) = panic_info.payload().downcast_ref::() { - error!("panic payload: {:?}", a); - } else { - error!("no panic payload"); - } - error!("Backtrace:\n{:?}", bt); - })); - - veilid_core_setup_android_no_log(env, ctx); -} - pub fn get_android_globals() -> (JavaVM, GlobalRef) { let globals_locked = ANDROID_GLOBALS.lock(); let globals = globals_locked.as_ref().unwrap(); diff --git a/veilid-core/src/intf/native/ios/mod.rs b/veilid-core/src/intf/native/ios/mod.rs deleted file mode 100644 index cf6a6465..00000000 --- a/veilid-core/src/intf/native/ios/mod.rs +++ /dev/null @@ -1,87 +0,0 @@ -use backtrace::Backtrace; -use log::*; -use simplelog::*; -use std::fs::OpenOptions; -use std::panic; -use std::path::{Path, PathBuf}; - -pub fn veilid_core_setup<'a>( - log_tag: &'a str, - terminal_log: Option, - file_log: Option<(Level, &Path)>, -) { - if let Err(e) = veilid_core_setup_internal(log_tag, terminal_log, file_log) { - panic!("failed to set up veilid-core: {}", e); - } -} - -fn veilid_core_setup_internal<'a>( - _log_tag: &'a str, - terminal_log: Option, - file_log: Option<(Level, &Path)>, -) -> Result<(), String> { - let mut logs: Vec> = Vec::new(); - - let mut cb = ConfigBuilder::new(); - for ig in veilid_core::DEFAULT_LOG_IGNORE_LIST { - cb.add_filter_ignore_str(ig); - } - - if let Some(level) = terminal_log { - logs.push(TermLogger::new( - level.to_level_filter(), - cb.build(), - TerminalMode::Mixed, - ColorChoice::Auto, - )) - } - if let Some((level, log_path)) = file_log { - let logfile = OpenOptions::new() - .truncate(true) - .create(true) - .write(true) - .open(log_path) - .map_err(|e| { - format!( - "log open error: {} path={:?} all_dirs={:?}", - e, - log_path, - std::fs::read_dir(std::env::var("HOME").unwrap()) - .unwrap() - .map(|d| d.unwrap().path()) - .collect::>() - ) - })?; - logs.push(WriteLogger::new( - level.to_level_filter(), - cb.build(), - logfile, - )) - } - CombinedLogger::init(logs).map_err(|e| format!("logger init error: {}", e))?; - - panic::set_hook(Box::new(|panic_info| { - let bt = Backtrace::new(); - if let Some(location) = panic_info.location() { - error!( - "panic occurred in file '{}' at line {}", - location.file(), - location.line(), - ); - } else { - error!("panic occurred but can't get location information..."); - } - if let Some(s) = panic_info.payload().downcast_ref::<&str>() { - error!("panic payload: {:?}", s); - } else if let Some(s) = panic_info.payload().downcast_ref::() { - error!("panic payload: {:?}", s); - } else if let Some(a) = panic_info.payload().downcast_ref::() { - error!("panic payload: {:?}", a); - } else { - error!("no panic payload"); - } - error!("Backtrace:\n{:?}", bt); - })); - - Ok(()) -} diff --git a/veilid-core/src/intf/native/mod.rs b/veilid-core/src/intf/native/mod.rs index 8f7e39bf..786b2dd1 100644 --- a/veilid-core/src/intf/native/mod.rs +++ b/veilid-core/src/intf/native/mod.rs @@ -10,6 +10,4 @@ pub use table_store::*; #[cfg(target_os = "android")] pub mod android; -#[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))] -pub mod ios_test_setup; pub mod network_interfaces; diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index d8379b94..8d6e28ee 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -59,7 +59,7 @@ pub fn veilid_version() -> (u32, u32, u32) { } #[cfg(target_os = "android")] -pub use intf::utils::android::{veilid_core_setup_android, veilid_core_setup_android_no_log}; +pub use intf::utils::android::veilid_core_setup_android; pub static DEFAULT_LOG_IGNORE_LIST: [&str; 21] = [ "mio", diff --git a/veilid-core/src/tests/android/mod.rs b/veilid-core/src/tests/android/mod.rs new file mode 100644 index 00000000..96b79aeb --- /dev/null +++ b/veilid-core/src/tests/android/mod.rs @@ -0,0 +1,58 @@ +use crate::*; +use backtrace::Backtrace; +use jni::{ + objects::GlobalRef, objects::JClass, objects::JObject, objects::JString, JNIEnv, JavaVM, +}; +use lazy_static::*; +use std::panic; +use tracing::*; +use tracing_subscriber::prelude::*; +use tracing_subscriber::*; + +#[no_mangle] +#[allow(non_snake_case)] +pub extern "system" fn Java_com_veilid_veilid_1core_1android_1tests_MainActivity_run_1tests( + env: JNIEnv, + _class: JClass, + ctx: JObject, +) { + crate::intf::utils::android::veilid_core_setup_android_tests(env, ctx); + run_all_tests(); +} + +pub fn veilid_core_setup_android_tests(env: JNIEnv, ctx: JObject) { + // Set up subscriber and layers + use tracing_subscriber::{filter, fmt, prelude::*}; + let filter = VeilidLayerFilter::new(VeilidConfigLogLevel::Trace, None); + let layer = tracing_android::layer("veilid-core").expect("failed to set up android logging"); + tracing_subscriber::registry() + .with(filters) + .with(fmt_layer) + .init(); + + // Set up panic hook for backtraces + panic::set_hook(Box::new(|panic_info| { + let bt = Backtrace::new(); + if let Some(location) = panic_info.location() { + error!( + "panic occurred in file '{}' at line {}", + location.file(), + location.line(), + ); + } else { + error!("panic occurred but can't get location information..."); + } + if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + error!("panic payload: {:?}", s); + } else if let Some(s) = panic_info.payload().downcast_ref::() { + error!("panic payload: {:?}", s); + } else if let Some(a) = panic_info.payload().downcast_ref::() { + error!("panic payload: {:?}", a); + } else { + error!("no panic payload"); + } + error!("Backtrace:\n{:?}", bt); + })); + + veilid_core_setup_android(env, ctx); +} diff --git a/veilid-core/src/tests/android/.gitignore b/veilid-core/src/tests/android/veilid_core_android_tests/.gitignore similarity index 100% rename from veilid-core/src/tests/android/.gitignore rename to veilid-core/src/tests/android/veilid_core_android_tests/.gitignore diff --git a/veilid-core/src/tests/android/.idea/.gitignore b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/.gitignore similarity index 100% rename from veilid-core/src/tests/android/.idea/.gitignore rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/.gitignore diff --git a/veilid-core/src/tests/android/.idea/.name b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/.name similarity index 100% rename from veilid-core/src/tests/android/.idea/.name rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/.name diff --git a/veilid-core/src/tests/android/.idea/compiler.xml b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/compiler.xml similarity index 100% rename from veilid-core/src/tests/android/.idea/compiler.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/compiler.xml diff --git a/veilid-core/src/tests/android/.idea/gradle.xml b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/gradle.xml similarity index 100% rename from veilid-core/src/tests/android/.idea/gradle.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/gradle.xml diff --git a/veilid-core/src/tests/android/.idea/jarRepositories.xml b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/jarRepositories.xml similarity index 100% rename from veilid-core/src/tests/android/.idea/jarRepositories.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/jarRepositories.xml diff --git a/veilid-core/src/tests/android/.idea/misc.xml b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/misc.xml similarity index 100% rename from veilid-core/src/tests/android/.idea/misc.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/misc.xml diff --git a/veilid-core/src/tests/android/.idea/vcs.xml b/veilid-core/src/tests/android/veilid_core_android_tests/.idea/vcs.xml similarity index 100% rename from veilid-core/src/tests/android/.idea/vcs.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/.idea/vcs.xml diff --git a/veilid-core/src/tests/android/.project b/veilid-core/src/tests/android/veilid_core_android_tests/.project similarity index 100% rename from veilid-core/src/tests/android/.project rename to veilid-core/src/tests/android/veilid_core_android_tests/.project diff --git a/veilid-core/src/tests/android/.settings/org.eclipse.buildship.core.prefs b/veilid-core/src/tests/android/veilid_core_android_tests/.settings/org.eclipse.buildship.core.prefs similarity index 100% rename from veilid-core/src/tests/android/.settings/org.eclipse.buildship.core.prefs rename to veilid-core/src/tests/android/veilid_core_android_tests/.settings/org.eclipse.buildship.core.prefs diff --git a/veilid-core/src/tests/android/adb+.sh b/veilid-core/src/tests/android/veilid_core_android_tests/adb+.sh similarity index 100% rename from veilid-core/src/tests/android/adb+.sh rename to veilid-core/src/tests/android/veilid_core_android_tests/adb+.sh diff --git a/veilid-core/src/tests/android/app/.classpath b/veilid-core/src/tests/android/veilid_core_android_tests/app/.classpath similarity index 100% rename from veilid-core/src/tests/android/app/.classpath rename to veilid-core/src/tests/android/veilid_core_android_tests/app/.classpath diff --git a/veilid-core/src/tests/android/app/.gitignore b/veilid-core/src/tests/android/veilid_core_android_tests/app/.gitignore similarity index 100% rename from veilid-core/src/tests/android/app/.gitignore rename to veilid-core/src/tests/android/veilid_core_android_tests/app/.gitignore diff --git a/veilid-core/src/tests/android/app/.project b/veilid-core/src/tests/android/veilid_core_android_tests/app/.project similarity index 100% rename from veilid-core/src/tests/android/app/.project rename to veilid-core/src/tests/android/veilid_core_android_tests/app/.project diff --git a/veilid-core/src/tests/android/app/.settings/org.eclipse.buildship.core.prefs b/veilid-core/src/tests/android/veilid_core_android_tests/app/.settings/org.eclipse.buildship.core.prefs similarity index 100% rename from veilid-core/src/tests/android/app/.settings/org.eclipse.buildship.core.prefs rename to veilid-core/src/tests/android/veilid_core_android_tests/app/.settings/org.eclipse.buildship.core.prefs diff --git a/veilid-core/src/tests/android/app/CMakeLists.txt b/veilid-core/src/tests/android/veilid_core_android_tests/app/CMakeLists.txt similarity index 100% rename from veilid-core/src/tests/android/app/CMakeLists.txt rename to veilid-core/src/tests/android/veilid_core_android_tests/app/CMakeLists.txt diff --git a/veilid-core/src/tests/android/app/build.gradle b/veilid-core/src/tests/android/veilid_core_android_tests/app/build.gradle similarity index 96% rename from veilid-core/src/tests/android/app/build.gradle rename to veilid-core/src/tests/android/veilid_core_android_tests/app/build.gradle index f4069114..af4abe42 100644 --- a/veilid-core/src/tests/android/app/build.gradle +++ b/veilid-core/src/tests/android/veilid_core_android_tests/app/build.gradle @@ -60,10 +60,10 @@ dependencies { apply plugin: 'org.mozilla.rust-android-gradle.rust-android' cargo { - module = "../../../../" + module = "../../../../../" libname = "veilid_core" targets = ["arm", "arm64", "x86", "x86_64"] - targetDirectory = "../../../../../target" + targetDirectory = "../../../../../../target" prebuiltToolchains = true profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release" pythonCommand = "python3" diff --git a/veilid-core/src/tests/android/app/cpplink.cpp b/veilid-core/src/tests/android/veilid_core_android_tests/app/cpplink.cpp similarity index 100% rename from veilid-core/src/tests/android/app/cpplink.cpp rename to veilid-core/src/tests/android/veilid_core_android_tests/app/cpplink.cpp diff --git a/veilid-core/src/tests/android/app/proguard-rules.pro b/veilid-core/src/tests/android/veilid_core_android_tests/app/proguard-rules.pro similarity index 100% rename from veilid-core/src/tests/android/app/proguard-rules.pro rename to veilid-core/src/tests/android/veilid_core_android_tests/app/proguard-rules.pro diff --git a/veilid-core/src/tests/android/app/src/main/AndroidManifest.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/AndroidManifest.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/AndroidManifest.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/AndroidManifest.xml diff --git a/veilid-core/src/tests/android/app/src/main/java/com/veilid/veilid_core_android_tests/MainActivity.java b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/java/com/veilid/veilid_core_android_tests/MainActivity.java similarity index 100% rename from veilid-core/src/tests/android/app/src/main/java/com/veilid/veilid_core_android_tests/MainActivity.java rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/java/com/veilid/veilid_core_android_tests/MainActivity.java diff --git a/veilid-core/src/tests/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/drawable-v24/ic_launcher_foreground.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/drawable-v24/ic_launcher_foreground.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/drawable/ic_launcher_background.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/drawable/ic_launcher_background.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/drawable/ic_launcher_background.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/drawable/ic_launcher_background.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/layout/activity_main.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/layout/activity_main.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/layout/activity_main.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/layout/activity_main.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-hdpi/ic_launcher.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-mdpi/ic_launcher.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/veilid-core/src/tests/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/veilid-core/src/tests/android/app/src/main/res/values-night/themes.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values-night/themes.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/values-night/themes.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values-night/themes.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/values/colors.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/colors.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/values/colors.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/colors.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/values/strings.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/strings.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/values/strings.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/strings.xml diff --git a/veilid-core/src/tests/android/app/src/main/res/values/themes.xml b/veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/themes.xml similarity index 100% rename from veilid-core/src/tests/android/app/src/main/res/values/themes.xml rename to veilid-core/src/tests/android/veilid_core_android_tests/app/src/main/res/values/themes.xml diff --git a/veilid-core/src/tests/android/build.gradle b/veilid-core/src/tests/android/veilid_core_android_tests/build.gradle similarity index 100% rename from veilid-core/src/tests/android/build.gradle rename to veilid-core/src/tests/android/veilid_core_android_tests/build.gradle diff --git a/veilid-core/src/tests/android/gradle.properties b/veilid-core/src/tests/android/veilid_core_android_tests/gradle.properties similarity index 100% rename from veilid-core/src/tests/android/gradle.properties rename to veilid-core/src/tests/android/veilid_core_android_tests/gradle.properties diff --git a/veilid-core/src/tests/android/gradle/wrapper/gradle-wrapper.jar b/veilid-core/src/tests/android/veilid_core_android_tests/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from veilid-core/src/tests/android/gradle/wrapper/gradle-wrapper.jar rename to veilid-core/src/tests/android/veilid_core_android_tests/gradle/wrapper/gradle-wrapper.jar diff --git a/veilid-core/src/tests/android/gradle/wrapper/gradle-wrapper.properties b/veilid-core/src/tests/android/veilid_core_android_tests/gradle/wrapper/gradle-wrapper.properties similarity index 100% rename from veilid-core/src/tests/android/gradle/wrapper/gradle-wrapper.properties rename to veilid-core/src/tests/android/veilid_core_android_tests/gradle/wrapper/gradle-wrapper.properties diff --git a/veilid-core/src/tests/android/gradlew b/veilid-core/src/tests/android/veilid_core_android_tests/gradlew similarity index 100% rename from veilid-core/src/tests/android/gradlew rename to veilid-core/src/tests/android/veilid_core_android_tests/gradlew diff --git a/veilid-core/src/tests/android/gradlew.bat b/veilid-core/src/tests/android/veilid_core_android_tests/gradlew.bat similarity index 100% rename from veilid-core/src/tests/android/gradlew.bat rename to veilid-core/src/tests/android/veilid_core_android_tests/gradlew.bat diff --git a/veilid-core/src/tests/android/install_on_all_devices.sh b/veilid-core/src/tests/android/veilid_core_android_tests/install_on_all_devices.sh similarity index 100% rename from veilid-core/src/tests/android/install_on_all_devices.sh rename to veilid-core/src/tests/android/veilid_core_android_tests/install_on_all_devices.sh diff --git a/veilid-core/src/tests/android/remove_from_all_devices.sh b/veilid-core/src/tests/android/veilid_core_android_tests/remove_from_all_devices.sh similarity index 100% rename from veilid-core/src/tests/android/remove_from_all_devices.sh rename to veilid-core/src/tests/android/veilid_core_android_tests/remove_from_all_devices.sh diff --git a/veilid-core/src/tests/android/settings.gradle b/veilid-core/src/tests/android/veilid_core_android_tests/settings.gradle similarity index 100% rename from veilid-core/src/tests/android/settings.gradle rename to veilid-core/src/tests/android/veilid_core_android_tests/settings.gradle diff --git a/veilid-core/src/tests/ios/mod.rs b/veilid-core/src/tests/ios/mod.rs new file mode 100644 index 00000000..bbbe7a59 --- /dev/null +++ b/veilid-core/src/tests/ios/mod.rs @@ -0,0 +1,45 @@ +use crate::*; +use backtrace::Backtrace; +use std::panic; + +#[no_mangle] +#[allow(dead_code)] +pub extern "C" fn run_veilid_core_tests() { + veilid_core_setup_ios_tests(); + run_all_tests(); +} + +pub fn veilid_core_setup_ios_tests() { + // Set up subscriber and layers + use tracing_subscriber::{filter, fmt, prelude::*}; + let filter = VeilidLayerFilter::new(VeilidConfigLogLevel::Trace, None); + let fmt_layer = fmt::layer(); + let layer = tracing_android::layer("veilid-core").expect("failed to set up android logging"); + tracing_subscriber::registry() + .with(filters) + .with(fmt_layer) + .init(); + + panic::set_hook(Box::new(|panic_info| { + let bt = Backtrace::new(); + if let Some(location) = panic_info.location() { + error!( + "panic occurred in file '{}' at line {}", + location.file(), + location.line(), + ); + } else { + error!("panic occurred but can't get location information..."); + } + if let Some(s) = panic_info.payload().downcast_ref::<&str>() { + error!("panic payload: {:?}", s); + } else if let Some(s) = panic_info.payload().downcast_ref::() { + error!("panic payload: {:?}", s); + } else if let Some(a) = panic_info.payload().downcast_ref::() { + error!("panic payload: {:?}", a); + } else { + error!("no panic payload"); + } + error!("Backtrace:\n{:?}", bt); + })); +} diff --git a/veilid-core/src/tests/mod.rs b/veilid-core/src/tests/mod.rs index 61f04f89..2a050ac5 100644 --- a/veilid-core/src/tests/mod.rs +++ b/veilid-core/src/tests/mod.rs @@ -1,7 +1,7 @@ -#[cfg(target_os = "android")] +#[cfg(all(target_os = "android", feature = "veilid_core_android_tests"))] mod android; pub mod common; -#[cfg(target_os = "ios")] +#[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))] mod ios; #[cfg(not(target_arch = "wasm32"))] mod native; diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index b1f96995..04431400 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -5,44 +5,6 @@ use crate::network_manager::tests::*; use crate::tests::common::*; use crate::*; -#[cfg(all(target_os = "android", feature = "veilid_core_android_tests"))] -use jni::{objects::JClass, objects::JObject, JNIEnv}; - -#[cfg(all(target_os = "android", feature = "veilid_core_android_tests"))] -#[no_mangle] -#[allow(non_snake_case)] -pub extern "system" fn Java_com_veilid_veilid_1core_1android_1tests_MainActivity_run_1tests( - env: JNIEnv, - _class: JClass, - ctx: JObject, -) { - crate::intf::utils::android::veilid_core_setup_android( - env, - ctx, - "veilid_core", - crate::veilid_config::VeilidConfigLogLevel::Trace, - ); - run_all_tests(); -} - -#[cfg(all(target_os = "ios", feature = "veilid_core_ios_tests"))] -#[no_mangle] -pub extern "C" fn run_veilid_core_tests() { - let log_path: std::path::PathBuf = [ - std::env::var("HOME").unwrap().as_str(), - "Documents", - "veilid-core.log", - ] - .iter() - .collect(); - crate::intf::utils::ios_test_setup::veilid_core_setup( - "veilid-core", - Some(Level::Trace), - Some((Level::Trace, log_path.as_path())), - ); - run_all_tests(); -} - /////////////////////////////////////////////////////////////////////////// #[allow(dead_code)] @@ -130,18 +92,26 @@ fn exec_test_envelope_receipt() { cfg_if! { if #[cfg(test)] { use serial_test::serial; - use simplelog::*; use std::sync::Once; static SETUP_ONCE: Once = Once::new(); pub fn setup() { SETUP_ONCE.call_once(|| { - let mut cb = ConfigBuilder::new(); - for ig in crate::DEFAULT_LOG_IGNORE_LIST { - cb.add_filter_ignore_str(ig); + cfg_if! { + if #[cfg(feature = "tracing")] { + use tracing_subscriber::{filter, fmt, prelude::*}; + let mut filters = filter::Targets::new().with_default(filter::LevelFilter::TRACE); + for ig in DEFAULT_LOG_IGNORE_LIST { + filters = filters.with_target(ig, filter::LevelFilter::OFF); + } + let fmt_layer = fmt::layer(); + tracing_subscriber::registry() + .with(fmt_layer) + .with(filters) + .init(); + } } - TestLogger::init(LevelFilter::Trace, cb.build()).unwrap(); }); } diff --git a/veilid-core/webdriver.json b/veilid-core/webdriver.json new file mode 100644 index 00000000..c2d6865e --- /dev/null +++ b/veilid-core/webdriver.json @@ -0,0 +1,15 @@ +{ + "moz:firefoxOptions": { + "prefs": { + "media.navigator.streams.fake": true, + "media.navigator.permission.disabled": true + }, + "args": [] + }, + "goog:chromeOptions": { + "args": [ + "--use-fake-device-for-media-stream", + "--use-fake-ui-for-media-stream" + ] + } +} diff --git a/veilid-tools/run_tests.sh b/veilid-tools/run_tests.sh index 0267d8aa..ad09bb88 100755 --- a/veilid-tools/run_tests.sh +++ b/veilid-tools/run_tests.sh @@ -3,7 +3,7 @@ SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" pushd $SCRIPTDIR 2>/dev/null if [[ "$1" == "wasm" ]]; then - WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --chrome --headless + WASM_BINDGEN_TEST_TIMEOUT=120 wasm-pack test --firefox --headless elif [[ "$1" == "ios" ]]; then SYMROOT=/tmp/testout APPNAME=veilidtools-tests @@ -56,9 +56,9 @@ elif [[ "$1" == "android" ]]; then popd >/dev/null else - cargo test --features=rt-tokio,tracing - cargo test --features=rt-async-std,tracing - cargo test --features=rt-tokio - cargo test --features=rt-async-std + cargo test --features=rt-tokio,tracing -- --nocapture + cargo test --features=rt-async-std,tracing -- --nocapture + cargo test --features=rt-tokio -- --nocapture + cargo test --features=rt-async-std -- --nocapture fi popd 2>/dev/null \ No newline at end of file diff --git a/veilid-tools/src/tests/android/mod.rs b/veilid-tools/src/tests/android/mod.rs index c238052e..676b26e0 100644 --- a/veilid-tools/src/tests/android/mod.rs +++ b/veilid-tools/src/tests/android/mod.rs @@ -1,35 +1,25 @@ +use super::native::*; use super::*; -//use jni::errors::Result as JniResult; use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM}; use lazy_static::*; use std::backtrace::Backtrace; use std::panic; -pub struct AndroidGlobals { - pub vm: JavaVM, - pub ctx: GlobalRef, +use jni::{objects::JClass, objects::JObject, JNIEnv}; + +#[no_mangle] +#[allow(non_snake_case)] +pub extern "system" fn Java_com_veilid_veilid_1tools_1android_1tests_MainActivity_run_1tests( + _env: JNIEnv, + _class: JClass, + _ctx: JObject, +) { + crate::tests::android::veilid_tools_setup_android_tests(); + run_all_tests(); } -impl Drop for AndroidGlobals { - fn drop(&mut self) { - // Ensure we're attached before dropping GlobalRef - self.vm.attach_current_thread_as_daemon().unwrap(); - } -} - -lazy_static! { - pub static ref ANDROID_GLOBALS: Arc>> = Arc::new(Mutex::new(None)); -} - -pub fn veilid_tools_setup_android_no_log<'a>(env: JNIEnv<'a>, ctx: JObject<'a>) { - *ANDROID_GLOBALS.lock() = Some(AndroidGlobals { - vm: env.get_java_vm().unwrap(), - ctx: env.new_global_ref(ctx).unwrap(), - }); -} - -pub fn veilid_tools_setup<'a>(env: JNIEnv<'a>, ctx: JObject<'a>, log_tag: &'a str) { +pub fn veilid_tools_setup_android_tests() { cfg_if! { if #[cfg(feature = "tracing")] { use tracing::*; @@ -44,7 +34,7 @@ pub fn veilid_tools_setup<'a>(env: JNIEnv<'a>, ctx: JObject<'a>, log_tag: &'a st // Set up subscriber and layers let subscriber = Registry::default(); let mut layers = Vec::new(); - let layer = tracing_android::layer(log_tag) + let layer = tracing_android::layer("veilid-tools") .expect("failed to set up android logging") .with_filter(filter::LevelFilter::TRACE) .with_filter(filters); @@ -89,25 +79,4 @@ pub fn veilid_tools_setup<'a>(env: JNIEnv<'a>, ctx: JObject<'a>, log_tag: &'a st } error!("Backtrace:\n{:?}", bt); })); - - veilid_tools_setup_android_no_log(env, ctx); } - -// pub fn get_android_globals() -> (JavaVM, GlobalRef) { -// let globals_locked = ANDROID_GLOBALS.lock(); -// let globals = globals_locked.as_ref().unwrap(); -// let env = globals.vm.attach_current_thread_as_daemon().unwrap(); -// let vm = env.get_java_vm().unwrap(); -// let ctx = globals.ctx.clone(); -// (vm, ctx) -// } - -// pub fn with_null_local_frame<'b, T, F>(env: JNIEnv<'b>, s: i32, f: F) -> JniResult -// where -// F: FnOnce() -> JniResult, -// { -// env.push_local_frame(s)?; -// let out = f(); -// env.pop_local_frame(JObject::null())?; -// out -// } diff --git a/veilid-tools/src/tests/ios/mod.rs b/veilid-tools/src/tests/ios/mod.rs index 358955a8..71584b8a 100644 --- a/veilid-tools/src/tests/ios/mod.rs +++ b/veilid-tools/src/tests/ios/mod.rs @@ -1,9 +1,16 @@ +use super::native::*; use super::*; use std::backtrace::Backtrace; use std::panic; -pub fn veilid_tools_setup<'a>() -> Result<(), String> { +#[no_mangle] +pub extern "C" fn run_veilid_tools_tests() { + crate::tests::ios::veilid_tools_setup_ios_tests(); + run_all_tests(); +} + +pub fn veilid_tools_setup_ios_tests() { cfg_if! { if #[cfg(feature = "tracing")] { use tracing_subscriber::{filter, fmt, prelude::*}; @@ -30,7 +37,7 @@ pub fn veilid_tools_setup<'a>() -> Result<(), String> { TerminalMode::Mixed, ColorChoice::Auto, )); - CombinedLogger::init(logs).map_err(|e| format!("logger init error: {}", e))?; + CombinedLogger::init(logs).expect("logger init error"); } } @@ -56,6 +63,4 @@ pub fn veilid_tools_setup<'a>() -> Result<(), String> { } error!("Backtrace:\n{:?}", bt); })); - - Ok(()) } diff --git a/veilid-tools/src/tests/mod.rs b/veilid-tools/src/tests/mod.rs index e10c08c2..e0b727a3 100644 --- a/veilid-tools/src/tests/mod.rs +++ b/veilid-tools/src/tests/mod.rs @@ -1,7 +1,7 @@ -#[cfg(target_os = "android")] +#[cfg(all(target_os = "android", feature = "veilid_tools_android_tests"))] mod android; pub mod common; -#[cfg(target_os = "ios")] +#[cfg(all(target_os = "ios", feature = "veilid_tools_ios_tests"))] mod ios; #[cfg(not(target_arch = "wasm32"))] mod native; diff --git a/veilid-tools/src/tests/native/mod.rs b/veilid-tools/src/tests/native/mod.rs index 120fa9cb..b97ac910 100644 --- a/veilid-tools/src/tests/native/mod.rs +++ b/veilid-tools/src/tests/native/mod.rs @@ -5,30 +5,8 @@ mod test_async_peek_stream; use super::*; -#[cfg(all(target_os = "android", feature = "veilid_tools_android_tests"))] -use jni::{objects::JClass, objects::JObject, JNIEnv}; - -#[cfg(all(target_os = "android", feature = "veilid_tools_android_tests"))] -#[no_mangle] -#[allow(non_snake_case)] -pub extern "system" fn Java_com_veilid_veilid_1tools_1android_1tests_MainActivity_run_1tests( - env: JNIEnv, - _class: JClass, - ctx: JObject, -) { - crate::tests::android::veilid_tools_setup(env, ctx, "veilid-tools"); - run_all_tests(); -} - -#[cfg(all(target_os = "ios", feature = "veilid_tools_ios_tests"))] -#[no_mangle] -#[allow(dead_code)] -pub extern "C" fn run_veilid_tools_tests() { - crate::tests::ios::veilid_tools_setup().expect("setup failed"); - run_all_tests(); -} - -/////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////// +// Allow access to tests from non cfg(test), as required for android and ios tests #[allow(dead_code)] pub fn run_all_tests() { @@ -68,6 +46,7 @@ fn exec_test_async_tag_lock() { test_async_tag_lock::test_all().await; }) } + /////////////////////////////////////////////////////////////////////////// cfg_if! { if #[cfg(test)] { @@ -83,15 +62,14 @@ cfg_if! { cfg_if! { if #[cfg(feature = "tracing")] { use tracing_subscriber::{filter, fmt, prelude::*}; - let mut filters = filter::Targets::new(); + let mut filters = filter::Targets::new().with_default(filter::LevelFilter::TRACE); 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(filters) .init(); } else { use simplelog::*; diff --git a/veilid-tools/tests/web.rs b/veilid-tools/tests/web.rs index 8a04bce8..ae522f3e 100644 --- a/veilid-tools/tests/web.rs +++ b/veilid-tools/tests/web.rs @@ -2,6 +2,7 @@ #![cfg(target_arch = "wasm32")] use veilid_tools::tests::*; +use veilid_tools::*; use wasm_bindgen_test::*;