diff mbox series

[v2,3/8] tests: gpt: Remove test order dependency

Message ID 20230823164755.2874792-4-JPEWhacker@gmail.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series cmd: gpt: GPT manipulation improvements | expand

Commit Message

Joshua Watt Aug. 23, 2023, 4:47 p.m. UTC
Re-create a clean disk image for each test to prevent modifications from
one test affecting another

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 test/py/tests/test_gpt.py | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

Comments

Simon Glass Aug. 23, 2023, 11:57 p.m. UTC | #1
Hi Joshua,

On Wed, 23 Aug 2023 at 10:48, Joshua Watt <jpewhacker@gmail.com> wrote:
>
> Re-create a clean disk image for each test to prevent modifications from
> one test affecting another
>
> Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
> ---
>  test/py/tests/test_gpt.py | 20 ++++++++------------
>  1 file changed, 8 insertions(+), 12 deletions(-)

I suppose this is OK, but is it expensive in terms of time?

Reviewed-by: Simon Glass <sjg@chromium.org>

Regards,
Simon
Joshua Watt Aug. 24, 2023, 3:29 a.m. UTC | #2
On Wed, Aug 23, 2023 at 5:59 PM Simon Glass <sjg@chromium.org> wrote:
>
> Hi Joshua,
>
> On Wed, 23 Aug 2023 at 10:48, Joshua Watt <jpewhacker@gmail.com> wrote:
> >
> > Re-create a clean disk image for each test to prevent modifications from
> > one test affecting another
> >
> > Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
> > ---
> >  test/py/tests/test_gpt.py | 20 ++++++++------------
> >  1 file changed, 8 insertions(+), 12 deletions(-)
>
> I suppose this is OK, but is it expensive in terms of time?

There wasn't a noticeable slowdown in test execution time on my
(admittedly powerful) workstation.

>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Regards,
> Simon
diff mbox series

Patch

diff --git a/test/py/tests/test_gpt.py b/test/py/tests/test_gpt.py
index 73bfbf77a2..339468bc12 100644
--- a/test/py/tests/test_gpt.py
+++ b/test/py/tests/test_gpt.py
@@ -61,18 +61,14 @@  class GptTestDiskImage(object):
         cmd = ('cp', persistent, self.path)
         u_boot_utils.run_and_log(u_boot_console, cmd)
 
-gtdi = None
 @pytest.fixture(scope='function')
 def state_disk_image(u_boot_console):
     """pytest fixture to provide a GptTestDiskImage object to tests.
     This is function-scoped because it uses u_boot_console, which is also
-    function-scoped. However, we don't need to actually do any function-scope
-    work, so this simply returns the same object over and over each time."""
+    function-scoped. A new disk is returned each time to prevent tests from
+    interfering with each other."""
 
-    global gtdi
-    if not gtdi:
-        gtdi = GptTestDiskImage(u_boot_console)
-    return gtdi
+    return GptTestDiskImage(u_boot_console)
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_gpt')
@@ -186,12 +182,12 @@  def test_gpt_swap_partitions(state_disk_image, u_boot_console):
 
     u_boot_console.run_command('host bind 0 ' + state_disk_image.path)
     output = u_boot_console.run_command('part list host 0')
-    assert '0x00000800	0x00000fff	"first"' in output
-    assert '0x00001000	0x00001bff	"second"' in output
-    u_boot_console.run_command('gpt swap host 0 first second')
+    assert '0x00000800	0x00000fff	"part1"' in output
+    assert '0x00001000	0x00001bff	"part2"' in output
+    u_boot_console.run_command('gpt swap host 0 part1 part2')
     output = u_boot_console.run_command('part list host 0')
-    assert '0x00000800	0x00000fff	"second"' in output
-    assert '0x00001000	0x00001bff	"first"' in output
+    assert '0x00000800	0x00000fff	"part2"' in output
+    assert '0x00001000	0x00001bff	"part1"' in output
 
 @pytest.mark.boardspec('sandbox')
 @pytest.mark.buildconfigspec('cmd_gpt')