[v4,2/2] support/testing: add bmap_tools test
diff mbox series

Message ID 20191105125039.1443-2-nicolas.carrier@orolia.com
State New
Headers show
Series
  • [v4,1/2] package/bmap-tools: new package
Related show

Commit Message

Nicolas Carrier Nov. 5, 2019, 12:51 p.m. UTC
This patch implements a simple test in which a dummy file system image
is created, then `bmaptool create` and `bmaptool copy` are used to copy
it to another file.

---

Changes v3 -> v4:
  - no change

Changes v2 -> v3:
  - title changed to "support/testing: add bmap_tools test"
    I followed Arnout's suggestion, but if there's a veto on that I can still
    change...
  - added myself in the DEVELOPERS file for both test scripts
  - implemented genericity following Thomas' comment, i.e. without ABC, which
    results in a simpler, cleaner and shorter code (thank you btw ^^)
  - fixed all the defects reported by flake8
  - increased timeout to 20s

I saw that most of the python tests duplicate code between tests for v2 and v3.
I think we should factor that, even if only small portions of code are
concerned and, of course, I'm willing to do that if it's considered a good idea.

---

Signed-off-by: Nicolas Carrier <nicolas.carrier@orolia.com>
---
 DEVELOPERS                                    |  2 +
 .../tests/package/sample_bmap_tools.sh        | 15 ++++++
 .../testing/tests/package/test_bmap_tools.py  | 47 +++++++++++++++++++
 3 files changed, 64 insertions(+)
 create mode 100755 support/testing/tests/package/sample_bmap_tools.sh
 create mode 100644 support/testing/tests/package/test_bmap_tools.py

Comments

Romain Naour Nov. 19, 2019, 9:41 p.m. UTC | #1
Le 05/11/2019 à 13:51, Nicolas Carrier a écrit :
> This patch implements a simple test in which a dummy file system image
> is created, then `bmaptool create` and `bmaptool copy` are used to copy
> it to another file.
> 
> ---
> 
> Changes v3 -> v4:
>   - no change
> 
> Changes v2 -> v3:
>   - title changed to "support/testing: add bmap_tools test"
>     I followed Arnout's suggestion, but if there's a veto on that I can still
>     change...
>   - added myself in the DEVELOPERS file for both test scripts
>   - implemented genericity following Thomas' comment, i.e. without ABC, which
>     results in a simpler, cleaner and shorter code (thank you btw ^^)
>   - fixed all the defects reported by flake8
>   - increased timeout to 20s
> 
> I saw that most of the python tests duplicate code between tests for v2 and v3.
> I think we should factor that, even if only small portions of code are
> concerned and, of course, I'm willing to do that if it's considered a good idea.
> 
> ---
> 
> Signed-off-by: Nicolas Carrier <nicolas.carrier@orolia.com>
> ---
>  DEVELOPERS                                    |  2 +
>  .../tests/package/sample_bmap_tools.sh        | 15 ++++++
>  .../testing/tests/package/test_bmap_tools.py  | 47 +++++++++++++++++++
>  3 files changed, 64 insertions(+)
>  create mode 100755 support/testing/tests/package/sample_bmap_tools.sh
>  create mode 100644 support/testing/tests/package/test_bmap_tools.py
> 
> diff --git a/DEVELOPERS b/DEVELOPERS
> index 947722a8c7..5a8888ab90 100644
> --- a/DEVELOPERS
> +++ b/DEVELOPERS
> @@ -1730,6 +1730,8 @@ F:	package/uacme/
>  
>  N:	Nicolas Carrier <nicolas.carrier@orolia.com>
>  F:	package/bmap-tools/
> +F:	support/testing/tests/package/sample_bmap_tools.sh
> +F:	support/testing/tests/package/test_bmap_tools.py
>  
>  N:	Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
>  F:	package/libgit2/
> diff --git a/support/testing/tests/package/sample_bmap_tools.sh b/support/testing/tests/package/sample_bmap_tools.sh
> new file mode 100755
> index 0000000000..7c90368c17
> --- /dev/null
> +++ b/support/testing/tests/package/sample_bmap_tools.sh
> @@ -0,0 +1,15 @@
> +#!/bin/sh
> +# simple test which creates a dummy file system image, then use bmaptool create
> +# and bmaptool copy to copy it to another file
> +
> +set -xeu
> +
> +# create the necessary test files
> +dd if=/dev/zero of=disk.img bs=2M count=1
> +mkfs.ext4 disk.img
> +fallocate -d disk.img
> +dd if=/dev/zero of=copy.img bs=2M count=1
> +
> +# do a test copy of the file system image
> +bmaptool create -o disk.img.bmap disk.img
> +bmaptool copy disk.img copy.img

bmaptool is able to use pbzip2, bzip2,
gzip, pigz, xz, lzop, lz4, tar and unzip system programs for decompressing.

Maybe we can extend the test using different compressed file format.

Note: bmaptool can use ssh program for remote file transfers.

Best regards,
Romain

> diff --git a/support/testing/tests/package/test_bmap_tools.py b/support/testing/tests/package/test_bmap_tools.py
> new file mode 100644
> index 0000000000..7ea4057aba
> --- /dev/null
> +++ b/support/testing/tests/package/test_bmap_tools.py
> @@ -0,0 +1,47 @@
> +import os
> +import infra
> +
> +from infra.basetest import BRTest
> +
> +
> +class TestBmapTools(BRTest):
> +    __test__ = False
> +    sample_script = "tests/package/sample_bmap_tools.sh"
> +    copy_script = 'tests/package/copy-sample-script-to-target.sh'
> +    config = f'''
> +        {infra.basetest.BASIC_TOOLCHAIN_CONFIG}
> +        BR2_TARGET_ROOTFS_CPIO=y
> +        BR2_PACKAGE_BMAP_TOOLS=y
> +        BR2_ROOTFS_POST_BUILD_SCRIPT="{infra.filepath(copy_script)}"
> +        BR2_ROOTFS_POST_SCRIPT_ARGS="{infra.filepath(sample_script)}"
> +        # BR2_TARGET_ROOTFS_TAR is not set
> +        BR2_PACKAGE_UTIL_LINUX=y
> +        BR2_PACKAGE_UTIL_LINUX_FALLOCATE=y
> +        BR2_PACKAGE_E2FSPROGS=y
> +        BR2_PACKAGE_UTIL_LINUX_LIBUUID=y
> +        '''
> +
> +    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()
> +        cmd = f"/root/{os.path.basename(self.sample_script)}"
> +        _, exit_code = self.emulator.run(cmd, timeout=20)
> +        self.assertEqual(exit_code, 0)
> +
> +
> +class TestPy2BmapTools(TestBmapTools):
> +    __test__ = True
> +    config = f"""{TestBmapTools.config}
> +    BR2_PACKAGE_PYTHON=y"""
> +
> +
> +class TestPy3BmapTools(TestBmapTools):
> +    __test__ = True
> +    config = f"""{TestBmapTools.config}
> +    BR2_PACKAGE_PYTHON3=y"""
>

Patch
diff mbox series

diff --git a/DEVELOPERS b/DEVELOPERS
index 947722a8c7..5a8888ab90 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -1730,6 +1730,8 @@  F:	package/uacme/
 
 N:	Nicolas Carrier <nicolas.carrier@orolia.com>
 F:	package/bmap-tools/
+F:	support/testing/tests/package/sample_bmap_tools.sh
+F:	support/testing/tests/package/test_bmap_tools.py
 
 N:	Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
 F:	package/libgit2/
diff --git a/support/testing/tests/package/sample_bmap_tools.sh b/support/testing/tests/package/sample_bmap_tools.sh
new file mode 100755
index 0000000000..7c90368c17
--- /dev/null
+++ b/support/testing/tests/package/sample_bmap_tools.sh
@@ -0,0 +1,15 @@ 
+#!/bin/sh
+# simple test which creates a dummy file system image, then use bmaptool create
+# and bmaptool copy to copy it to another file
+
+set -xeu
+
+# create the necessary test files
+dd if=/dev/zero of=disk.img bs=2M count=1
+mkfs.ext4 disk.img
+fallocate -d disk.img
+dd if=/dev/zero of=copy.img bs=2M count=1
+
+# do a test copy of the file system image
+bmaptool create -o disk.img.bmap disk.img
+bmaptool copy disk.img copy.img
diff --git a/support/testing/tests/package/test_bmap_tools.py b/support/testing/tests/package/test_bmap_tools.py
new file mode 100644
index 0000000000..7ea4057aba
--- /dev/null
+++ b/support/testing/tests/package/test_bmap_tools.py
@@ -0,0 +1,47 @@ 
+import os
+import infra
+
+from infra.basetest import BRTest
+
+
+class TestBmapTools(BRTest):
+    __test__ = False
+    sample_script = "tests/package/sample_bmap_tools.sh"
+    copy_script = 'tests/package/copy-sample-script-to-target.sh'
+    config = f'''
+        {infra.basetest.BASIC_TOOLCHAIN_CONFIG}
+        BR2_TARGET_ROOTFS_CPIO=y
+        BR2_PACKAGE_BMAP_TOOLS=y
+        BR2_ROOTFS_POST_BUILD_SCRIPT="{infra.filepath(copy_script)}"
+        BR2_ROOTFS_POST_SCRIPT_ARGS="{infra.filepath(sample_script)}"
+        # BR2_TARGET_ROOTFS_TAR is not set
+        BR2_PACKAGE_UTIL_LINUX=y
+        BR2_PACKAGE_UTIL_LINUX_FALLOCATE=y
+        BR2_PACKAGE_E2FSPROGS=y
+        BR2_PACKAGE_UTIL_LINUX_LIBUUID=y
+        '''
+
+    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()
+        cmd = f"/root/{os.path.basename(self.sample_script)}"
+        _, exit_code = self.emulator.run(cmd, timeout=20)
+        self.assertEqual(exit_code, 0)
+
+
+class TestPy2BmapTools(TestBmapTools):
+    __test__ = True
+    config = f"""{TestBmapTools.config}
+    BR2_PACKAGE_PYTHON=y"""
+
+
+class TestPy3BmapTools(TestBmapTools):
+    __test__ = True
+    config = f"""{TestBmapTools.config}
+    BR2_PACKAGE_PYTHON3=y"""