|
| 1 | +/** |
| 2 | + * Copyright Notice: |
| 3 | + * Copyright 2025 DMTF. All rights reserved. |
| 4 | + * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md |
| 5 | + **/ |
| 6 | + |
| 7 | +#include "spdm_unit_test.h" |
| 8 | +#include "internal/libspdm_requester_lib.h" |
| 9 | + |
| 10 | +#if (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP) |
| 11 | + |
| 12 | +static uint8_t m_spdm_request_buffer[0x1000]; |
| 13 | +static uint8_t m_spdm_response_buffer[0x1000]; |
| 14 | + |
| 15 | +static const uint32_t m_session_id = 0xffffffff; |
| 16 | + |
| 17 | +extern uint32_t g_supported_event_groups_list_len; |
| 18 | +extern uint8_t g_event_group_count; |
| 19 | + |
| 20 | +static void set_standard_state(libspdm_context_t *spdm_context) |
| 21 | +{ |
| 22 | + libspdm_session_info_t *session_info; |
| 23 | + |
| 24 | + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_13 << |
| 25 | + SPDM_VERSION_NUMBER_SHIFT_BIT; |
| 26 | + spdm_context->connection_info.connection_state = LIBSPDM_CONNECTION_STATE_NEGOTIATED; |
| 27 | + |
| 28 | + spdm_context->connection_info.capability.flags |= |
| 29 | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCRYPT_CAP; |
| 30 | + spdm_context->connection_info.capability.flags |= |
| 31 | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_MAC_CAP; |
| 32 | + spdm_context->connection_info.capability.flags |= |
| 33 | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_KEY_EX_CAP; |
| 34 | + spdm_context->connection_info.capability.flags |= |
| 35 | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_ENCAP_CAP; |
| 36 | + |
| 37 | + spdm_context->local_context.capability.flags |= |
| 38 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCRYPT_CAP; |
| 39 | + spdm_context->local_context.capability.flags |= |
| 40 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_MAC_CAP; |
| 41 | + spdm_context->local_context.capability.flags |= |
| 42 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_KEY_EX_CAP; |
| 43 | + spdm_context->local_context.capability.flags |= |
| 44 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_ENCAP_CAP; |
| 45 | + spdm_context->local_context.capability.flags |= |
| 46 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_EVENT_CAP; |
| 47 | + |
| 48 | + spdm_context->connection_info.algorithm.base_hash_algo = m_libspdm_use_hash_algo; |
| 49 | + spdm_context->connection_info.algorithm.base_asym_algo = m_libspdm_use_asym_algo; |
| 50 | + spdm_context->connection_info.algorithm.dhe_named_group = m_libspdm_use_dhe_algo; |
| 51 | + spdm_context->connection_info.algorithm.aead_cipher_suite = m_libspdm_use_aead_algo; |
| 52 | + |
| 53 | + spdm_context->latest_session_id = m_session_id; |
| 54 | + spdm_context->last_spdm_request_session_id_valid = true; |
| 55 | + spdm_context->last_spdm_request_session_id = m_session_id; |
| 56 | + session_info = &spdm_context->session_info[0]; |
| 57 | + libspdm_session_info_init(spdm_context, session_info, m_session_id, true); |
| 58 | + libspdm_secured_message_set_session_state( |
| 59 | + session_info->secured_message_context, |
| 60 | + LIBSPDM_SESSION_STATE_ESTABLISHED); |
| 61 | +} |
| 62 | + |
| 63 | +static void test_supported_event_types_case1(void **state) |
| 64 | +{ |
| 65 | + libspdm_return_t status; |
| 66 | + libspdm_test_context_t *spdm_test_context; |
| 67 | + libspdm_context_t *spdm_context; |
| 68 | + spdm_get_supported_event_types_request_t *get_supported_event_types; |
| 69 | + size_t request_size; |
| 70 | + spdm_supported_event_types_response_t *supported_event_types; |
| 71 | + size_t response_size = sizeof(m_spdm_response_buffer); |
| 72 | + |
| 73 | + spdm_test_context = *state; |
| 74 | + spdm_context = spdm_test_context->spdm_context; |
| 75 | + spdm_test_context->case_id = 0x01; |
| 76 | + |
| 77 | + set_standard_state(spdm_context); |
| 78 | + |
| 79 | + get_supported_event_types = (spdm_get_supported_event_types_request_t *)m_spdm_request_buffer; |
| 80 | + |
| 81 | + get_supported_event_types->header.spdm_version = SPDM_MESSAGE_VERSION_13; |
| 82 | + get_supported_event_types->header.request_response_code = SPDM_GET_SUPPORTED_EVENT_TYPES; |
| 83 | + get_supported_event_types->header.param1 = 0; |
| 84 | + get_supported_event_types->header.param2 = 0; |
| 85 | + |
| 86 | + request_size = sizeof(spdm_get_supported_event_types_request_t); |
| 87 | + |
| 88 | + status = libspdm_get_encap_supported_event_types(spdm_context, |
| 89 | + request_size, |
| 90 | + m_spdm_request_buffer, |
| 91 | + &response_size, |
| 92 | + m_spdm_response_buffer); |
| 93 | + |
| 94 | + supported_event_types = (spdm_supported_event_types_response_t *)m_spdm_response_buffer; |
| 95 | + |
| 96 | + assert_int_equal(status, LIBSPDM_STATUS_SUCCESS); |
| 97 | + assert_int_equal(supported_event_types->header.spdm_version, SPDM_MESSAGE_VERSION_13); |
| 98 | + assert_int_equal(supported_event_types->header.request_response_code, SPDM_SUPPORTED_EVENT_TYPES); |
| 99 | + assert_int_equal(supported_event_types->header.param1, g_event_group_count); |
| 100 | + assert_int_equal(supported_event_types->header.param2, 0); |
| 101 | + assert_int_equal(supported_event_types->supported_event_groups_list_len, |
| 102 | + g_supported_event_groups_list_len); |
| 103 | + |
| 104 | + for (uint32_t index = 0; index < supported_event_types->supported_event_groups_list_len; index++) |
| 105 | + { |
| 106 | + assert_int_equal(((char *)(supported_event_types + 1))[index], (char)index); |
| 107 | + } |
| 108 | + |
| 109 | + libspdm_dump_data(m_spdm_response_buffer, response_size); |
| 110 | + LIBSPDM_DEBUG((LIBSPDM_DEBUG_INFO, "\n")); |
| 111 | +} |
| 112 | + |
| 113 | +int libspdm_requester_encap_supported_event_types_test_main(void) |
| 114 | +{ |
| 115 | + const struct CMUnitTest spdm_requester_supported_event_types_tests[] = { |
| 116 | + cmocka_unit_test(test_supported_event_types_case1), |
| 117 | + }; |
| 118 | + |
| 119 | + libspdm_test_context_t test_context = { |
| 120 | + LIBSPDM_TEST_CONTEXT_VERSION, |
| 121 | + false, |
| 122 | + }; |
| 123 | + |
| 124 | + libspdm_setup_test_context(&test_context); |
| 125 | + |
| 126 | + return cmocka_run_group_tests(spdm_requester_supported_event_types_tests, |
| 127 | + libspdm_unit_test_group_setup, |
| 128 | + libspdm_unit_test_group_teardown); |
| 129 | +} |
| 130 | + |
| 131 | +#endif /* (LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP) && (LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP) */ |
0 commit comments