diff mbox series

[2/2] test/py: replace 'tpm2 init, startup, selftest' sequences

Message ID 20230601062041.524010-2-ilias.apalodimas@linaro.org
State Superseded
Headers show
Series [1/2] tpm: Add 'tpm autostart' shell command | expand

Commit Message

Ilias Apalodimas June 1, 2023, 6:20 a.m. UTC
Instead of copy pasting the commands needed to start a TPM consisting
of:
- tpm init
- tpm startup TPM2_SU_CLEAR
- tpm2 self_test full
use the newly added 'autostart' which does the same thing and simplify
our python scripts

Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
---
 test/py/tests/test_tpm2.py | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

Comments

Simon Glass June 1, 2023, 9:51 p.m. UTC | #1
On Thu, 1 Jun 2023 at 00:21, Ilias Apalodimas
<ilias.apalodimas@linaro.org> wrote:
>
> Instead of copy pasting the commands needed to start a TPM consisting
> of:
> - tpm init
> - tpm startup TPM2_SU_CLEAR
> - tpm2 self_test full
> use the newly added 'autostart' which does the same thing and simplify
> our python scripts
>
> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> ---
>  test/py/tests/test_tpm2.py | 13 ++-----------
>  1 file changed, 2 insertions(+), 11 deletions(-)

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

Were you able to test this on a real TPM?


>
> diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
> index d2ad6f9e73c0..1ade66a7eda4 100644
> --- a/test/py/tests/test_tpm2.py
> +++ b/test/py/tests/test_tpm2.py
> @@ -41,11 +41,9 @@ def force_init(u_boot_console, force=False):
>      skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
>      if skip_test:
>          pytest.skip('skip TPM device test')
> -    output = u_boot_console.run_command('tpm2 init')
> +    output = u_boot_console.run_command('tpm2 autostart')
>      if force or not 'Error' in output:
>          u_boot_console.run_command('echo --- start of init ---')
> -        u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
> -        u_boot_console.run_command('tpm2 self_test full')
>          u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
>          output = u_boot_console.run_command('echo $?')
>          if not output.endswith('0'):
> @@ -83,20 +81,13 @@ def tpm2_sandbox_init(u_boot_console):
>      This allows all tests to run in parallel, since no test depends on another.
>      """
>      u_boot_console.restart_uboot()
> -    u_boot_console.run_command('tpm2 init')
> +    u_boot_console.run_command('tpm2 autostart')
>      output = u_boot_console.run_command('echo $?')
>      assert output.endswith('0')
>
>      skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
>      if skip_test:
>          pytest.skip('skip TPM device test')
> -    u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
> -    output = u_boot_console.run_command('echo $?')
> -    assert output.endswith('0')
> -
> -    u_boot_console.run_command('tpm2 self_test full')
> -    output = u_boot_console.run_command('echo $?')
> -    assert output.endswith('0')
>
>  @pytest.mark.buildconfigspec('cmd_tpm_v2')
>  def test_tpm2_sandbox_self_test_full(u_boot_console):
> --
> 2.39.2
>
Ilias Apalodimas June 2, 2023, 7:58 a.m. UTC | #2
On Fri, 2 Jun 2023 at 00:51, Simon Glass <sjg@chromium.org> wrote:
>
> On Thu, 1 Jun 2023 at 00:21, Ilias Apalodimas
> <ilias.apalodimas@linaro.org> wrote:
> >
> > Instead of copy pasting the commands needed to start a TPM consisting
> > of:
> > - tpm init
> > - tpm startup TPM2_SU_CLEAR
> > - tpm2 self_test full
> > use the newly added 'autostart' which does the same thing and simplify
> > our python scripts
> >
> > Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> > ---
> >  test/py/tests/test_tpm2.py | 13 ++-----------
> >  1 file changed, 2 insertions(+), 11 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Were you able to test this on a real TPM?

No just on sandbox.  I can run it on proper hardware before merging

Thanks
/Ilias
>
>
> >
> > diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
> > index d2ad6f9e73c0..1ade66a7eda4 100644
> > --- a/test/py/tests/test_tpm2.py
> > +++ b/test/py/tests/test_tpm2.py
> > @@ -41,11 +41,9 @@ def force_init(u_boot_console, force=False):
> >      skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
> >      if skip_test:
> >          pytest.skip('skip TPM device test')
> > -    output = u_boot_console.run_command('tpm2 init')
> > +    output = u_boot_console.run_command('tpm2 autostart')
> >      if force or not 'Error' in output:
> >          u_boot_console.run_command('echo --- start of init ---')
> > -        u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
> > -        u_boot_console.run_command('tpm2 self_test full')
> >          u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
> >          output = u_boot_console.run_command('echo $?')
> >          if not output.endswith('0'):
> > @@ -83,20 +81,13 @@ def tpm2_sandbox_init(u_boot_console):
> >      This allows all tests to run in parallel, since no test depends on another.
> >      """
> >      u_boot_console.restart_uboot()
> > -    u_boot_console.run_command('tpm2 init')
> > +    u_boot_console.run_command('tpm2 autostart')
> >      output = u_boot_console.run_command('echo $?')
> >      assert output.endswith('0')
> >
> >      skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
> >      if skip_test:
> >          pytest.skip('skip TPM device test')
> > -    u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
> > -    output = u_boot_console.run_command('echo $?')
> > -    assert output.endswith('0')
> > -
> > -    u_boot_console.run_command('tpm2 self_test full')
> > -    output = u_boot_console.run_command('echo $?')
> > -    assert output.endswith('0')
> >
> >  @pytest.mark.buildconfigspec('cmd_tpm_v2')
> >  def test_tpm2_sandbox_self_test_full(u_boot_console):
> > --
> > 2.39.2
> >
diff mbox series

Patch

diff --git a/test/py/tests/test_tpm2.py b/test/py/tests/test_tpm2.py
index d2ad6f9e73c0..1ade66a7eda4 100644
--- a/test/py/tests/test_tpm2.py
+++ b/test/py/tests/test_tpm2.py
@@ -41,11 +41,9 @@  def force_init(u_boot_console, force=False):
     skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
     if skip_test:
         pytest.skip('skip TPM device test')
-    output = u_boot_console.run_command('tpm2 init')
+    output = u_boot_console.run_command('tpm2 autostart')
     if force or not 'Error' in output:
         u_boot_console.run_command('echo --- start of init ---')
-        u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
-        u_boot_console.run_command('tpm2 self_test full')
         u_boot_console.run_command('tpm2 clear TPM2_RH_LOCKOUT')
         output = u_boot_console.run_command('echo $?')
         if not output.endswith('0'):
@@ -83,20 +81,13 @@  def tpm2_sandbox_init(u_boot_console):
     This allows all tests to run in parallel, since no test depends on another.
     """
     u_boot_console.restart_uboot()
-    u_boot_console.run_command('tpm2 init')
+    u_boot_console.run_command('tpm2 autostart')
     output = u_boot_console.run_command('echo $?')
     assert output.endswith('0')
 
     skip_test = u_boot_console.config.env.get('env__tpm_device_test_skip', False)
     if skip_test:
         pytest.skip('skip TPM device test')
-    u_boot_console.run_command('tpm2 startup TPM2_SU_CLEAR')
-    output = u_boot_console.run_command('echo $?')
-    assert output.endswith('0')
-
-    u_boot_console.run_command('tpm2 self_test full')
-    output = u_boot_console.run_command('echo $?')
-    assert output.endswith('0')
 
 @pytest.mark.buildconfigspec('cmd_tpm_v2')
 def test_tpm2_sandbox_self_test_full(u_boot_console):