-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a single TPM context and avoid race conditions during tests #870
base: master
Are you sure you want to change the base?
Conversation
11c8157
to
ea16d5d
Compare
ea16d5d
to
8f6f651
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a brief look and LGTM, only a small question
/packit retest-failed |
8f6f651
to
7774527
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
|
7774527
to
6acaaab
Compare
4fac5f8
to
9b855cb
Compare
So I ended up implementing a mutex to let only a single test that creates keys in the TPM to run at once. This allows the tests to run in parallel, in multiple threads. I believe some of the flakyness we saw in the past is now solved. @THS-on Could you please take a look again? |
/packit retest-failed |
/packit test |
9b855cb
to
08c750a
Compare
This implements a singleton to use a single instance of the tss_espi::Context. This also avoids race conditions by using a thread-safe mutex to access the context. The tests were modified to cleanup generated key handles between test cases, preventing leftover handles to fill the TPM memory. Introduce a mutex to allow only a single test that create keys in the TPM to run at once. It is required that tests that create keys in the TPM to run the tpm::testing::lock_tests() to obtain the mutex and be able to continue executing without the risk of other tests filling the TPM memory. The QuoteData::fixture implementation (used only during tests) was modified to flush the created key contexts when dropped. It also was modified to lock the global mutex by calling the tpm::testing::lock_tests() and provide the respective guard, preventing other tests that use the fixture (which necessarily create TPM keys) to run in parallel. Note that it is necessary to drop the QuoteData explicitly to guarantee that the keys are flushed before releasing the global mutex. Finally, the following changes were made to the tests/run.sh: * Do not use tpm2-abrmd anymore, and use only the swtpm socket instead * Stop the started processes at exit With all these changes, the tests/run.sh can now be executed locally without any special setting. Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
Add the tests/setup_swtpm.sh script which setup a Software TPM in a temporary directory, starts the swtpm socket, and sets the environment TCTI accordingly. This allows the tests to be executed locally, even with the "testing" feature. Unfortunately, it is not possible to cleanup some of the transient objects created during tests, being necessary to cleanup manually between runs by running: $ tpm2_flushcontext -t -l -s Another caveat is that the tests need to run on a single thread to avoid test cases that create objects to run in parallel, which can fill up the TPM memory with transient object contexts. For this, please run the tests on a single thread: $ cargo test --features=testing -- --test-threads=1 The swtpm socket process is stopped when exiting from the started shell. Fixes: keylime#259 Signed-off-by: Anderson Toshiyuki Sasaki <[email protected]>
08c750a
to
ccd62eb
Compare
This implements a singleton to use a single instance of the
tss_espi::Context
.This also avoids race conditions by using a thread-safe mutex to access
the context.
The tests were modified to cleanup generated key handles between test
cases, preventing leftover handles to fill the TPM memory.
Introduce a mutex to allow only a single test that create keys in the
TPM to run at once. It is required that tests that create keys in the
TPM to run the
tpm::testing::lock_tests()
to obtain the mutex and beable to continue executing without the risk of other tests filling the
TPM memory.
The
QuoteData::fixture
implementation (used only during tests) wasmodified to flush the created key contexts when dropped. It also was
modified to lock the global mutex by calling the
tpm::testing::lock_tests()
and provide the respective guard, preventingother tests that use the fixture (which necessarily create TPM keys) to
run in parallel.
Note that it is necessary to
drop
theQuoteData
fixture explicitly to guaranteethat the keys are flushed before releasing the global mutex.
Finally, the following changes were made to the
tests/run.sh
:tpm2-abrmd
anymore, and use only theswtpm
socket insteadWith all these changes, the
tests/run.sh
can now be executed locallywithout any special setting.
This also adds a script to initialize a software TPM locally for testing.
Fixes #259