diff mbox series

[v2,3/3] test: efi_bootmgr: add a test case for a short-form path

Message ID 20220512022903.65346-4-takahiro.akashi@linaro.org
State New
Headers show
Series efi_loader: bootmgr: fix a problem in loading an image from a short-path | expand

Commit Message

AKASHI Takahiro May 12, 2022, 2:29 a.m. UTC
A short-form path starting with a file device path will be tested in
a new test case.

This type of short-form path will be created with "efidebug boot add -b",
in particular, when a file system has no partition table.

Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 test/py/tests/test_efi_bootmgr/conftest.py    | 25 +++++++++++++++++++
 .../test_efi_bootmgr/test_efi_bootmgr.py      | 25 +++++++++++++++++++
 2 files changed, 50 insertions(+)

Comments

Heinrich Schuchardt May 12, 2022, 7:02 a.m. UTC | #1
On 5/12/22 04:29, AKASHI Takahiro wrote:
> A short-form path starting with a file device path will be tested in
> a new test case.
>
> This type of short-form path will be created with "efidebug boot add -b",
> in particular, when a file system has no partition table.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> ---
>   test/py/tests/test_efi_bootmgr/conftest.py    | 25 +++++++++++++++++++
>   .../test_efi_bootmgr/test_efi_bootmgr.py      | 25 +++++++++++++++++++
>   2 files changed, 50 insertions(+)
>
> diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
> index a0a754afbe1b..5cd7252671fa 100644
> --- a/test/py/tests/test_efi_bootmgr/conftest.py
> +++ b/test/py/tests/test_efi_bootmgr/conftest.py
> @@ -38,3 +38,28 @@ def efi_bootmgr_data(u_boot_config):
>                  shell=True)
>
>       return image_path
> +
> +@pytest.fixture(scope='session')
> +def efi_bootmgr_data2(u_boot_config):
> +    """Set up a file system without a partition table to be used
> +       in UEFI bootmanager tests

Why do you want a file system without partition table? This is nothing
the UEFI specification expects to support. Your test should cover having
a partition table and a device path which is file only.

Best regards

Heinrich

> +
> +    Args:
> +        u_boot_config -- U-boot configuration.
> +
> +    Return:
> +        A path to disk image to be used for testing
> +    """
> +    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr'
> +    image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr_data2.img'
> +
> +    shutil.rmtree(mnt_point, ignore_errors=True)
> +    os.mkdir(mnt_point, mode = 0o755)
> +
> +    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi',
> +                    mnt_point + '/helloworld.efi')
> +
> +    check_call(f'virt-make-fs --size=+1M --type=vfat {mnt_point} {image_path}',
> +               shell=True)
> +
> +    return image_path
> diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> index 75a6e7c96296..ab3d53a2dc95 100644
> --- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> +++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> @@ -41,3 +41,28 @@ def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
>
>       u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
>       u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
> +
> +@pytest.mark.boardspec('sandbox')
> +@pytest.mark.buildconfigspec('cmd_efidebug')
> +@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
> +def test_efi_bootmgr_short(u_boot_console, efi_bootmgr_data2):
> +    """ Unit test for UEFI bootmanager with a short-form path
> +    In this test case,
> +    - File system has no partition table
> +    - UEFI load option has a short-form path starting with a file device path
> +
> +    Args:
> +        u_boot_console -- U-Boot console
> +        efi_bootmgr_data2 -- Path to the disk image used for testing.
> +    """
> +    u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data2}')
> +
> +    u_boot_console.run_command(cmd = 'efidebug boot add ' \
> +        '-b 0001 TEST2 host 0:0 helloworld.efi')

This will not create a file only device path. So this does not test
patch 1 and 2.

You could use setenv -e -i to create the boot option.

Best regards

Heinrich

> +    response = u_boot_console.run_command(cmd = 'efidebug boot dump')
> +    assert 'file_path: /helloworld.efi' in response
> +    u_boot_console.run_command(cmd = 'efidebug boot next 0001')
> +    response = u_boot_console.run_command(cmd = 'bootefi bootmgr')
> +    assert 'Hello, world!' in response
> +
> +    u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
AKASHI Takahiro May 12, 2022, 7:10 a.m. UTC | #2
On Thu, May 12, 2022 at 09:02:36AM +0200, Heinrich Schuchardt wrote:
> On 5/12/22 04:29, AKASHI Takahiro wrote:
> > A short-form path starting with a file device path will be tested in
> > a new test case.
> > 
> > This type of short-form path will be created with "efidebug boot add -b",
> > in particular, when a file system has no partition table.
> > 
> > Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
> > ---
> >   test/py/tests/test_efi_bootmgr/conftest.py    | 25 +++++++++++++++++++
> >   .../test_efi_bootmgr/test_efi_bootmgr.py      | 25 +++++++++++++++++++
> >   2 files changed, 50 insertions(+)
> > 
> > diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
> > index a0a754afbe1b..5cd7252671fa 100644
> > --- a/test/py/tests/test_efi_bootmgr/conftest.py
> > +++ b/test/py/tests/test_efi_bootmgr/conftest.py
> > @@ -38,3 +38,28 @@ def efi_bootmgr_data(u_boot_config):
> >                  shell=True)
> > 
> >       return image_path
> > +
> > +@pytest.fixture(scope='session')
> > +def efi_bootmgr_data2(u_boot_config):
> > +    """Set up a file system without a partition table to be used
> > +       in UEFI bootmanager tests
> 
> Why do you want a file system without partition table? This is nothing
> the UEFI specification expects to support.

As we discussed several times in the past, a partition table in the file
system is not mandatory in U-Boot's UEFI subsystem.

> Your test should cover having
> a partition table and a device path which is file only.
> 
> Best regards
> 
> Heinrich
> 
> > +
> > +    Args:
> > +        u_boot_config -- U-boot configuration.
> > +
> > +    Return:
> > +        A path to disk image to be used for testing
> > +    """
> > +    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr'
> > +    image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr_data2.img'
> > +
> > +    shutil.rmtree(mnt_point, ignore_errors=True)
> > +    os.mkdir(mnt_point, mode = 0o755)
> > +
> > +    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi',
> > +                    mnt_point + '/helloworld.efi')
> > +
> > +    check_call(f'virt-make-fs --size=+1M --type=vfat {mnt_point} {image_path}',
> > +               shell=True)
> > +
> > +    return image_path
> > diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> > index 75a6e7c96296..ab3d53a2dc95 100644
> > --- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> > +++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
> > @@ -41,3 +41,28 @@ def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
> > 
> >       u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
> >       u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
> > +
> > +@pytest.mark.boardspec('sandbox')
> > +@pytest.mark.buildconfigspec('cmd_efidebug')
> > +@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
> > +def test_efi_bootmgr_short(u_boot_console, efi_bootmgr_data2):
> > +    """ Unit test for UEFI bootmanager with a short-form path
> > +    In this test case,
> > +    - File system has no partition table
> > +    - UEFI load option has a short-form path starting with a file device path
> > +
> > +    Args:
> > +        u_boot_console -- U-Boot console
> > +        efi_bootmgr_data2 -- Path to the disk image used for testing.
> > +    """
> > +    u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data2}')
> > +
> > +    u_boot_console.run_command(cmd = 'efidebug boot add ' \
> > +        '-b 0001 TEST2 host 0:0 helloworld.efi')
> 
> This will not create a file only device path. So this does not test
> patch 1 and 2.

It does.
See the output from "efidebug boot dump" in the log.

> You could use setenv -e -i to create the boot option.
> 
> Best regards
> 
> Heinrich
> 
> > +    response = u_boot_console.run_command(cmd = 'efidebug boot dump')
> > +    assert 'file_path: /helloworld.efi' in response

Furthermore, here is the check for a device path only with a file.

-Takahiro Akashi

> > +    u_boot_console.run_command(cmd = 'efidebug boot next 0001')
> > +    response = u_boot_console.run_command(cmd = 'bootefi bootmgr')
> > +    assert 'Hello, world!' in response
> > +
> > +    u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
>
diff mbox series

Patch

diff --git a/test/py/tests/test_efi_bootmgr/conftest.py b/test/py/tests/test_efi_bootmgr/conftest.py
index a0a754afbe1b..5cd7252671fa 100644
--- a/test/py/tests/test_efi_bootmgr/conftest.py
+++ b/test/py/tests/test_efi_bootmgr/conftest.py
@@ -38,3 +38,28 @@  def efi_bootmgr_data(u_boot_config):
                shell=True)
 
     return image_path
+
+@pytest.fixture(scope='session')
+def efi_bootmgr_data2(u_boot_config):
+    """Set up a file system without a partition table to be used
+       in UEFI bootmanager tests
+
+    Args:
+        u_boot_config -- U-boot configuration.
+
+    Return:
+        A path to disk image to be used for testing
+    """
+    mnt_point = u_boot_config.persistent_data_dir + '/test_efi_bootmgr'
+    image_path = u_boot_config.persistent_data_dir + '/efi_bootmgr_data2.img'
+
+    shutil.rmtree(mnt_point, ignore_errors=True)
+    os.mkdir(mnt_point, mode = 0o755)
+
+    shutil.copyfile(u_boot_config.build_dir + '/lib/efi_loader/helloworld.efi',
+                    mnt_point + '/helloworld.efi')
+
+    check_call(f'virt-make-fs --size=+1M --type=vfat {mnt_point} {image_path}',
+               shell=True)
+
+    return image_path
diff --git a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
index 75a6e7c96296..ab3d53a2dc95 100644
--- a/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
+++ b/test/py/tests/test_efi_bootmgr/test_efi_bootmgr.py
@@ -41,3 +41,28 @@  def test_efi_bootmgr(u_boot_console, efi_bootmgr_data):
 
     u_boot_console.run_command(cmd = 'efidebug boot rm 0001')
     u_boot_console.run_command(cmd = 'efidebug boot rm 0002')
+
+@pytest.mark.boardspec('sandbox')
+@pytest.mark.buildconfigspec('cmd_efidebug')
+@pytest.mark.buildconfigspec('cmd_bootefi_bootmgr')
+def test_efi_bootmgr_short(u_boot_console, efi_bootmgr_data2):
+    """ Unit test for UEFI bootmanager with a short-form path
+    In this test case,
+    - File system has no partition table
+    - UEFI load option has a short-form path starting with a file device path
+
+    Args:
+        u_boot_console -- U-Boot console
+        efi_bootmgr_data2 -- Path to the disk image used for testing.
+    """
+    u_boot_console.run_command(cmd = f'host bind 0 {efi_bootmgr_data2}')
+
+    u_boot_console.run_command(cmd = 'efidebug boot add ' \
+        '-b 0001 TEST2 host 0:0 helloworld.efi')
+    response = u_boot_console.run_command(cmd = 'efidebug boot dump')
+    assert 'file_path: /helloworld.efi' in response
+    u_boot_console.run_command(cmd = 'efidebug boot next 0001')
+    response = u_boot_console.run_command(cmd = 'bootefi bootmgr')
+    assert 'Hello, world!' in response
+
+    u_boot_console.run_command(cmd = 'efidebug boot rm 0001')