Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert QEMU testing to use rexpect #1832

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ members = [
]
exclude = [
"tools/alert_codes",
"tools/qemu-runner",
"tools/sha256sum",
"tools/usb/bulk-echo",
"tools/usb/bulk-echo-fast",
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,7 @@ emulation-setup:
.PHONY: emulation-check
emulation-check: emulation-setup
@$(MAKE) -C "boards/hifive1"
$(eval TMPFILE := $(shell mktemp))
@PATH="${PATH}:../../tools/qemu/riscv32-softmmu/" timeout --foreground 10s $(MAKE) qemu -C "boards/hifive1" | tee $(TMPFILE) > /dev/null
grep "Entering main loop" $(TMPFILE) > /dev/null;
rm "$(TMPFILE)"
@cd tools/qemu-runner; PATH="$(shell pwd)/tools/qemu/riscv32-softmmu/:${PATH}" cargo run

.PHONY: clean
clean:
Expand Down
8 changes: 8 additions & 0 deletions tools/qemu-runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "qemu-runner"
version = "0.1.0"
authors = ["Tock Project Developers <tock-dev@googlegroups.com>"]
edition = "2018"

[dependencies]
rexpect = "0.3.0"
28 changes: 28 additions & 0 deletions tools/qemu-runner/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use rexpect::errors::Error;
use rexpect::session::PtySession;
use rexpect::spawn;

fn kill_qemu(p: &mut PtySession) -> Result<(), Error> {
p.send_control('a')?;
p.send("x")?;
p.flush()?;

Ok(())
}

fn hifive1() -> Result<(), Error> {
let mut p = spawn("make qemu -C ../../boards/hifive1", Some(3_000))?;

p.exp_string("HiFive1 initialization complete.")?;
p.exp_string("Entering main loop.")?;

// Test completed, kill QEMU
kill_qemu(&mut p)?;

p.exp_eof()?;
Ok(())
}

fn main() {
hifive1().unwrap_or_else(|e| panic!("hifive1 job failed with {}", e));
}