From 887978aed1b77749ac32c060414269aa6cb39f1b Mon Sep 17 00:00:00 2001 From: Wenxing Hou Date: Tue, 26 Mar 2024 15:57:36 +0800 Subject: [PATCH] Ensure that cached.csr always exists at the beginning Fix the issue: #2632 The successful unit_test will always make cached.csr name unchanged. But a failed unit_test may change cached.csr to cached.staging, which cause the next unit_test still failing even if the issue is fixed. Add new api to ensure that cached.csr always exists at the beginning. Signed-off-by: Wenxing Hou --- unit_test/test_spdm_requester/get_csr.c | 12 ++++++++++++ unit_test/test_spdm_responder/csr.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/unit_test/test_spdm_requester/get_csr.c b/unit_test/test_spdm_requester/get_csr.c index 850c05a339c..126fc62afbe 100644 --- a/unit_test/test_spdm_requester/get_csr.c +++ b/unit_test/test_spdm_requester/get_csr.c @@ -102,6 +102,15 @@ bool libspdm_read_requester_gen_csr(void **csr_data, size_t *csr_len) return res; } +/*ensure that cached.csr exists in test_csr at the beginning*/ +void libspdm_clear_cached_csr() +{ + char *new_name = "test_csr/cached.csr"; + char *file_name = "test_csr/cached.staging"; + + rename(file_name, new_name); +} + libspdm_return_t libspdm_requester_get_csr_test_send_message( void *spdm_context, size_t request_size, const void *request, uint64_t timeout) @@ -556,6 +565,9 @@ int libspdm_requester_get_csr_test_main(void) libspdm_setup_test_context( &m_libspdm_requester_get_csr_test_context); + /*ensure that cached.csr exists in test_csr at the beginning*/ + libspdm_clear_cached_csr(); + return cmocka_run_group_tests(spdm_requester_get_csr_tests, libspdm_unit_test_group_setup, libspdm_unit_test_group_teardown); diff --git a/unit_test/test_spdm_responder/csr.c b/unit_test/test_spdm_responder/csr.c index 689d78981ce..e36d7aebd80 100644 --- a/unit_test/test_spdm_responder/csr.c +++ b/unit_test/test_spdm_responder/csr.c @@ -169,6 +169,15 @@ bool libspdm_set_csr_after_reset() return true; } +/*ensure that cached.csr exists in test_csr at the beginning*/ +void libspdm_clear_cached_csr() +{ + char *new_name = "test_csr/cached.csr"; + char *file_name = "test_csr/cached.staging"; + + rename(file_name, new_name); +} + /*clean the cached last SPDM csr request*/ void libspdm_test_clear_cached_last_request() { @@ -1929,6 +1938,9 @@ int libspdm_responder_csr_test_main(void) libspdm_setup_test_context(&m_libspdm_responder_csr_test_context); + /*ensure that cached.csr exists in test_csr at the beginning*/ + libspdm_clear_cached_csr(); + return cmocka_run_group_tests(spdm_responder_csr_tests, libspdm_unit_test_group_setup, libspdm_unit_test_group_teardown);