* [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class
@ 2023-07-06 19:00 Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 2/4] support/testing/tests/package/test_gzip.py: new runtime test Julien Olivain
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Julien Olivain @ 2023-07-06 19:00 UTC (permalink / raw)
To: buildroot; +Cc: Julien Olivain
This is a helper class providing a template for testing data
compressor and decompressor programs such as gzip, bzip2, xz...
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
DEVELOPERS | 1 +
.../tests/package/test_compressor_base.py | 126 ++++++++++++++++++
2 files changed, 127 insertions(+)
create mode 100644 support/testing/tests/package/test_compressor_base.py
diff --git a/DEVELOPERS b/DEVELOPERS
index 188c579010..75cfbd85a8 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1721,6 +1721,7 @@ F: support/testing/tests/package/sample_python_gnupg.py
F: support/testing/tests/package/sample_python_hwdata.py
F: support/testing/tests/package/sample_python_pyalsa.py
F: support/testing/tests/package/sample_python_spake2.py
+F: support/testing/tests/package/test_compressor_base.py
F: support/testing/tests/package/test_ddrescue.py
F: support/testing/tests/package/test_ddrescue/
F: support/testing/tests/package/test_gnupg2.py
diff --git a/support/testing/tests/package/test_compressor_base.py b/support/testing/tests/package/test_compressor_base.py
new file mode 100644
index 0000000000..6555584c10
--- /dev/null
+++ b/support/testing/tests/package/test_compressor_base.py
@@ -0,0 +1,126 @@
+import os
+
+import infra.basetest
+
+
+class TestCompressorBase(infra.basetest.BRTest):
+ """Common class to test a data compression/decompression package.
+
+ Build an image containing the package enabled in config, start the
+ emulator, login to it. It prepares a test data file with some
+ redundancy to let compression program reduce the file size.
+
+ Each test case that inherits from this class must have:
+ __test__ = True - to let nose2 know that it is a test case
+ config - defconfig fragment with the packages to run the test
+ compress_cmd - the compression program command (ex: "gzip")
+ it can also contain arguments (ex: "gzip -9")
+ It also can have:
+ decompress_cmd - the decompression program (ex: "gunzip")
+ if unset, the default value is "un" appended with the
+ value of "compress_cmd".
+ check_integrity_cmd
+ - the integrity check command (ex: "gzip -t")
+ in unset, the default value is "compress_cmd" appended
+ with " -t".
+ compressed_file_ext
+ - the file extention of compressed files created by the
+ compress command. (ex: ".gz")
+ if unset, the default value is a dot "." appended with
+ the value of "compress_cmd".
+ timeout - timeout to the compression command. Some compression
+ program can take more time than the default value
+ (set to 5 seconds).
+ """
+ __test__ = False
+ config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \
+ """
+ BR2_TARGET_ROOTFS_CPIO=y
+ # BR2_TARGET_ROOTFS_TAR is not set
+ """
+ compress_cmd = "compressor-unknown"
+ decompress_cmd = None
+ check_integrity_cmd = None
+ compressed_file_ext = None
+ timeout = 5
+
+ def __init__(self, names):
+ """Setup common test variables."""
+ super(TestCompressorBase, self).__init__(names)
+
+ if self.decompress_cmd is None:
+ self.decompress_cmd = "un" + self.compress_cmd
+
+ if self.check_integrity_cmd is None:
+ self.check_integrity_cmd = self.compress_cmd + " -t"
+
+ if self.compressed_file_ext is None:
+ self.compressed_file_ext = "." + self.compress_cmd
+
+ self.ref_file = "reference.bin"
+ self.test_file = "test.bin"
+ self.comp_test_file = self.test_file + self.compressed_file_ext
+
+ def login(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()
+
+ def test_run(self):
+ self.login()
+ self.prepare_data()
+ self.compress_test()
+ self.check_integrity_test()
+ self.uncompress_test()
+ self.compare_test()
+
+ def prepare_data(self):
+ # Create a data file composed of: 128kB of random data, then
+ # 128kB of zeroes, then a repetition of the 1st 128kB of
+ # random.
+ self.assertRunOk("dd if=/dev/urandom of=rand.bin bs=128k count=1")
+ self.assertRunOk("dd if=/dev/zero of=zeroes.bin bs=128k count=1")
+ self.assertRunOk(f"cat rand.bin zeroes.bin rand.bin > {self.ref_file}")
+
+ # Keep a copy of the reference data since
+ # compressor/decompressor programs usually unlink source data
+ # file.
+ self.assertRunOk(f"cp {self.ref_file} {self.test_file}")
+
+ def compress_test(self):
+ # Run the compression
+ self.assertRunOk(f"{self.compress_cmd} {self.test_file}", timeout=self.timeout)
+
+ # Check that the compressed file was created with the expected name
+ self.assertRunOk(f"test -e {self.comp_test_file}")
+
+ # Remove the input test file. Some compressors (like gzip) are
+ # removing it automatically by default. Some others (like lz4)
+ # are keeping those by default. We always remove it to make
+ # sure a new file will be recreated by the decompression.
+ self.assertRunOk(f"rm -f {self.test_file}")
+
+ # Check the compressed file is smaller than the input.
+ # The "ls -l" command is for simplifying debugging
+ self.assertRunOk(f"ls -l {self.ref_file} {self.comp_test_file}")
+ ref_sz_cmd = f"wc -c < {self.ref_file}"
+ comp_sz_cmd = f"wc -c < {self.comp_test_file}"
+ self.assertRunOk(f"test $({ref_sz_cmd}) -gt $({comp_sz_cmd})")
+
+ def check_integrity_test(self):
+ # Check the compressed file integrity
+ self.assertRunOk(f"{self.check_integrity_cmd} {self.comp_test_file}")
+
+ def uncompress_test(self):
+ # Run the decompression
+ self.assertRunOk(f"{self.decompress_cmd} {self.comp_test_file}")
+
+ # Check the decompressed file was created with the correct name
+ self.assertRunOk(f"test -e {self.test_file}")
+
+ def compare_test(self):
+ # Check the decompressed file is exactly the same as the
+ # reference created at the beginning
+ self.assertRunOk(f"cmp {self.test_file} {self.ref_file}")
--
2.41.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 2/4] support/testing/tests/package/test_gzip.py: new runtime test
2023-07-06 19:00 [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Julien Olivain
@ 2023-07-06 19:01 ` Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 3/4] support/testing/tests/package/test_bzip2.py: " Julien Olivain
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Julien Olivain @ 2023-07-06 19:01 UTC (permalink / raw)
To: buildroot; +Cc: Julien Olivain
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
DEVELOPERS | 1 +
support/testing/tests/package/test_gzip.py | 13 +++++++++++++
2 files changed, 14 insertions(+)
create mode 100644 support/testing/tests/package/test_gzip.py
diff --git a/DEVELOPERS b/DEVELOPERS
index 75cfbd85a8..b0cab5c833 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1725,6 +1725,7 @@ F: support/testing/tests/package/test_compressor_base.py
F: support/testing/tests/package/test_ddrescue.py
F: support/testing/tests/package/test_ddrescue/
F: support/testing/tests/package/test_gnupg2.py
+F: support/testing/tests/package/test_gzip.py
F: support/testing/tests/package/test_highway.py
F: support/testing/tests/package/test_hwloc.py
F: support/testing/tests/package/test_iperf3.py
diff --git a/support/testing/tests/package/test_gzip.py b/support/testing/tests/package/test_gzip.py
new file mode 100644
index 0000000000..1d5f374853
--- /dev/null
+++ b/support/testing/tests/package/test_gzip.py
@@ -0,0 +1,13 @@
+from tests.package.test_compressor_base import TestCompressorBase
+
+
+class TestGzip(TestCompressorBase):
+ __test__ = True
+ config = TestCompressorBase.config + \
+ """
+ BR2_PACKAGE_BUSYBOX_SHOW_OTHERS=y
+ BR2_PACKAGE_GZIP=y
+ """
+ compress_cmd = "gzip"
+ decompress_cmd = "gunzip"
+ compressed_file_ext = ".gz"
--
2.41.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 3/4] support/testing/tests/package/test_bzip2.py: new runtime test
2023-07-06 19:00 [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 2/4] support/testing/tests/package/test_gzip.py: new runtime test Julien Olivain
@ 2023-07-06 19:01 ` Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 4/4] support/testing/tests/package/test_xz.py: " Julien Olivain
2023-07-11 21:03 ` [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Thomas Petazzoni via buildroot
3 siblings, 0 replies; 5+ messages in thread
From: Julien Olivain @ 2023-07-06 19:01 UTC (permalink / raw)
To: buildroot; +Cc: Julien Olivain
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
DEVELOPERS | 1 +
support/testing/tests/package/test_bzip2.py | 12 ++++++++++++
2 files changed, 13 insertions(+)
create mode 100644 support/testing/tests/package/test_bzip2.py
diff --git a/DEVELOPERS b/DEVELOPERS
index b0cab5c833..d22e3172be 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1721,6 +1721,7 @@ F: support/testing/tests/package/sample_python_gnupg.py
F: support/testing/tests/package/sample_python_hwdata.py
F: support/testing/tests/package/sample_python_pyalsa.py
F: support/testing/tests/package/sample_python_spake2.py
+F: support/testing/tests/package/test_bzip2.py
F: support/testing/tests/package/test_compressor_base.py
F: support/testing/tests/package/test_ddrescue.py
F: support/testing/tests/package/test_ddrescue/
diff --git a/support/testing/tests/package/test_bzip2.py b/support/testing/tests/package/test_bzip2.py
new file mode 100644
index 0000000000..4b7ae8180f
--- /dev/null
+++ b/support/testing/tests/package/test_bzip2.py
@@ -0,0 +1,12 @@
+from tests.package.test_compressor_base import TestCompressorBase
+
+
+class TestBzip2(TestCompressorBase):
+ __test__ = True
+ config = TestCompressorBase.config + \
+ """
+ BR2_PACKAGE_BZIP2=y
+ """
+ compress_cmd = "bzip2"
+ decompress_cmd = "bunzip2"
+ compressed_file_ext = ".bz2"
--
2.41.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Buildroot] [PATCH 4/4] support/testing/tests/package/test_xz.py: new runtime test
2023-07-06 19:00 [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 2/4] support/testing/tests/package/test_gzip.py: new runtime test Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 3/4] support/testing/tests/package/test_bzip2.py: " Julien Olivain
@ 2023-07-06 19:01 ` Julien Olivain
2023-07-11 21:03 ` [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Thomas Petazzoni via buildroot
3 siblings, 0 replies; 5+ messages in thread
From: Julien Olivain @ 2023-07-06 19:01 UTC (permalink / raw)
To: buildroot; +Cc: Julien Olivain
Signed-off-by: Julien Olivain <ju.o@free.fr>
---
DEVELOPERS | 1 +
support/testing/tests/package/test_xz.py | 10 ++++++++++
2 files changed, 11 insertions(+)
create mode 100644 support/testing/tests/package/test_xz.py
diff --git a/DEVELOPERS b/DEVELOPERS
index d22e3172be..f25d2ed9c9 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1751,6 +1751,7 @@ F: support/testing/tests/package/test_python_spake2.py
F: support/testing/tests/package/test_rdma_core.py
F: support/testing/tests/package/test_rdma_core/
F: support/testing/tests/package/test_stress_ng.py
+F: support/testing/tests/package/test_xz.py
F: support/testing/tests/package/test_z3.py
F: support/testing/tests/package/test_z3/
diff --git a/support/testing/tests/package/test_xz.py b/support/testing/tests/package/test_xz.py
new file mode 100644
index 0000000000..7776c1608f
--- /dev/null
+++ b/support/testing/tests/package/test_xz.py
@@ -0,0 +1,10 @@
+from tests.package.test_compressor_base import TestCompressorBase
+
+
+class TestXz(TestCompressorBase):
+ __test__ = True
+ config = TestCompressorBase.config + \
+ """
+ BR2_PACKAGE_XZ=y
+ """
+ compress_cmd = "xz"
--
2.41.0
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class
2023-07-06 19:00 [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Julien Olivain
` (2 preceding siblings ...)
2023-07-06 19:01 ` [Buildroot] [PATCH 4/4] support/testing/tests/package/test_xz.py: " Julien Olivain
@ 2023-07-11 21:03 ` Thomas Petazzoni via buildroot
3 siblings, 0 replies; 5+ messages in thread
From: Thomas Petazzoni via buildroot @ 2023-07-11 21:03 UTC (permalink / raw)
To: Julien Olivain; +Cc: buildroot
On Thu, 6 Jul 2023 21:00:59 +0200
Julien Olivain <ju.o@free.fr> wrote:
> This is a helper class providing a template for testing data
> compressor and decompressor programs such as gzip, bzip2, xz...
>
> Signed-off-by: Julien Olivain <ju.o@free.fr>
> ---
> DEVELOPERS | 1 +
> .../tests/package/test_compressor_base.py | 126 ++++++++++++++++++
> 2 files changed, 127 insertions(+)
> create mode 100644 support/testing/tests/package/test_compressor_base.py
Series applied, thanks!
Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-11 21:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-06 19:00 [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 2/4] support/testing/tests/package/test_gzip.py: new runtime test Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 3/4] support/testing/tests/package/test_bzip2.py: " Julien Olivain
2023-07-06 19:01 ` [Buildroot] [PATCH 4/4] support/testing/tests/package/test_xz.py: " Julien Olivain
2023-07-11 21:03 ` [Buildroot] [PATCH 1/4] support/testing/tests/package/test_compressor_base.py: new helper class Thomas Petazzoni via buildroot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox