Add unit test for rpi-eeprom-config

Add a basic unit test to verify that rpi-eeprom-config updates the
EEPROM image as expected (only the config + header updated).
This commit is contained in:
Tim Gover
2019-09-12 11:44:56 +01:00
parent 48a2302bcd
commit 694d936c99
5 changed files with 109 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
BOOT_UART=0
WAKE_ON_GPIO=0

View File

@@ -0,0 +1,16 @@
BOOT_UART=0
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0
FREEZE_VERSION=1

View File

@@ -0,0 +1,16 @@
BOOT_UART=0
WAKE_ON_GPIO=1
POWER_OFF_ON_HALT=0

Binary file not shown.

75
test/test-rpi-eeprom-config Executable file
View File

@@ -0,0 +1,75 @@
#!/bin/sh
set -e
script_dir="$(cd "$(dirname "$0")" && pwd)"
die() {
echo "$@" >&2
exit 1
}
TMP_CONFIG=""
TMP_EEPROM=""
cleanup() {
rm -f "${TMP_CONFIG}" -f "${TMP_EEPROM}"
TMP_CONFIG=""
TMP_EEPROM=""
}
trap cleanup EXIT
check_loopback()
{
echo "check_update $1 $2"
image="${script_dir}/$1"
conf="${script_dir}/$2"
# Check that the production config file can be read correctly
expected_md5="$(md5sum "${conf}" | awk '{print $1}')"
actual_md5="$("${script_dir}/../rpi-eeprom-config" "${image}" | md5sum | awk '{print $1}')"
[ "${actual_md5}" = "${expected_md5}" ] || die "Config-read: checksum mismatch"
# Check that overwriting the config section produces an identical binary
TMP_EEPROM=$(mktemp)
"${script_dir}/../rpi-eeprom-config" \
"${image}" \
--config "${conf}" \
--out "${TMP_EEPROM}"
expected_md5="$(md5sum "${image}" | awk '{print $1}')"
actual_md5="$(md5sum "${TMP_EEPROM}" | awk '{print $1}')"
[ "${actual_md5}" = "${expected_md5}" ] || die "EEPROM loopback: checksum mismatch"
}
# Update the EEPROM with a new config and check the expected image is produced
check_update()
{
echo "check_update $1 $2 $3"
image="${script_dir}/$1"
ref_image="${script_dir}/$2"
conf="${script_dir}/$3"
expected_md5="$(md5sum "${ref_image}" | awk '{print $1}')"
TMP_EEPROM="$(mktemp)"
"${script_dir}/../rpi-eeprom-config" \
"${image}" \
--config "${conf}" \
--out "${TMP_EEPROM}"
actual_md5="$(md5sum "${TMP_EEPROM}" | awk '{print $1}')"
if [ "${actual_md5}" != "${expected_md5}" ]; then
hexdump -C "${TMP_EEPROM}" > "tmp.hex"
die "EEPROM update: checksum mismatch"
fi
}
check_loopback "../firmware/critical/pieeprom-2019-05-10.bin" "bootconf-2019-05-10.txt"
cleanup
check_loopback "../firmware/critical/pieeprom-2019-07-15.bin" "bootconf-2019-07-15.txt"
cleanup
check_update "../firmware/critical/pieeprom-2019-07-15.bin" "pieeprom-2019-07-15-freeze.bin" "bootconf-2019-07-15-freeze.txt"
cleanup