-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merges: #102
- Loading branch information
Showing
5 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[package] | ||
name = "riot-wrappers-test-shell" | ||
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" ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# name of your application | ||
APPLICATION = riot-wrappers-test-shell | ||
BOARD ?= native | ||
APPLICATION_RUST_MODULE = riot_wrappers_test_shell | ||
BASELIBS += $(APPLICATION_RUST_MODULE).module | ||
FEATURES_REQUIRED += rust_target | ||
|
||
USEMODULE += shell | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#![no_std] | ||
|
||
use core::fmt::Write; | ||
use riot_wrappers::println; | ||
use riot_wrappers::riot_main; | ||
use riot_wrappers::shell::CommandList; | ||
|
||
riot_main!(main); | ||
|
||
fn main() -> ! { | ||
let mut nonglobal_state = 0; | ||
|
||
// Not running anything fancy with run_once (where we could, for example, play around with | ||
// different buffer sizes) because . | ||
|
||
riot_wrappers::shell::new() | ||
.and( | ||
c"closure", | ||
c"Run a command that holds a mutable reference", | ||
|stdout, _args| { | ||
writeln!(stdout, "Previous state was {}", nonglobal_state).unwrap(); | ||
nonglobal_state += 1; | ||
writeln!(stdout, "New state is {}", nonglobal_state).unwrap(); | ||
}, | ||
) | ||
.run_forever() | ||
} | ||
|
||
fn do_echo(_stdio: &mut riot_wrappers::stdio::Stdio, args: riot_wrappers::shell::Args<'_>) { | ||
println!("Arguments:"); | ||
for a in args.iter() { | ||
println!("- {}", a); | ||
} | ||
} | ||
riot_wrappers::static_command!( | ||
echo, | ||
"echo", | ||
"Print the arguments in separate lines", | ||
do_echo | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import sys | ||
from testrunner import run | ||
|
||
def test(child): | ||
child.expect("> ") | ||
child.sendline("help") | ||
# Could also be the other sequence, we're not guaranteeing that | ||
commands = ["closure", "echo"] | ||
helps = ["Run a command that holds a mutable reference", "Print the arguments in separate lines"] | ||
command1 = child.expect(commands) | ||
help1 = child.expect(helps) | ||
command2 = child.expect(commands) | ||
help2 = child.expect(helps) | ||
if command1 != help1 or command2 != help2: | ||
print("Commands and helps were mixed up") | ||
sys.exit(1) | ||
child.expect("> ") | ||
child.sendline("echo foo bar") | ||
child.expect("- echo") | ||
child.expect("- foo") | ||
child.expect("- bar") | ||
child.expect("> ") | ||
child.sendline("closure") | ||
child.expect("New state is 1") | ||
child.expect("> ") | ||
child.sendline("closure") | ||
child.expect("New state is 2") | ||
|
||
if __name__ == "__main__": | ||
sys.exit(run(test)) |