Skip to content

Commit

Permalink
Automate testing of serial-device example
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Mar 20, 2024
1 parent 466c8de commit 62c974e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
16 changes: 14 additions & 2 deletions hacking/nix/scope/world/instances/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,27 @@ 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;
};
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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=5)
time.sleep(1)
child.send('xxx')
child.expect('\[x\]\[x\]\[x\]', timeout=5)
print()

if __name__ == '__main__':
main()

0 comments on commit 62c974e

Please sign in to comment.