{"id":814347,"url":"http://patchwork.ozlabs.org/api/patches/814347/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/20170915172551.26500-1-swarren@wwwdotorg.org/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170915172551.26500-1-swarren@wwwdotorg.org>","list_archive_url":null,"date":"2017-09-15T17:25:51","name":"[U-Boot] test/py: gpt: make use of infra-structure","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"4db74e830152470fe03bb433ab522da53581a7f5","submitter":{"id":12517,"url":"http://patchwork.ozlabs.org/api/people/12517/?format=json","name":"Stephen Warren","email":"swarren@wwwdotorg.org"},"delegate":{"id":3651,"url":"http://patchwork.ozlabs.org/api/users/3651/?format=json","username":"trini","first_name":"Tom","last_name":"Rini","email":"trini@ti.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/20170915172551.26500-1-swarren@wwwdotorg.org/mbox/","series":[{"id":3342,"url":"http://patchwork.ozlabs.org/api/series/3342/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=3342","date":"2017-09-15T17:25:51","name":"[U-Boot] test/py: gpt: make use of infra-structure","version":1,"mbox":"http://patchwork.ozlabs.org/series/3342/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/814347/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/814347/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xv2PL5LbPz9s3w\n\tfor <incoming@patchwork.ozlabs.org>;\n\tSat, 16 Sep 2017 03:26:14 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 5C63AC21C4A; Fri, 15 Sep 2017 17:26:10 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 1063AC21C3C;\n\tFri, 15 Sep 2017 17:26:07 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 95B4FC21C3C; Fri, 15 Sep 2017 17:26:05 +0000 (UTC)","from avon.wwwdotorg.org (avon.wwwdotorg.org [104.237.132.123])\n\tby lists.denx.de (Postfix) with ESMTPS id 9F1ABC21C29\n\tfor <u-boot@lists.denx.de>; Fri, 15 Sep 2017 17:26:04 +0000 (UTC)","from swarren-lx1.nvidia.com (thunderhill.nvidia.com\n\t[216.228.112.22])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits))\n\t(No client certificate requested)\n\tby avon.wwwdotorg.org (Postfix) with ESMTPSA id 0E8101C02C7;\n\tFri, 15 Sep 2017 11:26:00 -0600 (MDT)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=0.0 required=5.0 tests=none autolearn=unavailable\n\tautolearn_force=no version=3.4.0","X-Virus-Status":"Clean","X-Virus-Scanned":"clamav-milter 0.99.2 at avon.wwwdotorg.org","From":"Stephen Warren <swarren@wwwdotorg.org>","To":"Tom Rini <trini@konsulko.com>","Date":"Fri, 15 Sep 2017 11:25:51 -0600","Message-Id":"<20170915172551.26500-1-swarren@wwwdotorg.org>","X-Mailer":"git-send-email 2.14.1","X-NVConfidentiality":"public","Cc":"Alison Chaiken <alison@peloton-tech.com>, u-boot@lists.denx.de,\n\tStephen Warren <swarren@nvidia.com>","Subject":"[U-Boot] [PATCH] test/py: gpt: make use of infra-structure","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"},"content":"From: Stephen Warren <swarren@nvidia.com>\n\nMake various changes to the GPT test:\n\n1) Reference the disk image using an absolute path in all cases. This\nallows test/py to operate correctly if it's run from a directory other\nthan the root of the U-Boot source tree.\n\n2) Store the disk image in the teswt/py persistent data directory. This\nremoves the need to re-generate it every time the tests are run.\n\n3) Execute sgdisk using u_boot_utils.run_and_log() so that its output is\ncaptured in the test log. This allows debugging any problems running it.\n\n4) Make the disk image a test fixture. This removes the requirement to\nalways run all GPT tests, and run them in order. The current code doesn't\ncreate the disk image if e.g. just test_gpt_uuid() is executed via the\ntest.py -k command-line option.\n\n5) Use @pytest.mark.buildconfigspec for all feature dependencies, rather\nthan manually implementing some of them.\n\nFixes: a2f422555fc8 (\"add pytests for 'gpt guid' command in sandbox\")\nFixes: c5772188ede9 (\"add pytests for 'gpt rename' and 'gpt swap'\")\nSigned-off-by: Stephen Warren <swarren@nvidia.com>\n---\n test/py/make_test_disk.py | 19 -----------\n test/py/tests/test_gpt.py | 83 +++++++++++++++++++++++++++++++++++------------\n 2 files changed, 62 insertions(+), 40 deletions(-)\n delete mode 100755 test/py/make_test_disk.py","diff":"diff --git a/test/py/make_test_disk.py b/test/py/make_test_disk.py\ndeleted file mode 100755\nindex 5288295588a7..000000000000\n--- a/test/py/make_test_disk.py\n+++ /dev/null\n@@ -1,19 +0,0 @@\n-# Copyright (c) 2017 Alison Chaiken\n-#\n-# SPDX-License-Identifier: GPL-2.0\n-#\n-# Create a block device for testing of 'gpt' and 'part' commands.\n-\n-import os\n-\n-def makeDisk():\n-    if (os.path.exists(\"testdisk.raw\")):\n-        os.remove(\"testdisk.raw\")\n-    fd = os.open(\"testdisk.raw\", os.O_RDWR|os.O_CREAT )\n-    os.ftruncate(fd, 4194304)\n-    os.close(fd)\n-    os.spawnl(os.P_WAIT, \"/sbin/sgdisk\", \"sgdisk\", \"-U\",\n-          \"375a56f7-d6c9-4e81-b5f0-09d41ca89efe\", \"testdisk.raw\")\n-    os.spawnl(os.P_WAIT, \"/sbin/sgdisk\", \"sgdisk\", \"--new=1:2048:2560\", \"testdisk.raw\")\n-    os.spawnl(os.P_WAIT, \"/sbin/sgdisk\", \"sgdisk\", \"--new=2:4096:4608\", \"testdisk.raw\")\n-    os.spawnl(os.P_WAIT, \"/sbin/gdisk\", \"sgdisk\", \"-l\", \"testdisk.raw\")\ndiff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py\nindex 06f24b66cef8..378d82a66e3b 100644\n--- a/test/py/tests/test_gpt.py\n+++ b/test/py/tests/test_gpt.py\n@@ -1,4 +1,5 @@\n # Copyright (c) 2017 Alison Chaiken\n+# Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.\n #\n # SPDX-License-Identifier: GPL-2.0\n \n@@ -7,42 +8,85 @@\n import os\n import pytest\n import u_boot_utils\n-import make_test_disk\n \n \"\"\"\n-These tests rely on a 4 MB block device called testdisk.raw\n-which is automatically removed at the end of the tests.\n+These tests rely on a 4 MB disk image, which is automatically created by\n+the test.\n \"\"\"\n \n+class GptTestDiskImage(object):\n+    \"\"\"Disk Image used by the GPT tests.\"\"\"\n+\n+    def __init__(self, u_boot_console):\n+        \"\"\"Initialize a new GptTestDiskImage object.\n+\n+        Args:\n+            u_boot_console: A U-Boot console.\n+\n+        Returns:\n+            Nothing.\n+        \"\"\"\n+\n+        filename = 'test_gpt_disk_image.bin'\n+        self.path = u_boot_console.config.persistent_data_dir + '/' + filename\n+\n+        if os.path.exists(self.path):\n+            u_boot_console.log.action('Disk image file ' + self.path +\n+                ' already exists')\n+        else:\n+            u_boot_console.log.action('Generating ' + self.path)\n+            fd = os.open(self.path, os.O_RDWR | os.O_CREAT)\n+            os.ftruncate(fd, 4194304)\n+            os.close(fd)\n+            sgdisk = '/sbin/sgdisk'\n+            cmd = (sgdisk, '-U', '375a56f7-d6c9-4e81-b5f0-09d41ca89efe',\n+                self.path)\n+            u_boot_utils.run_and_log(u_boot_console, cmd)\n+            cmd = (sgdisk, '--new=1:2048:2560', self.path)\n+            u_boot_utils.run_and_log(u_boot_console, cmd)\n+            cmd = (sgdisk, '--new=2:4096:4608', self.path)\n+            u_boot_utils.run_and_log(u_boot_console, cmd)\n+            cmd = (sgdisk, '-l', self.path)\n+            u_boot_utils.run_and_log(u_boot_console, cmd)\n+\n+gtdi = None\n+@pytest.fixture(scope='function')\n+def state_disk_image(u_boot_console):\n+    \"\"\"pytest fixture to provide a GptTestDiskImage object to tests.\n+    This is function-scoped because it uses u_boot_console, which is also\n+    function-scoped. However, we don't need to actually do any function-scope\n+    work, so this simply returns the same object over and over each time.\"\"\"\n+\n+    global gtdi\n+    if not gtdi:\n+        gtdi = GptTestDiskImage(u_boot_console)\n+    return gtdi\n+\n @pytest.mark.buildconfigspec('cmd_gpt')\n-def test_gpt_guid(u_boot_console):\n+def test_gpt_guid(state_disk_image, u_boot_console):\n     \"\"\"Test the gpt guid command.\"\"\"\n \n-    if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':\n-        pytest.skip('gpt command not supported')\n-    make_test_disk.makeDisk()\n-    u_boot_console.run_command('host bind 0 testdisk.raw')\n+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)\n     output = u_boot_console.run_command('gpt guid host 0')\n     assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output\n \n @pytest.mark.buildconfigspec('cmd_gpt')\n-def test_gpt_save_guid(u_boot_console):\n+def test_gpt_save_guid(state_disk_image, u_boot_console):\n     \"\"\"Test the gpt guid command to save GUID into a string.\"\"\"\n \n     if u_boot_console.config.buildconfig.get('config_cmd_gpt', 'n') != 'y':\n         pytest.skip('gpt command not supported')\n-    u_boot_console.run_command('host bind 0 testdisk.raw')\n+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)\n     output = u_boot_console.run_command('gpt guid host 0 newguid')\n     output = u_boot_console.run_command('printenv newguid')\n     assert '375a56f7-d6c9-4e81-b5f0-09d41ca89efe' in output\n \n @pytest.mark.buildconfigspec('cmd_gpt')\n-def test_gpt_rename_partition(u_boot_console):\n+@pytest.mark.buildconfigspec('cmd_gpt_rename')\n+def test_gpt_rename_partition(state_disk_image, u_boot_console):\n     \"\"\"Test the gpt rename command to write partition names.\"\"\"\n \n-    if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 'y':\n-        pytest.skip('gpt rename command not supported')\n-    u_boot_console.run_command('host bind 0 testdisk.raw')\n+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)\n     u_boot_console.run_command('gpt rename host 0 1 first')\n     output = u_boot_console.run_command('gpt read host 0')\n     assert 'name first' in output\n@@ -51,14 +95,12 @@ def test_gpt_rename_partition(u_boot_console):\n     assert 'name second' in output\n \n @pytest.mark.buildconfigspec('cmd_gpt')\n-def test_gpt_swap_partitions(u_boot_console):\n+@pytest.mark.buildconfigspec('cmd_gpt_rename')\n+@pytest.mark.buildconfigspec('cmd_part')\n+def test_gpt_swap_partitions(state_disk_image, u_boot_console):\n     \"\"\"Test the gpt swap command to exchange two partition names.\"\"\"\n \n-    if u_boot_console.config.buildconfig.get('config_cmd_gpt_rename', 'n') != 'y':\n-        pytest.skip('gpt rename command not supported')\n-    if u_boot_console.config.buildconfig.get('config_cmd_part', 'n') != 'y':\n-        pytest.skip('gpt swap test needs CMD_PART')\n-    u_boot_console.run_command('host bind 0 testdisk.raw')\n+    u_boot_console.run_command('host bind 0 ' + state_disk_image.path)\n     output = u_boot_console.run_command('part list host 0')\n     assert '0x000007ff\t\"first\"' in output\n     assert '0x000017ff\t\"second\"' in output\n@@ -66,4 +108,3 @@ def test_gpt_swap_partitions(u_boot_console):\n     output = u_boot_console.run_command('part list host 0')\n     assert '0x000007ff\t\"second\"' in output\n     assert '0x000017ff\t\"first\"' in output\n-    os.remove('testdisk.raw')\n","prefixes":["U-Boot"]}