Skip to content

Commit

Permalink
selftest: tpm2: Add Client.__del__() to close /dev/tpm* handle
Browse files Browse the repository at this point in the history
The following output can bee seen when the test is executed:

  test_flush_context (tpm2_tests.SpaceTest) ... \
    /usr/lib64/python3.6/unittest/case.py:605: ResourceWarning: \
    unclosed file <_io.FileIO name='/dev/tpmrm0' mode='rb+' closefd=True>

An instance of Client does not implicitly close /dev/tpm* handle, once it
gets destroyed. Close the file handle in the class destructor
Client.__del__().

Fixes: 6ea3dfe ("selftests: add TPM 2.0 tests")
Cc: Shuah Khan <shuah@kernel.org>
Cc: linux-kselftest@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
  • Loading branch information
Stefan Berger authored and Jarkko Sakkinen committed Oct 4, 2022
1 parent 72e9be6 commit 2d869f0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/testing/selftests/tpm2/tpm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ def __init__(self, flags = 0):
fcntl.fcntl(self.tpm, fcntl.F_SETFL, flags)
self.tpm_poll = select.poll()

def __del__(self):
if self.tpm:
self.tpm.close()

def close(self):
self.tpm.close()

Expand Down

0 comments on commit 2d869f0

Please sign in to comment.