From d1338f891cc3330b05b9de8d7bf5d68ddf181dc9 Mon Sep 17 00:00:00 2001 From: chrysn Date: Wed, 12 Jan 2022 12:05:52 +0100 Subject: [PATCH] tests: Add rust-as-a-module test Taken and simplified from shell test. --- tests/rust_libs/Makefile | 13 +++++++ tests/rust_libs/main.c | 1 + tests/rust_libs/tests/01-run.py | 68 +++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 tests/rust_libs/Makefile create mode 120000 tests/rust_libs/main.c create mode 100755 tests/rust_libs/tests/01-run.py diff --git a/tests/rust_libs/Makefile b/tests/rust_libs/Makefile new file mode 100644 index 000000000000..25b4606feaa4 --- /dev/null +++ b/tests/rust_libs/Makefile @@ -0,0 +1,13 @@ +include ../Makefile.tests_common + +USEMODULE += shell +USEMODULE += shell_commands +USEMODULE += rust_module_examples_shell_commands + +FEATURES_REQUIRED += rust_target + +# Currently unknown, something related to the LED_PORT definition that doesn't +# pass C2Rust's transpilation +BOARD_BLACKLIST := ek-lm4f120xl + +include $(RIOTBASE)/Makefile.include diff --git a/tests/rust_libs/main.c b/tests/rust_libs/main.c new file mode 120000 index 000000000000..c541a5892ab9 --- /dev/null +++ b/tests/rust_libs/main.c @@ -0,0 +1 @@ +../shell/main.c \ No newline at end of file diff --git a/tests/rust_libs/tests/01-run.py b/tests/rust_libs/tests/01-run.py new file mode 100755 index 000000000000..5ae6c09d5ed4 --- /dev/null +++ b/tests/rust_libs/tests/01-run.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +# Copyright (C) 2017 Alexandre Abadie +# 2022 Christian Amsüss +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. + +import sys +import os +from testrunner import run + + +EXPECTED_HELP = ( + 'Command Description', + '---------------------------------------', + 'bufsize Get the shell\'s buffer size', + 'start_test starts a test', + 'end_test ends a test', + 'echo prints the input command', + 'empty print nothing on command', + 'reboot Reboot the node', + 'version Prints current RIOT_VERSION', + 'pm interact with layered PM subsystem', + # That's what we're here for, the rest is what happens to be configured in + # the shell test this is derived from + 'ps.rs List the processes', + 'xfa_test1 xfa test command 1', + 'xfa_test2 xfa test command 2', +) + +EXPECTED_PSRS = ( + 'pri 7.*Running', +) + +PROMPT = '> ' + +CMDS = ( + ('start_test', '[TEST_START]'), + + # test default commands + ('help', EXPECTED_HELP), + ('ps.rs', EXPECTED_PSRS), + + ('end_test', '[TEST_END]'), +) + +CMDS_REGEX = {'ps.rs'} + +def check_cmd(child, cmd, expected): + regex = cmd in CMDS_REGEX + child.expect(PROMPT) + child.sendline(cmd) + for line in expected: + if regex: + child.expect(line) + else: + child.expect_exact(line) + +def testfunc(child): + # loop other defined commands and expected output + for cmd, expected in CMDS: + check_cmd(child, cmd, expected) + + +if __name__ == "__main__": + sys.exit(run(testfunc))