fix android unit tests and add better macos instructions

This commit is contained in:
John Smith
2022-08-23 10:37:41 -04:00
parent e112cc4527
commit 1793dd90e8
13 changed files with 227 additions and 75 deletions

View File

@@ -385,14 +385,6 @@ impl NetworkInterfaces {
inner.interface_address_cache.clone()
}
pub fn with_best_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
let inner = self.inner.lock();
f(&inner.interface_address_cache)
}
/////////////////////////////////////////////
fn cache_best_addresses(inner: &mut NetworkInterfacesInner) {

View File

@@ -268,9 +268,8 @@ impl Network {
if !from.ip().is_unspecified() {
vec![*from]
} else {
self.unlocked_inner
.interfaces
.best_addresses()
let addrs = self.get_usable_interface_addresses();
addrs
.iter()
.filter_map(|a| {
// We create sockets that are only ipv6 or ipv6 (not dual, so only translate matching unspecified address)
@@ -311,11 +310,21 @@ impl Network {
}
}
pub fn with_interface_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
self.unlocked_inner.interfaces.with_best_addresses(f)
pub fn is_usable_interface_address(&self, addr: IpAddr) -> bool {
let usable_addrs = self.get_usable_interface_addresses();
usable_addrs.contains(&addr)
}
pub fn get_usable_interface_addresses(&self) -> Vec<IpAddr> {
let addrs = self.unlocked_inner.interfaces.best_addresses();
let addrs: Vec<IpAddr> = addrs
.into_iter()
.filter(|addr| {
let address = Address::from_ip_addr(*addr);
address.is_local() || address.is_global()
})
.collect();
addrs
}
// See if our interface addresses have changed, if so we need to punt the network
@@ -591,7 +600,7 @@ impl Network {
{
let mut inner = self.inner.lock();
inner.enable_ipv4 = false;
for addr in self.unlocked_inner.interfaces.best_addresses() {
for addr in self.get_usable_interface_addresses() {
if addr.is_ipv4() {
log_net!(debug "enable address {:?} as ipv4", addr);
inner.enable_ipv4 = true;

View File

@@ -332,14 +332,15 @@ impl Network {
}
// See if this public address is also a local interface address we haven't registered yet
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if pdi_addr.ip() == *ip_addr {
let is_interface_address = (|| {
for ip_addr in self.get_usable_interface_addresses() {
if pdi_addr.ip() == ip_addr {
return true;
}
}
false
});
})();
if !local_dial_info_list.contains(&pdi) && is_interface_address {
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
@@ -428,15 +429,9 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if gsa.ip() == *ip_addr {
return true;
}
}
false
});
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
if !registered_addresses.contains(&gsa.ip())
&& self.is_usable_interface_address(gsa.ip())
{
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,
@@ -559,15 +554,9 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if gsa.ip() == *ip_addr {
return true;
}
}
false
});
if !registered_addresses.contains(&gsa.ip()) && is_interface_address {
if !registered_addresses.contains(&gsa.ip())
&& self.is_usable_interface_address(gsa.ip())
{
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,
@@ -679,15 +668,7 @@ impl Network {
}
// See if this public address is also a local interface address
let is_interface_address = self.with_interface_addresses(|ip_addrs| {
for ip_addr in ip_addrs {
if pdi_addr.ip() == *ip_addr {
return true;
}
}
false
});
if is_interface_address {
if self.is_usable_interface_address(pdi_addr.ip()) {
routing_table.register_dial_info(
RoutingDomain::LocalNetwork,
pdi,

View File

@@ -282,15 +282,12 @@ impl Network {
trace!("network stopped");
}
pub fn with_interface_addresses<F, R>(&self, f: F) -> R
where
F: FnOnce(&[IpAddr]) -> R,
{
f(&[])
pub fn is_usable_interface_address(&self, addr: IpAddr) -> bool {
false
}
pub async fn check_interface_addresses(&self) -> EyreResult<bool> {
Ok(false)
pub fn get_usable_interface_addresses(&self) -> Vec<IpAddr> {
Vec::new()
}
//////////////////////////////////////////

View File

@@ -8,14 +8,13 @@
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="1.8" />
<option name="gradleJvm" value="Embedded JDK" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Script adb+
# Usage
# You can run any command adb provide on all your current devices
# ./adb+ <command> is the equivalent of ./adb -s <serial number> <command>
#
# Examples
# ./adb+ version
# ./adb+ install apidemo.apk
# ./adb+ uninstall com.example.android.apis
adb devices | while read line
do
if [ ! "$line" = "" ] && [ `echo $line | awk '{print $2}'` = "device" ]
then
device=`echo $line | awk '{print $1}'`
echo "$device $@ ..."
adb -s $device $@
fi
done

View File

@@ -67,6 +67,7 @@ cargo {
targetDirectory = "../../../../../target"
prebuiltToolchains = true
profile = gradle.startParameter.taskNames.any{it.toLowerCase().contains("debug")} ? "debug" : "release"
pythonCommand = "python3"
features {
defaultAnd("android_tests", "rt-tokio")
}

View File

@@ -0,0 +1,2 @@
#!/bin/bash
./gradlew installDebug

View File

@@ -0,0 +1,3 @@
#!/bin/bash
./adb+.sh uninstall com.veilid.veilidcore.veilidcore_android_tests