|
1 | 1 | /**
|
2 | 2 | * Copyright Notice:
|
3 |
| - * Copyright 2021-2022 DMTF. All rights reserved. |
| 3 | + * Copyright 2021-2025 DMTF. All rights reserved. |
4 | 4 | * License: BSD 3-Clause License. For full text see link: https://github.com/DMTF/libspdm/blob/main/LICENSE.md
|
5 | 5 | **/
|
6 | 6 |
|
@@ -996,6 +996,101 @@ void libspdm_test_responder_chunk_get_rsp_case13(void** state)
|
996 | 996 | }
|
997 | 997 | }
|
998 | 998 |
|
| 999 | + |
| 1000 | +/** |
| 1001 | + * Test 14: Responder has reponse exceed chunk seq no |
| 1002 | + **/ |
| 1003 | +void libspdm_test_responder_chunk_get_rsp_case14(void** state) |
| 1004 | +{ |
| 1005 | + libspdm_return_t status; |
| 1006 | + libspdm_test_context_t* spdm_test_context; |
| 1007 | + libspdm_context_t* spdm_context; |
| 1008 | + size_t response_size; |
| 1009 | + uint8_t response[LIBSPDM_MAX_SPDM_MSG_SIZE]; |
| 1010 | + spdm_error_response_t* spdm_response; |
| 1011 | + spdm_chunk_get_request_t spdm_request; |
| 1012 | + void* scratch_buffer; |
| 1013 | + size_t scratch_buffer_size; |
| 1014 | + |
| 1015 | + uint8_t chunk_handle; |
| 1016 | + uint32_t data_transfer_size; |
| 1017 | + uint32_t total_chunk_size; |
| 1018 | + |
| 1019 | + spdm_test_context = *state; |
| 1020 | + spdm_context = spdm_test_context->spdm_context; |
| 1021 | + spdm_test_context->case_id = 10; |
| 1022 | + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 << |
| 1023 | + SPDM_VERSION_NUMBER_SHIFT_BIT; |
| 1024 | + |
| 1025 | + spdm_context->connection_info.connection_state = |
| 1026 | + LIBSPDM_CONNECTION_STATE_NEGOTIATED; |
| 1027 | + spdm_context->connection_info.algorithm.base_hash_algo = |
| 1028 | + m_libspdm_use_hash_algo; |
| 1029 | + |
| 1030 | + data_transfer_size = CHUNK_GET_RESPONDER_UNIT_TEST_DATA_TRANSFER_SIZE; |
| 1031 | + spdm_context->local_context.capability.data_transfer_size = data_transfer_size; |
| 1032 | + spdm_context->local_context.capability.flags |= |
| 1033 | + SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP; |
| 1034 | + spdm_context->connection_info.capability.flags |= |
| 1035 | + SPDM_GET_CAPABILITIES_REQUEST_FLAGS_CHUNK_CAP; |
| 1036 | + |
| 1037 | + /* large response need a large scratch buffer */ |
| 1038 | + spdm_context->connection_info.capability.max_spdm_msg_size = data_transfer_size * 65536; |
| 1039 | + spdm_context->local_context.capability.max_spdm_msg_size = data_transfer_size * 65536; |
| 1040 | + spdm_test_context->scratch_buffer_size = |
| 1041 | + libspdm_get_sizeof_required_scratch_buffer(spdm_context); |
| 1042 | + spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size); |
| 1043 | + libspdm_set_scratch_buffer (spdm_context, |
| 1044 | + spdm_test_context->scratch_buffer, |
| 1045 | + spdm_test_context->scratch_buffer_size); |
| 1046 | + |
| 1047 | + |
| 1048 | + libspdm_get_scratch_buffer(spdm_context, &scratch_buffer, &scratch_buffer_size); |
| 1049 | + |
| 1050 | + scratch_buffer = (uint8_t*)scratch_buffer + |
| 1051 | + libspdm_get_scratch_buffer_large_message_offset(spdm_context); |
| 1052 | + scratch_buffer_size = scratch_buffer_size - |
| 1053 | + libspdm_get_scratch_buffer_large_message_offset(spdm_context); |
| 1054 | + libspdm_zero_mem(scratch_buffer, scratch_buffer_size); |
| 1055 | + |
| 1056 | + /* a huge chunk size to cause the chunk seq no wrap */ |
| 1057 | + total_chunk_size = data_transfer_size * 65536; |
| 1058 | + |
| 1059 | + LIBSPDM_ASSERT(total_chunk_size <= scratch_buffer_size); |
| 1060 | + |
| 1061 | + chunk_handle = (uint8_t) spdm_test_context->case_id; /* Any number is fine */ |
| 1062 | + spdm_context->chunk_context.get.chunk_in_use = true; |
| 1063 | + spdm_context->chunk_context.get.chunk_handle = chunk_handle; |
| 1064 | + spdm_context->chunk_context.get.chunk_seq_no = 0; |
| 1065 | + spdm_context->chunk_context.get.large_message = scratch_buffer; |
| 1066 | + spdm_context->chunk_context.get.large_message_size = total_chunk_size; |
| 1067 | + spdm_context->chunk_context.get.chunk_bytes_transferred = 0; |
| 1068 | + |
| 1069 | + libspdm_zero_mem(&spdm_request, sizeof(spdm_request)); |
| 1070 | + spdm_request.header.spdm_version = SPDM_MESSAGE_VERSION_12; |
| 1071 | + spdm_request.header.request_response_code = SPDM_CHUNK_GET; |
| 1072 | + spdm_request.header.param1 = 0; |
| 1073 | + spdm_request.header.param2 = chunk_handle; |
| 1074 | + spdm_request.chunk_seq_no = 0; |
| 1075 | + |
| 1076 | + response_size = sizeof(response); |
| 1077 | + status = libspdm_get_response_chunk_get( |
| 1078 | + spdm_context, |
| 1079 | + sizeof(spdm_request), &spdm_request, |
| 1080 | + &response_size, response); |
| 1081 | + |
| 1082 | + assert_int_equal(status, LIBSPDM_STATUS_SUCCESS); |
| 1083 | + assert_int_equal(response_size, sizeof(spdm_error_response_t)); |
| 1084 | + |
| 1085 | + spdm_response = (spdm_error_response_t*) response; |
| 1086 | + |
| 1087 | + assert_int_equal(spdm_response->header.spdm_version, SPDM_MESSAGE_VERSION_12); |
| 1088 | + assert_int_equal(spdm_response->header.request_response_code, SPDM_ERROR); |
| 1089 | + assert_int_equal(spdm_response->header.param1, SPDM_ERROR_CODE_RESPONSE_TOO_LARGE); |
| 1090 | + assert_int_equal(spdm_response->header.param2, 0); |
| 1091 | +} |
| 1092 | + |
| 1093 | + |
999 | 1094 | int libspdm_responder_chunk_get_rsp_test_main(void)
|
1000 | 1095 | {
|
1001 | 1096 | const struct CMUnitTest spdm_responder_chunk_get_tests[] = {
|
@@ -1025,6 +1120,8 @@ int libspdm_responder_chunk_get_rsp_test_main(void)
|
1025 | 1120 | cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case12),
|
1026 | 1121 | /* Successful request of last chunk where chunk size is exactly 1 byte */
|
1027 | 1122 | cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case13),
|
| 1123 | + /* Responder has reponse exceed chunk seq no */ |
| 1124 | + cmocka_unit_test(libspdm_test_responder_chunk_get_rsp_case14), |
1028 | 1125 | };
|
1029 | 1126 |
|
1030 | 1127 | libspdm_test_context_t test_context = {
|
|
0 commit comments