diff --git a/crates/examples/root-task/serial-device/src/main.rs b/crates/examples/root-task/serial-device/src/main.rs index 4675a3f62..cbdba1f3e 100644 --- a/crates/examples/root-task/serial-device/src/main.rs +++ b/crates/examples/root-task/serial-device/src/main.rs @@ -128,11 +128,11 @@ fn main(bootinfo: &sel4::BootInfoPtr) -> sel4::Result { irq_notification_cap.wait(); - let c = serial_device.get_char().unwrap(); - - serial_device.put_char(b'['); - serial_device.put_char(c); - serial_device.put_char(b']'); + while let Some(c) = serial_device.get_char() { + serial_device.put_char(b'['); + serial_device.put_char(c); + serial_device.put_char(b']'); + } } } diff --git a/hacking/nix/scope/world/instances/default.nix b/hacking/nix/scope/world/instances/default.nix index 0e5674cf5..5c81a68d5 100644 --- a/hacking/nix/scope/world/instances/default.nix +++ b/hacking/nix/scope/world/instances/default.nix @@ -346,7 +346,7 @@ in rec { }; }); - serial-device = maybe (haveFullRuntime && hostPlatform.isAarch) (mkInstance { + serial-device = maybe (haveFullRuntime && hostPlatform.isAarch) (lib.fix (self: mkInstance { rootTask = mkTask { rootCrate = crates.serial-device; release = false; @@ -354,7 +354,19 @@ in rec { extraPlatformArgs = lib.optionalAttrs canSimulate { canAutomateSimply = true; }; - }); + } // lib.optionalAttrs canSimulate rec { + automate = + let + py = buildPackages.python3.withPackages (pkgs: [ + pkgs.pexpect + ]); + in + writeScript "automate" '' + #!${buildPackages.runtimeShell} + set -eu + ${py}/bin/python3 ${./test-automation-scripts/serial-device.py} ${self.simulate} + ''; + })); spawn-thread = maybe haveFullRuntime (mkInstance { rootTask = mkTask { diff --git a/hacking/nix/scope/world/instances/test-automation-scripts/serial-device.py b/hacking/nix/scope/world/instances/test-automation-scripts/serial-device.py new file mode 100644 index 000000000..f27a7ee9a --- /dev/null +++ b/hacking/nix/scope/world/instances/test-automation-scripts/serial-device.py @@ -0,0 +1,28 @@ +# +# Copyright 2023, Colias Group, LLC +# +# SPDX-License-Identifier: BSD-2-Clause +# + +import sys +import time +import argparse +import pexpect + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('simulate') + args = parser.parse_args() + run(args) + +def run(args): + child = pexpect.spawn(args.simulate, encoding='utf-8') + child.logfile = sys.stdout + child.expect('echo> ', timeout=10) + time.sleep(5) + child.sendline('xxx') + child.expect('[x][x][x]', timeout=10) + print() + +if __name__ == '__main__': + main()