Skip to contentSkip to conversation

support/testing: add swupdate runtime test

PATCH Applied Giulio Benetti 2 participants 3 messages Nov 9 – Nov 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support/testing: add swupdate runtime test

Add a runtime test for swupdate using the default swupdate configuration.

An SWU image containing a single file, installed by the "rawfile" handler, is generated at build time with host-swugenerator. Since the default configuration has no crypto backend, the image is generated without hashes.

At runtime, the test checks that:
- the swupdate daemon is started by the init script,
- the embedded webserver serves the default website,
- a dry run through swupdate-client does not install anything,
- the SWU image is correctly installed through swupdate-client,
- an invalid SWU image is rejected and the daemon keeps running.

---
 DEVELOPERS                                    |  2 +
 .../testing/tests/package/test_swupdate.py    | 46 +++++++++++++++++++
 .../tests/package/test_swupdate/post-build.sh | 14 ++++++
 .../package/test_swupdate/sw-description      | 16 +++++++
 .../package/test_swupdate/swupdate-test.txt   |  1 +
 5 files changed, 79 insertions(+)
 create mode 100644 support/testing/tests/package/test_swupdate.py
 create mode 100755 support/testing/tests/package/test_swupdate/post-build.sh
 create mode 100644 support/testing/tests/package/test_swupdate/sw-description
 create mode 100644 support/testing/tests/package/test_swupdate/swupdate-test.txt
DEVELOPERS +2 -0
index 848307a0ba..e1f629ed34 100644
@@ -1373,6 +1373,8 @@ F:	package/wilc-driver/
 F:	package/wireshark/
 F:	package/zlib-ng/
 F:	support/testing/tests/package/test_swugenerator.py
+F:	support/testing/tests/package/test_swupdate.py
+F:	support/testing/tests/package/test_swupdate/
 F:	toolchain/
 
 N:	Graeme Smecher <[email protected]>
support/testing/tests/package/test_swupdate.py new file +46 -0

46 lines not on this page · raw message

support/testing/tests/package/test_swupdate/post-build.sh new file +14 -0
new file mode 100755
index 0000000000..ea08c863ae
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+set -e
+
+SWU_SRC_DIR="$(dirname "$0")"
+
+# Generate the SWU image to be installed by the runtime test. The
+# default swupdate configuration has no crypto support, so do not
+# store hashes in sw-description.
+"${HOST_DIR}"/bin/swugenerator \
+	--no-hash \
+	--sw-description "${SWU_SRC_DIR}"/sw-description \
+	--artifactory "${SWU_SRC_DIR}" \
+	--swu-file "${TARGET_DIR}"/root/test.swu \
+	create
support/testing/tests/package/test_swupdate/sw-description new file +16 -0
new file mode 100644
index 0000000000..b38a04860f
@@ -0,0 +1,16 @@
+software =
+{
+	version = "1.0.0";
+	description = "Buildroot runtime test update";
+
+	files: (
+		{
+			filename = "swupdate-test.txt";
+			path = "/tmp/swupdate-test/swupdate-test.txt";
+			type = "rawfile";
+			properties = {
+				create-destination = "true";
+			};
+		}
+	);
+}
support/testing/tests/package/test_swupdate/swupdate-test.txt new file +1 -0
new file mode 100644
index 0000000000..924abe196a
@@ -0,0 +1 @@
+Hello from SWUpdate!
Signature · 6 lines
2.47.3

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 15 lines · Giulio Benetti

Add a runtime test for swupdate using the default swupdate configuration.

An SWU image containing a single file, installed by the "rawfile" handler, is generated at build time with host-swugenerator. Since the default configuration has no crypto backend, the image is generated without hashes.

At runtime, the test checks that:
- the swupdate daemon is started by the init script,
- the embedded webserver serves the default website,
- a dry run through swupdate-client does not install anything,
- the SWU image is correctly installed through swupdate-client,
- an invalid SWU image is rejected and the daemon keeps running.

Quoted 2 lines

Applied to master, thanks.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#2 lore raw
In reply to Giulio Benetti

In reply of:

Quoted 15 lines

Add a runtime test for swupdate using the default swupdate configuration.

An SWU image containing a single file, installed by the "rawfile" handler, is generated at build time with host-swugenerator. Since the default configuration has no crypto backend, the image is generated without hashes.

At runtime, the test checks that:
- the swupdate daemon is started by the init script,
- the embedded webserver serves the default website,
- a dry run through swupdate-client does not install anything,
- the SWU image is correctly installed through swupdate-client,
- an invalid SWU image is rejected and the daemon keeps running.

Quoted 2 lines

Applied to 2026.08.x. Thanks

Quoted 125 lines
---
 DEVELOPERS                                    |  2 +
 .../testing/tests/package/test_swupdate.py    | 46 +++++++++++++++++++
 .../tests/package/test_swupdate/post-build.sh | 14 ++++++
 .../package/test_swupdate/sw-description      | 16 +++++++
 .../package/test_swupdate/swupdate-test.txt   |  1 +
 5 files changed, 79 insertions(+)
 create mode 100644 support/testing/tests/package/test_swupdate.py
 create mode 100755 support/testing/tests/package/test_swupdate/post-build.sh
 create mode 100644 support/testing/tests/package/test_swupdate/sw-description
 create mode 100644 support/testing/tests/package/test_swupdate/swupdate-test.txt
DEVELOPERS +2 -0
index 848307a0ba..e1f629ed34 100644
@@ -1373,6 +1373,8 @@ F:	package/wilc-driver/
 F:	package/wireshark/
 F:	package/zlib-ng/
 F:	support/testing/tests/package/test_swugenerator.py
+F:	support/testing/tests/package/test_swupdate.py
+F:	support/testing/tests/package/test_swupdate/
 F:	toolchain/
 
 N:	Graeme Smecher <[email protected]>
support/testing/tests/package/test_swupdate.py new file +46 -0
new file mode 100644
index 0000000000..7092cb3309
@@ -0,0 +1,46 @@
+import os
+
+import infra.basetest
+
+
+class TestSwupdate(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_SWUPDATE=y
+        BR2_PACKAGE_HOST_SWUGENERATOR=y
+        BR2_ROOTFS_POST_BUILD_SCRIPT="{}"
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """.format(infra.filepath("tests/package/test_swupdate/post-build.sh"))
+
+    def test_run(self):
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=["-initrd", cpio_file])
+        self.emulator.login()
+
+        # Check the swupdate daemon was started by the init script
+        self.assertRunOk("pidof swupdate")
+
+        # Check the embedded webserver serves the default website
+        self.assertRunOk("wget -q -O - http://127.0.0.1:8080/ | grep -qi swupdate")
+
+        # A dry run must succeed without installing anything
+        self.assertRunOk("swupdate-client -d /root/test.swu", timeout=30)
+        self.assertRunNotOk("test -e /tmp/swupdate-test/swupdate-test.txt")
+
+        # Install the SWU image through the daemon
+        self.assertRunOk("swupdate-client /root/test.swu", timeout=30)
+
+        # Check the file was installed by the rawfile handler
+        out, ret = self.emulator.run("cat /tmp/swupdate-test/swupdate-test.txt")
+        self.assertEqual(ret, 0)
+        self.assertEqual(out[0], "Hello from SWUpdate!")
+
+        # An invalid SWU image must be rejected
+        self.assertRunOk("echo garbage > /tmp/bad.swu")
+        self.assertRunNotOk("swupdate-client /tmp/bad.swu", timeout=30)
+
+        # The daemon must still be running after a failed update
+        self.assertRunOk("pidof swupdate")
support/testing/tests/package/test_swupdate/post-build.sh new file +14 -0
new file mode 100755
index 0000000000..ea08c863ae
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+set -e
+
+SWU_SRC_DIR="$(dirname "$0")"
+
+# Generate the SWU image to be installed by the runtime test. The
+# default swupdate configuration has no crypto support, so do not
+# store hashes in sw-description.
+"${HOST_DIR}"/bin/swugenerator \
+	--no-hash \
+	--sw-description "${SWU_SRC_DIR}"/sw-description \
+	--artifactory "${SWU_SRC_DIR}" \
+	--swu-file "${TARGET_DIR}"/root/test.swu \
+	create
support/testing/tests/package/test_swupdate/sw-description new file +16 -0
new file mode 100644
index 0000000000..b38a04860f
@@ -0,0 +1,16 @@
+software =
+{
+	version = "1.0.0";
+	description = "Buildroot runtime test update";
+
+	files: (
+		{
+			filename = "swupdate-test.txt";
+			path = "/tmp/swupdate-test/swupdate-test.txt";
+			type = "rawfile";
+			properties = {
+				create-destination = "true";
+			};
+		}
+	);
+}
support/testing/tests/package/test_swupdate/swupdate-test.txt new file +0 -0
new file mode 100644
index 0000000000..924abe196a

support/testing/tests/package/test_swupdate/swupdate-test.txt line 1

Quoted 1 line
support/testing/tests/package/test_swupdate/swupdate-test.txt new file +1 -0
@@ -0,0 +1 @@
+Hello from SWUpdate!

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot