Skip to content

Commit

Permalink
Merge pull request #1960 from embassy-rs/test-eth-2
Browse files Browse the repository at this point in the history
Net fixes
  • Loading branch information
Dirbaio authored Sep 28, 2023
2 parents 901d31e + 6b3745f commit e538aea
Show file tree
Hide file tree
Showing 14 changed files with 260 additions and 698 deletions.
1 change: 1 addition & 0 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ cargo batch \
--- build --release --manifest-path tests/riscv32/Cargo.toml --target riscv32imac-unknown-none-elf \
$BUILD_EXTRA

rm out/tests/nrf52840-dk/wifi_esp_hosted_perf

if [[ -z "${TELEPROBE_TOKEN-}" ]]; then
echo No teleprobe token found, skipping running HIL tests
Expand Down
6 changes: 3 additions & 3 deletions embassy-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> HardwareAddress
}
}

impl<D: Driver + 'static> Stack<D> {
impl<D: Driver> Stack<D> {
/// Create a new network stack.
pub fn new<const SOCK: usize>(
mut device: D,
Expand Down Expand Up @@ -555,7 +555,7 @@ impl<D: Driver + 'static> Stack<D> {
}

#[cfg(feature = "igmp")]
impl<D: Driver + 'static> Stack<D> {
impl<D: Driver> Stack<D> {
/// Join a multicast group.
pub async fn join_multicast_group<T>(&self, addr: T) -> Result<bool, MulticastError>
where
Expand Down Expand Up @@ -645,7 +645,7 @@ impl SocketStack {
}
}

impl<D: Driver + 'static> Inner<D> {
impl<D: Driver> Inner<D> {
#[cfg(feature = "proto-ipv4")]
pub fn set_config_v4(&mut self, _s: &mut SocketStack, config: ConfigV4) {
// Handle static config.
Expand Down
4 changes: 1 addition & 3 deletions embassy-stm32/src/eth/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ impl interrupt::typelevel::Handler<interrupt::typelevel::ETH> for InterruptHandl
}
}

const MTU: usize = 1514; // 14 Ethernet header + 1500 IP packet

pub struct Ethernet<'d, T: Instance, P: PHY> {
_peri: PeripheralRef<'d, T>,
pub(crate) tx: TDesRing<'d>,
Expand Down Expand Up @@ -163,7 +161,7 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
dma.dmactx_cr().modify(|w| w.set_txpbl(1)); // 32 ?
dma.dmacrx_cr().modify(|w| {
w.set_rxpbl(1); // 32 ?
w.set_rbsz(MTU as u16);
w.set_rbsz(RX_BUFFER_SIZE as u16);
});

// NOTE(unsafe) We got the peripheral singleton, which means that `rcc::init` was called
Expand Down
2 changes: 1 addition & 1 deletion tests/nrf/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ runner = "teleprobe client run"
target = "thumbv7em-none-eabi"

[env]
DEFMT_LOG = "trace"
DEFMT_LOG = "trace,embassy_hal_internal=debug,embassy_net_esp_hosted=debug,smoltcp=info"
1 change: 1 addition & 0 deletions tests/nrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60",
embedded-hal-async = { version = "1.0.0-rc.1" }
embedded-hal-bus = { version = "0.1.0-rc.1", features = ["async"] }
static_cell = { version = "1.1", features = [ "nightly" ] }
perf-client = { path = "../perf-client" }

defmt = "0.3"
defmt-rtt = "0.4"
Expand Down
182 changes: 12 additions & 170 deletions tests/nrf/src/bin/ethernet_enc28j60_perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
teleprobe_meta::target!(b"ak-gwe-r7");
teleprobe_meta::timeout!(120);

use defmt::{error, info, unwrap};
use defmt::{info, unwrap};
use embassy_executor::Spawner;
use embassy_futures::join::join;
use embassy_net::tcp::TcpSocket;
use embassy_net::{Ipv4Address, Stack, StackResources};
use embassy_net::{Stack, StackResources};
use embassy_net_enc28j60::Enc28j60;
use embassy_nrf::gpio::{Level, Output, OutputDrive};
use embassy_nrf::rng::Rng;
use embassy_nrf::spim::{self, Spim};
use embassy_nrf::{bind_interrupts, peripherals};
use embassy_time::{with_timeout, Delay, Duration, Timer};
use embassy_time::Delay;
use embedded_hal_bus::spi::ExclusiveDevice;
use static_cell::make_static;
use {defmt_rtt as _, panic_probe as _};
Expand Down Expand Up @@ -79,172 +77,16 @@ async fn main(spawner: Spawner) {

unwrap!(spawner.spawn(net_task(stack)));

info!("Waiting for DHCP up...");
while stack.config_v4().is_none() {
Timer::after(Duration::from_millis(100)).await;
}
info!("IP addressing up!");

let down = test_download(stack).await;
let up = test_upload(stack).await;
let updown = test_upload_download(stack).await;

assert!(down > TEST_EXPECTED_DOWNLOAD_KBPS);
assert!(up > TEST_EXPECTED_UPLOAD_KBPS);
assert!(updown > TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS);
perf_client::run(
stack,
perf_client::Expected {
down_kbps: 200,
up_kbps: 200,
updown_kbps: 150,
},
)
.await;

info!("Test OK");
cortex_m::asm::bkpt();
}

const TEST_DURATION: usize = 10;
const TEST_EXPECTED_DOWNLOAD_KBPS: usize = 200;
const TEST_EXPECTED_UPLOAD_KBPS: usize = 200;
const TEST_EXPECTED_UPLOAD_DOWNLOAD_KBPS: usize = 150;
const RX_BUFFER_SIZE: usize = 4096;
const TX_BUFFER_SIZE: usize = 4096;
const SERVER_ADDRESS: Ipv4Address = Ipv4Address::new(192, 168, 2, 2);
const DOWNLOAD_PORT: u16 = 4321;
const UPLOAD_PORT: u16 = 4322;
const UPLOAD_DOWNLOAD_PORT: u16 = 4323;

async fn test_download(stack: &'static Stack<MyDriver>) -> usize {
info!("Testing download...");

let mut rx_buffer = [0; RX_BUFFER_SIZE];
let mut tx_buffer = [0; TX_BUFFER_SIZE];
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.set_timeout(Some(Duration::from_secs(10)));

info!("connecting to {:?}:{}...", SERVER_ADDRESS, DOWNLOAD_PORT);
if let Err(e) = socket.connect((SERVER_ADDRESS, DOWNLOAD_PORT)).await {
error!("connect error: {:?}", e);
return 0;
}
info!("connected, testing...");

let mut rx_buf = [0; 4096];
let mut total: usize = 0;
with_timeout(Duration::from_secs(TEST_DURATION as _), async {
loop {
match socket.read(&mut rx_buf).await {
Ok(0) => {
error!("read EOF");
return 0;
}
Ok(n) => total += n,
Err(e) => {
error!("read error: {:?}", e);
return 0;
}
}
}
})
.await
.ok();

let kbps = (total + 512) / 1024 / TEST_DURATION;
info!("download: {} kB/s", kbps);
kbps
}

async fn test_upload(stack: &'static Stack<MyDriver>) -> usize {
info!("Testing upload...");

let mut rx_buffer = [0; RX_BUFFER_SIZE];
let mut tx_buffer = [0; TX_BUFFER_SIZE];
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.set_timeout(Some(Duration::from_secs(10)));

info!("connecting to {:?}:{}...", SERVER_ADDRESS, UPLOAD_PORT);
if let Err(e) = socket.connect((SERVER_ADDRESS, UPLOAD_PORT)).await {
error!("connect error: {:?}", e);
return 0;
}
info!("connected, testing...");

let buf = [0; 4096];
let mut total: usize = 0;
with_timeout(Duration::from_secs(TEST_DURATION as _), async {
loop {
match socket.write(&buf).await {
Ok(0) => {
error!("write zero?!??!?!");
return 0;
}
Ok(n) => total += n,
Err(e) => {
error!("write error: {:?}", e);
return 0;
}
}
}
})
.await
.ok();

let kbps = (total + 512) / 1024 / TEST_DURATION;
info!("upload: {} kB/s", kbps);
kbps
}

async fn test_upload_download(stack: &'static Stack<MyDriver>) -> usize {
info!("Testing upload+download...");

let mut rx_buffer = [0; RX_BUFFER_SIZE];
let mut tx_buffer = [0; TX_BUFFER_SIZE];
let mut socket = TcpSocket::new(stack, &mut rx_buffer, &mut tx_buffer);
socket.set_timeout(Some(Duration::from_secs(10)));

info!("connecting to {:?}:{}...", SERVER_ADDRESS, UPLOAD_DOWNLOAD_PORT);
if let Err(e) = socket.connect((SERVER_ADDRESS, UPLOAD_DOWNLOAD_PORT)).await {
error!("connect error: {:?}", e);
return 0;
}
info!("connected, testing...");

let (mut reader, mut writer) = socket.split();

let tx_buf = [0; 4096];
let mut rx_buf = [0; 4096];
let mut total: usize = 0;
let tx_fut = async {
loop {
match writer.write(&tx_buf).await {
Ok(0) => {
error!("write zero?!??!?!");
return 0;
}
Ok(_) => {}
Err(e) => {
error!("write error: {:?}", e);
return 0;
}
}
}
};

let rx_fut = async {
loop {
match reader.read(&mut rx_buf).await {
Ok(0) => {
error!("read EOF");
return 0;
}
Ok(n) => total += n,
Err(e) => {
error!("read error: {:?}", e);
return 0;
}
}
}
};

with_timeout(Duration::from_secs(TEST_DURATION as _), join(tx_fut, rx_fut))
.await
.ok();

let kbps = (total + 512) / 1024 / TEST_DURATION;
info!("upload+download: {} kB/s", kbps);
kbps
}
Loading

0 comments on commit e538aea

Please sign in to comment.