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@xxxxxxxxx> 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. /Jarkko