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 % 109 56
Test Date: 2026-09-13 08:13:44 Functions: 100.0 % 1 1

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

Generated by: LCOV version 2.0-1