diff --git a/Cargo.lock b/Cargo.lock index 209bfa55..31a72bd1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5800,7 +5800,6 @@ dependencies = [ "rkyv", "rtnetlink", "rusqlite", - "rust-fsm", "rustls", "rustls-pemfile", "secrecy", @@ -5945,6 +5944,7 @@ dependencies = [ "owo-colors", "parking_lot 0.11.2", "rand 0.7.3", + "rust-fsm", "send_wrapper 0.6.0", "serial_test", "simplelog 0.12.0", diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 626ec92f..fa0656da 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -25,7 +25,6 @@ tracing-subscriber = "^0" tracing-error = "^0" eyre = "^0" capnp = { version = "^0", default_features = false } -rust-fsm = "^0" static_assertions = "^1" cfg-if = "^1" thiserror = "^1" diff --git a/veilid-core/run_tests.sh b/veilid-core/run_tests.sh new file mode 100755 index 00000000..a4bbb16f --- /dev/null +++ b/veilid-core/run_tests.sh @@ -0,0 +1,62 @@ +#!/bin/bash +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 +elif [[ "$1" == "ios" ]]; then + SYMROOT=/tmp/testout + APPNAME=veilidcore-tests + BUNDLENAME=com.veilid.veilidcore-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 + + # Run in temporary simulator + xcrun simctl install $ID $SYMROOT/Debug-iphonesimulator/$APPNAME.app + xcrun simctl launch --console $ID $BUNDLENAME + + # 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=veilidcore-tests + APPID=com.veilid.veilidcore_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-core: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 +fi +popd 2>/dev/null \ No newline at end of file diff --git a/veilid-core/src/api_tracing_layer.rs b/veilid-core/src/api_tracing_layer.rs index dac00241..8de371ec 100644 --- a/veilid-core/src/api_tracing_layer.rs +++ b/veilid-core/src/api_tracing_layer.rs @@ -1,6 +1,6 @@ use crate::core_context::*; use crate::veilid_api::*; -use crate::xx::*; +use crate::*; use core::fmt::Write; use once_cell::sync::OnceCell; use tracing_subscriber::*; diff --git a/veilid-core/src/attachment_manager.rs b/veilid-core/src/attachment_manager.rs index c05cf628..c47b9f52 100644 --- a/veilid-core/src/attachment_manager.rs +++ b/veilid-core/src/attachment_manager.rs @@ -1,8 +1,6 @@ -use crate::callback_state_machine::*; use crate::crypto::Crypto; use crate::network_manager::*; use crate::routing_table::*; -use crate::xx::*; use crate::*; use core::convert::TryFrom; use core::fmt; diff --git a/veilid-core/src/core_context.rs b/veilid-core/src/core_context.rs index 8af47ab5..aa4c2593 100644 --- a/veilid-core/src/core_context.rs +++ b/veilid-core/src/core_context.rs @@ -3,7 +3,6 @@ use crate::attachment_manager::*; use crate::crypto::Crypto; use crate::veilid_api::*; use crate::veilid_config::*; -use crate::xx::*; use crate::*; pub type UpdateCallback = Arc; diff --git a/veilid-core/src/crypto/envelope.rs b/veilid-core/src/crypto/envelope.rs index ea84e5c6..efdec697 100644 --- a/veilid-core/src/crypto/envelope.rs +++ b/veilid-core/src/crypto/envelope.rs @@ -2,7 +2,6 @@ #![allow(clippy::absurd_extreme_comparisons)] use super::*; use crate::routing_table::VersionRange; -use crate::xx::*; use crate::*; use core::convert::TryInto; diff --git a/veilid-core/src/crypto/key.rs b/veilid-core/src/crypto/key.rs index 02a4ef72..218ffcb8 100644 --- a/veilid-core/src/crypto/key.rs +++ b/veilid-core/src/crypto/key.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use core::cmp::{Eq, Ord, PartialEq, PartialOrd}; diff --git a/veilid-core/src/crypto/mod.rs b/veilid-core/src/crypto/mod.rs index 30b658e5..60c96897 100644 --- a/veilid-core/src/crypto/mod.rs +++ b/veilid-core/src/crypto/mod.rs @@ -13,7 +13,6 @@ pub use value::*; pub const MIN_CRYPTO_VERSION: u8 = 0u8; pub const MAX_CRYPTO_VERSION: u8 = 0u8; -use crate::xx::*; use crate::*; use chacha20::cipher::{KeyIvInit, StreamCipher}; use chacha20::XChaCha20; @@ -25,6 +24,7 @@ use ed25519_dalek as ed; use hashlink::linked_hash_map::Entry; use hashlink::LruCache; use serde::{Deserialize, Serialize}; + use x25519_dalek as xd; pub type SharedSecret = [u8; 32]; diff --git a/veilid-core/src/crypto/receipt.rs b/veilid-core/src/crypto/receipt.rs index b622d2f9..d59e5f36 100644 --- a/veilid-core/src/crypto/receipt.rs +++ b/veilid-core/src/crypto/receipt.rs @@ -1,7 +1,6 @@ #![allow(dead_code)] #![allow(clippy::absurd_extreme_comparisons)] use super::*; -use crate::xx::*; use crate::*; use core::convert::TryInto; use data_encoding::BASE64URL_NOPAD; diff --git a/veilid-core/src/crypto/tests/test_crypto.rs b/veilid-core/src/crypto/tests/test_crypto.rs index c1a03800..5710c8d9 100644 --- a/veilid-core/src/crypto/tests/test_crypto.rs +++ b/veilid-core/src/crypto/tests/test_crypto.rs @@ -1,6 +1,5 @@ use super::*; use crate::tests::common::test_veilid_config::*; -use crate::xx::*; static LOREM_IPSUM:&[u8] = b"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "; diff --git a/veilid-core/src/crypto/tests/test_dht_key.rs b/veilid-core/src/crypto/tests/test_dht_key.rs index d6876ac3..26526d7b 100644 --- a/veilid-core/src/crypto/tests/test_dht_key.rs +++ b/veilid-core/src/crypto/tests/test_dht_key.rs @@ -1,7 +1,6 @@ #![allow(clippy::bool_assert_comparison)] use super::*; -use crate::xx::*; use core::convert::TryFrom; static LOREM_IPSUM:&str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. "; diff --git a/veilid-core/src/crypto/tests/test_envelope_receipt.rs b/veilid-core/src/crypto/tests/test_envelope_receipt.rs index 1a221dd3..723eeaff 100644 --- a/veilid-core/src/crypto/tests/test_envelope_receipt.rs +++ b/veilid-core/src/crypto/tests/test_envelope_receipt.rs @@ -1,6 +1,5 @@ use super::*; use crate::tests::common::test_veilid_config::*; -use crate::xx::*; pub async fn test_envelope_round_trip() { info!("--- test envelope round trip ---"); diff --git a/veilid-core/src/intf/native/utils/android/get_directories.rs b/veilid-core/src/intf/native/android/get_directories.rs similarity index 98% rename from veilid-core/src/intf/native/utils/android/get_directories.rs rename to veilid-core/src/intf/native/android/get_directories.rs index 5bd07e5c..0dfc2ace 100644 --- a/veilid-core/src/intf/native/utils/android/get_directories.rs +++ b/veilid-core/src/intf/native/android/get_directories.rs @@ -1,5 +1,4 @@ use super::*; -use crate::xx::*; pub fn get_files_dir() -> String { let aglock = ANDROID_GLOBALS.lock(); diff --git a/veilid-core/src/intf/native/utils/android/mod.rs b/veilid-core/src/intf/native/android/mod.rs similarity index 99% rename from veilid-core/src/intf/native/utils/android/mod.rs rename to veilid-core/src/intf/native/android/mod.rs index a6e3097a..424efe7f 100644 --- a/veilid-core/src/intf/native/utils/android/mod.rs +++ b/veilid-core/src/intf/native/android/mod.rs @@ -6,7 +6,6 @@ mod get_directories; pub use get_directories::*; use crate::veilid_config::VeilidConfigLogLevel; -use crate::xx::*; use crate::*; use backtrace::Backtrace; use jni::errors::Result as JniResult; diff --git a/veilid-core/src/intf/native/block_store.rs b/veilid-core/src/intf/native/block_store.rs index 6df36e6b..a5ced7e5 100644 --- a/veilid-core/src/intf/native/block_store.rs +++ b/veilid-core/src/intf/native/block_store.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; struct BlockStoreInner { diff --git a/veilid-core/src/intf/native/utils/ios/mod.rs b/veilid-core/src/intf/native/ios/mod.rs similarity index 99% rename from veilid-core/src/intf/native/utils/ios/mod.rs rename to veilid-core/src/intf/native/ios/mod.rs index 1a6b4f02..cf6a6465 100644 --- a/veilid-core/src/intf/native/utils/ios/mod.rs +++ b/veilid-core/src/intf/native/ios/mod.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use backtrace::Backtrace; use log::*; use simplelog::*; diff --git a/veilid-core/src/intf/native/mod.rs b/veilid-core/src/intf/native/mod.rs index 663d9082..369a0183 100644 --- a/veilid-core/src/intf/native/mod.rs +++ b/veilid-core/src/intf/native/mod.rs @@ -2,9 +2,14 @@ mod block_store; mod protected_store; mod system; mod table_store; -pub mod utils; pub use block_store::*; pub use protected_store::*; pub use system::*; pub use table_store::*; + +#[cfg(target_os = "android")] +pub mod android; +#[cfg(all(target_os = "ios", feature = "ios_tests"))] +pub mod ios_test_setup; +pub mod network_interfaces; diff --git a/veilid-core/src/intf/native/utils/network_interfaces/apple.rs b/veilid-core/src/intf/native/network_interfaces/apple.rs similarity index 99% rename from veilid-core/src/intf/native/utils/network_interfaces/apple.rs rename to veilid-core/src/intf/native/network_interfaces/apple.rs index 97b6d8fd..c643b2ad 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/apple.rs +++ b/veilid-core/src/intf/native/network_interfaces/apple.rs @@ -1,5 +1,5 @@ use super::*; -use crate::*; + use libc::{ close, freeifaddrs, getifaddrs, if_nametoindex, ifaddrs, ioctl, pid_t, sockaddr, sockaddr_in6, socket, sysctl, time_t, AF_INET6, CTL_NET, IFF_BROADCAST, IFF_LOOPBACK, IFF_RUNNING, IFNAMSIZ, diff --git a/veilid-core/src/intf/native/utils/network_interfaces/mod.rs b/veilid-core/src/intf/native/network_interfaces/mod.rs similarity index 99% rename from veilid-core/src/intf/native/utils/network_interfaces/mod.rs rename to veilid-core/src/intf/native/network_interfaces/mod.rs index 1b14053f..3a05cb98 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/mod.rs +++ b/veilid-core/src/intf/native/network_interfaces/mod.rs @@ -1,7 +1,7 @@ -use crate::xx::*; -use core::fmt; mod tools; +use crate::*; + cfg_if::cfg_if! { if #[cfg(any(target_os = "linux", target_os = "android"))] { mod netlink; diff --git a/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs b/veilid-core/src/intf/native/network_interfaces/netlink.rs similarity index 99% rename from veilid-core/src/intf/native/utils/network_interfaces/netlink.rs rename to veilid-core/src/intf/native/network_interfaces/netlink.rs index f41988a6..94f53a1f 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/netlink.rs +++ b/veilid-core/src/intf/native/network_interfaces/netlink.rs @@ -1,5 +1,4 @@ use super::*; -use crate::*; use alloc::collections::btree_map::Entry; use futures_util::stream::TryStreamExt; diff --git a/veilid-core/src/intf/native/utils/network_interfaces/sockaddr_tools.rs b/veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs similarity index 100% rename from veilid-core/src/intf/native/utils/network_interfaces/sockaddr_tools.rs rename to veilid-core/src/intf/native/network_interfaces/sockaddr_tools.rs diff --git a/veilid-core/src/intf/native/utils/network_interfaces/tools.rs b/veilid-core/src/intf/native/network_interfaces/tools.rs similarity index 100% rename from veilid-core/src/intf/native/utils/network_interfaces/tools.rs rename to veilid-core/src/intf/native/network_interfaces/tools.rs diff --git a/veilid-core/src/intf/native/utils/network_interfaces/windows.rs b/veilid-core/src/intf/native/network_interfaces/windows.rs similarity index 99% rename from veilid-core/src/intf/native/utils/network_interfaces/windows.rs rename to veilid-core/src/intf/native/network_interfaces/windows.rs index d4ca6ec1..53b74ba2 100644 --- a/veilid-core/src/intf/native/utils/network_interfaces/windows.rs +++ b/veilid-core/src/intf/native/network_interfaces/windows.rs @@ -63,7 +63,8 @@ impl PlatformSupportWindows { // } // Iterate all the interfaces - let windows_interfaces = WindowsInterfaces::new().wrap_err("failed to get windows interfaces")?; + let windows_interfaces = + WindowsInterfaces::new().wrap_err("failed to get windows interfaces")?; for windows_interface in windows_interfaces.iter() { // Get name let intf_name = windows_interface.name(); diff --git a/veilid-core/src/intf/native/protected_store.rs b/veilid-core/src/intf/native/protected_store.rs index a3c35f68..e3a3be94 100644 --- a/veilid-core/src/intf/native/protected_store.rs +++ b/veilid-core/src/intf/native/protected_store.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use data_encoding::BASE64URL_NOPAD; use keyring_manager::*; diff --git a/veilid-core/src/intf/native/system.rs b/veilid-core/src/intf/native/system.rs index 1c2fa281..5491bff4 100644 --- a/veilid-core/src/intf/native/system.rs +++ b/veilid-core/src/intf/native/system.rs @@ -1,5 +1,6 @@ #![allow(dead_code)] -use crate::xx::*; + +use crate::*; pub async fn get_outbound_relay_peer() -> Option { panic!("Native Veilid should never require an outbound relay"); diff --git a/veilid-core/src/intf/native/table_store.rs b/veilid-core/src/intf/native/table_store.rs index 5d5ceb14..fca78232 100644 --- a/veilid-core/src/intf/native/table_store.rs +++ b/veilid-core/src/intf/native/table_store.rs @@ -1,5 +1,4 @@ use crate::intf::table_db::*; -use crate::xx::*; use crate::*; use keyvaluedb_sqlite::*; use std::path::PathBuf; diff --git a/veilid-core/src/intf/native/utils/mod.rs b/veilid-core/src/intf/native/utils/mod.rs deleted file mode 100644 index d49d97ff..00000000 --- a/veilid-core/src/intf/native/utils/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -#[cfg(target_os = "android")] -pub mod android; -#[cfg(all(target_os = "ios", feature = "ios_tests"))] -pub mod ios_test_setup; -pub mod network_interfaces; diff --git a/veilid-core/src/intf/table_db.rs b/veilid-core/src/intf/table_db.rs index 6e080247..23f789c7 100644 --- a/veilid-core/src/intf/table_db.rs +++ b/veilid-core/src/intf/table_db.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use rkyv::{Archive as RkyvArchive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; diff --git a/veilid-core/src/intf/wasm/block_store.rs b/veilid-core/src/intf/wasm/block_store.rs index 3b207947..2bd7d280 100644 --- a/veilid-core/src/intf/wasm/block_store.rs +++ b/veilid-core/src/intf/wasm/block_store.rs @@ -1,5 +1,3 @@ - -use crate::xx::*; use crate::*; struct BlockStoreInner { diff --git a/veilid-core/src/intf/wasm/protected_store.rs b/veilid-core/src/intf/wasm/protected_store.rs index e736739d..20f6ae89 100644 --- a/veilid-core/src/intf/wasm/protected_store.rs +++ b/veilid-core/src/intf/wasm/protected_store.rs @@ -1,8 +1,8 @@ use super::*; -use crate::xx::*; use crate::*; use data_encoding::BASE64URL_NOPAD; use rkyv::{Archive as RkyvArchive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; + use web_sys::*; #[derive(Clone)] diff --git a/veilid-core/src/intf/wasm/system.rs b/veilid-core/src/intf/wasm/system.rs index 36b8bd14..6de02714 100644 --- a/veilid-core/src/intf/wasm/system.rs +++ b/veilid-core/src/intf/wasm/system.rs @@ -1,5 +1,3 @@ -use crate::xx::*; - use async_executors::{Bindgen, LocalSpawnHandleExt, SpawnHandleExt, Timer}; use futures_util::future::{select, Either}; use js_sys::*; diff --git a/veilid-core/src/intf/wasm/table_store.rs b/veilid-core/src/intf/wasm/table_store.rs index b49481ff..2123e8ea 100644 --- a/veilid-core/src/intf/wasm/table_store.rs +++ b/veilid-core/src/intf/wasm/table_store.rs @@ -1,7 +1,6 @@ use super::*; use crate::intf::table_db::*; -use crate::xx::*; use crate::*; use keyvaluedb_web::*; diff --git a/veilid-core/src/intf/wasm/utils/mod.rs b/veilid-core/src/intf/wasm/utils/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/veilid-core/src/intf/wasm/utils/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index 89a6456c..e66eb522 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -20,7 +20,6 @@ extern crate alloc; mod api_tracing_layer; mod attachment_manager; -mod callback_state_machine; mod core_context; mod crypto; mod intf; @@ -84,3 +83,5 @@ pub static DEFAULT_LOG_IGNORE_LIST: [&str; 21] = [ "trust_dns_proto", "attohttpc", ]; + +use veilid_tools::*; diff --git a/veilid-core/src/network_manager/mod.rs b/veilid-core/src/network_manager/mod.rs index f5fec43e..a91e55ed 100644 --- a/veilid-core/src/network_manager/mod.rs +++ b/veilid-core/src/network_manager/mod.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; #[cfg(not(target_arch = "wasm32"))] diff --git a/veilid-core/src/network_manager/native/mod.rs b/veilid-core/src/network_manager/native/mod.rs index 8978918f..b588273b 100644 --- a/veilid-core/src/network_manager/native/mod.rs +++ b/veilid-core/src/network_manager/native/mod.rs @@ -8,12 +8,12 @@ mod start_protocols; use super::*; use crate::routing_table::*; use connection_manager::*; +use network_interfaces::*; use network_tcp::*; use protocol::tcp::RawTcpProtocolHandler; use protocol::udp::RawUdpProtocolHandler; use protocol::ws::WebsocketProtocolHandler; pub use protocol::*; -use utils::network_interfaces::*; use async_tls::TlsAcceptor; use futures_util::StreamExt; diff --git a/veilid-core/src/network_manager/native/protocol/mod.rs b/veilid-core/src/network_manager/native/protocol/mod.rs index 4c2dab23..0a41a77b 100644 --- a/veilid-core/src/network_manager/native/protocol/mod.rs +++ b/veilid-core/src/network_manager/native/protocol/mod.rs @@ -5,7 +5,6 @@ pub mod wrtc; pub mod ws; use super::*; -use crate::xx::*; use std::io; #[derive(Debug)] diff --git a/veilid-core/src/network_manager/native/protocol/sockets.rs b/veilid-core/src/network_manager/native/protocol/sockets.rs index 0cf7454d..608e19b5 100644 --- a/veilid-core/src/network_manager/native/protocol/sockets.rs +++ b/veilid-core/src/network_manager/native/protocol/sockets.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use async_io::Async; use std::io; diff --git a/veilid-core/src/receipt_manager.rs b/veilid-core/src/receipt_manager.rs index 54f37765..be548ff1 100644 --- a/veilid-core/src/receipt_manager.rs +++ b/veilid-core/src/receipt_manager.rs @@ -5,7 +5,6 @@ use futures_util::stream::{FuturesUnordered, StreamExt}; use network_manager::*; use routing_table::*; use stop_token::future::FutureExt; -use xx::*; #[derive(Clone, Debug)] pub enum ReceiptEvent { diff --git a/veilid-core/src/routing_table/mod.rs b/veilid-core/src/routing_table/mod.rs index bb8a4058..9b885d2f 100644 --- a/veilid-core/src/routing_table/mod.rs +++ b/veilid-core/src/routing_table/mod.rs @@ -11,7 +11,6 @@ mod routing_table_inner; mod stats_accounting; mod tasks; -use crate::xx::*; use crate::*; use crate::crypto::*; diff --git a/veilid-core/src/routing_table/stats_accounting.rs b/veilid-core/src/routing_table/stats_accounting.rs index 7ef69bd6..7167636e 100644 --- a/veilid-core/src/routing_table/stats_accounting.rs +++ b/veilid-core/src/routing_table/stats_accounting.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use alloc::collections::VecDeque; diff --git a/veilid-core/src/rpc_processor/mod.rs b/veilid-core/src/rpc_processor/mod.rs index 646c665f..5a159899 100644 --- a/veilid-core/src/rpc_processor/mod.rs +++ b/veilid-core/src/rpc_processor/mod.rs @@ -30,7 +30,6 @@ pub use rpc_status::*; use super::*; use crate::crypto::*; -use crate::xx::*; use futures_util::StreamExt; use network_manager::*; use receipt_manager::*; diff --git a/veilid-core/src/tests/common/mod.rs b/veilid-core/src/tests/common/mod.rs index a2e63d10..f0fbc066 100644 --- a/veilid-core/src/tests/common/mod.rs +++ b/veilid-core/src/tests/common/mod.rs @@ -1,4 +1,3 @@ -pub mod test_async_tag_lock; pub mod test_host_interface; pub mod test_protected_store; pub mod test_table_store; diff --git a/veilid-core/src/tests/common/test_async_tag_lock.rs b/veilid-core/src/tests/common/test_async_tag_lock.rs deleted file mode 100644 index 350cd9a4..00000000 --- a/veilid-core/src/tests/common/test_async_tag_lock.rs +++ /dev/null @@ -1,158 +0,0 @@ -use crate::xx::*; - -pub async fn test_simple_no_contention() { - info!("test_simple_no_contention"); - - let table = AsyncTagLockTable::new(); - - let a1 = SocketAddr::new("1.2.3.4".parse().unwrap(), 1234); - let a2 = SocketAddr::new("6.9.6.9".parse().unwrap(), 6969); - - { - let g1 = table.lock_tag(a1).await; - let g2 = table.lock_tag(a2).await; - drop(g2); - drop(g1); - } - - { - let g1 = table.lock_tag(a1).await; - let g2 = table.lock_tag(a2).await; - drop(g1); - drop(g2); - } - - assert_eq!(table.len(), 0); -} - -pub async fn test_simple_single_contention() { - info!("test_simple_single_contention"); - - let table = AsyncTagLockTable::new(); - - let a1 = SocketAddr::new("1.2.3.4".parse().unwrap(), 1234); - - let g1 = table.lock_tag(a1).await; - - info!("locked"); - let t1 = spawn(async move { - // move the guard into the task - let _g1_take = g1; - // hold the guard for a bit - info!("waiting"); - sleep(1000).await; - // release the guard - info!("released"); - }); - - // wait to lock again, will contend until spawned task exits - let _g1_b = table.lock_tag(a1).await; - info!("locked"); - - // Ensure task is joined - t1.await; - - assert_eq!(table.len(), 1); -} - -pub async fn test_simple_double_contention() { - info!("test_simple_double_contention"); - - let table = AsyncTagLockTable::new(); - - let a1 = SocketAddr::new("1.2.3.4".parse().unwrap(), 1234); - let a2 = SocketAddr::new("6.9.6.9".parse().unwrap(), 6969); - - let g1 = table.lock_tag(a1).await; - let g2 = table.lock_tag(a2).await; - - info!("locked"); - let t1 = spawn(async move { - // move the guard into the tas - let _g1_take = g1; - // hold the guard for a bit - info!("waiting"); - sleep(1000).await; - // release the guard - info!("released"); - }); - let t2 = spawn(async move { - // move the guard into the task - let _g2_take = g2; - // hold the guard for a bit - info!("waiting"); - sleep(500).await; - // release the guard - info!("released"); - }); - - // wait to lock again, will contend until spawned task exits - let _g1_b = table.lock_tag(a1).await; - // wait to lock again, should complete immediately - let _g2_b = table.lock_tag(a2).await; - - info!("locked"); - - // Ensure tasks are joined - t1.await; - t2.await; - - assert_eq!(table.len(), 2); -} - -pub async fn test_parallel_single_contention() { - info!("test_parallel_single_contention"); - - let table = AsyncTagLockTable::new(); - - let a1 = SocketAddr::new("1.2.3.4".parse().unwrap(), 1234); - - let table1 = table.clone(); - let t1 = spawn(async move { - // lock the tag - let _g = table1.lock_tag(a1).await; - info!("locked t1"); - // hold the guard for a bit - info!("waiting t1"); - sleep(500).await; - // release the guard - info!("released t1"); - }); - - let table2 = table.clone(); - let t2 = spawn(async move { - // lock the tag - let _g = table2.lock_tag(a1).await; - info!("locked t2"); - // hold the guard for a bit - info!("waiting t2"); - sleep(500).await; - // release the guard - info!("released t2"); - }); - - let table3 = table.clone(); - let t3 = spawn(async move { - // lock the tag - let _g = table3.lock_tag(a1).await; - info!("locked t3"); - // hold the guard for a bit - info!("waiting t3"); - sleep(500).await; - // release the guard - info!("released t3"); - }); - - // Ensure tasks are joined - t1.await; - t2.await; - t3.await; - - assert_eq!(table.len(), 0); -} - -pub async fn test_all() { - test_simple_no_contention().await; - test_simple_single_contention().await; - test_parallel_single_contention().await; -} diff --git a/veilid-core/src/tests/common/test_host_interface.rs b/veilid-core/src/tests/common/test_host_interface.rs index 322f5d5e..83618b7f 100644 --- a/veilid-core/src/tests/common/test_host_interface.rs +++ b/veilid-core/src/tests/common/test_host_interface.rs @@ -1,469 +1,13 @@ -use crate::xx::*; use crate::*; -cfg_if! { - if #[cfg(target_arch = "wasm32")] { - use js_sys::*; - } else { - use std::time::{Duration, SystemTime}; - } -} - -pub async fn test_log() { - info!("testing log"); -} - -pub async fn test_get_timestamp() { - info!("testing get_timestamp"); - let t1 = get_timestamp(); - let t2 = get_timestamp(); - assert!(t2 >= t1); -} - -pub async fn test_eventual() { - info!("testing Eventual"); - { - let e1 = Eventual::new(); - let i1 = e1.instance_clone(1u32); - let i2 = e1.instance_clone(2u32); - let i3 = e1.instance_clone(3u32); - drop(i3); - let i4 = e1.instance_clone(4u32); - drop(i2); - - let jh = spawn(async move { - sleep(1000).await; - e1.resolve(); - }); - - assert_eq!(i1.await, 1u32); - assert_eq!(i4.await, 4u32); - - jh.await; - } - { - let e1 = Eventual::new(); - let i1 = e1.instance_clone(1u32); - let i2 = e1.instance_clone(2u32); - let i3 = e1.instance_clone(3u32); - let i4 = e1.instance_clone(4u32); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - let i5 = e1.instance_clone(5u32); - let i6 = e1.instance_clone(6u32); - assert_eq!(i1.await, 1u32); - assert_eq!(i5.await, 5u32); - assert_eq!(i6.await, 6u32); - }); - sleep(1000).await; - let resolved = e1_c1.resolve(); - drop(i2); - drop(i3); - assert_eq!(i4.await, 4u32); - resolved.await; - jh.await; - } - { - let e1 = Eventual::new(); - let i1 = e1.instance_clone(1u32); - let i2 = e1.instance_clone(2u32); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - assert_eq!(i1.await, 1u32); - assert_eq!(i2.await, 2u32); - }); - sleep(1000).await; - e1_c1.resolve().await; - - jh.await; - - e1_c1.reset(); - // - let j1 = e1.instance_clone(1u32); - let j2 = e1.instance_clone(2u32); - let jh = spawn(async move { - assert_eq!(j1.await, 1u32); - assert_eq!(j2.await, 2u32); - }); - sleep(1000).await; - e1_c1.resolve().await; - - jh.await; - - e1_c1.reset(); - } -} - -pub async fn test_eventual_value() { - info!("testing Eventual Value"); - { - let e1 = EventualValue::::new(); - let i1 = e1.instance(); - let i2 = e1.instance(); - let i3 = e1.instance(); - drop(i3); - let i4 = e1.instance(); - drop(i2); - - let e1_c1 = e1.clone(); - let jh = spawn(async move { - sleep(1000).await; - e1_c1.resolve(3u32); - }); - - i1.await; - i4.await; - jh.await; - assert_eq!(e1.take_value(), Some(3u32)); - } - { - let e1 = EventualValue::new(); - let i1 = e1.instance(); - let i2 = e1.instance(); - let i3 = e1.instance(); - let i4 = e1.instance(); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - let i5 = e1.instance(); - let i6 = e1.instance(); - i1.await; - i5.await; - i6.await; - }); - sleep(1000).await; - let resolved = e1_c1.resolve(4u16); - drop(i2); - drop(i3); - i4.await; - resolved.await; - jh.await; - assert_eq!(e1_c1.take_value(), Some(4u16)); - } - { - let e1 = EventualValue::new(); - assert_eq!(e1.take_value(), None); - let i1 = e1.instance(); - let i2 = e1.instance(); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - i1.await; - i2.await; - }); - sleep(1000).await; - e1_c1.resolve(5u32).await; - jh.await; - assert_eq!(e1_c1.take_value(), Some(5u32)); - e1_c1.reset(); - assert_eq!(e1_c1.take_value(), None); - // - let j1 = e1.instance(); - let j2 = e1.instance(); - let jh = spawn(async move { - j1.await; - j2.await; - }); - sleep(1000).await; - e1_c1.resolve(6u32).await; - jh.await; - assert_eq!(e1_c1.take_value(), Some(6u32)); - e1_c1.reset(); - assert_eq!(e1_c1.take_value(), None); - } -} - -pub async fn test_eventual_value_clone() { - info!("testing Eventual Value Clone"); - { - let e1 = EventualValueClone::::new(); - let i1 = e1.instance(); - let i2 = e1.instance(); - let i3 = e1.instance(); - drop(i3); - let i4 = e1.instance(); - drop(i2); - - let jh = spawn(async move { - sleep(1000).await; - e1.resolve(3u32); - }); - - assert_eq!(i1.await, 3); - assert_eq!(i4.await, 3); - - jh.await; - } - - { - let e1 = EventualValueClone::new(); - let i1 = e1.instance(); - let i2 = e1.instance(); - let i3 = e1.instance(); - let i4 = e1.instance(); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - let i5 = e1.instance(); - let i6 = e1.instance(); - assert_eq!(i1.await, 4); - assert_eq!(i5.await, 4); - assert_eq!(i6.await, 4); - }); - sleep(1000).await; - let resolved = e1_c1.resolve(4u16); - drop(i2); - drop(i3); - assert_eq!(i4.await, 4); - resolved.await; - jh.await; - } - - { - let e1 = EventualValueClone::new(); - let i1 = e1.instance(); - let i2 = e1.instance(); - let e1_c1 = e1.clone(); - let jh = spawn(async move { - assert_eq!(i1.await, 5); - assert_eq!(i2.await, 5); - }); - sleep(1000).await; - e1_c1.resolve(5u32).await; - jh.await; - e1_c1.reset(); - // - let j1 = e1.instance(); - let j2 = e1.instance(); - let jh = spawn(async move { - assert_eq!(j1.await, 6); - assert_eq!(j2.await, 6); - }); - sleep(1000).await; - e1_c1.resolve(6u32).await; - jh.await; - e1_c1.reset(); - } -} -pub async fn test_interval() { - info!("testing interval"); - - let tick: Arc> = Arc::new(Mutex::new(0u32)); - let stopper = interval(1000, move || { - let tick = tick.clone(); - async move { - let mut tick = tick.lock(); - trace!("tick {}", tick); - *tick += 1; - } - }); - - sleep(5500).await; - - stopper.await; -} - -pub async fn test_timeout() { - info!("testing timeout"); - - let tick: Arc> = Arc::new(Mutex::new(0u32)); - let tick_1 = tick.clone(); - assert!( - timeout(2500, async move { - let mut tick = tick_1.lock(); - trace!("tick {}", tick); - sleep(1000).await; - *tick += 1; - trace!("tick {}", tick); - sleep(1000).await; - *tick += 1; - trace!("tick {}", tick); - sleep(1000).await; - *tick += 1; - trace!("tick {}", tick); - sleep(1000).await; - *tick += 1; - }) - .await - .is_err(), - "should have timed out" - ); - - let ticks = *tick.lock(); - assert!(ticks <= 2); -} - -pub async fn test_sleep() { - info!("testing sleep"); - cfg_if! { - if #[cfg(target_arch = "wasm32")] { - - let t1 = Date::now(); - intf::sleep(1000).await; - let t2 = Date::now(); - assert!((t2-t1) >= 1000.0); - - } else { - - let sys_time = SystemTime::now(); - let one_sec = Duration::from_secs(1); - - sleep(1000).await; - assert!(sys_time.elapsed().unwrap() >= one_sec); - } - } -} - -macro_rules! assert_split_url { - ($url:expr, $scheme:expr, $host:expr) => { - assert_eq!( - SplitUrl::from_str($url), - Ok(SplitUrl::new($scheme, None, $host, None, None)) - ); - }; - ($url:expr, $scheme:expr, $host:expr, $port:expr) => { - assert_eq!( - SplitUrl::from_str($url), - Ok(SplitUrl::new($scheme, None, $host, $port, None)) - ); - }; - ($url:expr, $scheme:expr, $host:expr, $port:expr, $path:expr) => { - assert_eq!( - SplitUrl::from_str($url), - Ok(SplitUrl::new( - $scheme, - None, - $host, - $port, - Some(SplitUrlPath::new( - $path, - Option::::None, - Option::::None - )) - )) - ); - }; - ($url:expr, $scheme:expr, $host:expr, $port:expr, $path:expr, $frag:expr, $query:expr) => { - assert_eq!( - SplitUrl::from_str($url), - Ok(SplitUrl::new( - $scheme, - None, - $host, - $port, - Some(SplitUrlPath::new($path, $frag, $query)) - )) - ); - }; -} - -macro_rules! assert_split_url_parse { - ($url:expr) => { - let url = $url; - let su1 = SplitUrl::from_str(url).expect("should parse"); - assert_eq!(su1.to_string(), url); - }; -} - -fn host>(s: S) -> SplitUrlHost { - SplitUrlHost::Hostname(s.as_ref().to_owned()) -} - -fn ip>(s: S) -> SplitUrlHost { - SplitUrlHost::IpAddr(IpAddr::from_str(s.as_ref()).unwrap()) -} - -pub async fn test_split_url() { - info!("testing split_url"); - - assert_split_url!("http://foo", "http", host("foo")); - assert_split_url!("http://foo:1234", "http", host("foo"), Some(1234)); - assert_split_url!("http://foo:1234/", "http", host("foo"), Some(1234), ""); - assert_split_url!( - "http://foo:1234/asdf/qwer", - "http", - host("foo"), - Some(1234), - "asdf/qwer" - ); - assert_split_url!("http://foo/", "http", host("foo"), None, ""); - assert_split_url!("http://11.2.3.144/", "http", ip("11.2.3.144"), None, ""); - assert_split_url!("http://[1111::2222]/", "http", ip("1111::2222"), None, ""); - assert_split_url!( - "http://[1111::2222]:123/", - "http", - ip("1111::2222"), - Some(123), - "" - ); - - assert_split_url!( - "http://foo/asdf/qwer", - "http", - host("foo"), - None, - "asdf/qwer" - ); - assert_split_url!( - "http://foo/asdf/qwer#3", - "http", - host("foo"), - None, - "asdf/qwer", - Some("3"), - Option::::None - ); - assert_split_url!( - "http://foo/asdf/qwer?xxx", - "http", - host("foo"), - None, - "asdf/qwer", - Option::::None, - Some("xxx") - ); - assert_split_url!( - "http://foo/asdf/qwer#yyy?xxx", - "http", - host("foo"), - None, - "asdf/qwer", - Some("yyy"), - Some("xxx") - ); - assert_err!(SplitUrl::from_str("://asdf")); - assert_err!(SplitUrl::from_str("")); - assert_err!(SplitUrl::from_str("::")); - assert_err!(SplitUrl::from_str("://:")); - assert_err!(SplitUrl::from_str("a://:")); - assert_err!(SplitUrl::from_str("a://:1243")); - assert_err!(SplitUrl::from_str("a://:65536")); - assert_err!(SplitUrl::from_str("a://:-16")); - assert_err!(SplitUrl::from_str("a:///")); - assert_err!(SplitUrl::from_str("a:///qwer:")); - assert_err!(SplitUrl::from_str("a:///qwer://")); - assert_err!(SplitUrl::from_str("a://qwer://")); - assert_err!(SplitUrl::from_str("a://[1111::2222]:/")); - assert_err!(SplitUrl::from_str("a://[1111::2222]:")); - - assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux?zuz"); - assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord#qux"); - assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord?zuz"); - assert_split_url_parse!("sch://foo:bar@baz.com:1234/fnord/"); - assert_split_url_parse!("sch://foo:bar@baz.com:1234//"); - assert_split_url_parse!("sch://foo:bar@baz.com:1234"); - assert_split_url_parse!("sch://foo:bar@[1111::2222]:1234"); - assert_split_url_parse!("sch://foo:bar@[::]:1234"); - assert_split_url_parse!("sch://foo:bar@1.2.3.4:1234"); - assert_split_url_parse!("sch://@baz.com:1234"); - assert_split_url_parse!("sch://baz.com/asdf/asdf"); - assert_split_url_parse!("sch://baz.com/"); - assert_split_url_parse!("s://s"); -} - cfg_if! { if #[cfg(not(target_arch = "wasm32"))] { + use intf::network_interfaces::NetworkInterfaces; + pub async fn test_network_interfaces() { info!("testing network interfaces"); let t1 = get_timestamp(); - let interfaces = intf::utils::network_interfaces::NetworkInterfaces::new(); + let interfaces = NetworkInterfaces::new(); let count = 100; for x in 0..count { info!("loop {}", x); @@ -479,99 +23,7 @@ cfg_if! { } } -pub async fn test_get_random_u64() { - info!("testing random number generator for u64"); - let t1 = get_timestamp(); - let count = 10000; - for _ in 0..count { - let _ = get_random_u64(); - } - let t2 = get_timestamp(); - let tdiff = ((t2 - t1) as f64) / 1000000.0f64; - info!( - "running network interface test with {} iterations took {} seconds", - count, tdiff - ); -} - -pub async fn test_get_random_u32() { - info!("testing random number generator for u32"); - let t1 = get_timestamp(); - let count = 10000; - for _ in 0..count { - let _ = get_random_u32(); - } - let t2 = get_timestamp(); - let tdiff = ((t2 - t1) as f64) / 1000000.0f64; - info!( - "running network interface test with {} iterations took {} seconds", - count, tdiff - ); -} - -pub async fn test_must_join_single_future() { - info!("testing must join single future"); - let sf = MustJoinSingleFuture::::new(); - assert_eq!(sf.check().await, Ok(None)); - assert_eq!( - sf.single_spawn(async { - sleep(2000).await; - 69 - }) - .await, - Ok((None, true)) - ); - assert_eq!(sf.check().await, Ok(None)); - assert_eq!(sf.single_spawn(async { panic!() }).await, Ok((None, false))); - assert_eq!(sf.join().await, Ok(Some(69))); - assert_eq!( - sf.single_spawn(async { - sleep(1000).await; - 37 - }) - .await, - Ok((None, true)) - ); - sleep(2000).await; - assert_eq!( - sf.single_spawn(async { - sleep(1000).await; - 27 - }) - .await, - Ok((Some(37), true)) - ); - sleep(2000).await; - assert_eq!(sf.join().await, Ok(Some(27))); - assert_eq!(sf.check().await, Ok(None)); -} - -pub async fn test_tools() { - info!("testing retry_falloff_log"); - let mut last_us = 0u64; - for x in 0..1024 { - let cur_us = x as u64 * 1000000u64; - if retry_falloff_log(last_us, cur_us, 10_000_000u64, 6_000_000_000u64, 2.0f64) { - info!(" retry at {} secs", timestamp_to_secs(cur_us)); - last_us = cur_us; - } - } -} - pub async fn test_all() { - test_log().await; - test_get_timestamp().await; - test_tools().await; - test_split_url().await; - test_get_random_u64().await; - test_get_random_u32().await; - test_sleep().await; #[cfg(not(target_arch = "wasm32"))] - test_network_interfaces().await; XXX KEEP THIS IN NATIVE TESTS - test_must_join_single_future().await; - test_eventual().await; - test_eventual_value().await; - test_eventual_value_clone().await; - test_interval().await; - test_timeout().await; + test_network_interfaces().await; } diff --git a/veilid-core/src/tests/common/test_protected_store.rs b/veilid-core/src/tests/common/test_protected_store.rs index ef48c11a..49d56d4e 100644 --- a/veilid-core/src/tests/common/test_protected_store.rs +++ b/veilid-core/src/tests/common/test_protected_store.rs @@ -1,5 +1,4 @@ use super::test_veilid_config::*; -use crate::xx::*; use crate::*; async fn startup() -> VeilidAPI { diff --git a/veilid-core/src/tests/common/test_table_store.rs b/veilid-core/src/tests/common/test_table_store.rs index 5e3478a3..773f8b3e 100644 --- a/veilid-core/src/tests/common/test_table_store.rs +++ b/veilid-core/src/tests/common/test_table_store.rs @@ -1,5 +1,4 @@ use super::test_veilid_config::*; -use crate::xx::*; use crate::*; async fn startup() -> VeilidAPI { diff --git a/veilid-core/src/tests/common/test_veilid_config.rs b/veilid-core/src/tests/common/test_veilid_config.rs index c5c6f56f..1eab6ea4 100644 --- a/veilid-core/src/tests/common/test_veilid_config.rs +++ b/veilid-core/src/tests/common/test_veilid_config.rs @@ -1,7 +1,7 @@ #![allow(clippy::bool_assert_comparison)] -use crate::xx::*; use crate::*; + cfg_if! { if #[cfg(not(target_arch = "wasm32"))] { use std::fs::File; diff --git a/veilid-core/src/tests/common/test_veilid_core.rs b/veilid-core/src/tests/common/test_veilid_core.rs index e3ba0670..27bf3e2e 100644 --- a/veilid-core/src/tests/common/test_veilid_core.rs +++ b/veilid-core/src/tests/common/test_veilid_core.rs @@ -1,5 +1,4 @@ use super::test_veilid_config::*; -use crate::xx::*; use crate::*; pub async fn test_startup_shutdown() { diff --git a/veilid-core/src/tests/native/mod.rs b/veilid-core/src/tests/native/mod.rs index b41ab132..a7a0580d 100644 --- a/veilid-core/src/tests/native/mod.rs +++ b/veilid-core/src/tests/native/mod.rs @@ -1,13 +1,9 @@ //! Test suite for Native #![cfg(not(target_arch = "wasm32"))] - -mod test_async_peek_stream; - -use crate::xx::*; - use crate::crypto::tests::*; use crate::network_manager::tests::*; use crate::tests::common::*; +use crate::*; #[cfg(all(target_os = "android", feature = "android_tests"))] use jni::{objects::JClass, objects::JObject, JNIEnv}; @@ -59,8 +55,6 @@ pub fn run_all_tests() { exec_test_veilid_core(); info!("TEST: exec_test_veilid_config"); exec_test_veilid_config(); - info!("TEST: exec_test_async_peek_stream"); - exec_test_async_peek_stream(); info!("TEST: exec_test_connection_table"); exec_test_connection_table(); info!("TEST: exec_test_table_store"); @@ -71,8 +65,6 @@ pub fn run_all_tests() { exec_test_crypto(); info!("TEST: exec_test_envelope_receipt"); exec_test_envelope_receipt(); - info!("TEST: exec_test_async_tag_lock"); - exec_test_async_tag_lock(); info!("Finished unit tests"); } @@ -108,11 +100,6 @@ fn exec_test_veilid_config() { test_veilid_config::test_all().await; }) } -fn exec_test_async_peek_stream() { - block_on(async { - test_async_peek_stream::test_all().await; - }) -} fn exec_test_connection_table() { block_on(async { test_connection_table::test_all().await; @@ -138,11 +125,7 @@ fn exec_test_envelope_receipt() { test_envelope_receipt::test_all().await; }) } -fn exec_test_async_tag_lock() { - block_on(async { - test_async_tag_lock::test_all().await; - }) -} + /////////////////////////////////////////////////////////////////////////// cfg_if! { if #[cfg(test)] { @@ -190,13 +173,6 @@ cfg_if! { exec_test_veilid_config(); } - #[test] - #[serial] - fn run_test_async_peek_stream() { - setup(); - exec_test_async_peek_stream(); - } - #[test] #[serial] fn run_test_connection_table() { @@ -232,11 +208,5 @@ cfg_if! { exec_test_envelope_receipt(); } - #[test] - #[serial] - fn run_test_async_tag_lock() { - setup(); - exec_test_async_tag_lock(); - } } } diff --git a/veilid-core/src/tests/native/test_async_peek_stream.rs b/veilid-core/src/tests/native/test_async_peek_stream.rs deleted file mode 100644 index 2aaa5d97..00000000 --- a/veilid-core/src/tests/native/test_async_peek_stream.rs +++ /dev/null @@ -1,352 +0,0 @@ -use crate::xx::*; - -cfg_if! { - if #[cfg(feature="rt-async-std")] { - use async_std::net::{TcpListener, TcpStream}; - use async_std::prelude::FutureExt; - use async_std::task::sleep; - } else if #[cfg(feature="rt-tokio")] { - use tokio::net::{TcpListener, TcpStream}; - use tokio::time::sleep; - use tokio_util::compat::*; - } -} - -use futures_util::{AsyncReadExt, AsyncWriteExt}; -use std::io; - -static MESSAGE: &[u8; 62] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - -async fn make_tcp_loopback() -> Result<(TcpStream, TcpStream), io::Error> { - let listener = TcpListener::bind("127.0.0.1:0").await?; - let local_addr = listener.local_addr()?; - - let accept_future = async { - let (accepted_stream, peer_address) = listener.accept().await?; - trace!("connection from {}", peer_address); - accepted_stream.set_nodelay(true)?; - Result::::Ok(accepted_stream) - }; - let connect_future = async { - sleep(Duration::from_secs(1)).await; - let connected_stream = TcpStream::connect(local_addr).await?; - connected_stream.set_nodelay(true)?; - Result::::Ok(connected_stream) - }; - - cfg_if! { - if #[cfg(feature="rt-async-std")] { - accept_future.try_join(connect_future).await - } else if #[cfg(feature="rt-tokio")] { - tokio::try_join!(accept_future, connect_future) - } - } -} - -async fn make_async_peek_stream_loopback() -> (AsyncPeekStream, AsyncPeekStream) { - let (acc, conn) = make_tcp_loopback().await.unwrap(); - #[cfg(feature = "rt-tokio")] - let acc = acc.compat(); - #[cfg(feature = "rt-tokio")] - let conn = conn.compat(); - - let aps_a = AsyncPeekStream::new(acc); - let aps_c = AsyncPeekStream::new(conn); - - (aps_a, aps_c) -} - -#[cfg(feature = "rt-tokio")] -async fn make_stream_loopback() -> (Compat, Compat) { - let (a, c) = make_tcp_loopback().await.unwrap(); - (a.compat(), c.compat()) -} -#[cfg(feature = "rt-async-std")] -async fn make_stream_loopback() -> (TcpStream, TcpStream) { - make_tcp_loopback().await.unwrap() -} - -pub async fn test_nothing() { - info!("test_nothing"); - let (mut a, mut c) = make_stream_loopback().await; - let outbuf = MESSAGE.to_vec(); - - a.write_all(&outbuf).await.unwrap(); - - let mut inbuf: Vec = Vec::new(); - inbuf.resize(outbuf.len(), 0u8); - c.read_exact(&mut inbuf).await.unwrap(); - - assert_eq!(inbuf, outbuf); -} - -pub async fn test_no_peek() { - info!("test_no_peek"); - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - let outbuf = MESSAGE.to_vec(); - - a.write_all(&outbuf).await.unwrap(); - - let mut inbuf: Vec = Vec::new(); - inbuf.resize(outbuf.len(), 0u8); - c.read_exact(&mut inbuf).await.unwrap(); - - assert_eq!(inbuf, outbuf); -} - -pub async fn test_peek_all_read() { - info!("test_peek_all_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek everything - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len(), 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - - assert_eq!(peeksize1, peekbuf1.len()); - // read everything - let mut inbuf: Vec = Vec::new(); - inbuf.resize(outbuf.len(), 0u8); - c.read_exact(&mut inbuf).await.unwrap(); - - assert_eq!(inbuf, outbuf); - assert_eq!(peekbuf1, outbuf); -} - -pub async fn test_peek_some_read() { - info!("test_peek_some_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 2, 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - // read everything - let mut inbuf: Vec = Vec::new(); - inbuf.resize(outbuf.len(), 0u8); - c.read_exact(&mut inbuf).await.unwrap(); - - assert_eq!(inbuf, outbuf); - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); -} - -pub async fn test_peek_some_peek_some_read() { - info!("test_peek_some_peek_some_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 4, 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - - // peek partially - let mut peekbuf2: Vec = Vec::new(); - peekbuf2.resize(peeksize1 + 1, 0u8); - let peeksize2 = c.peek(&mut peekbuf2).await.unwrap(); - assert_eq!(peeksize2, peekbuf2.len()); - - // read everything - let mut inbuf: Vec = Vec::new(); - inbuf.resize(outbuf.len(), 0u8); - c.read_exact(&mut inbuf).await.unwrap(); - - assert_eq!(inbuf, outbuf); - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); - assert_eq!(peekbuf2, outbuf[0..peeksize2].to_vec()); -} - -pub async fn test_peek_some_read_peek_some_read() { - info!("test_peek_some_read_peek_some_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 4, 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - - // read partially - let mut inbuf1: Vec = Vec::new(); - inbuf1.resize(peeksize1 - 1, 0u8); - c.read_exact(&mut inbuf1).await.unwrap(); - - // peek partially - let mut peekbuf2: Vec = Vec::new(); - peekbuf2.resize(2, 0u8); - let peeksize2 = c.peek(&mut peekbuf2).await.unwrap(); - assert_eq!(peeksize2, peekbuf2.len()); - - // read partially - let mut inbuf2: Vec = Vec::new(); - inbuf2.resize(2, 0u8); - c.read_exact(&mut inbuf2).await.unwrap(); - - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); - assert_eq!(inbuf1, outbuf[0..peeksize1 - 1].to_vec()); - assert_eq!(peekbuf2, outbuf[peeksize1 - 1..peeksize1 + 1].to_vec()); - assert_eq!(inbuf2, peekbuf2); -} - -pub async fn test_peek_some_read_peek_all_read() { - info!("test_peek_some_read_peek_all_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 4, 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - - // read partially - let mut inbuf1: Vec = Vec::new(); - inbuf1.resize(peeksize1 + 1, 0u8); - c.read_exact(&mut inbuf1).await.unwrap(); - - // peek past end - let mut peekbuf2: Vec = Vec::new(); - peekbuf2.resize(outbuf.len(), 0u8); - let peeksize2 = c.peek(&mut peekbuf2).await.unwrap(); - assert_eq!(peeksize2, outbuf.len() - (peeksize1 + 1)); - - // read remaining - let mut inbuf2: Vec = Vec::new(); - inbuf2.resize(peeksize2, 0u8); - c.read_exact(&mut inbuf2).await.unwrap(); - - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); - assert_eq!(inbuf1, outbuf[0..peeksize1 + 1].to_vec()); - assert_eq!( - peekbuf2[0..peeksize2].to_vec(), - outbuf[peeksize1 + 1..outbuf.len()].to_vec() - ); - assert_eq!(inbuf2, peekbuf2[0..peeksize2].to_vec()); -} - -pub async fn test_peek_some_read_peek_some_read_all_read() { - info!("test_peek_some_read_peek_some_read_peek_all_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 4, 0u8); - let peeksize1 = c.peek(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - - // read partially - let mut inbuf1: Vec = Vec::new(); - inbuf1.resize(peeksize1 - 1, 0u8); - c.read_exact(&mut inbuf1).await.unwrap(); - - // peek partially - let mut peekbuf2: Vec = Vec::new(); - peekbuf2.resize(2, 0u8); - let peeksize2 = c.peek(&mut peekbuf2).await.unwrap(); - assert_eq!(peeksize2, peekbuf2.len()); - // read partially - let mut inbuf2: Vec = Vec::new(); - inbuf2.resize(1, 0u8); - c.read_exact(&mut inbuf2).await.unwrap(); - - // read remaining - let mut inbuf3: Vec = Vec::new(); - inbuf3.resize(outbuf.len() - peeksize1, 0u8); - c.read_exact(&mut inbuf3).await.unwrap(); - - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); - assert_eq!(inbuf1, outbuf[0..peeksize1 - 1].to_vec()); - assert_eq!( - peekbuf2[0..peeksize2].to_vec(), - outbuf[peeksize1 - 1..peeksize1 + 1].to_vec() - ); - assert_eq!(inbuf2, peekbuf2[0..1].to_vec()); - assert_eq!(inbuf3, outbuf[peeksize1..outbuf.len()].to_vec()); -} - -pub async fn test_peek_exact_read_peek_exact_read_all_read() { - info!("test_peek_exact_read_peek_exact_read_all_read"); - - let (mut a, mut c) = make_async_peek_stream_loopback().await; - - // write everything - let outbuf = MESSAGE.to_vec(); - a.write_all(&outbuf).await.unwrap(); - - // peek partially - let mut peekbuf1: Vec = Vec::new(); - peekbuf1.resize(outbuf.len() / 4, 0u8); - let peeksize1 = c.peek_exact(&mut peekbuf1).await.unwrap(); - assert_eq!(peeksize1, peekbuf1.len()); - - // read partially - let mut inbuf1: Vec = Vec::new(); - inbuf1.resize(peeksize1 - 1, 0u8); - c.read_exact(&mut inbuf1).await.unwrap(); - - // peek partially - let mut peekbuf2: Vec = Vec::new(); - peekbuf2.resize(2, 0u8); - let peeksize2 = c.peek_exact(&mut peekbuf2).await.unwrap(); - assert_eq!(peeksize2, peekbuf2.len()); - // read partially - let mut inbuf2: Vec = Vec::new(); - inbuf2.resize(1, 0u8); - c.read_exact(&mut inbuf2).await.unwrap(); - - // read remaining - let mut inbuf3: Vec = Vec::new(); - inbuf3.resize(outbuf.len() - peeksize1, 0u8); - c.read_exact(&mut inbuf3).await.unwrap(); - - assert_eq!(peekbuf1, outbuf[0..peeksize1].to_vec()); - assert_eq!(inbuf1, outbuf[0..peeksize1 - 1].to_vec()); - assert_eq!( - peekbuf2[0..peeksize2].to_vec(), - outbuf[peeksize1 - 1..peeksize1 + 1].to_vec() - ); - assert_eq!(inbuf2, peekbuf2[0..1].to_vec()); - assert_eq!(inbuf3, outbuf[peeksize1..outbuf.len()].to_vec()); -} - -pub async fn test_all() { - test_nothing().await; - test_no_peek().await; - test_peek_all_read().await; - test_peek_some_read().await; - test_peek_some_peek_some_read().await; - test_peek_some_read_peek_some_read().await; - test_peek_some_read_peek_all_read().await; - test_peek_some_read_peek_some_read_all_read().await; - test_peek_exact_read_peek_exact_read_all_read().await; -} diff --git a/veilid-core/src/veilid_api/mod.rs b/veilid-core/src/veilid_api/mod.rs index a293cd46..9dd2cebe 100644 --- a/veilid-core/src/veilid_api/mod.rs +++ b/veilid-core/src/veilid_api/mod.rs @@ -14,12 +14,6 @@ pub use routing_context::*; pub use serialize_helpers::*; pub use types::*; -use crate::*; - -pub use crate::xx::{ - IpAddr, Ipv4Addr, Ipv6Addr, SendPinBoxFuture, SocketAddr, SocketAddrV4, SocketAddrV6, - ToSocketAddrs, -}; pub use alloc::string::ToString; pub use attachment_manager::AttachmentManager; pub use core::str::FromStr; @@ -31,6 +25,7 @@ pub use intf::TableStore; pub use network_manager::NetworkManager; pub use routing_table::{NodeRef, NodeRefBase}; +use crate::*; use core::fmt; use core_context::{api_shutdown, VeilidCoreContext}; use enumset::*; @@ -38,6 +33,5 @@ use rkyv::{Archive as RkyvArchive, Deserialize as RkyvDeserialize, Serialize as use routing_table::{RouteSpecStore, RoutingTable}; use rpc_processor::*; use serde::*; -use xx::*; ///////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/veilid-core/src/veilid_config.rs b/veilid-core/src/veilid_config.rs index c1469dfa..b610a989 100644 --- a/veilid-core/src/veilid_config.rs +++ b/veilid-core/src/veilid_config.rs @@ -1,4 +1,3 @@ -use crate::xx::*; use crate::*; use rkyv::{Archive as RkyvArchive, Deserialize as RkyvDeserialize, Serialize as RkyvSerialize}; use serde::*; diff --git a/veilid-core/src/veilid_layer_filter.rs b/veilid-core/src/veilid_layer_filter.rs index a40fbc7a..73e02a85 100644 --- a/veilid-core/src/veilid_layer_filter.rs +++ b/veilid-core/src/veilid_layer_filter.rs @@ -1,5 +1,4 @@ use super::*; -use crate::xx::*; use tracing::level_filters::LevelFilter; use tracing::subscriber::Interest; use tracing_subscriber::layer; diff --git a/veilid-tools/Cargo.toml b/veilid-tools/Cargo.toml index 0a223274..d85ae4c6 100644 --- a/veilid-tools/Cargo.toml +++ b/veilid-tools/Cargo.toml @@ -33,6 +33,7 @@ once_cell = "^1" owo-colors = "^3" stop-token = { version = "^0", default-features = false } rand = "^0.7" +rust-fsm = "^0" # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android diff --git a/veilid-core/src/callback_state_machine.rs b/veilid-tools/src/callback_state_machine.rs similarity index 98% rename from veilid-core/src/callback_state_machine.rs rename to veilid-tools/src/callback_state_machine.rs index 64ab36c1..80085d37 100644 --- a/veilid-core/src/callback_state_machine.rs +++ b/veilid-tools/src/callback_state_machine.rs @@ -1,4 +1,5 @@ -use crate::xx::*; +use super::*; +pub use rust_fsm; pub use rust_fsm::*; pub type StateChangeCallback = Arc< diff --git a/veilid-tools/src/lib.rs b/veilid-tools/src/lib.rs index 0f16316b..ed8e90c8 100644 --- a/veilid-tools/src/lib.rs +++ b/veilid-tools/src/lib.rs @@ -1,6 +1,7 @@ // mod bump_port; mod async_peek_stream; mod async_tag_lock; +mod callback_state_machine; mod clone_stream; mod eventual; mod eventual_base; @@ -110,6 +111,7 @@ cfg_if! { // pub use bump_port::*; pub use async_peek_stream::*; pub use async_tag_lock::*; +pub use callback_state_machine::*; pub use clone_stream::*; pub use eventual::*; pub use eventual_base::{EventualCommon, EventualResolvedFuture}; diff --git a/veilid-tools/src/tests/common/test_host_interface.rs b/veilid-tools/src/tests/common/test_host_interface.rs index 8f31a953..43b9b3a8 100644 --- a/veilid-tools/src/tests/common/test_host_interface.rs +++ b/veilid-tools/src/tests/common/test_host_interface.rs @@ -467,7 +467,7 @@ pub async fn test_get_random_u64() { let t2 = get_timestamp(); let tdiff = ((t2 - t1) as f64) / 1000000.0f64; info!( - "running network interface test with {} iterations took {} seconds", + "running get_random_u64 with {} iterations took {} seconds", count, tdiff ); } @@ -482,7 +482,7 @@ pub async fn test_get_random_u32() { let t2 = get_timestamp(); let tdiff = ((t2 - t1) as f64) / 1000000.0f64; info!( - "running network interface test with {} iterations took {} seconds", + "running get_random_u32 with {} iterations took {} seconds", count, tdiff ); } diff --git a/veilid-tools/tests/web.rs b/veilid-tools/tests/web.rs index ac81ab39..8a04bce8 100644 --- a/veilid-tools/tests/web.rs +++ b/veilid-tools/tests/web.rs @@ -2,7 +2,7 @@ #![cfg(target_arch = "wasm32")] use veilid_tools::tests::*; -use veilid_tools::*; + use wasm_bindgen_test::*; wasm_bindgen_test_configure!(run_in_browser);