LCOV - code coverage report
Current view: top level - unit_test/test_spdm_requester - test_spdm_requester.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 51.4 % 107 55
Test Date: 2025-10-12 08:10:56 Functions: 100.0 % 1 1

            Line data    Source code
       1              : /**
       2              :  *  Copyright Notice:
       3              :  *  Copyright 2021-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              : int libspdm_req_get_version_test(void);
      11              : int libspdm_req_get_version_error_test(void);
      12              : int libspdm_req_get_capabilities_test(void);
      13              : int libspdm_req_get_capabilities_error_test(void);
      14              : int libspdm_req_negotiate_algorithms_test(void);
      15              : int libspdm_req_negotiate_algorithms_error_test(void);
      16              : 
      17              : #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
      18              : int libspdm_req_get_digests_test(void);
      19              : int libspdm_req_get_digests_error_test(void);
      20              : int libspdm_req_get_certificate_test(void);
      21              : #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
      22              : 
      23              : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
      24              : int libspdm_req_challenge_test(void);
      25              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
      26              : 
      27              : #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
      28              : int libspdm_req_get_measurements_test(void);
      29              : int libspdm_req_get_measurements_error_test(void);
      30              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP*/
      31              : 
      32              : #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
      33              : int libspdm_req_get_measurement_extension_log_test(void);
      34              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP*/
      35              : 
      36              : #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
      37              : int libspdm_req_key_exchange_test(void);
      38              : int libspdm_req_key_exchange_error_test(void);
      39              : int libspdm_req_finish_test(void);
      40              : #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
      41              : 
      42              : #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
      43              : int libspdm_req_psk_exchange_test(void);
      44              : int libspdm_req_psk_finish_test(void);
      45              : #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
      46              : 
      47              : #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
      48              : int libspdm_req_heartbeat_test(void);
      49              : int libspdm_req_key_update_test(void);
      50              : int libspdm_req_end_session_test(void);
      51              : #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
      52              : 
      53              : #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
      54              : int libspdm_req_encap_request_test(void);
      55              : #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
      56              : #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
      57              : int libspdm_req_encap_digests_test(void);
      58              : int libspdm_req_encap_certificate_test(void);
      59              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
      60              : #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
      61              : int libspdm_req_encap_challenge_auth_test(void);
      62              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
      63              : #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
      64              : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
      65              : int libspdm_req_encap_event_ack_test(void);
      66              : int libspdm_req_encap_event_ack_error_test(void);
      67              : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
      68              : #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
      69              : int libspdm_req_encap_supported_event_types_test(void);
      70              : int libspdm_req_encap_supported_event_types_error_test(void);
      71              : int libspdm_req_encap_subscribe_event_types_ack_test(void);
      72              : int libspdm_req_encap_subscribe_event_types_ack_error_test(void);
      73              : int libspdm_req_send_event_test(void);
      74              : int libspdm_req_send_event_error_test(void);
      75              : #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
      76              : int libspdm_req_encap_key_update_ack_test(void);
      77              : #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
      78              : int libspdm_req_encap_endpoint_info_test(void);
      79              : int libspdm_req_encap_endpoint_info_error_test(void);
      80              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
      81              : #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
      82              : 
      83              : int libspdm_req_set_certificate_test(void);
      84              : int libspdm_req_get_csr_test(void);
      85              : 
      86              : #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
      87              : int libspdm_req_chunk_get_test(void);
      88              : int libspdm_req_chunk_send_test(void);
      89              : #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
      90              : 
      91              : #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
      92              : int libspdm_req_get_supported_event_types_test(void);
      93              : int libspdm_req_get_supported_event_types_error_test(void);
      94              : int libspdm_req_subscribe_event_types_test(void);
      95              : int libspdm_req_subscribe_event_types_error_test(void);
      96              : #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
      97              : 
      98              : #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
      99              : int libspdm_req_vendor_defined_request_test(void);
     100              : int libspdm_req_vendor_defined_request_error_test(void);
     101              : #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
     102              : 
     103              : #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
     104              : int libspdm_req_get_key_pair_info_test(void);
     105              : int libspdm_req_get_key_pair_info_error_test(void);
     106              : #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
     107              : 
     108              : #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
     109              : int libspdm_req_set_key_pair_info_test(void);
     110              : int libspdm_req_set_key_pair_info_error_test(void);
     111              : #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
     112              : 
     113              : #if LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT
     114              : int libspdm_req_get_endpoint_info_test(void);
     115              : int libspdm_req_get_endpoint_info_error_test(void);
     116              : #endif /* LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT */
     117              : 
     118            1 : int main(void)
     119              : {
     120            1 :     int return_value = 0;
     121              : 
     122            1 :     if (libspdm_req_get_version_test() != 0) {
     123            0 :         return_value = 1;
     124              :     }
     125            1 :     if (libspdm_req_get_version_error_test() != 0) {
     126            0 :         return_value = 1;
     127              :     }
     128              : 
     129            1 :     if (libspdm_req_get_capabilities_test() != 0) {
     130            0 :         return_value = 1;
     131              :     }
     132            1 :     if (libspdm_req_get_capabilities_error_test() != 0) {
     133            0 :         return_value = 1;
     134              :     }
     135              : 
     136            1 :     if (libspdm_req_negotiate_algorithms_test() != 0) {
     137            0 :         return_value = 1;
     138              :     }
     139            1 :     if (libspdm_req_negotiate_algorithms_error_test() != 0) {
     140            0 :         return_value = 1;
     141              :     }
     142              : 
     143              :     #if LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT
     144            1 :     if (libspdm_req_get_digests_test() != 0) {
     145            0 :         return_value = 1;
     146              :     }
     147            1 :     if (libspdm_req_get_digests_error_test() != 0) {
     148            0 :         return_value = 1;
     149              :     }
     150            1 :     if (libspdm_req_get_certificate_test() != 0) {
     151            0 :         return_value = 1;
     152              :     }
     153              :     #endif /* LIBSPDM_SEND_GET_CERTIFICATE_SUPPORT */
     154              : 
     155              :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
     156            1 :     if (libspdm_req_challenge_test() != 0) {
     157            0 :         return_value = 1;
     158              :     }
     159              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP*/
     160              : 
     161              :     #if LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP
     162            1 :     if (libspdm_req_get_measurements_test() != 0) {
     163            0 :         return_value = 1;
     164              :     }
     165            1 :     if (libspdm_req_get_measurements_error_test() != 0) {
     166            0 :         return_value = 1;
     167              :     }
     168              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEAS_CAP */
     169              : 
     170              :     #if LIBSPDM_ENABLE_CAPABILITY_MEL_CAP
     171            1 :     if (libspdm_req_get_measurement_extension_log_test() != 0) {
     172            0 :         return_value = 1;
     173              :     }
     174              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MEL_CAP */
     175              : 
     176              :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
     177            1 :     if (libspdm_req_key_exchange_test() != 0) {
     178            0 :         return_value = 1;
     179              :     }
     180            1 :     if (libspdm_req_key_exchange_error_test() != 0) {
     181            0 :         return_value = 1;
     182              :     }
     183              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
     184              : 
     185              :     #if LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP
     186            1 :     if (libspdm_req_finish_test() != 0) {
     187            0 :         return_value = 1;
     188              :     }
     189              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP*/
     190              : 
     191              :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
     192            1 :     if (libspdm_req_psk_exchange_test() != 0) {
     193            0 :         return_value = 1;
     194              :     }
     195              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
     196              : 
     197              :     #if LIBSPDM_ENABLE_CAPABILITY_PSK_CAP
     198            1 :     if (libspdm_req_psk_finish_test() != 0) {
     199            0 :         return_value = 1;
     200              :     }
     201              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_PSK_CAP*/
     202              : 
     203              :     #if (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP)
     204            1 :     if (libspdm_req_heartbeat_test() != 0) {
     205            0 :         return_value = 1;
     206              :     }
     207            1 :     if (libspdm_req_key_update_test() != 0) {
     208            0 :         return_value = 1;
     209              :     }
     210            1 :     if (libspdm_req_end_session_test() != 0) {
     211            0 :         return_value = 1;
     212              :     }
     213              :     #endif /* (LIBSPDM_ENABLE_CAPABILITY_KEY_EX_CAP) || (LIBSPDM_ENABLE_CAPABILITY_PSK_CAP) */
     214              : 
     215              :     #if (LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT) && (LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP)
     216            1 :     if (libspdm_req_get_endpoint_info_test() != 0) {
     217            0 :         return_value = 1;
     218              :     }
     219            1 :     if (libspdm_req_get_endpoint_info_error_test() != 0) {
     220            0 :         return_value = 1;
     221              :     }
     222              :     #endif /* LIBSPDM_SEND_GET_ENDPOINT_INFO_SUPPORT */
     223              : 
     224              :     #if LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP
     225            1 :     if (libspdm_req_encap_request_test() != 0) {
     226            0 :         return_value = 1;
     227              :     }
     228              :     #if LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP
     229              :     #if LIBSPDM_ENABLE_CAPABILITY_CERT_CAP
     230            1 :     if (libspdm_req_encap_digests_test() != 0) {
     231            0 :         return_value = 1;
     232              :     }
     233            1 :     if (libspdm_req_encap_certificate_test() != 0) {
     234            0 :         return_value = 1;
     235              :     }
     236              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
     237              :     #if LIBSPDM_ENABLE_CAPABILITY_CHAL_CAP
     238            1 :     if (libspdm_req_encap_challenge_auth_test() != 0) {
     239            0 :         return_value = 1;
     240              :     }
     241              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CERT_CAP */
     242              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_MUT_AUTH_CAP */
     243            1 :     if (libspdm_req_encap_key_update_ack_test() != 0) {
     244            0 :         return_value = 1;
     245              :     }
     246              :     #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
     247            1 :     if (libspdm_req_encap_event_ack_test() != 0) {
     248            0 :         return_value = 1;
     249              :     }
     250            1 :     if (libspdm_req_encap_event_ack_error_test() != 0) {
     251            0 :         return_value = 1;
     252              :     }
     253              :     #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
     254              :     #if LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP
     255            1 :     if (libspdm_req_encap_endpoint_info_test() != 0) {
     256            0 :         return_value = 1;
     257              :     }
     258            1 :     if (libspdm_req_encap_endpoint_info_error_test() != 0) {
     259            0 :         return_value = 1;
     260              :     }
     261              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_ENDPOINT_INFO_CAP */
     262              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_ENCAP_CAP */
     263              :     #if LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP
     264            1 :     if (libspdm_req_encap_supported_event_types_test() != 0) {
     265            0 :         return_value = 1;
     266              :     }
     267            1 :     if (libspdm_req_encap_supported_event_types_error_test() != 0) {
     268            0 :         return_value = 1;
     269              :     }
     270            1 :     if (libspdm_req_encap_subscribe_event_types_ack_test() != 0) {
     271            0 :         return_value = 1;
     272              :     }
     273            1 :     if (libspdm_req_encap_subscribe_event_types_ack_error_test() != 0) {
     274            0 :         return_value = 1;
     275              :     }
     276            1 :     if (libspdm_req_send_event_test() != 0) {
     277            0 :         return_value = 1;
     278              :     }
     279            1 :     if (libspdm_req_send_event_error_test() != 0) {
     280            0 :         return_value = 1;
     281              :     }
     282              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_EVENT_CAP */
     283              :     #if LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP
     284            1 :     if (libspdm_req_set_certificate_test() != 0) {
     285            0 :         return_value = 1;
     286              :     }
     287              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_CERT_CAP */
     288              : 
     289              :     #if LIBSPDM_ENABLE_CAPABILITY_CSR_CAP
     290            1 :     if (libspdm_req_get_csr_test() != 0) {
     291            0 :         return_value = 1;
     292              :     }
     293              :     #endif /*LIBSPDM_ENABLE_CAPABILITY_CSR_CAP*/
     294              : 
     295              :     #if LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP
     296            1 :     if (libspdm_req_chunk_get_test() != 0) {
     297            0 :         return_value = 1;
     298              :     }
     299            1 :     if (libspdm_req_chunk_send_test() != 0) {
     300            0 :         return_value = 1;
     301              :     }
     302              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_CHUNK_CAP */
     303              : 
     304              :     #if LIBSPDM_EVENT_RECIPIENT_SUPPORT
     305            1 :     if (libspdm_req_get_supported_event_types_test() != 0) {
     306            0 :         return_value = 1;
     307              :     }
     308            1 :     if (libspdm_req_get_supported_event_types_error_test() != 0) {
     309            0 :         return_value = 1;
     310              :     }
     311            1 :     if (libspdm_req_subscribe_event_types_test() != 0) {
     312            0 :         return_value = 1;
     313              :     }
     314            1 :     if (libspdm_req_subscribe_event_types_error_test() != 0) {
     315            0 :         return_value = 1;
     316              :     }
     317              :     #endif /* LIBSPDM_EVENT_RECIPIENT_SUPPORT */
     318              : 
     319              :     #if LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP
     320            1 :     if (libspdm_req_get_key_pair_info_test() != 0) {
     321            0 :         return_value = 1;
     322              :     }
     323            1 :     if (libspdm_req_get_key_pair_info_error_test() != 0) {
     324            0 :         return_value = 1;
     325              :     }
     326              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_GET_KEY_PAIR_INFO_CAP */
     327              : 
     328              :     #if LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP
     329            1 :     if (libspdm_req_set_key_pair_info_test() != 0) {
     330            0 :         return_value = 1;
     331              :     }
     332            1 :     if (libspdm_req_set_key_pair_info_error_test() != 0) {
     333            0 :         return_value = 1;
     334              :     }
     335              :     #endif /* LIBSPDM_ENABLE_CAPABILITY_SET_KEY_PAIR_INFO_CAP */
     336              : 
     337              :     #if LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES
     338            1 :     if (libspdm_req_vendor_defined_request_test() != 0) {
     339            0 :         return_value = 1;
     340              :     }
     341            1 :     if (libspdm_req_vendor_defined_request_error_test() != 0) {
     342            0 :         return_value = 1;
     343              :     }
     344              :     #endif /* LIBSPDM_ENABLE_VENDOR_DEFINED_MESSAGES */
     345              : 
     346            1 :     return return_value;
     347              : }
        

Generated by: LCOV version 2.0-1