diff --git a/.ci/docker.run b/.ci/docker.run index c45c8ad52..8d214dd0b 100755 --- a/.ci/docker.run +++ b/.ci/docker.run @@ -94,7 +94,7 @@ fi if [ "$SCANBUILD" == "yes" ]; then scan-build --status-bugs make -j elif [ "$CC" == "clang" ]; then - make -j distcheck + make -j distcheck V=1 else make -j check fi diff --git a/src/tss2-esys/api/Esys_GetRandom.c b/src/tss2-esys/api/Esys_GetRandom.c index fb00e65b5..eba3b4e4f 100644 --- a/src/tss2-esys/api/Esys_GetRandom.c +++ b/src/tss2-esys/api/Esys_GetRandom.c @@ -7,7 +7,6 @@ #ifdef HAVE_CONFIG_H #include "config.h" // IWYU pragma: keep #endif - #include // for PRIx32, PRIx16, int32_t #include // for NULL, calloc @@ -247,6 +246,7 @@ Esys_GetRandom_Finish( /*Receive the TPM response and handle resubmissions if necessary. */ r = Tss2_Sys_ExecuteFinish(esysContext->sys, esysContext->timeout); + LOG_ERROR("XXX GetRandom Test return code %x", r); if (base_rc(r) == TSS2_BASE_RC_TRY_AGAIN) { LOG_DEBUG("A layer below returned TRY_AGAIN: %" PRIx32, r); esysContext->state = ESYS_STATE_SENT; @@ -254,6 +254,7 @@ Esys_GetRandom_Finish( } /* This block handle the resubmission of TPM commands given a certain set of * TPM response codes. */ + if (r == TPM2_RC_RETRY || r == TPM2_RC_TESTING || r == TPM2_RC_YIELDED) { LOG_DEBUG("TPM returned RETRY, TESTING or YIELDED, which triggers a " "resubmission: %" PRIx32, r); diff --git a/test/integration/esys-cp-hash.int.c b/test/integration/esys-cp-hash.int.c index d1e69c593..8b900ecba 100644 --- a/test/integration/esys-cp-hash.int.c +++ b/test/integration/esys-cp-hash.int.c @@ -8,6 +8,9 @@ #include "config.h" // IWYU pragma: keep #endif +#include +#include + #include // for free, NULL, EXIT_FAILURE, EXIT_SUCCESS #include "tss2_common.h" // for BYTE, TSS2_RC @@ -19,6 +22,47 @@ #define base_rc(r) ((r) & ~TSS2_RC_LAYER_MASK) + +int is_ubuntu_2204() { + FILE *file = fopen("/etc/os-release", "r"); + if (!file) { + perror("Failed to open /etc/os-release"); + return 0; // Could not determine OS + } + + char line[256]; + int is_ubuntu = 0; + int is_2204 = 0; + + while (fgets(line, sizeof(line), file)) { + // Check for "Ubuntu" + if (strstr(line, "ID=ubuntu")) { + is_ubuntu = 1; + } + // Check for "22.04" + if (strstr(line, "VERSION_ID=\"22.04\"")) { + is_2204 = 1; + } + // If both conditions are met, break early + if (is_ubuntu && is_2204) { + break; + } + } + + fclose(file); + return is_ubuntu && is_2204; // Return 1 if both conditions are true, 0 otherwise +} + +int is_cc_clang() { + const char *cc_env = getenv("CC"); // Get the value of CC environment variable + if (cc_env && strstr(cc_env, "clang")) { + return 1; // Contains "clang" + } + return 0; // Does not contain "clang" or CC is not set +} + + + /** Test the ESYS function Esys_GetRandom. * * Tested ESYS commands: @@ -98,7 +142,9 @@ test_esyscp_hash(ESYS_CONTEXT * esys_context) free(cp_hash); r = Esys_GetRandom_Finish(esys_context, &randomBytes); - while (r == TSS2_ESYS_RC_TRY_AGAIN) { + LOG_ERROR("XXX Test return code2 %x", r); + while (base_rc(r) == TSS2_BASE_RC_TRY_AGAIN) { + // while (r == TSS2_ESYS_RC_TRY_AGAIN) { r = Esys_GetRandom_Finish(esys_context, &randomBytes); } if (r != TPM2_RC_SUCCESS) { @@ -154,8 +200,13 @@ test_esyscp_hash(ESYS_CONTEXT * esys_context) if (r != TPM2_RC_SUCCESS) { LOG_ERROR("FlushContext FAILED! Response Code : 0x%x", r); } - - return EXIT_SUCCESS; + if (is_ubuntu_2204() && is_cc_clang()) { + LOG_ERROR("XXX Ubuntu 22.04"); + fflush(stderr); + return 77; + } else { + return EXIT_SUCCESS; + } error_cleansession: r = Esys_FlushContext(esys_context, session); diff --git a/test/integration/fapi-nv-written-policy.int.c b/test/integration/fapi-nv-written-policy.int.c index 35880a633..586693755 100644 --- a/test/integration/fapi-nv-written-policy.int.c +++ b/test/integration/fapi-nv-written-policy.int.c @@ -8,6 +8,10 @@ #include "config.h" // IWYU pragma: keep #endif +#include +#include + + #include // for uint8_t #include // for NULL, fopen, fclose, fileno, fseek, ftell #include // for calloc, malloc, EXIT_FAILURE, EXIT_SUCCESS @@ -24,6 +28,47 @@ #define NV_SIZE 10 #define APP_DATA_SIZE 10*1024*1024 + +int is_ubuntu_2204() { + FILE *file = fopen("/etc/os-release", "r"); + if (!file) { + perror("Failed to open /etc/os-release"); + return 0; // Could not determine OS + } + + char line[256]; + int is_ubuntu = 0; + int is_2204 = 0; + + while (fgets(line, sizeof(line), file)) { + // Check for "Ubuntu" + if (strstr(line, "ID=ubuntu")) { + is_ubuntu = 1; + } + // Check for "22.04" + if (strstr(line, "VERSION_ID=\"22.04\"")) { + is_2204 = 1; + } + // If both conditions are met, break early + if (is_ubuntu && is_2204) { + break; + } + } + + fclose(file); + return is_ubuntu && is_2204; // Return 1 if both conditions are true, 0 otherwise +} + +int is_cc_clang() { + const char *cc_env = getenv("CC"); // Get the value of CC environment variable + if (cc_env && strstr(cc_env, "clang")) { + return 1; // Contains "clang" + } + return 0; // Does not contain "clang" or CC is not set +} + + + /** Test the FAPI policy PolicyNvWritten. * * Tested FAPI commands: @@ -123,7 +168,14 @@ test_fapi_nv_written_policy(FAPI_CONTEXT *context) SAFE_FREE(appDataOut); SAFE_FREE(appDataIn); - return EXIT_SUCCESS; + if (is_ubuntu_2204() && is_cc_clang()) { + LOG_ERROR("XXX Ubuntu 22.04"); + fflush(stderr); + return EXIT_FAILURE; + } else { + return EXIT_SUCCESS; + } + error: Fapi_Delete(context, "/");