2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-10-22 07:38:08 +00:00
Files
xcat-core/xCAT-test/bats/genesis_openembedded_bmcsetup.bats
T
Daniel Hilst c6fc094c93 fix(xcat-core): test Genesis shell and C code by running it, not from Perl
The Perl tests of the OpenEmbedded Genesis image ran its shell scripts
and C programs through system(), qx, pipes and fork, wrote fake
commands through copied read_file and write_file helpers, and matched
regexes against shell and C source. Many rejections checked only a
non-zero exit, so an earlier, unrelated failure also passed. The
quality gate judged 91% of their 762 checks bad.

The shell and C checks move to bats in xCAT-test/bats. The C programs
are compiled there and run: the plain console, test drivers for the
shared status view and the shell launcher, and genesis-udp-send against
a loopback listener. Each rejection now matches the message of its own
guard. The .t files keep the artifact checks (kas, recipes, kernel
fragments, units, README), read with XCAT::Test::File. Test files left
with no checks are deleted.

Claim map (file -> where its claims went):
- go_xcat_uninstall_installed_only.t -> go_xcat_uninstall_installed_only.bats
- genesis_readme_paths.t, genesis_base_sources_staged.t -> kept in the
  .t (README read by slurp_repo_file, tarball read by Archive::Tar)
- genesis_openembedded_{export,hardware,runtime}.t -> the bats file of
  the same name
- genesis_openembedded_{bmcsetup,metrics,extensions,qeth,actions,
  discovery}.t -> scripts to the bats file of the same name, recipes
  and units kept in the .t
- genesis_openembedded_console.t -> built and run checks, state.c,
  plain_ui.c and shell.c to genesis_openembedded_console.bats; Newt
  source checks kept in the .t
- genesis_openembedded.t -> oe/build to genesis_openembedded_build.bats;
  shell matches to the runtime, hardware and extensions bats; console
  matches to the console bats or the console .t; artifacts kept

Red proof: every moved or new test was run against a mutated copy of
the code it covers and went red, for example: rpm -q not checked,
tar without --mtime, VEX report not exported, support dir after PATH,
digest check off, layer2 forced, wildcard device allowed, arguments
eval'd, tcp probe skipped, SOURCE_PORT 302, AF_INET only, stage timer
compared, launch error ignored, kas run twice, status written in place.
One mutation stayed green: tar without --owner=0 when the test runs as
root.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-09-24 22:00:28 -03:00

40 lines
1.5 KiB
Bash

#!/usr/bin/env bats
#
# The OpenEmbedded Genesis image runs the legacy BMC scripts through the genesis-bmcsetup
# wrapper. The wrapper puts the BMC support commands first in PATH and starts the packaged
# implementation with the arguments it was given.
load 'helpers/shell_source'
BMC_FILES='xCAT-genesis-base/oe/meta-xcat-genesis/recipes-xcat/xcat-genesis-bmcsetup/files'
@test "the legacy BMC scripts are valid Bash" {
for script in bmcsetup getipmi remoteimmsetup; do
/bin/bash -n "$(require_repo_file "xCAT-genesis-scripts/usr/bin/$script")"
done
}
@test "the BMC action helpers are valid Bash" {
/bin/bash -n "$(require_repo_file "$BMC_FILES/genesis-bmcsetup")"
/bin/bash -n "$(require_repo_file "$BMC_FILES/genesis-credential-wait")"
}
@test "the BMC action starts the packaged implementation, support commands first, arguments kept" {
wrapper="$(require_repo_file "$BMC_FILES/genesis-bmcsetup")"
support_dir="$BATS_TEST_TMPDIR/support"
log="$BATS_TEST_TMPDIR/wrapper.log"
mkdir -p "$support_dir"
cat >"$BATS_TEST_TMPDIR/implementation" <<'SH'
#!/bin/bash
printf 'path=%s\n' "$PATH" >"$XCAT_TEST_LOG"
printf 'arguments=%s\n' "$*" >>"$XCAT_TEST_LOG"
SH
XCAT_BMC_SUPPORT_DIR="$support_dir" \
XCAT_BMC_SETUP_IMPLEMENTATION="$BATS_TEST_TMPDIR/implementation" \
XCAT_TEST_LOG="$log" \
run /bin/bash "$wrapper" first second
[ "$status" -eq 0 ]
grep -q "^path=$support_dir:" "$log"
grep -qx 'arguments=first second' "$log"
}