Skip to content

Commit

Permalink
tests: Add gnrc-pktbuf
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Oct 15, 2023
1 parent 1862792 commit 54b67f3
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/gnrc-pktbuf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "riot-wrappers-test-gnrc-pktbuf"
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 = { version = "*", features = [ "set_panic_handler", "panic_handler_format" ] }
riot-sys = "*"

[patch.crates-io]
riot-sys = { git = "https://github.com/RIOT-OS/rust-riot-sys" }
14 changes: 14 additions & 0 deletions tests/gnrc-pktbuf/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# name of your application
APPLICATION = riot-wrappers-test-gnrc-pktbuf
APPLICATION_RUST_MODULE = riot_wrappers_test_gnrc_pktbuf
BASELIBS += $(APPLICATION_RUST_MODULE).module
FEATURES_REQUIRED += rust_target

# FIXME: That's not a good criterion, gnrc_pktbuf can well stand alone
USEMODULE += gnrc
USEMODULE += gnrc_pktbuf

# thus we get `gnrc_pktbuf_is_empty` and `_is_sane`
CFLAGS += -DTEST_SUITES

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

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

riot_main!(main);

#[track_caller]
fn check() {
assert!(
unsafe { riot_sys::gnrc_pktbuf_is_sane() },
"GNRC packet buffer in unsound state"
);
}

#[track_caller]
fn check_empty() {
check();
assert!(
unsafe { riot_sys::gnrc_pktbuf_is_empty() },
"GNRC packet buffer should be empty at this point"
);
}

fn main() {
check_empty();

let snip1 = riot_wrappers::gnrc::pktbuf::Pktsnip::allocate(
128,
riot_sys::gnrc_nettype_t_GNRC_NETTYPE_UNDEF,
)
.unwrap();
println!("Allocated pktsnip {:?}", snip1);

check();

let snip2 = riot_wrappers::gnrc::pktbuf::Pktsnip::allocate_from(
&[1, 2, 3, 4],
riot_sys::gnrc_nettype_t_GNRC_NETTYPE_UNDEF,
)
.unwrap();
println!("Allocated another pktsnip {:?}", snip2);
let snip2 = snip2
.add(10, riot_sys::gnrc_nettype_t_GNRC_NETTYPE_UNDEF)
.unwrap();
println!("... and prefixed it with 10 bytes into {:?}", snip2);

check();

drop(snip1);
drop(snip2);
println!("Dropped it");

check_empty();

println!("Tests completed.");
}
10 changes: 10 additions & 0 deletions tests/gnrc-pktbuf/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3

import sys
from testrunner import run

def test(child):
child.expect_exact("Tests completed.")

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

0 comments on commit 54b67f3

Please sign in to comment.