Skip to content

Commit 02784af

Browse files
oshovalcursoragent
andcommitted
test: add unit tests for find_rpm_linux_srcdir
Simulate RPM BUILD directory layouts across distros to validate the source extraction logic introduced in the previous commit: - Flat layout (Fedora < 42, RHEL 9, aarch64 variant) - Nested layout (Fedora 42+, aarch64 variant) - configs/ directory exclusion - Error cases: ambiguous matches, missing source, excessive depth Signed-off-by: Or Shoval <oshoval@redhat.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 93c0a18 commit 02784af

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
# Test find_rpm_linux_srcdir() from kpatch-build.
3+
#
4+
# Verifies source directory detection across RPM BUILD layouts:
5+
# Flat: BUILD/kernel-6.12.0/linux-6.12.0-100.fc41.x86_64/ (Fedora <42, RHEL, CentOS)
6+
# Nested: BUILD/kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64/ (Fedora 42+)
7+
set -euo pipefail
8+
9+
SCRIPT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
10+
11+
# Stub kpatch-build helpers so die doesn't exit and logger doesn't need a logfile.
12+
die() { echo "die: $*" >&2; return 1; }
13+
logger() { cat >/dev/null; }
14+
15+
source "$SCRIPT_DIR/kpatch-build/kpatch-funcs.sh"
16+
17+
TESTDIR=$(mktemp -d)
18+
trap 'rm -rf "$TESTDIR"' EXIT
19+
ERRORS=0
20+
21+
# Create a BUILD tree, run find_rpm_linux_srcdir, check result.
22+
# $1 = test name
23+
# $2 = expected: "ok" (source moved) or "fail" (die called)
24+
# $3... = paths to create under BUILD/
25+
assert_layout() {
26+
local name="$1" expect="$2"; shift 2
27+
local dir="$TESTDIR/$name"
28+
local rc=0
29+
30+
mkdir -p "$dir/BUILD" "$dir/dest"
31+
for p in "$@"; do mkdir -p "$dir/BUILD/$p"; done
32+
33+
RPMTOPDIR="$dir" KERNEL_SRCDIR="$dir/dest/linux" \
34+
find_rpm_linux_srcdir 2>/dev/null || rc=$?
35+
36+
case "$expect" in
37+
ok) [[ $rc -eq 0 && -d "$dir/dest/linux" ]] || { echo "FAIL $name"; ((ERRORS++)); return; } ;;
38+
fail) [[ $rc -ne 0 ]] || { echo "FAIL $name — expected error"; ((ERRORS++)); return; } ;;
39+
esac
40+
echo "ok $name"
41+
}
42+
43+
# Flat layout: Fedora 41 / RHEL / CentOS
44+
assert_layout "flat-fc41-x86_64" ok "kernel-6.12.0/linux-6.12.0-100.fc41.x86_64"
45+
assert_layout "flat-fc41-aarch64" ok "kernel-6.12.0/linux-6.12.0-100.fc41.aarch64"
46+
assert_layout "flat-rhel9" ok "kernel-5.14.0/linux-5.14.0-362.el9.x86_64"
47+
48+
# Nested layout: Fedora 42+
49+
assert_layout "nested-fc42" ok "kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64"
50+
assert_layout "nested-fc42-arm" ok "kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.aarch64"
51+
52+
# configs/linux-* dirs must be ignored by the nested search
53+
assert_layout "nested-with-configs" ok "kernel-6.14.0-build/configs/linux-extra" \
54+
"kernel-6.14.0-build/kernel-6.14/linux-6.14.0-63.fc42.x86_64"
55+
56+
# Error: ambiguous (multiple matches)
57+
assert_layout "multi-flat" fail "kernel-6.14.0/linux-6.14.0-aaa" \
58+
"kernel-6.14.0/linux-6.14.0-bbb"
59+
assert_layout "multi-nested" fail "kernel-6.14.0-build/kernel-6.14/linux-aaa" \
60+
"kernel-6.14.0-build/kernel-6.14/linux-bbb"
61+
62+
# Error: nothing to find
63+
assert_layout "empty-build" fail
64+
assert_layout "no-linux-dir" fail "kernel-6.14.0-build/kernel-6.14/sources"
65+
assert_layout "too-deep" fail "a/b/c/d/linux-6.14.0"
66+
67+
echo ""
68+
[[ $ERRORS -gt 0 ]] && { echo "$ERRORS test(s) failed"; exit 1; }
69+
echo "All tests passed."

0 commit comments

Comments
 (0)