veilid-tools work
This commit is contained in:
@@ -6,15 +6,15 @@ edition = "2021"
|
||||
license = "LGPL-2.0-or-later OR MPL-2.0 OR (MIT AND BSD-3-Clause)"
|
||||
|
||||
[lib]
|
||||
# Staticlib for iOS tests, rlib for everything else
|
||||
crate-type = [ "staticlib", "rlib" ]
|
||||
# staticlib for iOS tests, cydlib for android tests, rlib for everything else
|
||||
crate-type = [ "cdylib", "staticlib", "rlib" ]
|
||||
|
||||
[features]
|
||||
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", ]
|
||||
|
||||
android_tests = []
|
||||
android_tests = [ "dep:tracing-android" ]
|
||||
ios_tests = []
|
||||
tracking = []
|
||||
tracing = [ "dep:tracing", "dep:tracing-subscriber" ]
|
||||
@@ -61,7 +61,9 @@ jni = "^0"
|
||||
jni-sys = "^0"
|
||||
ndk = { version = "^0", features = ["trace"] }
|
||||
ndk-glue = { version = "^0", features = ["logger"] }
|
||||
lazy_static = "^1.4.0"
|
||||
tracing-android = { version = "^0", optional = true }
|
||||
android-logd-logger = "0.2.1"
|
||||
|
||||
# Dependencies for Windows
|
||||
# [target.'cfg(target_os = "windows")'.dependencies]
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
CARGO_MANIFEST_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/Cargo.toml\"))")
|
||||
TARGET_PATH=$(python3 -c "import os; print(os.path.realpath(\"$SCRIPTDIR/../target\"))")
|
||||
CARGO_MANIFEST_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('cargo locate-project').read())['root'])")
|
||||
CARGO_WORKSPACE_PATH=$(python3 -c "import os; import json; print(json.loads(os.popen('cargo locate-project --workspace').read())['root'])")
|
||||
TARGET_PATH=$(python3 -c "import os; print(os.path.realpath(\"$CARGO_WORKSPACE_PATH/../target\"))")
|
||||
PACKAGE_NAME=$1
|
||||
shift
|
||||
# echo CARGO_MANIFEST_PATH: $CARGO_MANIFEST_PATH
|
||||
|
||||
if [ "$CONFIGURATION" == "Debug" ]; then
|
||||
EXTRA_CARGO_OPTIONS="$@"
|
||||
|
||||
24
veilid-tools/new_android_sim.sh
Executable file
24
veilid-tools/new_android_sim.sh
Executable file
@@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
UNAME_M=`uname -m`
|
||||
if [[ "$UNAME_M" == "arm64" ]]; then
|
||||
ANDROID_ABI=arm64-v8a
|
||||
elif [[ "$UNAME_M" == "x86_64" ]]; then
|
||||
ANDROID_ABI=x86
|
||||
else
|
||||
echo "Unknown platform"
|
||||
exit 1
|
||||
fi
|
||||
AVD_NAME="testavd"
|
||||
AVD_TAG="google_atd"
|
||||
AVD_IMAGE="system-images;android-30;$AVD_TAG;$ANDROID_ABI"
|
||||
AVD_DEVICE="Nexus 10"
|
||||
# Install AVD image
|
||||
$ANDROID_SDK_ROOT/tools/bin/sdkmanager --install "$AVD_IMAGE"
|
||||
# Make AVD
|
||||
echo "no" | $ANDROID_SDK_ROOT/tools/bin/avdmanager --verbose create avd --force --name "$AVD_NAME" --package "$AVD_IMAGE" --tag "$AVD_TAG" --abi "$ANDROID_ABI" --device "$AVD_DEVICE"
|
||||
# Run emulator
|
||||
$ANDROID_SDK_ROOT/emulator/emulator -avd testavd -no-snapshot -no-boot-anim -no-window &
|
||||
( trap exit SIGINT ; read -r -d '' _ </dev/tty ) ## wait for Ctrl-C
|
||||
kill %1
|
||||
wait
|
||||
9
veilid-tools/new_ios_sim.sh
Executable file
9
veilid-tools/new_ios_sim.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/bash
|
||||
ID=$(xcrun simctl create test-iphone com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro com.apple.CoreSimulator.SimRuntime.iOS-16-1 2>/dev/null)
|
||||
xcrun simctl boot $ID
|
||||
xcrun simctl bootstatus $ID
|
||||
echo Simulator ID is $ID
|
||||
( trap exit SIGINT ; read -r -d '' _ </dev/tty ) ## wait for Ctrl-C
|
||||
xcrun simctl delete $ID
|
||||
|
||||
|
||||
@@ -8,15 +8,53 @@ elif [[ "$1" == "ios" ]]; then
|
||||
SYMROOT=/tmp/testout
|
||||
APPNAME=veilidtools-tests
|
||||
BUNDLENAME=com.veilid.veilidtools-tests
|
||||
ID="$2"
|
||||
if [[ "$ID" == "" ]]; then
|
||||
echo "No emulator ID specified"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Build for simulator
|
||||
xcrun xcodebuild -project src/tests/ios/$APPNAME/$APPNAME.xcodeproj/ -scheme $APPNAME -destination "generic/platform=iOS Simulator" SYMROOT=$SYMROOT
|
||||
ID=$(xcrun simctl create test-iphone com.apple.CoreSimulator.SimDeviceType.iPhone-14-Pro com.apple.CoreSimulator.SimRuntime.iOS-16-1 2>/dev/null)
|
||||
xcrun simctl boot $ID
|
||||
xcrun simctl bootstatus $ID
|
||||
|
||||
# Run in temporary simulator
|
||||
xcrun simctl install $ID $SYMROOT/Debug-iphonesimulator/$APPNAME.app
|
||||
xcrun simctl launch --console $ID $BUNDLENAME
|
||||
xcrun simctl delete all
|
||||
|
||||
# Clean up build output
|
||||
rm -rf /tmp/testout
|
||||
|
||||
elif [[ "$1" == "android" ]]; then
|
||||
ID="$2"
|
||||
if [[ "$ID" == "" ]]; then
|
||||
echo "No emulator ID specified"
|
||||
exit 1
|
||||
fi
|
||||
APPNAME=veilidtools-tests
|
||||
APPID=com.veilid.veilidtools_tests
|
||||
ACTIVITYNAME=MainActivity
|
||||
pushd src/tests/android/$APPNAME >/dev/null
|
||||
# Build apk
|
||||
./gradlew assembleDebug
|
||||
# Wait for boot
|
||||
adb -s $ID wait-for-device
|
||||
# Install app
|
||||
adb -s $ID install -r ./app/build/outputs/apk/debug/app-debug.apk
|
||||
# Start activity
|
||||
adb -s $ID shell am start-activity -W $APPID/.$ACTIVITYNAME
|
||||
# Get the pid of the program
|
||||
APP_PID=`adb -s $ID shell pidof -s $APPID`
|
||||
# Print the logcat
|
||||
adb -s $ID shell logcat -d veilid-tools:V *:S &
|
||||
# Wait for the pid to be done
|
||||
while [ "$(adb -s $ID shell pidof -s $APPID)" != "" ]; do
|
||||
sleep 1
|
||||
done
|
||||
# Terminate logcat
|
||||
kill %1
|
||||
# Finished
|
||||
popd >/dev/null
|
||||
|
||||
else
|
||||
cargo test --features=rt-tokio
|
||||
cargo test --features=rt-async-std
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use super::*;
|
||||
|
||||
use jni::errors::Result as JniResult;
|
||||
use jni::{objects::GlobalRef, objects::JObject, objects::JString, JNIEnv, JavaVM};
|
||||
//use jni::errors::Result as JniResult;
|
||||
use jni::{objects::GlobalRef, objects::JObject, JNIEnv, JavaVM};
|
||||
use lazy_static::*;
|
||||
use std::backtrace::Backtrace;
|
||||
use std::panic;
|
||||
use tracing::*;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::*;
|
||||
|
||||
pub struct AndroidGlobals {
|
||||
pub vm: JavaVM,
|
||||
@@ -35,46 +32,82 @@ pub fn veilid_tools_setup_android_no_log<'a>(env: JNIEnv<'a>, ctx: JObject<'a>)
|
||||
pub fn veilid_tools_setup<'a>(env: JNIEnv<'a>, ctx: JObject<'a>, log_tag: &'a str) {
|
||||
cfg_if! {
|
||||
if #[cfg(feature = "tracing")] {
|
||||
// Set up subscriber and layers
|
||||
use tracing::*;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::*;
|
||||
|
||||
let mut filters = filter::Targets::new();
|
||||
for ig in DEFAULT_LOG_IGNORE_LIST {
|
||||
filters = filters.with_target(ig, filter::LevelFilter::OFF);
|
||||
}
|
||||
|
||||
// Set up subscriber and layers
|
||||
let subscriber = Registry::default();
|
||||
let mut layers = Vec::new();
|
||||
let layer = tracing_android::layer(log_tag)
|
||||
.expect("failed to set up android logging")
|
||||
.with_filter(LevelFilter::TRACE);
|
||||
.with_filter(filter::LevelFilter::TRACE)
|
||||
.with_filter(filters);
|
||||
layers.push(layer.boxed());
|
||||
|
||||
let subscriber = subscriber.with(layers);
|
||||
subscriber
|
||||
.try_init()
|
||||
.expect("failed to init android tracing");
|
||||
} else {
|
||||
let mut builder = android_logd_logger::builder();
|
||||
builder.tag(log_tag);
|
||||
builder.prepend_module(true);
|
||||
builder.filter_level(LevelFilter::Trace);
|
||||
for ig in DEFAULT_LOG_IGNORE_LIST {
|
||||
builder.filter_module(ig, LevelFilter::Off);
|
||||
}
|
||||
builder.init();
|
||||
}
|
||||
}
|
||||
|
||||
// Set up panic hook for backtraces
|
||||
panic::set_hook(Box::new(|panic_info| {
|
||||
let bt = Backtrace::capture();
|
||||
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::<String>() {
|
||||
error!("panic payload: {:?}", s);
|
||||
} else if let Some(a) = panic_info.payload().downcast_ref::<std::fmt::Arguments>() {
|
||||
error!("panic payload: {:?}", a);
|
||||
} else {
|
||||
error!("no panic payload");
|
||||
}
|
||||
error!("Backtrace:\n{:?}", bt);
|
||||
}));
|
||||
|
||||
veilid_core_setup_android_no_log(env, ctx);
|
||||
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 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<T>
|
||||
where
|
||||
F: FnOnce() -> JniResult<T>,
|
||||
{
|
||||
env.push_local_frame(s)?;
|
||||
let out = f();
|
||||
env.pop_local_frame(JObject::null())?;
|
||||
out
|
||||
}
|
||||
// pub fn with_null_local_frame<'b, T, F>(env: JNIEnv<'b>, s: i32, f: F) -> JniResult<T>
|
||||
// where
|
||||
// F: FnOnce() -> JniResult<T>,
|
||||
// {
|
||||
// env.push_local_frame(s)?;
|
||||
// let out = f();
|
||||
// env.pop_local_frame(JObject::null())?;
|
||||
// out
|
||||
// }
|
||||
|
||||
@@ -1 +1 @@
|
||||
Veilid Tools Tests
|
||||
Veilid-Tools Tests
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../../../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/../../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -3,13 +3,13 @@ plugins {
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 30
|
||||
buildToolsVersion "30.0.3"
|
||||
compileSdkVersion 33
|
||||
buildToolsVersion "33.0.1"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.veilid.veilidtools.veilidtools_android_tests"
|
||||
applicationId "com.veilid.veilidtools_tests"
|
||||
minSdkVersion 24
|
||||
targetSdkVersion 30
|
||||
targetSdkVersion 33
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
@@ -38,33 +38,53 @@ android {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
ndkVersion '22.0.7026061'
|
||||
ndkVersion '25.1.8937393'
|
||||
|
||||
// Required to copy libc++_shared.so
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
version '3.22.1'
|
||||
path file('CMakeLists.txt')
|
||||
}
|
||||
}
|
||||
namespace 'com.veilid.veilidtools_tests'
|
||||
|
||||
testOptions {
|
||||
managedDevices {
|
||||
devices {
|
||||
pixel2api30 (com.android.build.api.dsl.ManagedVirtualDevice) {
|
||||
// Use device profiles you typically see in Android Studio.
|
||||
device = "Pixel 2"
|
||||
// ATD currently support only API level 30.
|
||||
apiLevel = 30
|
||||
// You can also specify "google-atd" if you require Google
|
||||
// Play Services.
|
||||
systemImageSource = "aosp-atd"
|
||||
// Whether the image must be a 64 bit image.
|
||||
require64Bit = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'androidx.appcompat:appcompat:1.3.1'
|
||||
implementation 'com.google.android.material:material:1.4.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha03'
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.5.1'
|
||||
implementation 'com.google.android.material:material:1.7.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.security:security-crypto:1.1.0-alpha04'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
|
||||
androidTestImplementation 'androidx.test:runner:1.5.1'
|
||||
androidTestImplementation 'androidx.test:rules:1.5.0'
|
||||
}
|
||||
|
||||
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
|
||||
|
||||
cargo {
|
||||
module = "../../../../../veilid-tools"
|
||||
module = "../../../../../"
|
||||
libname = "veilid_tools"
|
||||
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"
|
||||
@@ -84,4 +104,3 @@ afterEvaluate {
|
||||
tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.veilid.veilidtools.veilidtools_android_tests">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
@@ -13,7 +12,7 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.VeilidToolsTests">
|
||||
<activity android:name=".MainActivity">
|
||||
<activity android:name=".MainActivity" android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.veilid.veilidtools.veilidtools_android_tests;
|
||||
package com.veilid.veilidtools_tests;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import android.content.Context;
|
||||
@@ -23,6 +23,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void run() {
|
||||
run_tests(this.context);
|
||||
((MainActivity)this.context).finish();
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.android.tools.build:gradle:4.1.2"
|
||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.0"
|
||||
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3"
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@@ -25,4 +25,4 @@ allprojects {
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#Mon Jun 21 14:26:26 PDT 2021
|
||||
#Mon Nov 28 22:38:53 EST 2022
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
include ':app'
|
||||
rootProject.name = "Veilid Tools Tests"
|
||||
rootProject.name = "Veilid-Tools Tests"
|
||||
@@ -11,7 +11,7 @@ use jni::{objects::JClass, objects::JObject, JNIEnv};
|
||||
#[cfg(all(target_os = "android", feature = "android_tests"))]
|
||||
#[no_mangle]
|
||||
#[allow(non_snake_case)]
|
||||
pub extern "system" fn Java_com_veilid_veilidtools_veilidtools_1android_1tests_MainActivity_run_1tests(
|
||||
pub extern "system" fn Java_com_veilid_veilidtools_1tests_MainActivity_run_1tests(
|
||||
env: JNIEnv,
|
||||
_class: JClass,
|
||||
ctx: JObject,
|
||||
|
||||
@@ -22,6 +22,8 @@ pub fn setup() -> () {
|
||||
builder.set_max_level(Level::TRACE);
|
||||
builder.set_console_config(tracing_wasm::ConsoleConfig::ReportWithConsoleColor);
|
||||
tracing_wasm::set_as_global_default_with_config(builder.build());
|
||||
} else {
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user