|
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 |
|
@@ -105,6 +105,10 @@ libspdm_return_t libspdm_requester_chunk_send_test_send_message(
|
105 | 105 | LIBSPDM_ASSERT(chunk_send->header.request_response_code == SPDM_CHUNK_SEND);
|
106 | 106 | return LIBSPDM_STATUS_SUCCESS;
|
107 | 107 | }
|
| 108 | + if (spdm_test_context->case_id == 13) { |
| 109 | + /* Should never reach here since the test case is meant to fail before send */ |
| 110 | + LIBSPDM_ASSERT(0); |
| 111 | + } |
108 | 112 | return LIBSPDM_STATUS_SEND_FAIL;
|
109 | 113 | }
|
110 | 114 |
|
@@ -323,6 +327,10 @@ libspdm_return_t libspdm_requester_chunk_send_test_receive_message(
|
323 | 327 |
|
324 | 328 | return LIBSPDM_STATUS_SUCCESS;
|
325 | 329 | }
|
| 330 | + if (spdm_test_context->case_id == 13) { |
| 331 | + /* Should never reach here since the test case is meant to fail before send */ |
| 332 | + LIBSPDM_ASSERT(0); |
| 333 | + } |
326 | 334 | return LIBSPDM_STATUS_RECEIVE_FAIL;
|
327 | 335 | }
|
328 | 336 |
|
@@ -380,6 +388,56 @@ libspdm_return_t libspdm_test_requester_chunk_send_generic_test_case(
|
380 | 388 | return status;
|
381 | 389 | }
|
382 | 390 |
|
| 391 | +libspdm_return_t libspdm_test_requester_chunk_send_vendor_specific_test_case( |
| 392 | + void** state, uint32_t case_id) |
| 393 | +{ |
| 394 | + /* Use vendor specific request to generate a large request. */ |
| 395 | + libspdm_return_t status; |
| 396 | + libspdm_test_context_t* spdm_test_context; |
| 397 | + libspdm_context_t* spdm_context; |
| 398 | + |
| 399 | + uint16_t standard_id = 6; |
| 400 | + uint8_t vendor_id_len = 2; |
| 401 | + uint8_t vendor_id[SPDM_MAX_VENDOR_ID_LENGTH] = {0xAA, 0xAA}; |
| 402 | + uint16_t data_len = 65535; |
| 403 | + uint8_t data[65535] = {0}; |
| 404 | + |
| 405 | + spdm_test_context = *state; |
| 406 | + spdm_context = spdm_test_context->spdm_context; |
| 407 | + spdm_test_context->case_id = case_id; |
| 408 | + spdm_context->connection_info.version = SPDM_MESSAGE_VERSION_12 << |
| 409 | + SPDM_VERSION_NUMBER_SHIFT_BIT; |
| 410 | + /* Large request need a large scratch buffer. */ |
| 411 | + spdm_context->connection_info.capability.max_spdm_msg_size = 0x12000; |
| 412 | + spdm_context->local_context.capability.max_spdm_msg_size = 0x12000; |
| 413 | + spdm_context->connection_info.connection_state = |
| 414 | + LIBSPDM_CONNECTION_STATE_NEGOTIATED; |
| 415 | + spdm_context->connection_info.capability.flags |= |
| 416 | + (SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CERT_CAP |
| 417 | + | SPDM_GET_CAPABILITIES_RESPONSE_FLAGS_CHUNK_CAP); |
| 418 | + spdm_context->connection_info.capability.data_transfer_size |
| 419 | + = sizeof(spdm_chunk_send_request_t) + 1; |
| 420 | + spdm_context->local_context.capability.sender_data_transfer_size |
| 421 | + = CHUNK_SEND_REQUESTER_UNIT_TEST_DATA_TRANSFER_SIZE; |
| 422 | + spdm_context->local_context.is_requester = true; |
| 423 | + |
| 424 | + spdm_test_context->scratch_buffer_size = |
| 425 | + libspdm_get_sizeof_required_scratch_buffer(spdm_context); |
| 426 | + spdm_test_context->scratch_buffer = (void *)malloc(spdm_test_context->scratch_buffer_size); |
| 427 | + libspdm_set_scratch_buffer (spdm_context, |
| 428 | + spdm_test_context->scratch_buffer, |
| 429 | + spdm_test_context->scratch_buffer_size); |
| 430 | + |
| 431 | + libspdm_reset_message_a(spdm_context); |
| 432 | + |
| 433 | + status = libspdm_vendor_send_request_receive_response(spdm_context, NULL, |
| 434 | + standard_id, vendor_id_len, vendor_id, |
| 435 | + data_len, data, |
| 436 | + &standard_id, &vendor_id_len, vendor_id, |
| 437 | + &data_len, data); |
| 438 | + return status; |
| 439 | +} |
| 440 | + |
383 | 441 | void libspdm_test_requester_chunk_send_case1(void** state)
|
384 | 442 | {
|
385 | 443 | libspdm_return_t status;
|
@@ -472,6 +530,20 @@ void libspdm_test_requester_chunk_send_case12(void** state)
|
472 | 530 | assert_int_equal(status, LIBSPDM_STATUS_ERROR_PEER);
|
473 | 531 | }
|
474 | 532 |
|
| 533 | +#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES |
| 534 | +/** |
| 535 | + * Test 13: Request size shall not exceed max supported transfer size. |
| 536 | + * Expected behavior: returns a status of LIBSPDM_STATUS_SEND_FAIL, |
| 537 | + **/ |
| 538 | +void libspdm_test_requester_chunk_send_case13(void** state) |
| 539 | +{ |
| 540 | + libspdm_return_t status; |
| 541 | + |
| 542 | + status = libspdm_test_requester_chunk_send_vendor_specific_test_case(state, 13); |
| 543 | + assert_int_equal(status, LIBSPDM_STATUS_SEND_FAIL); |
| 544 | +} |
| 545 | +#endif |
| 546 | + |
475 | 547 | int libspdm_requester_chunk_send_test_main(void)
|
476 | 548 | {
|
477 | 549 | /* Test the CHUNK_SEND handlers in various requester handlers */
|
@@ -500,6 +572,10 @@ int libspdm_requester_chunk_send_test_main(void)
|
500 | 572 | cmocka_unit_test(libspdm_test_requester_chunk_send_case11),
|
501 | 573 | /* ErrorCode == LargeResponse shall not be allowed in ResponseToLargeRequest */
|
502 | 574 | cmocka_unit_test(libspdm_test_requester_chunk_send_case12),
|
| 575 | +#if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES |
| 576 | + /* Request size exceed max chunks */ |
| 577 | + cmocka_unit_test(libspdm_test_requester_chunk_send_case13), |
| 578 | +#endif |
503 | 579 | };
|
504 | 580 |
|
505 | 581 | libspdm_test_context_t test_context = {
|
|
0 commit comments