Skip to content

Commit

Permalink
tests: Add some netif/nib processing
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Aug 30, 2024
1 parent 986e11e commit 7eff52a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/network-properties/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "riot-wrappers-test-networkproperties"
version = "0.1.0"
authors = ["Christian Amsüss <[email protected]>"]
edition = "2021"
publish = false

[lib]
crate-type = ["staticlib"]

[profile.release]
panic = "abort"

[dependencies]
riot-wrappers = { path = "../..", features = [ "set_panic_handler", "panic_handler_format" ] }
21 changes: 21 additions & 0 deletions tests/network-properties/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# name of your application
APPLICATION = riot-wrappers-test-networkproperties
BOARD ?= native
APPLICATION_RUST_MODULE = riot_wrappers_test_networkproperties
BASELIBS += $(APPLICATION_RUST_MODULE).module
FEATURES_REQUIRED += rust_target

# This may not be a GNRC netdev in all cases; when it is not, the test will
# break, and that will be the time to split it. So far, also IPv6 support can
# just be assumed. (Really, anyone writing an IoT application without IPv6
# support may want to look into Cobol).
USEMODULE += netdev_default
USEMODULE += auto_init_gnrc_netif
USEMODULE += gnrc_ipv6_default
# This is an easy way to visibly populate entries into the neighbor cache: ping
# the RIOT instance.
USEMODULE += gnrc_icmpv6_echo

USEMODULE += ztimer_msec

include $(RIOTBASE)/Makefile.include
41 changes: 41 additions & 0 deletions tests/network-properties/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#![no_std]

use riot_wrappers::println;
use riot_wrappers::riot_main;

riot_main!(main);

fn main() {
use riot_wrappers::ztimer::*;

let msec = Clock::msec();

loop {
for netif in riot_wrappers::gnrc::Netif::all() {
println!(
"Netif at PID {:?} with link-layer addr {:?}",
netif.pid(),
netif.l2addr()
);
for addr in &netif.ipv6_addrs().unwrap() {
println!("- Address {:?}", addr);
}
}

println!("Cache entries:");
for cache_entry in riot_wrappers::gnrc::nib::NcEntry::all() {
println!(
"- on interface {:?}: {:02x?} <=> {:?}, router? {:?}, NUD {:?}, AR {:?}",
cache_entry.iface(),
cache_entry.l2addr(),
cache_entry.ipv6_addr(),
cache_entry.is_router(),
cache_entry.nud_state(),
cache_entry.ar_state()
);
}
println!("");

msec.sleep(Ticks(300));
}
}
15 changes: 15 additions & 0 deletions tests/network-properties/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3

import os
import sys
from testrunner import run

def test(child):
# Cant' make any predictions about network addresses, but showing them
# should not crash.
for _ in range(3):
child.expect("Netif at ")
child.expect("Cache entries")

if __name__ == "__main__":
sys.exit(run(test))

0 comments on commit 7eff52a

Please sign in to comment.