lkml.org 
[lkml]   [2020]   [Jun]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] Kernel selftests: TPM2: upgrade TPM2 tests from Python 2 to Python 3
On Tue, Jun 23, 2020 at 12:46:18AM +0300, Jarkko Sakkinen wrote:
> On Thu, Jun 18, 2020 at 04:15:02PM +0800, Pengfei Xu wrote:
> > Python 2 is no longer supported by the Python upstream project, so
> > upgrade TPM2 tests to Python 3.
> >
> > Signed-off-by: Pengfei Xu <pengfei.xu@intel.com>
>
> Use "selftests: tpm: <short summary>".
>
> > ---
> > tools/testing/selftests/tpm2/test_smoke.sh | 4 +-
> > tools/testing/selftests/tpm2/test_space.sh | 2 +-
> > tools/testing/selftests/tpm2/tpm2.py | 68 ++++++++++++++--------
> > tools/testing/selftests/tpm2/tpm2_tests.py | 24 +++++---
> > 4 files changed, 61 insertions(+), 37 deletions(-)
> >
> > diff --git a/tools/testing/selftests/tpm2/test_smoke.sh b/tools/testing/selftests/tpm2/test_smoke.sh
> > index 663062701d5a..d05467f6d258 100755
> > --- a/tools/testing/selftests/tpm2/test_smoke.sh
> > +++ b/tools/testing/selftests/tpm2/test_smoke.sh
> > @@ -6,8 +6,8 @@ ksft_skip=4
> >
> > [ -f /dev/tpm0 ] || exit $ksft_skip
> >
> > -python -m unittest -v tpm2_tests.SmokeTest
> > -python -m unittest -v tpm2_tests.AsyncTest
> > +python3 -m unittest -v tpm2_tests.SmokeTest
> > +python3 -m unittest -v tpm2_tests.AsyncTest
> >
> > CLEAR_CMD=$(which tpm2_clear)
> > if [ -n $CLEAR_CMD ]; then
> > diff --git a/tools/testing/selftests/tpm2/test_space.sh b/tools/testing/selftests/tpm2/test_space.sh
> > index 36c9d030a1c6..151c64e8ee9f 100755
> > --- a/tools/testing/selftests/tpm2/test_space.sh
> > +++ b/tools/testing/selftests/tpm2/test_space.sh
> > @@ -6,4 +6,4 @@ ksft_skip=4
> >
> > [ -f /dev/tpmrm0 ] || exit $ksft_skip
> >
> > -python -m unittest -v tpm2_tests.SpaceTest
> > +python3 -m unittest -v tpm2_tests.SpaceTest
> > diff --git a/tools/testing/selftests/tpm2/tpm2.py b/tools/testing/selftests/tpm2/tpm2.py
> > index d0fcb66a88a6..b0ccc1499c53 100644
> > --- a/tools/testing/selftests/tpm2/tpm2.py
> > +++ b/tools/testing/selftests/tpm2/tpm2.py
> > @@ -247,14 +247,18 @@ class ProtocolError(Exception):
> > class AuthCommand(object):
> > """TPMS_AUTH_COMMAND"""
> >
> > - def __init__(self, session_handle=TPM2_RS_PW, nonce='', session_attributes=0,
> > - hmac=''):
> > + def __init__(self, session_handle=TPM2_RS_PW, nonce=''.encode(),
> > + session_attributes=0, hmac=''.encode()):
> > + if not isinstance(nonce, bytes):
> > + nonce = nonce.encode()
> > + if not isinstance(hmac, bytes):
> > + hmac = hmac.encode()
>
> This looks messy. Please, instead
>
> def __init__(self, session_handle=TPM2_RS_PW, nonce=bytes(),
> session_attributes=0, hmac=bytes()):
> self.session_handle = session_handle
> self.nonce = nonce
> self.session_attributes = session_attributes
>
> Applies also to other places.

I.e. use '.encode()' in the call site.

/Jarkko

\
 
 \ /
  Last update: 2020-06-22 23:48    [W:0.073 / U:0.144 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site