Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3089745ybt; Mon, 22 Jun 2020 14:52:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTtqFQM8AA0+BuyStO1ncW2erATcJMbzCVWZbwrx7coYe/81tenXZ3YhuMVMrY2jFpjsHx X-Received: by 2002:a05:6402:8d8:: with SMTP id d24mr18738769edz.287.1592862738839; Mon, 22 Jun 2020 14:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592862738; cv=none; d=google.com; s=arc-20160816; b=yGEqBBH7e2ClZK+D6IZp6/rYgdhUE2QmsI9gBRK0Sz23UIZY1U+94KMaDLHbsDHTg6 RdApahEOQKk6NmCBkl+kllgJSsB8uLHiWq43uftonYMgA751t/V7ZDLlvjfAKrq/RueI S5yJNzdoPHpLuFoNei070nvT5RZob8P2pYXfAlasNfr6cIS/zOhbWwhbYxgvrMyzK22a +6GuHkmIx5fbLkaSORwYRB1IIyhar0ZOUsmeiAiAx7S0LUOEhr2x9P7fxtYItPdhkiD9 Vo+wcOSBg315GqFTj2jzzWM/8nXjOC26h1vrV1XecuW3a//SDCpmN+/2a2Vfv4Ty3YJx ucXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:ironport-sdr:ironport-sdr; bh=Bg4JdYt4n8iy6UX9OrmwK9r9vH+t6QD/VpPmqAOT8MI=; b=Rih/oQIBhMfwXk/2jydww2f/lBZRcERoFLPnAbr6eF+QNoLBnOShkfjEKdHlKPwDPP /9trFdzQKTQfVpsz8K3g9Pv9YwA7AheMzUutI80C9+qTzYF2mpWLINawZQ7wvyhbKViZ 3izDd9bK9B2ptlpvp/B1uPVsh6aa50tDecQAgGH0hvAxt3eMM9QN5jzXZGtjXGr3o0CG DI2F75uMhNxqgDHVyqJV7tmickHB7K8Py6XDbgEA2P83B0dzVBbJQzYFbQzQCBcuRfbu Msv9pmaIYulDdcMU8gL3G3LtKh3BzBOnKTf8ky2wNUaknpGkMEAZfGTstfRvNgs1n/KU kNtA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si10119616edy.470.2020.06.22.14.51.56; Mon, 22 Jun 2020 14:52:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730765AbgFVVrp (ORCPT + 99 others); Mon, 22 Jun 2020 17:47:45 -0400 Received: from mga04.intel.com ([192.55.52.120]:20842 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727049AbgFVVro (ORCPT ); Mon, 22 Jun 2020 17:47:44 -0400 IronPort-SDR: ZodNfaIS04hWJQ/CSIq/9ZzvLmfdIoJYAwAq9Wufyfh4FohkrZOqLUjpjnFm9XztGr0bdIC1PI 3frgASyl8p1g== X-IronPort-AV: E=McAfee;i="6000,8403,9660"; a="141383919" X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="141383919" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2020 14:47:44 -0700 IronPort-SDR: klFt9lM/VG83Mhux4A2krEf8V3LNHiXvB3y999chqZTg8LqBCVpQ6q0ad+pbfZFpJjqSGAbrD9 9Jva/FrFlMhA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,268,1589266800"; d="scan'208";a="300984512" Received: from jczajka-mobl.ger.corp.intel.com (HELO localhost) ([10.249.40.133]) by fmsmga004.fm.intel.com with ESMTP; 22 Jun 2020 14:47:40 -0700 Date: Tue, 23 Jun 2020 00:47:39 +0300 From: Jarkko Sakkinen To: Pengfei Xu Cc: Shuah Khan , Qiuxu Zhuo , Heng Su , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Svahn Subject: Re: [PATCH v2] Kernel selftests: TPM2: upgrade TPM2 tests from Python 2 to Python 3 Message-ID: <20200622214739.GB22727@linux.intel.com> References: <20200618081502.15302-1-pengfei.xu@intel.com> <20200622214613.GA22727@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200622214613.GA22727@linux.intel.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > > Use "selftests: tpm: ". > > > --- > > 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