mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-10-21 23:28:19 +00:00
c6fc094c93
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>
87 lines
3.3 KiB
Bash
87 lines
3.3 KiB
Bash
#!/usr/bin/env bats
|
|
#
|
|
# genesis-metrics runs in the OpenEmbedded Genesis image and records the boot-ready time and
|
|
# memory use. oe/report runs on the build host and reports the image sizes with those metrics,
|
|
# and the growth against a baseline. Inputs are scratch files named by environment variables.
|
|
|
|
load 'helpers/shell_source'
|
|
|
|
INIT_FILES='xCAT-genesis-base/oe/meta-xcat-genesis/recipes-core/xcat-genesis-init/files'
|
|
|
|
setup()
|
|
{
|
|
METRICS="$(require_repo_file "$INIT_FILES/genesis-metrics")"
|
|
REPORT="$(require_repo_file 'xCAT-genesis-base/oe/report')"
|
|
export XCAT_REGISTRATION_STATUS_FILE="$BATS_TEST_TMPDIR/registration.env"
|
|
export XCAT_MEMINFO_FILE="$BATS_TEST_TMPDIR/meminfo"
|
|
export XCAT_UPTIME_FILE="$BATS_TEST_TMPDIR/uptime"
|
|
runtime="$BATS_TEST_TMPDIR/metrics.env"
|
|
printf 'SCHEMA=1\nSTATE=ACTION_RECEIVED\nDETAIL=Destiny shell\nUPDATED_SECONDS=42\n' \
|
|
>"$XCAT_REGISTRATION_STATUS_FILE"
|
|
printf 'MemTotal: 1048576 kB\nMemFree: 524288 kB\nMemAvailable: 786432 kB\n' \
|
|
>"$XCAT_MEMINFO_FILE"
|
|
printf '45.92 12.34\n' >"$XCAT_UPTIME_FILE"
|
|
|
|
image_dir="$BATS_TEST_TMPDIR/image"
|
|
mkdir -p "$image_dir"
|
|
printf 'kernel\n' >"$image_dir/kernel"
|
|
printf 'cpio payload\n' | gzip -c >"$image_dir/initramfs.cpio.gz"
|
|
}
|
|
|
|
EXPECTED_RUNTIME='SCHEMA=1
|
|
BOOT_READY_SECONDS=42
|
|
CAPTURE_UPTIME_SECONDS=45
|
|
MEMORY_TOTAL_KIB=1048576
|
|
MEMORY_AVAILABLE_KIB=786432
|
|
MEMORY_USED_KIB=262144'
|
|
|
|
# The value of one NAME=VALUE line of $output.
|
|
value()
|
|
{
|
|
sed -n "s/^$1=//p" <<<"$output"
|
|
}
|
|
|
|
@test "runtime metrics are collected: boot time and memory use" {
|
|
run "$METRICS"
|
|
[ "$status" -eq 0 ]
|
|
[ "$(sort <<<"$output")" = "$(sort <<<"$EXPECTED_RUNTIME")" ]
|
|
}
|
|
|
|
@test "runtime metrics are stored atomically, complete and readable" {
|
|
run "$METRICS" --output "$runtime"
|
|
[ "$status" -eq 0 ]
|
|
[ "$(cat "$runtime")" = "$EXPECTED_RUNTIME" ]
|
|
[ "$(stat -c %a "$runtime")" = 644 ]
|
|
}
|
|
|
|
@test "image and runtime metrics are reported together" {
|
|
"$METRICS" --output "$runtime"
|
|
run "$REPORT" --runtime "$runtime" x86_64 "$image_dir"
|
|
[ "$status" -eq 0 ]
|
|
[ "$(value ARCHITECTURE)" = x86_64 ]
|
|
[ "$(value KERNEL_BYTES)" = "$(stat -c %s "$image_dir/kernel")" ]
|
|
[ "$(value COMPRESSED_INITRAMFS_BYTES)" = "$(stat -c %s "$image_dir/initramfs.cpio.gz")" ]
|
|
[ "$(value UNPACKED_INITRAMFS_BYTES)" = 13 ]
|
|
[ "$(value BOOT_READY_SECONDS)" = 42 ]
|
|
[ "$(value MEMORY_USED_KIB)" = 262144 ]
|
|
}
|
|
|
|
@test "the report compares against a matching baseline and reports the growth" {
|
|
"$METRICS" --output "$runtime"
|
|
baseline="$BATS_TEST_TMPDIR/baseline.env"
|
|
{
|
|
printf 'SCHEMA=1\nARCHITECTURE=x86_64\n'
|
|
printf 'KERNEL_BYTES=%d\n' $(($(stat -c %s "$image_dir/kernel") - 2))
|
|
printf 'COMPRESSED_INITRAMFS_BYTES=%d\n' $(($(stat -c %s "$image_dir/initramfs.cpio.gz") - 3))
|
|
printf 'UNPACKED_INITRAMFS_BYTES=%d\n' $((13 - 4))
|
|
printf 'BOOT_READY_SECONDS=40\nMEMORY_USED_KIB=250000\n'
|
|
} >"$baseline"
|
|
run "$REPORT" --runtime "$runtime" --baseline "$baseline" x86_64 "$image_dir"
|
|
[ "$status" -eq 0 ]
|
|
[ "$(value KERNEL_BYTES_DELTA)" = 2 ]
|
|
[ "$(value COMPRESSED_INITRAMFS_BYTES_DELTA)" = 3 ]
|
|
[ "$(value UNPACKED_INITRAMFS_BYTES_DELTA)" = 4 ]
|
|
[ "$(value BOOT_READY_SECONDS_DELTA)" = 2 ]
|
|
[ "$(value MEMORY_USED_KIB_DELTA)" = 12144 ]
|
|
}
|