From patchwork Wed Aug 23 20:45:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Petazzoni X-Patchwork-Id: 805171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=busybox.net (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=buildroot-bounces@busybox.net; receiver=) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xczwd5ygGz9t34 for ; Thu, 24 Aug 2017 06:46:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 1837330B31; Wed, 23 Aug 2017 20:46:08 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id bTBSr0FMRDAV; Wed, 23 Aug 2017 20:46:07 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by silver.osuosl.org (Postfix) with ESMTP id 44D3C30B34; Wed, 23 Aug 2017 20:46:07 +0000 (UTC) X-Original-To: buildroot@lists.busybox.net Delivered-To: buildroot@osuosl.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by ash.osuosl.org (Postfix) with ESMTP id 85F261C1FCF for ; Wed, 23 Aug 2017 20:46:00 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 819188A268 for ; Wed, 23 Aug 2017 20:46:00 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WXOae0PcVpiC for ; Wed, 23 Aug 2017 20:45:59 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail.free-electrons.com (mail.free-electrons.com [62.4.15.54]) by hemlock.osuosl.org (Postfix) with ESMTP id 4B35A8A266 for ; Wed, 23 Aug 2017 20:45:59 +0000 (UTC) Received: by mail.free-electrons.com (Postfix, from userid 110) id 7F78D209C6; Wed, 23 Aug 2017 22:45:57 +0200 (CEST) Received: from localhost (132.230.147.77.rev.sfr.net [77.147.230.132]) by mail.free-electrons.com (Postfix) with ESMTPSA id 0BC2320993; Wed, 23 Aug 2017 22:45:56 +0200 (CEST) From: Thomas Petazzoni To: Buildroot List , "Yann E. MORIN" , "Arnout Vandecappelle (Essensium/Mind)" , Peter Korsgaard Date: Wed, 23 Aug 2017 22:45:47 +0200 Message-Id: <20170823204547.16672-3-thomas.petazzoni@free-electrons.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170823204547.16672-1-thomas.petazzoni@free-electrons.com> References: <20170823204547.16672-1-thomas.petazzoni@free-electrons.com> Cc: Thomas Petazzoni Subject: [Buildroot] [RFC-next 2/2] support/testing: add tests for the genimage generation logic X-BeenThere: buildroot@busybox.net X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: buildroot-bounces@busybox.net Sender: "buildroot" This commit adds two new test cases, to validate that the genimage related functionality in Buildroot is working as expected: - One test case with just one ext4 partition. We do the build, check in the image that one partition is available with the right type, and then boot the system under Qemu to validate that the root filesystem can be mounted from /dev/mmcblk0p1. - One test case with one VFAT partition and one ext4 partition. We do the build, check in the image that two partitions are available with the right types, and then boot the system under Qemu. This allows to validate that the root filesystem can be mounted from /dev/mmcblk0p2, and that /dev/mmcblk0p1 can be mounted as a VFAT filesystem and contains the expected file. Signed-off-by: Thomas Petazzoni --- support/testing/tests/fs/genimage-simple.cfg | 9 ++++ support/testing/tests/fs/genimage-vfat.cfg | 25 ++++++++++ support/testing/tests/fs/test_genimage.py | 74 ++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 support/testing/tests/fs/genimage-simple.cfg create mode 100644 support/testing/tests/fs/genimage-vfat.cfg create mode 100644 support/testing/tests/fs/test_genimage.py diff --git a/support/testing/tests/fs/genimage-simple.cfg b/support/testing/tests/fs/genimage-simple.cfg new file mode 100644 index 0000000..baafe31 --- /dev/null +++ b/support/testing/tests/fs/genimage-simple.cfg @@ -0,0 +1,9 @@ +image sdcard.img { + hdimage { + } + + partition rootfs { + partition-type = 0x83 + image = "rootfs.ext4" + } +} diff --git a/support/testing/tests/fs/genimage-vfat.cfg b/support/testing/tests/fs/genimage-vfat.cfg new file mode 100644 index 0000000..5a5388b --- /dev/null +++ b/support/testing/tests/fs/genimage-vfat.cfg @@ -0,0 +1,25 @@ +image boot.vfat { + vfat { + files = { + "rootfs.tar", + } + } + size = 16M +} + +image sdcard.img { + hdimage { + } + + partition boot { + partition-type = 0xC + bootable = "true" + image = "boot.vfat" + offset = 8M + } + + partition rootfs { + partition-type = 0x83 + image = "rootfs.ext4" + } +} diff --git a/support/testing/tests/fs/test_genimage.py b/support/testing/tests/fs/test_genimage.py new file mode 100644 index 0000000..f2edd2b --- /dev/null +++ b/support/testing/tests/fs/test_genimage.py @@ -0,0 +1,74 @@ +import json +import os +import subprocess +import infra.basetest + +class TestGenimageSimple(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_TARGET_ROOTFS_EXT2=y + BR2_TARGET_ROOTFS_EXT2_4=y + BR2_TARGET_ROOTFS_GENIMAGE=y + BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE="{}" + """.format(infra.filepath("tests/fs/genimage-simple.cfg")) + + def test_run(self): + img = os.path.join(self.builddir, "images", "sdcard.img") + sfdisk_cmd = ["host/usr/sbin/sfdisk", "-J", img] + out = subprocess.check_output(sfdisk_cmd, cwd=self.builddir, + env={"LANG":"C"}) + data = json.loads(out) + partitions = data['partitiontable']['partitions'] + self.assertEqual(len(partitions), 1) + ext_part = partitions[0] + self.assertTrue(ext_part['node'].endswith("sdcard.img1")) + self.assertEqual(ext_part['type'], "83") + + subprocess.call(["truncate", "-s", "%1M", img]) + + self.emulator.boot(arch="armv7", + kernel="builtin", + kernel_cmdline=["root=/dev/mmcblk0p1", "rootfstype=ext4"], + options=["-drive", "file={},if=sd,format=raw".format(img)]) + self.emulator.login() + +class TestGenimageVfat(infra.basetest.BRTest): + config = infra.basetest.BASIC_TOOLCHAIN_CONFIG + \ + """ + BR2_TARGET_ROOTFS_EXT2=y + BR2_TARGET_ROOTFS_EXT2_4=y + BR2_TARGET_ROOTFS_GENIMAGE=y + BR2_TARGET_ROOTFS_GENIMAGE_CFG_FILE="{}" + BR2_TARGET_ROOTFS_GENIMAGE_USES_VFAT=y + """.format(infra.filepath("tests/fs/genimage-vfat.cfg")) + + def test_run(self): + img = os.path.join(self.builddir, "images", "sdcard.img") + sfdisk_cmd = ["host/usr/sbin/sfdisk", "-J", img] + out = subprocess.check_output(sfdisk_cmd, cwd=self.builddir, + env={"LANG":"C"}) + data = json.loads(out) + partitions = data['partitiontable']['partitions'] + self.assertEqual(len(partitions), 2) + vfat_part = partitions[0] + self.assertTrue(vfat_part['node'].endswith("sdcard.img1")) + self.assertEqual(vfat_part['type'], "c") + ext_part = partitions[1] + self.assertTrue(ext_part['node'].endswith("sdcard.img2")) + self.assertEqual(ext_part['type'], "83") + + subprocess.call(["truncate", "-s", "%1M", img]) + + self.emulator.boot(arch="armv7", + kernel="builtin", + kernel_cmdline=["root=/dev/mmcblk0p2", "rootfstype=ext4"], + options=["-drive", "file={},if=sd,format=raw".format(img)]) + self.emulator.login() + + cmd = "mount -t vfat /dev/mmcblk0p1 /mnt" + _, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, 0) + cmd = "ls -l /mnt/rootfs.tar" + _, exit_code = self.emulator.run(cmd) + self.assertEqual(exit_code, 0) +