test work

This commit is contained in:
John Smith 2022-12-01 14:32:02 -05:00
parent e1be2bac67
commit e2153a34e4
13 changed files with 55 additions and 40 deletions

42
Cargo.lock generated
View File

@ -3070,7 +3070,7 @@ checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0"
dependencies = [
"bitflags",
"jni-sys",
"ndk-sys",
"ndk-sys 0.4.1+23.1.7779620",
"num_enum",
"raw-window-handle",
"thiserror",
@ -3094,7 +3094,7 @@ dependencies = [
"ndk",
"ndk-context",
"ndk-macro",
"ndk-sys",
"ndk-sys 0.4.1+23.1.7779620",
"once_cell",
"parking_lot 0.12.1",
]
@ -3112,6 +3112,15 @@ dependencies = [
"syn",
]
[[package]]
name = "ndk-sys"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e5a6ae77c8ee183dcbbba6150e2e6b9f3f4196a7666c02a715a95692ec1fa97"
dependencies = [
"jni-sys",
]
[[package]]
name = "ndk-sys"
version = "0.4.1+23.1.7779620"
@ -3560,6 +3569,20 @@ version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "paranoid-android"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e736c9fbaf42b43459cd1fded3dd272968daadfcbc5660ee231a12899f092289"
dependencies = [
"lazy_static",
"ndk-sys 0.3.0",
"sharded-slab",
"smallvec",
"tracing-core",
"tracing-subscriber",
]
[[package]]
name = "parity-scale-codec"
version = "3.2.1"
@ -5400,17 +5423,6 @@ dependencies = [
"tracing-core",
]
[[package]]
name = "tracing-android"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12612be8f868a09c0ceae7113ff26afe79d81a24473a393cb9120ece162e86c0"
dependencies = [
"android_log-sys",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-appender"
version = "0.2.2"
@ -5858,6 +5870,7 @@ dependencies = [
"once_cell",
"owning_ref",
"owo-colors",
"paranoid-android",
"parking_lot 0.12.1",
"rand 0.7.3",
"rkyv",
@ -5880,7 +5893,6 @@ dependencies = [
"tokio-stream",
"tokio-util",
"tracing",
"tracing-android",
"tracing-error",
"tracing-oslog",
"tracing-subscriber",
@ -6007,6 +6019,7 @@ dependencies = [
"once_cell",
"oslog",
"owo-colors",
"paranoid-android",
"parking_lot 0.11.2",
"rand 0.7.3",
"rust-fsm",
@ -6019,7 +6032,6 @@ dependencies = [
"tokio 1.22.0",
"tokio-util",
"tracing",
"tracing-android",
"tracing-oslog",
"tracing-subscriber",
"tracing-wasm",

View File

@ -14,7 +14,7 @@ default = []
rt-async-std = [ "async-std", "async-std-resolver", "async_executors/async_std", "rtnetlink?/smol_socket", "veilid-tools/rt-async-std" ]
rt-tokio = [ "tokio", "tokio-util", "tokio-stream", "trust-dns-resolver/tokio-runtime", "async_executors/tokio_tp", "async_executors/tokio_io", "async_executors/tokio_timer", "rtnetlink?/tokio_socket", "veilid-tools/rt-tokio" ]
veilid_core_android_tests = [ "dep:tracing-android" ]
veilid_core_android_tests = [ "dep:paranoid-android" ]
veilid_core_ios_tests = [ "dep:tracing-oslog" ]
tracking = []
@ -130,7 +130,7 @@ jni = "^0"
jni-sys = "^0"
ndk = { version = "^0.7" }
ndk-glue = { version = "^0.7", features = ["logger"] }
tracing-android = { version = "^0", optional = true }
paranoid-android = { version = "^0", optional = true }
# Dependenices for all Unix (Linux, Android, MacOS, iOS)
[target.'cfg(unix)'.dependencies]

View File

@ -201,8 +201,7 @@ impl VeilidCoreContext {
) -> Result<VeilidCoreContext, VeilidAPIError> {
cfg_if! {
if #[cfg(target_os = "android")] {
if crate::intf::utils::android::ANDROID_GLOBALS.lock().is_none() {
error!("Android globals are not set up");
if !crate::intf::android::is_android_ready() {
apibail_internal!("Android globals are not set up");
}
}

View File

@ -1,5 +1,7 @@
use super::*;
use jni::objects::JString;
#[allow(dead_code)]
pub fn get_files_dir() -> String {
let aglock = ANDROID_GLOBALS.lock();
let ag = aglock.as_ref().unwrap();
@ -24,6 +26,7 @@ pub fn get_files_dir() -> String {
.unwrap()
}
#[allow(dead_code)]
pub fn get_cache_dir() -> String {
let aglock = ANDROID_GLOBALS.lock();
let ag = aglock.as_ref().unwrap();

View File

@ -29,6 +29,10 @@ pub fn veilid_core_setup_android(env: JNIEnv, ctx: JObject) {
});
}
pub fn is_android_ready() -> bool {
ANDROID_GLOBALS.lock().is_some()
}
pub fn get_android_globals() -> (JavaVM, GlobalRef) {
let globals_locked = ANDROID_GLOBALS.lock();
let globals = globals_locked.as_ref().unwrap();

View File

@ -55,7 +55,7 @@ impl ProtectedStore {
// Attempt to open the secure keyring
cfg_if! {
if #[cfg(target_os = "android")] {
inner.keyring_manager = KeyringManager::new_secure(&c.program_name, intf::native::utils::android::get_android_globals()).ok();
inner.keyring_manager = KeyringManager::new_secure(&c.program_name, crate::intf::android::get_android_globals()).ok();
} else {
inner.keyring_manager = KeyringManager::new_secure(&c.program_name).ok();
}

View File

@ -59,7 +59,7 @@ pub fn veilid_version() -> (u32, u32, u32) {
}
#[cfg(target_os = "android")]
pub use intf::utils::android::veilid_core_setup_android;
pub use intf::android::veilid_core_setup_android;
pub static DEFAULT_LOG_IGNORE_LIST: [&str; 21] = [
"mio",

View File

@ -1,12 +1,9 @@
use super::native::*;
use crate::*;
use backtrace::Backtrace;
use jni::{
objects::GlobalRef, objects::JClass, objects::JObject, objects::JString, JNIEnv, JavaVM,
};
use lazy_static::*;
use jni::{objects::JClass, objects::JObject, JNIEnv};
use std::panic;
use tracing_subscriber::{filter, fmt, prelude::*};
use tracing_subscriber::prelude::*;
#[no_mangle]
#[allow(non_snake_case)]
@ -15,7 +12,7 @@ pub extern "system" fn Java_com_veilid_veilid_1core_1android_1tests_MainActivity
_class: JClass,
ctx: JObject,
) {
crate::intf::utils::android::veilid_core_setup_android_tests(env, ctx);
veilid_core_setup_android_tests(env, ctx);
block_on(async {
run_all_tests().await;
})
@ -24,10 +21,9 @@ pub extern "system" fn Java_com_veilid_veilid_1core_1android_1tests_MainActivity
pub fn veilid_core_setup_android_tests(env: JNIEnv, ctx: JObject) {
// Set up subscriber and layers
let filter = VeilidLayerFilter::new(VeilidConfigLogLevel::Trace, None);
let layer = tracing_android::layer("veilid-core").expect("failed to set up android logging");
let layer = paranoid_android::layer("veilid-core");
tracing_subscriber::registry()
.with(filter)
.with(layer)
.with(layer.with_filter(filter))
.init();
// Set up panic hook for backtraces

View File

@ -22,6 +22,9 @@ public class MainActivity extends AppCompatActivity {
}
public void run() {
run_tests(this.context);
((MainActivity)this.context).finish();
System.exit(0);
}
}
@ -30,6 +33,7 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
run_tests(this.context);
this.testThread = new TestThread(this);
this.testThread.start();
}
}

View File

@ -85,7 +85,7 @@ cfg_if! {
fn get_data_dir() -> PathBuf {
cfg_if! {
if #[cfg(target_os = "android")] {
PathBuf::from(intf::utils::android::get_files_dir())
PathBuf::from(crate::intf::android::get_files_dir())
} else {
use directories::*;

View File

@ -13,5 +13,5 @@ pub extern "system" fn Java_com_veilid_veilid_VeilidPlugin_init_1android(
_class: JClass,
ctx: JObject,
) {
veilid_core::veilid_core_setup_android_no_log(env, ctx);
veilid_core::veilid_core_setup_android(env, ctx);
}

View File

@ -14,7 +14,7 @@ default = []
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_android_tests = [ "dep:paranoid-android" ]
veilid_tools_ios_tests = [ "dep:oslog", "dep:tracing-oslog" ]
tracing = [ "dep:tracing", "dep:tracing-subscriber" ]
@ -62,7 +62,7 @@ jni-sys = "^0"
ndk = { version = "^0.7" }
ndk-glue = { version = "^0.7", features = ["logger"] }
lazy_static = "^1.4.0"
tracing-android = { version = "^0", optional = true }
paranoid-android = { version = "^0", optional = true }
android-logd-logger = "0.2.1"
# Dependencies for Windows

View File

@ -1,8 +1,6 @@
use super::native::*;
use super::*;
use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM};
use lazy_static::*;
use std::backtrace::Backtrace;
use std::panic;
@ -36,8 +34,7 @@ pub fn veilid_tools_setup_android_tests() {
// Set up subscriber and layers
let subscriber = Registry::default();
let mut layers = Vec::new();
let layer = tracing_android::layer("veilid-tools")
.expect("failed to set up android logging")
let layer = paranoid_android::layer("veilid-tools")
.with_filter(filter::LevelFilter::TRACE)
.with_filter(filters);
layers.push(layer.boxed());
@ -48,7 +45,7 @@ pub fn veilid_tools_setup_android_tests() {
.expect("failed to init android tracing");
} else {
let mut builder = android_logd_logger::builder();
builder.tag(log_tag);
builder.tag("veilid-tools");
builder.prepend_module(true);
builder.filter_level(LevelFilter::Trace);
for ig in DEFAULT_LOG_IGNORE_LIST {