Use firmware-config.js as driver for tests
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# Test all patches against the cached firmware using kobopatch -t.
|
||||
# This builds the native kobopatch binary, extracts the patch set,
|
||||
# and runs each patch in test mode to check if it can be applied.
|
||||
# Test all patches against cached firmware using kobopatch -t.
|
||||
# Iterates over all firmware versions in tests/firmware-config.js,
|
||||
# builds the native kobopatch binary, and generates blacklist.json.
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
@@ -14,19 +14,10 @@ if [ -x "$LOCAL_GO_DIR/bin/go" ]; then
|
||||
export PATH="$LOCAL_GO_DIR/bin:$PATH"
|
||||
fi
|
||||
|
||||
FIRMWARE_FILE="${FIRMWARE_ZIP:-$(cd .. && pwd)/tests/cached_assets/kobo-update-4.45.23646.zip}"
|
||||
PATCHES_ZIP="${PATCHES_ZIP:-$(cd .. && pwd)/web/src/patches/patches_4.45.zip}"
|
||||
|
||||
if [ ! -f "$FIRMWARE_FILE" ]; then
|
||||
echo "ERROR: Firmware zip not found at $FIRMWARE_FILE"
|
||||
echo "Run ./test.sh from the project root to download test assets first."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ ! -f "$PATCHES_ZIP" ]; then
|
||||
echo "ERROR: Patches zip not found at $PATCHES_ZIP"
|
||||
exit 1
|
||||
fi
|
||||
FIRMWARE_CONFIG="$(cd .. && pwd)/tests/firmware-config.js"
|
||||
CACHED_ASSETS="$(cd .. && pwd)/tests/cached_assets"
|
||||
PATCHES_DIR="$(cd .. && pwd)/web/src/patches"
|
||||
BLACKLIST_FILE="$PATCHES_DIR/blacklist.json"
|
||||
|
||||
# Build the native kobopatch binary.
|
||||
echo "=== Building kobopatch ==="
|
||||
@@ -35,64 +26,81 @@ go build -o ../kobopatch ./kobopatch
|
||||
cd ..
|
||||
echo "Built kobopatch successfully."
|
||||
|
||||
# Extract patches to a temp directory.
|
||||
TMPDIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
# Start with an empty blacklist.
|
||||
echo "{}" > "$BLACKLIST_FILE"
|
||||
|
||||
echo ""
|
||||
echo "=== Extracting patches ==="
|
||||
unzip -q "$PATCHES_ZIP" -d "$TMPDIR"
|
||||
# Iterate over all firmware versions in the config.
|
||||
CONFIGS=$(node -e "console.log(JSON.stringify(require('$FIRMWARE_CONFIG')))")
|
||||
COUNT=$(echo "$CONFIGS" | jq 'length')
|
||||
|
||||
# Rewrite the config to point at the cached firmware and create output dir.
|
||||
sed -i "s|^in:.*|in: $FIRMWARE_FILE|" "$TMPDIR/kobopatch.yaml"
|
||||
mkdir -p "$TMPDIR/out"
|
||||
for i in $(seq 0 $((COUNT - 1))); do
|
||||
ENTRY=$(echo "$CONFIGS" | jq -c ".[$i]")
|
||||
VERSION=$(echo "$ENTRY" | jq -r '.version')
|
||||
SHORT_VERSION=$(echo "$ENTRY" | jq -r '.shortVersion')
|
||||
PATCHES=$(echo "$ENTRY" | jq -r '.patches')
|
||||
|
||||
BLACKLIST_FILE="$(cd .. && pwd)/web/src/patches/blacklist.json"
|
||||
VERSION="${VERSION:-4.45}"
|
||||
FIRMWARE_FILE="$CACHED_ASSETS/kobo-update-${VERSION}.zip"
|
||||
PATCHES_ZIP="$PATCHES_DIR/$PATCHES"
|
||||
|
||||
# Run patch tests and capture output.
|
||||
echo ""
|
||||
echo "=== Testing patches against $(basename "$FIRMWARE_FILE") ==="
|
||||
echo ""
|
||||
OUTPUT=$(./kobopatch -t -f "$FIRMWARE_FILE" "$TMPDIR/kobopatch.yaml" 2>&1 || true)
|
||||
echo "$OUTPUT"
|
||||
if [ ! -f "$FIRMWARE_FILE" ]; then
|
||||
echo ""
|
||||
echo "=== Skipping $VERSION (firmware not downloaded) ==="
|
||||
continue
|
||||
fi
|
||||
|
||||
# Generate blacklist.json from failed patches.
|
||||
echo ""
|
||||
echo "=== Generating blacklist.json ==="
|
||||
echo "$OUTPUT" | python3 -c "
|
||||
if [ ! -f "$PATCHES_ZIP" ]; then
|
||||
echo ""
|
||||
echo "=== Skipping $VERSION (patches zip $PATCHES not found) ==="
|
||||
continue
|
||||
fi
|
||||
|
||||
# Extract patches to a temp directory.
|
||||
TMPDIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
|
||||
echo ""
|
||||
echo "=== Extracting $PATCHES ==="
|
||||
unzip -q "$PATCHES_ZIP" -d "$TMPDIR"
|
||||
|
||||
# Rewrite the config to point at the cached firmware and create output dir.
|
||||
sed -i "s|^in:.*|in: $FIRMWARE_FILE|" "$TMPDIR/kobopatch.yaml"
|
||||
mkdir -p "$TMPDIR/out"
|
||||
|
||||
# Run patch tests and capture output.
|
||||
echo ""
|
||||
echo "=== Testing patches against kobo-update-${VERSION}.zip ==="
|
||||
echo ""
|
||||
OUTPUT=$(./kobopatch -t -f "$FIRMWARE_FILE" "$TMPDIR/kobopatch.yaml" 2>&1 || true)
|
||||
echo "$OUTPUT"
|
||||
|
||||
# Update blacklist.json with failed patches for this version.
|
||||
echo ""
|
||||
echo "=== Updating blacklist.json for $SHORT_VERSION ==="
|
||||
echo "$OUTPUT" | python3 -c "
|
||||
import sys, json, os
|
||||
|
||||
version = '$VERSION'
|
||||
version = '$SHORT_VERSION'
|
||||
blacklist_file = '$BLACKLIST_FILE'
|
||||
tmpdir = '$TMPDIR'
|
||||
|
||||
# Load existing blacklist to preserve other versions.
|
||||
if os.path.exists(blacklist_file):
|
||||
with open(blacklist_file) as f:
|
||||
blacklist = json.load(f)
|
||||
else:
|
||||
blacklist = {}
|
||||
with open(blacklist_file) as f:
|
||||
blacklist = json.load(f)
|
||||
|
||||
# Map binary paths back to patch file names.
|
||||
# kobopatch prints 'Patching ./usr/local/Kobo/libnickel.so.1.0.0' but we need 'src/libnickel.so.1.0.0.yaml'.
|
||||
target_to_src = {}
|
||||
current_file = None
|
||||
failed = {}
|
||||
|
||||
for line in sys.stdin:
|
||||
line = line.rstrip()
|
||||
if line.startswith('Patching ./'):
|
||||
target = line.split('Patching ./')[1]
|
||||
current_file = target
|
||||
current_file = line.split('Patching ./')[1]
|
||||
elif '✕' in line and current_file:
|
||||
name = line.split('✕')[1].strip()
|
||||
failed.setdefault(current_file, []).append(name)
|
||||
|
||||
# Read kobopatch.yaml to get target -> src mapping.
|
||||
# Parse the 'patches:' section without a YAML dependency.
|
||||
# Parse kobopatch.yaml patches section to get target -> src mapping.
|
||||
src_to_target = {}
|
||||
in_patches = False
|
||||
with open('$TMPDIR/kobopatch.yaml') as f:
|
||||
with open(os.path.join(tmpdir, 'kobopatch.yaml')) as f:
|
||||
for cfg_line in f:
|
||||
cfg_line = cfg_line.rstrip()
|
||||
if cfg_line.startswith('patches:'):
|
||||
@@ -108,7 +116,7 @@ with open('$TMPDIR/kobopatch.yaml') as f:
|
||||
# Build a patch-name -> src file mapping by scanning patch files.
|
||||
patch_name_to_src = {}
|
||||
for src in src_to_target:
|
||||
src_path = os.path.join('$TMPDIR', src)
|
||||
src_path = os.path.join(tmpdir, src)
|
||||
if not os.path.exists(src_path):
|
||||
continue
|
||||
with open(src_path) as pf:
|
||||
@@ -131,5 +139,12 @@ with open(blacklist_file, 'w') as f:
|
||||
f.write('\n')
|
||||
|
||||
total_failed = sum(len(v) for v in version_entry.values())
|
||||
print(f'Wrote {total_failed} blacklisted patch(es) for version {version} to {blacklist_file}')
|
||||
print(f'Wrote {total_failed} blacklisted patch(es) for version {version}')
|
||||
"
|
||||
|
||||
rm -rf "$TMPDIR"
|
||||
trap - EXIT
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "=== Blacklist written to $BLACKLIST_FILE ==="
|
||||
|
||||
Reference in New Issue
Block a user