aboutsummaryrefslogtreecommitdiff
path: root/tools/testing/selftests/tpm2
AgeCommit message (Collapse)AuthorFilesLines
2024-09-17selftests: tpm2: test_smoke: Run only when TPM2 is avaialable.Michal Suchanek1-0/+2
Since Linux 5.6 tpm_version_major sysfs file is avaialble which gives the TPM version. Using this file the test can be skipped on systems with TPM 1.2. Signed-off-by: Michal Suchanek <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2024-07-31selftests: tpm2: redirect python unittest logs to stdoutMuhammad Usama Anjum3-3/+3
The python unittest module writes all its output to stderr, even when the run is clean. Redirect its output logs to stdout. Cc: Jarkko Sakkinen <[email protected]> Signed-off-by: Muhammad Usama Anjum <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2023-02-13selftests: tpm2: remove redundant ord()Tzung-Bi Shih1-1/+1
When testing with FLAG_DEBUG enabled client, it emits the following error messages: File "/root/tpm2/tpm2.py", line 347, in hex_dump d = [format(ord(x), '02x') for x in d] File "/root/tpm2/tpm2.py", line 347, in <listcomp> d = [format(ord(x), '02x') for x in d] TypeError: ord() expected string of length 1, but int found The input of hex_dump() should be packed binary data. Remove the ord(). Signed-off-by: Tzung-Bi Shih <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2022-11-29selftests/tpm2: Split async tests call to separate shell script runnerNĂ­colas F. R. A. Prado3-2/+11
When the async test case was introduced, despite being a completely independent test case, the command to run it was added to the same shell script as the smoke test case. Since a shell script implicitly returns the error code from the last run command, this effectively caused the script to only return as error code the result from the async test case, hiding the smoke test result (which could then only be seen from the python unittest logs). Move the async test case call to its own shell script runner to avoid the aforementioned issue. This also makes the output clearer to read, since each kselftest KTAP result now matches with one python unittest report. While at it, also make it so the async test case is skipped if /dev/tpmrm0 doesn't exist, since commit 8335adb8f9d3 ("selftests: tpm: add async space test with noneexisting handle") added a test that relies on it. Signed-off-by: NĂ­colas F. R. A. Prado <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2022-10-05selftest: tpm2: Add Client.__del__() to close /dev/tpm* handleStefan Berger1-0/+4
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: 6ea3dfe1e0732 ("selftests: add TPM 2.0 tests") Cc: Shuah Khan <[email protected]> Cc: [email protected] Cc: Jarkko Sakkinen <[email protected]> Signed-off-by: Stefan Berger <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2022-06-28selftests/tpm2: increase timeout for kselftestsJohannes Holland1-0/+1
Due to CreatePrimary commands which need to create RSA keys of increasing size, the timeout value need to be raised, as well. Default is 45s. Fixed git am white space warns: Shuah Khan <[email protected]> Signed-off-by: Johannes Holland <[email protected]> Signed-off-by: Stefan Mahnke-Hartmann <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2022-03-08selftests: tpm: add async space test with noneexisting handleTadeusz Struk1-0/+16
Add a test for /dev/tpmrm0 in async mode that checks if the code handles invalid handles correctly. Cc: Jarkko Sakkinen <[email protected]> Cc: Shuah Khan <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Tested-by: Jarkko Sakkinen<[email protected]> Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2022-03-08selftests: tpm2: Determine available PCR bankStefan Berger2-8/+52
Determine an available PCR bank to be used by a test case by querying the capability TPM2_GET_CAP. The TPM2 returns TPML_PCR_SELECTIONS that contains an array of TPMS_PCR_SELECTIONs indicating available PCR banks and the bitmasks that show which PCRs are enabled in each bank. Collect the data in a dictionary. From the dictionary determine the PCR bank that has the PCRs enabled that the test needs. This avoids test failures with TPM2's that either to not have a SHA-1 bank or whose SHA-1 bank is disabled. Signed-off-by: Stefan Berger <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2020-07-06selftests: tpm: upgrade TPM2 tests from Python 2 to Python 3Pengfei Xu4-49/+52
Python 2 is no longer supported by the Python upstream project, so upgrade TPM2 tests to Python 3. Fixed minor merge conflicts Shuah Khan <[email protected]> Signed-off-by: Pengfei Xu <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-06-29selftests: tpm: Use /bin/sh instead of /bin/bashJarkko Sakkinen2-2/+2
It's better to use /bin/sh instead of /bin/bash in order to run the tests in the BusyBox shell. Fixes: 6ea3dfe1e073 ("selftests: add TPM 2.0 tests") Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-06-29selftests: tpm: Use 'test -e' instead of 'test -f'Jarkko Sakkinen2-2/+2
'test -f' is suitable only for *regular* files. Use 'test -e' instead. Cc: Nikita Sobolev <[email protected]> Cc: [email protected] Cc: [email protected] Fixes: 5627f9cffee7 ("Kernel selftests: Add check if TPM devices are supported") Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-06-29Revert "tpm: selftest: cleanup after unseal with wrong auth/policy test"Jarkko Sakkinen1-5/+0
The reverted commit illegitly uses tpm2-tools. External dependencies are absolutely forbidden from these tests. There is also the problem that clearing is not necessarily wanted behavior if the test/target computer is not used only solely for testing. Fixes: a9920d3bad40 ("tpm: selftest: cleanup after unseal with wrong auth/policy test") Cc: Tadeusz Struk <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-05-22Kernel selftests: Add check if TPM devices are supportedNikita Sobolev2-0/+10
TPM2 tests set uses /dev/tpm0 and /dev/tpmrm0 without check if they are available. In case, when these devices are not available test fails, but expected behaviour is skipped test. Signed-off-by: Nikita Sobolev <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-04-14Revert "Kernel selftests: tpm2: check for tpm support"Jarkko Sakkinen2-19/+3
This reverts commit b32694cd0724d4ceca2c62cc7c3d3a8d1ffa11fc. The original comment was neither reviewed nor tested. Thus, this the *only* possible action to take. Cc: Nikita Sobolev <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2020-02-10Kernel selftests: tpm2: check for tpm supportNikita Sobolev2-3/+19
tpm2 tests set fails if there is no /dev/tpm0 and /dev/tpmrm0 supported. Check if these files exist before run and mark test as skipped in case of absence. Signed-off-by: Nikita Sobolev <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2019-12-17tpm: selftest: cleanup after unseal with wrong auth/policy testTadeusz Struk1-0/+5
Unseal with wrong auth or wrong policy test affects DA lockout and eventually causes the tests to fail with: "ProtocolError: TPM_RC_LOCKOUT: rc=0x00000921" when the tests run multiple times. Send tpm clear command after the test to reset the DA counters. Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2019-12-17tpm: selftest: add test covering async modeTadeusz Struk3-2/+31
Add a test that sends a tpm cmd in an async mode. Currently there is a gap in test coverage with regards to this functionality. Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
2019-09-23selftests: tpm2: install python filesAnders Roxell1-0/+1
Both test_smoke.sh and test_space.sh require tpm2.py and tpm2_test.py. Rework so that tpm2.py and tpm2_test.py gets installed, added them to the variable TEST_PROGS_EXTENDED. Signed-off-by: Anders Roxell <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
2019-04-08selftests/tpm2: Open tpm dev in unbuffered modeTadeusz Struk1-2/+2
In order to have control over how many bytes are read or written the device needs to be opened in unbuffered mode. Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: James Morris <[email protected]>
2019-04-08selftests/tpm2: Extend tests to cover partial readsTadeusz Struk2-0/+64
Three new tests added: 1. Send get random cmd, read header in 1st read, read the rest in second read - expect success 2. Send get random cmd, read only part of the response, send another get random command, read the response - expect success 3. Send get random cmd followed by another get random cmd, without reading the first response - expect the second cmd to fail with -EBUSY Signed-off-by: Tadeusz Struk <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Tested-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Signed-off-by: James Morris <[email protected]>
2019-02-08selftests: add TPM 2.0 testsJarkko Sakkinen5-0/+935
Added the tests that I've been using for testing TPM 2.0 functionality for a long time but have been out-of-tree so far, residing in https://github.com/jsakkine-intel/tpm2-scripts Cc: Tadeusz Struk <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]> Acked-by: Joey Pabalinas <[email protected]> Reviewed-by: Petr Vorel <[email protected]>