From c235cb62beefd03087e7cfc7f7f55f0c7c6601c9 Mon Sep 17 00:00:00 2001 From: Lena Date: Sat, 1 Aug 2026 00:00:00 +0000 Subject: Enter vmm A QEMU/KVM virtual machine manager in one POSIX shell script. Each VM is a directory of plain files under $VMMDIR, configured by a hand-edited KEY=VALUE file that is parsed rather than sourced, so nothing in it can inject a raw QEMU argument. Control is a QMP FIFO pair inside that directory, guarded by its permissions alone; nothing binds a TCP port. The tests are TAP without a framework and boot real guests where the host allows. --- tests/config | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 tests/config (limited to 'tests/config') diff --git a/tests/config b/tests/config new file mode 100644 index 0000000..2229bf5 --- /dev/null +++ b/tests/config @@ -0,0 +1,187 @@ +# The config parser, against hostile input. dryrun is the parser's only +# observable behaviour, so every case runs through it. + +"$VMM" create cfg1 64M >/dev/null 2>&1 + +: > "$VMMDIR/cfg1/config" +exits 0 "minimal config parses" dryrun cfg1 + +cfg cfg1 < "$VMMDIR/cfg1/config" +refuses 'config:2: NUL byte' "a NUL byte is refused on its own line" dryrun cfg1 + +# The parser is byte oriented whatever the caller's locale says, or a +# multibyte character passes for one printable character. +printf 'CDROM="/tmp/\303\251.iso"\n' > "$VMMDIR/cfg1/config" +out=$(env LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 "$VMM" dryrun cfg1 2>&1) && got=0 || got=$? +if [ "$got" != 0 ] && printf '%s' "$out" | grep -q 'non-printable'; then + ok "a UTF-8 byte is refused under a UTF-8 locale" +else + notok "a UTF-8 byte is refused under a UTF-8 locale" "exit $got: $out" +fi + +# A final line with no trailing newline must still be seen. +printf 'CPUS=3' > "$VMMDIR/cfg1/config" +outputs "-smp '3'" "final line without a newline is parsed" dryrun cfg1 + +# CRLF must not leak into a value. +printf 'CPUS=4\r\n' > "$VMMDIR/cfg1/config" +outputs "-smp '4'" "CRLF line endings are handled" dryrun cfg1 + +# An unreadable config must say so, not blame a key it never got to read. +chmod 000 "$VMMDIR/cfg1/config" +refuses 'not readable' "an unreadable config names the real problem" dryrun cfg1 +chmod 600 "$VMMDIR/cfg1/config" + +# edit exists to re-read the config once the editor has been through it, +# which is the only reason to run one from here. EDITOR=true is exported +# by the harness, so what is left of edit is the check. +: > "$VMMDIR/cfg1/config" +exits 0 "edit re-validates the config it just wrote" edit cfg1 +outputs 'config ok' "edit says so when the config parses" edit cfg1 + +cfg cfg1 <