Skip to content

selftest: migrate from expect to rust - #288

Merged
ddiss merged 13 commits into
rapido-linux:masterfrom
ddiss:selftest_rs
Nov 11, 2026
Merged

ddiss merged 13 commits into
rapido-linux:masterfrom
ddiss:selftest_rs

Conversation

@ddiss

@ddiss ddiss commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

The main reason for this patchset is that "expect" isn't installed on many systems by default, and it's unfamiliar for most people (including myself, despite writing the tests). std rust provides some nice abstractions for interacting with a spawned Command via stdin and stdout, so use them instead.

The selftests now run in parallel as part of regular cargo test, so they generally run much faster. However there may be problems on resource-constrained systems.

The following changes since commit 430d11e733dd61d81ee75dd3fe3fc729496e547e:

  rapido-cut: only install modprobe if kmods are gathered (2026-11-09 17:04:16 +1100)

are available in the Git repository at:

  https://github.com/ddiss/rapido.git selftest_rs

for you to fetch changes up to 7add062565d8d2e028f4b322063acb90bc5b0f08:

  docs: add rustfmt coding style expectation (2026-11-11 17:18:55 +1100)

----------------------------------------------------------------
David Disseldorp (13):
      cut: set rs bins PATH once in rapido wrapper
      test-utils: split TempDir helper into new crate
      selftest: migrate 001 to rust
      selftest: migrate 002 to rust
      selftest: migrate 003 to rust
      selftest: migrate 004 to rust
      selftest: migrate 005 to rust
      selftest: migrate 006 to rust
      ci: run new rs selftests via cargo test
      selftest: drop now unused selftest.sh harness
      rapido-vm: silence host stty stderr output
      docs: add Developer Certificate of Origin version 1.1 text
      docs: add rustfmt coding style expectation

 .github/workflows/ci.yml  |  17 +-
 Cargo.lock                |   5 +
 Cargo.toml                |   3 +-
 cut/cifs.sh               |   1 -
 cut/fstests_btrfs.sh      |   1 -
 cut/fstests_ext4.sh       |   1 -
 cut/fstests_ovl_xfs.sh    |   1 -
 cut/fstests_xfs.sh        |   1 -
 cut/kselftest.sh          |   1 -
 cut/ksmbd_btrfs.sh        |   1 -
 cut/libiscsi_test_tool.sh |   1 -
 cut/lio_local.sh          |   1 -
 cut/lkl_tests.sh          |   1 -
 cut/lklfuse_udev_usb.sh   |   1 -
 cut/simple_example.sh     |   1 -
 cut/simple_network.sh     |   1 -
 cut/simple_systemd.sh     |   1 -
 docs/contributing.md      |   5 +-
 docs/contributing_dco.txt |  34 ++++
 rapido                    |   5 +-
 selftest/selftest.sh      |  93 ----------
 selftest/test/001         |  22 ---
 selftest/test/002         |  34 ----
 selftest/test/003         |  92 ----------
 selftest/test/004         |  78 ---------
 selftest/test/005         |  34 ----
 selftest/test/006         |  20 ---
 src/bin/rapido-cut.rs     |  57 ++----
 src/bin/rapido-vm.rs      |   8 +-
 src/lib.rs                |  39 +----
 src/test-utils/Cargo.toml |   8 +
 src/test-utils/src/lib.rs |  38 ++++
 tests/selftest.rs         | 435 ++++++++++++++++++++++++++++++++++++++++++++++
 33 files changed, 559 insertions(+), 482 deletions(-)
 create mode 100644 docs/contributing_dco.txt
 delete mode 100755 selftest/selftest.sh
 delete mode 100755 selftest/test/001
 delete mode 100755 selftest/test/002
 delete mode 100755 selftest/test/003
 delete mode 100755 selftest/test/004
 delete mode 100755 selftest/test/005
 delete mode 100755 selftest/test/006
 create mode 100644 src/test-utils/Cargo.toml
 create mode 100644 src/test-utils/src/lib.rs
 create mode 100644 tests/selftest.rs

ddiss added 13 commits November 11, 2026 15:06
Cut scripts currently set PATH="target/release:${PATH}" prior to calling
the rapido-cut binary. This makes override difficult if we e.g. want to
trigger "target/debug" invocation.

This change drops cut/*.sh PATH setting and instead exports PATH from
the rapido wrapper script. RAPIDO_BIN_PATH can be used to e.g. specify
a "target/debug" path.

The intention is to use this from rust integration tests, where
"cargo test" only ensures that debug bins are compiled.

Signed-off-by: David Disseldorp <[email protected]>
TempDir is already used in a few places. This changes the src/lib.rs
and rapido-cut callers over to use the new crate. dracut-cpio isn't
switched, as it needs extra mutex behaviour for per-test chdir.

Signed-off-by: David Disseldorp <[email protected]>
expect isn't available by default on some distros, e.g. default Github
runners. This reimplementation uses cargo's integration test
functionality, which means that the selftests are run (in parallel) as
part of regular "cargo test".

./rapido invocation is currently done via (coreutils) "timeout".

Signed-off-by: David Disseldorp <[email protected]>
simple-example runner with separate cut + boot invocations.

Signed-off-by: David Disseldorp <[email protected]>
Boot two simple-example VMs in parallel. Check vm_num and pid files.

Signed-off-by: David Disseldorp <[email protected]>
Exercise -f and -x post-autorun cut parameters.

Signed-off-by: David Disseldorp <[email protected]>
Check net-conf hostnames are propagated through to VMs

Signed-off-by: David Disseldorp <[email protected]>
Cut+boot the simple-systemd runner and check for greeting and flag file.

Signed-off-by: David Disseldorp <[email protected]>
"cargo test" runs unit and integration tests, so split them into
separate --lib / --bin, and --test calls.

Signed-off-by: David Disseldorp <[email protected]>
"cargo test" now handles all selftests, complete with filter support.

Signed-off-by: David Disseldorp <[email protected]>
Under cargo test, "stty size" spits out:
  stty: 'standard input': Inappropriate ioctl for device
The function already has fallback to ignore errors, so silence the
stderr output.

Signed-off-by: David Disseldorp <[email protected]>
We shouldn't rely on external websites for contributor requirements.

Signed-off-by: David Disseldorp <[email protected]>
@ddiss

ddiss commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

v2:

  • fix rustfmt complaint
  • update docs to mention rustfmt style expectation and include DCO text

@ddiss
ddiss merged commit 7add062 into rapido-linux:master Nov 11, 2026
2 checks passed
@ddiss
ddiss deleted the selftest_rs branch November 11, 2026 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant