Skip to content

Commit

Permalink
test: gracefully handle TPM2_RC_COMMAND_CODE in various tests
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Holland <johannes.holland@infineon.de>
  • Loading branch information
Johannes Holland committed Jul 16, 2024
1 parent 89be4c7 commit 29291bc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 4 additions & 2 deletions test/integration/esys-audit.int.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ test_esys_audit(ESYS_CONTEXT * esys_context)
LOG_WARNING("Platform authorization not possible.");
failure_return = EXIT_SKIP;
goto error;
} else if (r == TPM2_RC_COMMAND_CODE) {
/* Ignore command not supported */
} else {
goto_if_error(r, "Error: SetCommandCodeAuditStatus", error);
}

goto_if_error(r, "Error: SetCommandCodeAuditStatus", error);

r = Esys_FlushContext(esys_context, signHandle);
goto_if_error(r, "Error: FlushContext", error);

Expand Down
3 changes: 3 additions & 0 deletions test/integration/sys-create-loaded.int.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <stdlib.h> // for exit, NULL, size_t
#include <string.h> // for memset, memcpy

#include "test-esys.h" // for EXIT_SKIP
#include "tss2_common.h" // for TSS2_RC, TSS2_RC_SUCCESS, TSS2_BASE_RC_...
#include "tss2_mu.h" // for Tss2_MU_TPMT_PUBLIC_Marshal
#include "tss2_sys.h" // for Tss2_Sys_CreateLoaded, Tss2_Sys_FlushCo...
Expand Down Expand Up @@ -86,6 +87,8 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
&auth_rsp);
if (rc == TPM2_RC_SUCCESS) {
LOG_INFO("success object handle: 0x%x", object_handle);
} else if (rc == TPM2_RC_COMMAND_CODE) {
return EXIT_SKIP;
} else {
LOG_ERROR("CreateLoaded FAILED! Response Code : 0x%x", rc);
exit(1);
Expand Down
32 changes: 31 additions & 1 deletion test/integration/sys-policy-authorizeNV.int.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,37 @@ test_invoke (TSS2_SYS_CONTEXT *sys_context)
&out_public,
&name,
&rsp_auth);
if (rc != TPM2_RC_SUCCESS) {
if (rc == TPM2_RC_COMMAND_CODE) {
TPM2B_PUBLIC in_public_with_size = {
.size = sizeof(TPMT_PUBLIC),
.publicArea = { 0 },
};
memcpy(&in_public_with_size.publicArea, &in_public, sizeof(TPMT_PUBLIC));

TPM2B_DATA outside_info = {0};
TPM2B_CREATION_DATA creation_data = {0};
TPML_PCR_SELECTION creation_pcr = {0};
TPM2B_DIGEST creation_hash = {0};
TPMT_TK_CREATION creation_ticket = {0};
rc = Tss2_Sys_CreatePrimary (sys_context,
TPM2_RH_OWNER,
&cmd_auth,
&in_sensitive,
&in_public_with_size,
&outside_info,
&creation_pcr,
&object_handle,
&out_public,
&creation_data,
&creation_hash,
&creation_ticket,
&name,
&rsp_auth);
if (rc != TPM2_RC_SUCCESS) {
LOG_ERROR("CreatePrimary FAILED! Response Code: 0x%x", rc);
exit(1);
}
} else if (rc != TPM2_RC_SUCCESS) {
LOG_ERROR("CreateLoaded FAILED! Response Code: 0x%x", rc);
exit(1);
}
Expand Down

0 comments on commit 29291bc

Please sign in to comment.