Skip to content

Commit 026163b

Browse files
authored
Bugfixes and improvements (#43)
* also run snapshot test (and correctly treat the "snapshot" case, in which images and generated files are named a bit differently (without a version)) * minor fixes * refactor the tests
1 parent e19347d commit 026163b

9 files changed

Lines changed: 98 additions & 77 deletions

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
name: test nix builds
1919
strategy:
2020
matrix:
21-
example: ["x86_64", "rpi4", "glinet-gl-ar750", "glinet-gl-mt300n-v2", "nexx-wt3020", "rpi2", "wrt1043nd"]
21+
example: ["x86_64", "x86_64-snapshot", "rpi4", "glinet-gl-ar750", "glinet-gl-mt300n-v2", "nexx-wt3020", "rpi2", "wrt1043nd"]
2222
steps:
2323
- name: Checkout
2424
uses: actions/checkout@v4
@@ -36,7 +36,7 @@ jobs:
3636
name: test container builds
3737
strategy:
3838
matrix:
39-
example: ["x86_64", "rpi4", "glinet-gl-ar750", "glinet-gl-mt300n-v2", "nexx-wt3020", "rpi2", "wrt1043nd"]
39+
example: ["x86_64", "x86_64-snapshot", "rpi4", "glinet-gl-ar750", "glinet-gl-mt300n-v2", "nexx-wt3020", "rpi2", "wrt1043nd"]
4040
option: ["--docker --sudo", "--podman", "--podman --sudo"]
4141
steps:
4242
- name: Checkout

.test/run_all.sh

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,45 @@
11
#!/bin/bash
22
# run all tests for a given configuration. tests are run after images are
3-
# built. we do some simple assertions on the generated artifiacts to e.g. make
3+
# built. we do some simple assertions on the generated artifacts to e.g. make
44
# sure the configured packages are included etc.
55
set -eou pipefail
66

77
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
8+
9+
if (( $# != 2 )); then
10+
echo "Usage: $(basename "$0") <configuration> <output-directory>"
11+
echo "Example: $(basename "$0") example-x86_64.conf output"
12+
exit 1
13+
fi
14+
815
CONF=$1
916
OUT=$2
10-
RC=0
17+
PASSED=0
18+
FAILED=0
19+
20+
if ! source "$CONF" 2>/dev/null; then
21+
echo "ERROR: cannot load configuration: $CONF"
22+
exit 1
23+
fi
24+
25+
echo "======================================================================"
26+
echo " TEST RESULTS $CONF in $OUT"
27+
echo "======================================================================"
1128

12-
echo "----------------------------------------------------------------------"
13-
echo "run tests for $CONF"
14-
echo "----------------------------------------------------------------------"
1529
for t in "$SCRIPT_DIR"/test_*.sh; do
16-
echo "******************** RUNNING CASE TEST $t ************************"
17-
if "$t" "$CONF" "$OUT"; then
18-
echo ">>> TEST OK"
30+
name=$(basename "$t" .sh | sed 's/^test_//')
31+
if output=$("$t" "$CONF" "$OUT" 2>&1); then
32+
echo " [ PASS ] $name"
33+
PASSED=$(( PASSED + 1 ))
1934
else
20-
echo ">>> TEST FAILED"
21-
RC=1
35+
echo " [ FAIL ] $name"
36+
echo "$output" | sed 's/^/ /'
37+
FAILED=$(( FAILED + 1 ))
2238
fi
23-
echo "******************************************************************"
2439
done
2540

26-
exit $RC
41+
total=$(( PASSED + FAILED ))
42+
echo "----------------------------------------------------------------------"
43+
echo " $total tests: $PASSED passed, $FAILED failed"
44+
echo "======================================================================"
45+
[[ $FAILED -eq 0 ]] || exit 1

.test/test-common

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CONF="$1"
2+
source "$1"
3+
DIR="$2"
4+
FAIL=0
5+
6+
if [[ "$LEDE_RELEASE" == "snapshots" ]]; then
7+
PREFIX="openwrt-$LEDE_TARGET-$LEDE_SUBTARGET-$LEDE_PROFILE"
8+
else
9+
PREFIX="openwrt-$LEDE_RELEASE-$LEDE_TARGET-$LEDE_SUBTARGET-$LEDE_PROFILE"
10+
fi
11+
12+
fail() {
13+
echo "FAIL: $*"
14+
FAIL=1
15+
}
16+
17+
dump_context() {
18+
echo "conf: $CONF"
19+
echo "output: $DIR"
20+
echo "prefix: $PREFIX"
21+
echo "packages: $LEDE_PACKAGES"
22+
}

.test/test_images_are_generated.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
#!/bin/bash
2-
source $1
3-
DIR=$2 # e.g. output/
4-
FAIL=0
2+
source "$(dirname "${BASH_SOURCE[0]}")/test-common" "$@"
53

6-
fail() {
7-
echo " ERROR: $*"
8-
FAIL=1
9-
}
4+
FILES=$(find "$DIR" -type f \( -name "$PREFIX-*.img.gz" -o -name "$PREFIX-*.bin" \) | wc -l)
105

11-
PREFIX="openwrt-$LEDE_RELEASE-$LEDE_TARGET-$LEDE_SUBTARGET-$LEDE_PROFILE"
12-
13-
echo "Test if images are generated for $PREFIX ..."
14-
15-
FILES=$(find "$DIR" -type f -name "$PREFIX-*.img.gz" \
16-
-o -name "$PREFIX-*.bin" | wc -l)
17-
18-
[ "$FILES" -eq "0" ] && fail "no images were built for $PREFIX"
6+
if (( FILES == 0 )); then
7+
fail "no images found for prefix '$PREFIX'"
8+
dump_context
9+
echo "files in $DIR:"
10+
ls "$DIR" 2>/dev/null || echo "(directory empty or missing)"
11+
fi
1912

2013
exit $FAIL
Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
#!/bin/bash
2+
source "$(dirname "${BASH_SOURCE[0]}")/test-common" "$@"
23

3-
source $1
4-
DIR=$2 # e.g. output/
5-
FAIL=0
6-
7-
fail() {
8-
echo " ERROR: $*"
9-
FAIL=1
10-
}
11-
12-
PREFIX="openwrt-$LEDE_RELEASE-$LEDE_TARGET-$LEDE_SUBTARGET-$LEDE_PROFILE"
134
MANIFEST="$DIR/$PREFIX.manifest"
145

15-
echo "Test all configured packages are in manifest file $MANIFEST..."
166
if [ ! -f "$MANIFEST" ]; then
17-
fail "$MANIFEST does not exist"
7+
fail "manifest not found: $MANIFEST"
8+
dump_context
189
exit 1
1910
fi
2011

2112
for p in $LEDE_PACKAGES; do
2213
[[ $p == -* ]] && continue
23-
grep -q -E "^$p " "$MANIFEST" || fail "package not in manifest: $p"
14+
grep -q -E "^$p " "$MANIFEST" || fail "package not in manifest: $p"
2415
done
2516

26-
if [ $FAIL -ne 0 ]; then
27-
echo "======== TEST FAILED ======="
28-
echo "LEDE_PACKAGES: $LEDE_PACKAGES"
29-
echo "MANIFEST: $MANIFEST"
30-
cat "$MANIFEST"
17+
if (( FAIL )); then
18+
dump_context
19+
echo "manifest:"
20+
cat "$MANIFEST"
3121
fi
3222

3323
exit $FAIL
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
#!/bin/bash
2+
source "$(dirname "${BASH_SOURCE[0]}")/test-common" "$@"
23

3-
source $1
4-
DIR=$2 # e.g. output/
5-
FAIL=0
6-
7-
fail() {
8-
echo " ERROR: $*"
9-
FAIL=1
10-
}
11-
12-
PREFIX="openwrt-$LEDE_RELEASE-$LEDE_TARGET-$LEDE_SUBTARGET-$LEDE_PROFILE"
134
MANIFEST="$DIR/$PREFIX.manifest"
145

15-
echo "Test all excluded packages are not in manifest file $MANIFEST..."
166
if [ ! -f "$MANIFEST" ]; then
17-
fail "$MANIFEST does not exist"
7+
fail "manifest not found: $MANIFEST"
8+
dump_context
189
exit 1
1910
fi
2011

21-
for p in $LEDE_PACKAGES; do
22-
# consider only excluded packages, starting with "-", e.g. "-ppp"
23-
[[ ! $p == -* ]] && continue
12+
for p in $LEDE_PACKAGES; do
13+
[[ $p != -* ]] && continue
2414
p=${p:1}
25-
grep -q -E "^$p " "$MANIFEST" && fail "package not expected to be in manifest: $p"
15+
grep -q -E "^$p " "$MANIFEST" && fail "excluded package found in manifest: $p"
2616
done
2717

18+
if (( FAIL )); then
19+
dump_context
20+
fi
21+
2822
exit $FAIL

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## v3.9 [2026-05-30]
44

55
- Upgrade to OpenWrt 25.12.4
6+
- Bugfixes and test refactoring
67

78
## v3.8 [2025-02-09]
89

builder.sh

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ Example:
6363
# use nix to build the OpenWrt image, no need to build a container first
6464
$PROG build example-x86_64.conf --nix
6565
EOT
66-
exit 0
6766
}
6867

6968
# return given file path as absolute path. path to file must exist.
@@ -83,7 +82,7 @@ function build_docker_image {
8382
}
8483

8584
function run_cmd_in_nix_shell {
86-
nix-shell --pure --run "bash -c '$*'"
85+
nix-shell --pure --run "$*"
8786
}
8887

8988
function run_cmd_in_container {
@@ -103,9 +102,9 @@ function run_cmd_in_container {
103102
-v "$(abspath "$ROOTFS_OVERLAY")":/lede/rootfs-overlay \
104103
-v "$(abspath "$OUTPUT_DIR")":/lede/output \
105104
"${repositories_volume[@]}" \
106-
${DOCKER_OPTS[@]} \
105+
"${DOCKER_OPTS[@]}" \
107106
${_DOCKER_OPTS:-} \
108-
--rm "$(image_tag)" bash -c "$*"
107+
"$(image_tag)" bash -c "$*"
109108
}
110109

111110
function run_cmd {
@@ -162,11 +161,16 @@ download_builder() {
162161
return
163162
fi
164163

165-
mkdir -p "$dir"
166-
echo curl "download $url -> $dir"
167-
curl --progress-bar "$url" -o "$dir/tmpbuilder" \
168-
&& tar xfa "$dir/tmpbuilder" --strip-components=1 -C "$dir" \
169-
&& rm "$dir/tmpbuilder"
164+
local tmpdir="${dir}.tmp"
165+
rm -rf "$tmpdir"
166+
mkdir -p "$tmpdir"
167+
trap 'rm -rf "$tmpdir"' ERR INT TERM
168+
echo "downloading $url -> $dir"
169+
curl --progress-bar "$url" -o "$tmpdir/tmpbuilder" \
170+
&& tar xfa "$tmpdir/tmpbuilder" --strip-components=1 -C "$tmpdir" \
171+
&& rm "$tmpdir/tmpbuilder" \
172+
&& mv "$tmpdir" "$dir"
173+
trap - ERR INT TERM
170174
}
171175

172176
function print_config {
@@ -195,7 +199,7 @@ EOT
195199
# tests if given version is at least provided reference version.
196200
# version_ge_than("23.05.1", "24") -> false
197201
# version_ge_than("24.0.10", "24") -> true
198-
function version_ge_than { [ "${1%%.*}" -ge "$2" ]; }
202+
function version_ge_than { local major="${1%%.*}"; [[ "$major" =~ ^[0-9]+$ ]] && [ "$major" -ge "$2" ]; }
199203

200204
# return default LEDE_BUILDER_URL if not overriden in configuration file
201205
function builder_url {
@@ -300,7 +304,7 @@ function dispatch_command {
300304
run_cmd "$cmd"
301305
;;
302306
build-docker-image)
303-
[ "$RUNTIME" == "nix" ] && warn "refusing to build docker image when using --nix" && exit
307+
[ "$RUNTIME" == "nix" ] && warn "refusing to build docker image when using --nix" && exit 1
304308
print_config
305309
build_docker_image "$(builder_url)" "$(image_tag)"
306310
;;
@@ -313,15 +317,13 @@ function dispatch_command {
313317
;;
314318
*)
315319
usage "$0"
316-
# shellcheck disable=2317
317320
exit 0
318321
;;
319322
esac
320323
}
321324

322325
if [ $# -lt 2 ]; then
323326
usage "$0"
324-
# shellcheck disable=2317
325327
exit 1
326328
fi
327329

example-x86_64-snapshot.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LEDE_SUBTARGET=64
1010
LEDE_PACKAGES="base-files busybox dropbear mtd uci netifd \
1111
fstools uclient-fetch logd kmod-usb-hid dnsmasq luci-nginx "
1212

13-
LEDE_BUILDER_URL="https://downloads.openwrt.org/$LEDE_RELEASE/targets/$LEDE_TARGET/$LEDE_SUBTARGET/openwrt-imagebuilder-$LEDE_TARGET-$LEDE_SUBTARGET.Linux-x86_64.tar.xz"
13+
LEDE_BUILDER_URL="https://downloads.openwrt.org/$LEDE_RELEASE/targets/$LEDE_TARGET/$LEDE_SUBTARGET/openwrt-imagebuilder-$LEDE_TARGET-$LEDE_SUBTARGET.Linux-x86_64.tar.zst"
1414

1515
# optionally override OUTPUT_DIR and ROOTFS_OVERLAY directory location here
1616

0 commit comments

Comments
 (0)