Merge pull request #30015 from poettering/tpm2-slow-tests

tests: skip slow tpm2 tests if slow tests aren't enabled
This commit is contained in:
Yu Watanabe
2023-11-14 02:38:33 +09:00
committed by GitHub
3 changed files with 30 additions and 1 deletions
+3
View File
@@ -104,6 +104,9 @@ extern const TestFunc _weak_ __stop_SYSTEMD_TEST_TABLE[];
REGISTER_TEST(test_##name, ##__VA_ARGS__); \
static int test_##name(void)
#define TEST_LOG_FUNC() \
log_info("/* %s() */", __func__)
static inline int run_test_table(void) {
_cleanup_strv_free_ char **tests = NULL;
int r = EXIT_SUCCESS;
+1
View File
@@ -408,6 +408,7 @@ executables += [
test_template + {
'sources' : files('test-tpm2.c'),
'dependencies' : libopenssl,
'timeout' : 120,
},
test_template + {
'sources' : files('test-utmp.c'),
+26 -1
View File
@@ -2,8 +2,9 @@
#include "hexdecoct.h"
#include "macro.h"
#include "tpm2-util.h"
#include "tests.h"
#include "tpm2-util.h"
#include "virt.h"
TEST(tpm2_pcr_index_from_string) {
assert_se(tpm2_pcr_index_from_string("platform-code") == 0);
@@ -995,6 +996,8 @@ TEST(tpm2_get_srk_template) {
}
static void check_best_srk_template(Tpm2Context *c) {
TEST_LOG_FUNC();
TPMT_PUBLIC template;
assert_se(tpm2_get_best_srk_template(c, &template) >= 0);
@@ -1009,6 +1012,8 @@ static void check_best_srk_template(Tpm2Context *c) {
static void check_test_parms(Tpm2Context *c) {
assert(c);
TEST_LOG_FUNC();
TPMU_PUBLIC_PARMS parms = {
.symDetail.sym = {
.algorithm = TPM2_ALG_AES,
@@ -1031,6 +1036,8 @@ static void check_test_parms(Tpm2Context *c) {
static void check_supports_alg(Tpm2Context *c) {
assert(c);
TEST_LOG_FUNC();
/* Test invalid algs */
assert_se(!tpm2_supports_alg(c, TPM2_ALG_ERROR));
assert_se(!tpm2_supports_alg(c, TPM2_ALG_LAST + 1));
@@ -1044,6 +1051,8 @@ static void check_supports_alg(Tpm2Context *c) {
static void check_supports_command(Tpm2Context *c) {
assert(c);
TEST_LOG_FUNC();
/* Test invalid commands. TPM specification Part 2 ("Structures") section "TPM_CC (Command Codes)"
* states bits 31:30 and 28:16 are reserved and must be 0. */
assert_se(!tpm2_supports_command(c, UINT32_C(0x80000000)));
@@ -1062,6 +1071,8 @@ static void check_supports_command(Tpm2Context *c) {
}
static void check_get_or_create_srk(Tpm2Context *c) {
TEST_LOG_FUNC();
_cleanup_free_ TPM2B_PUBLIC *public = NULL;
_cleanup_free_ TPM2B_NAME *name = NULL, *qname = NULL;
_cleanup_(tpm2_handle_freep) Tpm2Handle *handle = NULL;
@@ -1132,6 +1143,13 @@ static int check_calculate_seal(Tpm2Context *c) {
assert(c);
int r;
if (detect_virtualization() == VIRTUALIZATION_NONE && !slow_tests_enabled()) {
log_notice("Skipping slow calculate seal TPM2 tests. Physical system detected, and slow tests disabled.");
return 0;
}
TEST_LOG_FUNC();
_cleanup_free_ TPM2B_PUBLIC *srk_public = NULL;
assert_se(tpm2_get_srk(c, NULL, &srk_public, NULL, NULL, NULL) >= 0);
calculate_seal_and_unseal(c, TPM2_SRK_HANDLE, srk_public);
@@ -1204,6 +1222,13 @@ static void check_seal_unseal(Tpm2Context *c) {
assert(c);
if (detect_virtualization() == VIRTUALIZATION_NONE && !slow_tests_enabled()) {
log_notice("Skipping slow seal/unseal TPM2 tests. Physical system detected, and slow tests disabled.");
return;
}
TEST_LOG_FUNC();
check_seal_unseal_for_handle(c, 0);
check_seal_unseal_for_handle(c, TPM2_SRK_HANDLE);