diff --git a/rauc/tests/rauc-install-bad/task.yaml b/rauc/tests/rauc-install-bad/task.yaml index 968c07da76f76974560145e95d594f1465d92b70..6114abdc38bd1d3c4dd0c41d56475ae4a7df8ce9 100644 --- a/rauc/tests/rauc-install-bad/task.yaml +++ b/rauc/tests/rauc-install-bad/task.yaml @@ -33,33 +33,13 @@ prepare: | filename=system.img RAUC_MANIFEST - rauc bundle --cert="$RAUC_KEYS_DIR/cert.pem" --key="$RAUC_KEYS_DIR/key.pem" bundle-dir bundle.img - - # Create a fake rauc slot configuration - mkdir -p /etc/rauc - cat <<RAUC_SYSTEM_CONF >/etc/rauc/system.conf - [system] - compatible=OSTC SystemOTA Test Environment - bootloader=custom - statusfile=$(pwd)/status.raucs - bundle-formats=plain - - [slot.system.0] - device=$(pwd)/slot-a - bootname=A - - [slot.system.1] - device=$(pwd)/slot-b - bootname=B - + # Modify the fake rauc configuration file to set a custom bootloader handler. + cat <<RAUC_SYSTEM_CONF >>/etc/rauc/system.conf [handlers] bootloader-custom-backend=$(pwd)/backend.sh - - [keyring] - path=$RAUC_KEYS_DIR/cert.pem RAUC_SYSTEM_CONF - touch slot-{a,b} + rauc bundle --cert="$RAUC_KEYS_DIR/cert.pem" --key="$RAUC_KEYS_DIR/key.pem" bundle-dir bundle.img # Store /proc/cmdline and allow us to fake /proc/cmdline easily in the execute phase below. cp /proc/cmdline cmdline.orig @@ -85,7 +65,7 @@ execute: | truncate --size=0 /tmp/backend.log # The slot contains the image we prescribed. - cmp slot-b bundle-dir/system.img + cmp "$RAUC_FAKE_SYSTEM_DIR/slot-b" bundle-dir/system.img # On a real system, we would reboot here. @@ -123,15 +103,12 @@ restore: | rm -rf system-dir bundle-dir rm -f *.img rm -f *.pem - rm -f /etc/rauc/system.conf rm -f /tmp/backend.{log,state} rm -f cursor rm -f cmdline{,.orig} - rm -f status.raucs debug: | cat /proc/cmdline test -f /tmp/backend.log && cat /tmp/backend.log test -f /tmp/backend.state && cat /tmp/backend.state - test -f status.raucs && cat status.raucs journalctl --cursor-file=cursor -u rauc.service diff --git a/rauc/tests/rauc-install-good/task.yaml b/rauc/tests/rauc-install-good/task.yaml index 3b1165b6f77399467d3b70f5035062638d609c74..6508e50cf1e39e530f276397f87bd1cf2666adf8 100644 --- a/rauc/tests/rauc-install-good/task.yaml +++ b/rauc/tests/rauc-install-good/task.yaml @@ -30,33 +30,13 @@ prepare: | filename=system.img RAUC_MANIFEST - rauc bundle --cert="$RAUC_KEYS_DIR/cert.pem" --key="$RAUC_KEYS_DIR/key.pem" bundle-dir bundle.img - - # Create a fake rauc slot configuration - mkdir -p /etc/rauc - cat <<RAUC_SYSTEM_CONF >/etc/rauc/system.conf - [system] - compatible=OSTC SystemOTA Test Environment - bootloader=custom - statusfile=$(pwd)/status.raucs - bundle-formats=plain - - [slot.system.0] - device=$(pwd)/slot-a - bootname=A - - [slot.system.1] - device=$(pwd)/slot-b - bootname=B - + # Modify the fake rauc configuration file to set a custom bootloader handler. + cat <<RAUC_SYSTEM_CONF >>/etc/rauc/system.conf [handlers] bootloader-custom-backend=$(pwd)/backend.sh - - [keyring] - path=$RAUC_KEYS_DIR/cert.pem RAUC_SYSTEM_CONF - touch slot-{a,b} + rauc bundle --cert="$RAUC_KEYS_DIR/cert.pem" --key="$RAUC_KEYS_DIR/key.pem" bundle-dir bundle.img # Store /proc/cmdline and allow us to fake /proc/cmdline easily in the execute phase below. cp /proc/cmdline cmdline.orig @@ -82,7 +62,7 @@ execute: | truncate --size=0 /tmp/backend.log # The slot contains the image we prescribed. - cmp slot-b bundle-dir/system.img + cmp "$RAUC_FAKE_SYSTEM_DIR/slot-b" bundle-dir/system.img # On a real system, we would reboot here. @@ -102,15 +82,12 @@ restore: | rm -rf system-dir bundle-dir rm -f *.img rm -f *.pem - rm -f /etc/rauc/system.conf rm -f /tmp/backend.{log,state} rm -f cursor rm -f cmdline{,.orig} - rm -f status.raucs debug: | cat /proc/cmdline test -f /tmp/backend.log && cat /tmp/backend.log test -f /tmp/backend.state && cat /tmp/backend.state - test -f status.raucs && cat status.raucs journalctl --cursor-file=cursor -u rauc.service diff --git a/rauc/tests/rauc-install-handlers/task.yaml b/rauc/tests/rauc-install-handlers/task.yaml index ae72b269e734e5642434dd1b5a045daae8235301..c5e5e0a1bb5ad7b343a2958013e21939d94d7933 100644 --- a/rauc/tests/rauc-install-handlers/task.yaml +++ b/rauc/tests/rauc-install-handlers/task.yaml @@ -19,6 +19,14 @@ prepare: | mksquashfs system-dir bundle-dir/system.img -comp zstd + # Modify the fake rauc configuration file to set a custom bootloader handler. + cat <<RAUC_SYSTEM_CONF >>/etc/rauc/system.conf + [handlers] + pre-install=$(pwd)/pre-install.sh + post-install=$(pwd)/post-install.sh + bootloader-custom-backend=$(pwd)/backend.sh + RAUC_SYSTEM_CONF + # Create a fake rauc bundle with that system image cat <<RAUC_MANIFEST >bundle-dir/manifest.raucm [update] @@ -32,36 +40,6 @@ prepare: | rauc bundle --cert="$RAUC_KEYS_DIR/cert.pem" --key="$RAUC_KEYS_DIR/key.pem" bundle-dir bundle.img - # Create a fake rauc slot configuration - mkdir -p /etc/rauc - cat <<RAUC_SYSTEM_CONF >/etc/rauc/system.conf - [system] - compatible=OSTC SystemOTA Test Environment - bootloader=custom - statusfile=$(pwd)/status.raucs - bundle-formats=plain - - [handlers] - pre-install=$(pwd)/pre-install.sh - post-install=$(pwd)/post-install.sh - - [slot.system.0] - device=$(pwd)/slot-a - bootname=A - - [slot.system.1] - device=$(pwd)/slot-b - bootname=B - - [handlers] - bootloader-custom-backend=$(pwd)/backend.sh - - [keyring] - path=$RAUC_KEYS_DIR/cert.pem - RAUC_SYSTEM_CONF - - touch slot-{a,b} - # Store /proc/cmdline and allow us to fake /proc/cmdline easily in the execute phase below. cp /proc/cmdline cmdline.orig cp cmdline.orig cmdline @@ -98,8 +76,8 @@ execute: | MATCH 'RAUC_SLOT_BOOTNAME_2=A$' /tmp/pre-install.log MATCH 'RAUC_SLOT_CLASS_1=system$' /tmp/pre-install.log MATCH 'RAUC_SLOT_CLASS_2=system$' /tmp/pre-install.log - MATCH 'RAUC_SLOT_DEVICE_1=.*/rauc/tests/rauc-install-handlers/slot-b' /tmp/pre-install.log - MATCH 'RAUC_SLOT_DEVICE_2=.*/rauc/tests/rauc-install-handlers/slot-a' /tmp/pre-install.log + MATCH 'RAUC_SLOT_DEVICE_1='"$RAUC_FAKE_SYSTEM_DIR"'/slot-b' /tmp/pre-install.log + MATCH 'RAUC_SLOT_DEVICE_2='"$RAUC_FAKE_SYSTEM_DIR"'/slot-a' /tmp/pre-install.log MATCH 'RAUC_SLOT_NAME_1=system.1$' /tmp/pre-install.log MATCH 'RAUC_SLOT_NAME_2=system.0$' /tmp/pre-install.log MATCH 'RAUC_SLOT_PARENT_1=$' /tmp/pre-install.log @@ -124,8 +102,8 @@ execute: | MATCH 'RAUC_SLOT_BOOTNAME_2=A$' </tmp/post-install.log MATCH 'RAUC_SLOT_CLASS_1=system$' </tmp/post-install.log MATCH 'RAUC_SLOT_CLASS_2=system$' </tmp/post-install.log - MATCH 'RAUC_SLOT_DEVICE_1=.*/rauc/tests/rauc-install-handlers/slot-b$' </tmp/post-install.log - MATCH 'RAUC_SLOT_DEVICE_2=.*/rauc/tests/rauc-install-handlers/slot-a$' </tmp/post-install.log + MATCH 'RAUC_SLOT_DEVICE_1='"$RAUC_FAKE_SYSTEM_DIR"'/slot-b' /tmp/pre-install.log + MATCH 'RAUC_SLOT_DEVICE_2='"$RAUC_FAKE_SYSTEM_DIR"'/slot-a' /tmp/pre-install.log MATCH 'RAUC_SLOT_NAME_1=system.1$' </tmp/post-install.log MATCH 'RAUC_SLOT_NAME_2=system.0$' </tmp/post-install.log MATCH 'RAUC_SLOT_PARENT_1=$' </tmp/post-install.log @@ -144,12 +122,10 @@ restore: | rm -rf system-dir bundle-dir rm -f *.img - rm -f /etc/rauc/system.conf rm -f /tmp/backend.{log,state} rm -f /tmp/{pre,post}-install.log rm -f cursor rm -f cmdline{,.orig} - rm -f status.raucs debug: | cat /proc/cmdline @@ -157,5 +133,4 @@ debug: | test -f /tmp/backend.state && cat /tmp/backend.state test -f /tmp/pre-install.log && cat /tmp/pre-install.log test -f /tmp/post-install.log && cat /tmp/post-install.log - test -f status.raucs && cat status.raucs journalctl --cursor-file=cursor -u rauc.service diff --git a/spread.yaml b/spread.yaml index 0cfd38146af4d9bcc1ae380d9d97252818e563bd..5d70e4bfc396e6bc23426e480841084cdd41b0c1 100644 --- a/spread.yaml +++ b/spread.yaml @@ -179,9 +179,13 @@ suites: rauc/tests/: environment: RAUC_KEYS_DIR: /tmp/rauc-keys + RAUC_FAKE_SYSTEM_DIR: /tmp/rauc-fake-system summary: tests for RAUC interactions prepare: | mkdir -p "$RAUC_KEYS_DIR" + mkdir -p "$RAUC_FAKE_SYSTEM_DIR" + mkdir -p /etc/rauc + # Create a certificate to get RAUC to sign the bundle openssl req -x509 -newkey rsa:4096 \ -keyout "$RAUC_KEYS_DIR/key.pem" \ @@ -189,5 +193,54 @@ suites: -days 365 -nodes -subj "/C=PL/ST=Fake/L=Fake" </dev/null test -f "$RAUC_KEYS_DIR/key.pem" test -f "$RAUC_KEYS_DIR/cert.pem" + + # Create a fake rauc system configuration file containing the A/B + # slots. Note that the name ends with .vanilla and we use it as a + # template for prepare-each. + cat <<RAUC_SYSTEM_CONF >/etc/rauc/system.conf.vanilla + [system] + compatible=OSTC SystemOTA Test Environment + # Use a custom bootloader but do NOT set the backend program as that + # is specified in each test. + bootloader=custom + statusfile=$RAUC_FAKE_SYSTEM_DIR/status.raucs + bundle-formats=plain + + [slot.system.0] + device=$RAUC_FAKE_SYSTEM_DIR/slot-a + bootname=A + + [slot.system.1] + device=$RAUC_FAKE_SYSTEM_DIR/slot-b + bootname=B + + [keyring] + path=$RAUC_KEYS_DIR/cert.pem + + RAUC_SYSTEM_CONF + + touch "$RAUC_FAKE_SYSTEM_DIR"/slot-{a,b} + prepare-each: | + # Stop RAUC to allow task-level prepare to modify the configuration file. + systemctl stop rauc.service || true + + # Truncate the slot files to avoid leaking state across tests. + truncate --size=0 "$RAUC_FAKE_SYSTEM_DIR/slot-a" + truncate --size=0 "$RAUC_FAKE_SYSTEM_DIR/slot-b" + + # Remove RAUC state file to make sure we avoid leaking across tests. + rm -f "$RAUC_FAKE_SYSTEM_DIR/status.raucs" + + # Copy the vanilla rauc system configuration file to give each test + # a chance to modify it. + cp /etc/rauc/system.conf.vanilla /etc/rauc/system.conf + restore: | + # Stop RAUC again since we want to remove all configuration. + systemctl stop rauc.service || true + + rm -rf /etc/rauc rm -rf "$RAUC_KEYS_DIR" + rm -rf "$RAUC_FAKE_SYSTEM_DIR" + debug: | + test -f "$RAUC_FAKE_SYSTEM_DIR/status.raucs" && cat "$RAUC_FAKE_SYSTEM_DIR/status.raucs"