All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/testing: add parted runtime test
@ 2024-08-25 11:52 Julien Olivain
  2024-08-26 16:55 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 2+ messages in thread
From: Julien Olivain @ 2024-08-25 11:52 UTC (permalink / raw)
  To: buildroot; +Cc: Julien Olivain

Signed-off-by: Julien Olivain <ju.o@free.fr>
---
 DEVELOPERS                                   |   1 +
 support/testing/tests/package/test_parted.py | 107 +++++++++++++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 support/testing/tests/package/test_parted.py

diff --git a/DEVELOPERS b/DEVELOPERS
index 426590d5c5..208edc724c 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1933,6 +1933,7 @@ F:	support/testing/tests/package/test_octave.py
 F:	support/testing/tests/package/test_ola.py
 F:	support/testing/tests/package/test_ola/
 F:	support/testing/tests/package/test_openblas.py
+F:	support/testing/tests/package/test_parted.py
 F:	support/testing/tests/package/test_pciutils.py
 F:	support/testing/tests/package/test_perftest.py
 F:	support/testing/tests/package/test_pigz.py
diff --git a/support/testing/tests/package/test_parted.py b/support/testing/tests/package/test_parted.py
new file mode 100644
index 0000000000..ca585b7e02
--- /dev/null
+++ b/support/testing/tests/package/test_parted.py
@@ -0,0 +1,107 @@
+import os
+import subprocess
+
+import infra.basetest
+
+
+class TestParted(infra.basetest.BRTest):
+    config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+        """
+        BR2_PACKAGE_E2FSPROGS=y
+        BR2_PACKAGE_PARTED=y
+        BR2_TARGET_ROOTFS_CPIO=y
+        # BR2_TARGET_ROOTFS_TAR is not set
+        """
+
+    def test_run(self):
+        # Prepare the disk image.
+        disk_file = os.path.join(self.builddir, "images", "disk.img")
+        self.emulator.logfile.write(f"Creating disk image: {disk_file}\n")
+        self.emulator.logfile.flush()
+        subprocess.check_call(
+            ["dd", "if=/dev/zero", f"of={disk_file}", "bs=1M", "count=256"],
+            stdout=self.emulator.logfile,
+            stderr=self.emulator.logfile)
+
+        # Run the emulator with a drive.
+        cpio_file = os.path.join(self.builddir, "images", "rootfs.cpio")
+        self.emulator.boot(arch="armv5",
+                           kernel="builtin",
+                           options=[
+                                "-initrd", cpio_file,
+                                "-drive", f"file={disk_file},format=raw"])
+        self.emulator.login()
+
+        # We check the program can run.
+        self.assertRunOk("parted --version")
+
+        dev = "/dev/sda"
+        parted = f"parted {dev}"
+
+        # We print the partition list of our drive. Since the drive is
+        # supposed to be blank, it should not have a partition table.
+        part_list_cmd = f"{parted} print list"
+        out, ret = self.emulator.run(part_list_cmd, timeout=10)
+        self.assertEqual(ret, 0)
+        self.assertIn("Partition Table: unknown", out)
+
+        # We create a GPT partition table.
+        mklabel_cmd = f"{parted} mklabel gpt"
+        self.assertRunOk(mklabel_cmd, timeout=10)
+
+        # We print again the partition list. We should now see our
+        # partition table.
+        out, ret = self.emulator.run(part_list_cmd, timeout=10)
+        self.assertEqual(ret, 0)
+        self.assertIn("Partition Table: gpt", out)
+
+        # We create 3 partitions on our drive.
+        partitions = [
+            "MyPart1 ext2 1MiB 25%",
+            "MyPart2 ext4 25% 50%",
+            "MyPart3 ext4 50% 100%"
+        ]
+        for part in partitions:
+            mkpart_cmd = f"{parted} mkpart {part}"
+            self.assertRunOk(mkpart_cmd, timeout=10)
+
+        # We print again the list of partitions, this time in machine
+        # parseable format. We check we have our 3 partitions.
+        cmd = f"parted -m {dev} print list"
+        out, ret = self.emulator.run(cmd, timeout=10)
+        self.assertEqual(ret, 0)
+        for part in range(1, 4):
+            self.assertTrue(out[1+part].startswith(f"{part}:"))
+            self.assertTrue(out[1+part].endswith(f":MyPart{part}:;"))
+
+        # We format our partitions.
+        self.assertRunOk(f"mkfs.ext2 {dev}1", timeout=10)
+        self.assertRunOk(f"mkfs.ext4 {dev}2", timeout=10)
+        self.assertRunOk(f"mkfs.ext4 {dev}3", timeout=10)
+
+        # We create a random data file in the temporary directory. It
+        # will be the reference source file that will be copied later
+        # on each of our filesystems.
+        data_file = "data.bin"
+        cmd = f"dd if=/dev/urandom of=/tmp/{data_file} bs=1M count=10"
+        self.assertRunOk(cmd)
+
+        # We compute the sha256 hash and save it for later.
+        hash_cmd = f"sha256sum {data_file}"
+        out, ret = self.emulator.run(f"( cd /tmp && {hash_cmd} )")
+        self.assertEqual(ret, 0)
+        data_sha256 = out[0]
+
+        # For each partition, we create a mount point directory, mount
+        # the filesystem, copy the reference data file in it, sync the
+        # filesystem, and compute the sha256 hash of the file. This
+        # sequence will exercise a bit the partitions and filesystems
+        # in read/write operations.
+        for part in range(1, 4):
+            self.assertRunOk(f"mkdir -p /tmp/MyPart{part}")
+            self.assertRunOk(f"mount {dev}{part} /tmp/MyPart{part}")
+            self.assertRunOk(f"cp /tmp/{data_file} /tmp/MyPart{part}/")
+            self.assertRunOk("sync")
+            out, ret = self.emulator.run(f"( cd /tmp/MyPart{part} && {hash_cmd} )")
+            self.assertEqual(ret, 0)
+            self.assertEqual(out[0], data_sha256)
-- 
2.46.0

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-26 16:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-25 11:52 [Buildroot] [PATCH 1/1] support/testing: add parted runtime test Julien Olivain
2024-08-26 16:55 ` Thomas Petazzoni via buildroot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.