LCOV - code coverage report
Current view: top level - test - main.c (source / functions) Coverage Total Hit
Test: lcov.info Lines: 100.0 % 153 153
Test Date: 2026-11-06 14:43:19 Functions: 100.0 % 101 101
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /*
       2                 :             :    Copyright (c) 2021 Fraunhofer AISEC. See the COPYRIGHT
       3                 :             :    file at the top-level directory of this distribution.
       4                 :             : 
       5                 :             :    Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
       6                 :             :    http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
       7                 :             :    <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
       8                 :             :    option. This file may not be copied, modified, or distributed
       9                 :             :    except according to those terms.
      10                 :             : */
      11                 :             : 
      12                 :             : #include <zephyr/kernel.h>
      13                 :             : #include <zephyr/ztest.h>
      14                 :             : #include "edhoc_integration_tests/edhoc_tests.h"
      15                 :             : #include "oscore_tests.h"
      16                 :             : 
      17                 :             : #define TEST_EDHOC_EXPORTER 1
      18                 :             : #define TEST_INITIATOR_RESPONDER_INTERACTION1 2
      19                 :             : #define TEST_INITIATOR_RESPONDER_INTERACTION2 3
      20                 :             : #define T1_OSCORE_CLIENT_REQUEST_RESPONSE 4
      21                 :             : #define T2_OSCORE_SERVER_REQUEST_RESPONSE 5
      22                 :             : #define T3_OSCORE_CLIENT_REQUEST 6
      23                 :             : #define T4_OSCORE_SERVER_KEY_DERIVATION 7
      24                 :             : #define T5_OSCORE_CLIENT_REQUEST 8
      25                 :             : #define T6_OSCORE_SERVER_KEY_DERIVATION 9
      26                 :             : #define T8_OSCORE_SERVER_RESPONSE_SIMPLE_ACK 10
      27                 :             : #define T9_OSCORE_CLIENT_SERVER_OBSERVE 11
      28                 :             : #define T10_OSCORE_CLIENT_SERVER_AFTER_REBOOT 12
      29                 :             : #define T100_INNER_OUTER_OPTION_SPLIT__NO_SPECIAL_OPTIONS 13
      30                 :             : #define T101_INNER_OUTER_OPTION_SPLIT__WITH_OBSERVE_NOTIFICATION 14
      31                 :             : #define T102_INNER_OUTER_OPTION_SPLIT__WITH_OBSERVE_REGISTRATION 15
      32                 :             : #define T103_OSCORE_PKG_GENERATE__REQUEST_WITH_OBSERVE_REGISTRATION 16
      33                 :             : #define T104_OSCORE_PKG_GENERATE__REQUEST_WITH_OBSERVE_NOTIFICATION 17
      34                 :             : #define T105_INNER_OUTER_OPTION_SPLIT__TOO_MANY_OPTIONS 18
      35                 :             : #define T106_OSCORE_OPTION_GENERATE_NO_PIV 19
      36                 :             : #define T200_OPTIONS_SERIALIZE_DESERIALIZE 20
      37                 :             : #define T201_COAP_SERIALIZE_DESERIALIZE 21
      38                 :             : #define T202_OPTIONS_DESERIALIZE_CORNER_CASES 22
      39                 :             : #define T300_OSCORE_OPTION_PARSER_NO_PIV 23
      40                 :             : #define T301_OSCORE_OPTION_PARSER_WRONG_N 24
      41                 :             : #define T302_OSCORE_OPTION_PARSER_NO_KID 25
      42                 :             : #define T303_OPTIONS_REORDER 26
      43                 :             : #define T400_IS_CLASS_E 27
      44                 :             : #define T401_CACHE_ECHO_VAL 28
      45                 :             : #define T402_ECHO_VAL_IS_FRESH 29
      46                 :             : #define T500_OSCORE_CONTEXT_INIT_CORNER_CASES 30
      47                 :             : #define T501_PIV2SSN 31
      48                 :             : #define T502_SSN2PIV 32
      49                 :             : #define T503_DERIVE_CORNER_CASE 33
      50                 :             : #define T600_SERVER_REPLAY_INIT_TEST 34
      51                 :             : #define T601_SERVER_REPLAY_REINIT_TEST 35
      52                 :             : #define T602_SERVER_REPLAY_CHECK_AT_START_TEST 36
      53                 :             : #define T603_SERVER_REPLAY_CHECK_IN_PROGRESS_TEST 37
      54                 :             : #define T604_SERVER_REPLAY_INSERT_ZERO_TEST 38
      55                 :             : #define T605_SERVER_REPLAY_INSERT_TEST 39
      56                 :             : #define T606_SERVER_REPLAY_STANDARD_SCENARIO_TEST 40
      57                 :             : #define T800_OSCORE_LATENCY_TEST 41
      58                 :             : #define TEST_EDHOC_INITIATOR_X509_X5T_RFC9529 42
      59                 :             : #define TEST_EDHOC_RESPONDER_X509_X5T_RFC9529 43
      60                 :             : #define TEST_EDHOC_INITIATOR_STATIC_DH_KID_RFC9529 44
      61                 :             : #define TEST_EDHOC_RESPONDER_STATIC_DH_KID_RFC9529 45
      62                 :             : #define T_KID_ID_CRED2KID 46
      63                 :             : #define T_KID_PLAINTEXT_SPLIT 47
      64                 :             : #define T_KID_RETRIEVE_CRED 48
      65                 :             : #define TEST_EDHOC_INITIATOR_EMPTY_C_R 49
      66                 :             : #define TEST_EDHOC_RESPONDER_EMPTY_C_R 50
      67                 :             : #define T_RETRIEVE_CRED_UNCOMPRESSED_G 51
      68                 :             : 
      69                 :             : // if this macro is defined all tests will be executed
      70                 :             :  #define EXECUTE_ALL_TESTS
      71                 :             : 
      72                 :             : // in order to execute only a specific tes set this macro to a specific
      73                 :             : // test macro and comment out EXECUTE_ALL_TESTS
      74                 :             : #define EXECUTE_ONLY_TEST TEST_EDHOC_RESPONDER_X509_X5T_RFC9529
      75                 :             : 
      76                 :             : /**
      77                 :             :  * @brief       This function allows to skip a given test if only one other test 
      78                 :             :  *              needs to be executed.
      79                 :             :  * 
      80                 :             :  * @param test_name_macro 
      81                 :             :  */
      82                 :          50 : static void skip(int test_name_macro, void (*test_function)())
      83                 :             : {
      84                 :             : #if !defined EXECUTE_ALL_TESTS
      85                 :             :         if (EXECUTE_ONLY_TEST == test_name_macro) {
      86                 :             :                 test_function();
      87                 :             :         } else {
      88                 :             :                 ztest_test_skip();
      89                 :             :         }
      90                 :             : #else
      91                 :          50 :         test_function();
      92                 :             : #endif
      93                 :          50 : }
      94                 :             : 
      95                 :             : ZTEST_SUITE(uoscore_uedhoc, NULL, NULL, NULL, NULL, NULL);
      96                 :             : 
      97                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_exporter)
      98                 :             : {
      99                 :           1 :         skip(TEST_EDHOC_EXPORTER, test_exporter);
     100                 :           1 : };
     101                 :             : 
     102                 :           2 : ZTEST(uoscore_uedhoc, test_initiator_responder_interaction1)
     103                 :             : {
     104                 :           1 :         skip(TEST_INITIATOR_RESPONDER_INTERACTION1,
     105                 :             :              t_initiator_responder_interaction1);
     106                 :           1 : };
     107                 :             : 
     108                 :           2 : ZTEST(uoscore_uedhoc, test_initiator_responder_interaction2)
     109                 :             : {
     110                 :           1 :         skip(TEST_INITIATOR_RESPONDER_INTERACTION2,
     111                 :             :              t_initiator_responder_interaction2);
     112                 :           1 : };
     113                 :             : 
     114                 :           2 : ZTEST(uoscore_uedhoc, t1_oscore)
     115                 :             : {
     116                 :           1 :         skip(T1_OSCORE_CLIENT_REQUEST_RESPONSE,
     117                 :             :              t1_oscore_client_request_response);
     118                 :           1 : }
     119                 :             : 
     120                 :           2 : ZTEST(uoscore_uedhoc, t2_oscore)
     121                 :             : {
     122                 :           1 :         skip(T2_OSCORE_SERVER_REQUEST_RESPONSE,
     123                 :             :              t2_oscore_server_request_response);
     124                 :           1 : }
     125                 :             : 
     126                 :           2 : ZTEST(uoscore_uedhoc, t3_oscore)
     127                 :             : {
     128                 :           1 :         skip(T3_OSCORE_CLIENT_REQUEST, t3_oscore_client_request);
     129                 :           1 : }
     130                 :             : 
     131                 :           2 : ZTEST(uoscore_uedhoc, t4_oscore)
     132                 :             : {
     133                 :           1 :         skip(T4_OSCORE_SERVER_KEY_DERIVATION, t4_oscore_server_key_derivation);
     134                 :           1 : }
     135                 :             : 
     136                 :           2 : ZTEST(uoscore_uedhoc, t5_oscore)
     137                 :             : {
     138                 :           1 :         skip(T5_OSCORE_CLIENT_REQUEST, t5_oscore_client_request);
     139                 :           1 : }
     140                 :             : 
     141                 :           2 : ZTEST(uoscore_uedhoc, t6_oscore)
     142                 :             : {
     143                 :           1 :         skip(T6_OSCORE_SERVER_KEY_DERIVATION, t6_oscore_server_key_derivation);
     144                 :           1 : }
     145                 :             : 
     146                 :           2 : ZTEST(uoscore_uedhoc, t8_oscore)
     147                 :             : {
     148                 :           1 :         skip(T8_OSCORE_SERVER_RESPONSE_SIMPLE_ACK,
     149                 :             :              t8_oscore_server_response_simple_ack);
     150                 :           1 : }
     151                 :             : 
     152                 :           2 : ZTEST(uoscore_uedhoc, t9_oscore)
     153                 :             : {
     154                 :           1 :         skip(T9_OSCORE_CLIENT_SERVER_OBSERVE, t9_oscore_client_server_observe);
     155                 :           1 : }
     156                 :             : 
     157                 :           2 : ZTEST(uoscore_uedhoc, t10_oscore)
     158                 :             : {
     159                 :           1 :         skip(T10_OSCORE_CLIENT_SERVER_AFTER_REBOOT,
     160                 :             :              t10_oscore_client_server_after_reboot);
     161                 :           1 : }
     162                 :             : 
     163                 :           2 : ZTEST(uoscore_uedhoc, t100_oscore)
     164                 :             : {
     165                 :           1 :         skip(T100_INNER_OUTER_OPTION_SPLIT__NO_SPECIAL_OPTIONS,
     166                 :             :              t100_inner_outer_option_split__no_special_options);
     167                 :           1 : }
     168                 :             : 
     169                 :           2 : ZTEST(uoscore_uedhoc, t101_oscore)
     170                 :             : {
     171                 :           1 :         skip(T101_INNER_OUTER_OPTION_SPLIT__WITH_OBSERVE_NOTIFICATION,
     172                 :             :              t101_inner_outer_option_split__with_observe_notification);
     173                 :           1 : }
     174                 :             : 
     175                 :           2 : ZTEST(uoscore_uedhoc, t102_oscore)
     176                 :             : {
     177                 :           1 :         skip(T102_INNER_OUTER_OPTION_SPLIT__WITH_OBSERVE_REGISTRATION,
     178                 :             :              t102_inner_outer_option_split__with_observe_registration);
     179                 :           1 : }
     180                 :             : 
     181                 :           2 : ZTEST(uoscore_uedhoc, t103_oscore)
     182                 :             : {
     183                 :           1 :         skip(T103_OSCORE_PKG_GENERATE__REQUEST_WITH_OBSERVE_REGISTRATION,
     184                 :             :              t103_oscore_pkg_generate__request_with_observe_registration);
     185                 :           1 : }
     186                 :             : 
     187                 :           2 : ZTEST(uoscore_uedhoc, t104_oscore)
     188                 :             : {
     189                 :           1 :         skip(T104_OSCORE_PKG_GENERATE__REQUEST_WITH_OBSERVE_NOTIFICATION,
     190                 :             :              t104_oscore_pkg_generate__request_with_observe_notification);
     191                 :           1 : }
     192                 :             : 
     193                 :           2 : ZTEST(uoscore_uedhoc, t105_oscore)
     194                 :             : {
     195                 :           1 :         skip(T105_INNER_OUTER_OPTION_SPLIT__TOO_MANY_OPTIONS,
     196                 :             :              t105_inner_outer_option_split__too_many_options);
     197                 :           1 : }
     198                 :             : 
     199                 :           2 : ZTEST(uoscore_uedhoc, t106_oscore)
     200                 :             : {
     201                 :           1 :         skip(T106_OSCORE_OPTION_GENERATE_NO_PIV,
     202                 :             :              t106_oscore_option_generate_no_piv);
     203                 :           1 : }
     204                 :             : 
     205                 :           2 : ZTEST(uoscore_uedhoc, t200_oscore)
     206                 :             : {
     207                 :           1 :         skip(T200_OPTIONS_SERIALIZE_DESERIALIZE,
     208                 :             :              t200_options_serialize_deserialize);
     209                 :           1 : }
     210                 :             : 
     211                 :           2 : ZTEST(uoscore_uedhoc, t201_oscore)
     212                 :             : {
     213                 :           1 :         skip(T201_COAP_SERIALIZE_DESERIALIZE, t201_coap_serialize_deserialize);
     214                 :           1 : }
     215                 :             : 
     216                 :           2 : ZTEST(uoscore_uedhoc, t202_oscore)
     217                 :             : {
     218                 :           1 :         skip(T202_OPTIONS_DESERIALIZE_CORNER_CASES,
     219                 :             :              t202_options_deserialize_corner_cases);
     220                 :           1 : }
     221                 :             : 
     222                 :           2 : ZTEST(uoscore_uedhoc, t300_oscore)
     223                 :             : {
     224                 :           1 :         skip(T300_OSCORE_OPTION_PARSER_NO_PIV,
     225                 :             :              t300_oscore_option_parser_no_piv);
     226                 :           1 : }
     227                 :             : 
     228                 :           2 : ZTEST(uoscore_uedhoc, t301_oscore)
     229                 :             : {
     230                 :           1 :         skip(T301_OSCORE_OPTION_PARSER_WRONG_N,
     231                 :             :              t301_oscore_option_parser_wrong_n);
     232                 :           1 : }
     233                 :             : 
     234                 :           2 : ZTEST(uoscore_uedhoc, t302_oscore)
     235                 :             : {
     236                 :           1 :         skip(T302_OSCORE_OPTION_PARSER_NO_KID,
     237                 :             :              t302_oscore_option_parser_no_kid);
     238                 :           1 : }
     239                 :             : 
     240                 :           2 : ZTEST(uoscore_uedhoc, t303_oscore)
     241                 :             : {
     242                 :           1 :         skip(T303_OPTIONS_REORDER, t303_options_reorder);
     243                 :           1 : }
     244                 :             : 
     245                 :           2 : ZTEST(uoscore_uedhoc, t400_oscore)
     246                 :             : {
     247                 :           1 :         skip(T400_IS_CLASS_E, t400_is_class_e);
     248                 :           1 : }
     249                 :             : 
     250                 :           2 : ZTEST(uoscore_uedhoc, t401_oscore)
     251                 :             : {
     252                 :           1 :         skip(T401_CACHE_ECHO_VAL, t401_cache_echo_val);
     253                 :           1 : }
     254                 :             : 
     255                 :           2 : ZTEST(uoscore_uedhoc, t402_oscore)
     256                 :             : {
     257                 :           1 :         skip(T402_ECHO_VAL_IS_FRESH, t402_echo_val_is_fresh);
     258                 :           1 : }
     259                 :             : 
     260                 :           2 : ZTEST(uoscore_uedhoc, t500_oscore)
     261                 :             : {
     262                 :           1 :         skip(T500_OSCORE_CONTEXT_INIT_CORNER_CASES,
     263                 :             :              t500_oscore_context_init_corner_cases);
     264                 :           1 : }
     265                 :             : 
     266                 :           2 : ZTEST(uoscore_uedhoc, t501_oscore)
     267                 :             : {
     268                 :           1 :         skip(T501_PIV2SSN, t501_piv2ssn);
     269                 :           1 : }
     270                 :             : 
     271                 :           2 : ZTEST(uoscore_uedhoc, t502_oscore)
     272                 :             : {
     273                 :           1 :         skip(T502_SSN2PIV, t502_ssn2piv);
     274                 :           1 : }
     275                 :             : 
     276                 :           2 : ZTEST(uoscore_uedhoc, t503_oscore)
     277                 :             : {
     278                 :           1 :         skip(T503_DERIVE_CORNER_CASE, t503_derive_corner_case);
     279                 :           1 : }
     280                 :             : 
     281                 :           2 : ZTEST(uoscore_uedhoc, t600_oscore)
     282                 :             : {
     283                 :           1 :         skip(T600_SERVER_REPLAY_INIT_TEST, t600_server_replay_init_test);
     284                 :           1 : }
     285                 :             : 
     286                 :           2 : ZTEST(uoscore_uedhoc, t601_oscore)
     287                 :             : {
     288                 :           1 :         skip(T601_SERVER_REPLAY_REINIT_TEST, t601_server_replay_reinit_test);
     289                 :           1 : }
     290                 :             : 
     291                 :           2 : ZTEST(uoscore_uedhoc, t602_oscore)
     292                 :             : {
     293                 :           1 :         skip(T602_SERVER_REPLAY_CHECK_AT_START_TEST,
     294                 :             :              t602_server_replay_check_at_start_test);
     295                 :           1 : }
     296                 :             : 
     297                 :           2 : ZTEST(uoscore_uedhoc, t603_oscore)
     298                 :             : {
     299                 :           1 :         skip(T603_SERVER_REPLAY_CHECK_IN_PROGRESS_TEST,
     300                 :             :              t603_server_replay_check_in_progress_test);
     301                 :           1 : }
     302                 :             : 
     303                 :           2 : ZTEST(uoscore_uedhoc, t604_oscore)
     304                 :             : {
     305                 :           1 :         skip(T604_SERVER_REPLAY_INSERT_ZERO_TEST,
     306                 :             :              t604_server_replay_insert_zero_test);
     307                 :           1 : }
     308                 :             : 
     309                 :           2 : ZTEST(uoscore_uedhoc, t605_oscore)
     310                 :             : {
     311                 :           1 :         skip(T605_SERVER_REPLAY_INSERT_TEST, t605_server_replay_insert_test);
     312                 :           1 : }
     313                 :             : 
     314                 :           2 : ZTEST(uoscore_uedhoc, t606_oscore)
     315                 :             : {
     316                 :           1 :         skip(T606_SERVER_REPLAY_STANDARD_SCENARIO_TEST,
     317                 :             :              t606_server_replay_standard_scenario_test);
     318                 :           1 : }
     319                 :             : 
     320                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_initiator_x509_x5t_rfc9529)
     321                 :             : {
     322                 :           1 :         skip(TEST_EDHOC_INITIATOR_X509_X5T_RFC9529,
     323                 :             :              test_edhoc_initiator_x509_x5t_rfc9529);
     324                 :           1 : }
     325                 :             : 
     326                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_responder_x509_x5t_rfc9529)
     327                 :             : {
     328                 :           1 :         skip(TEST_EDHOC_RESPONDER_X509_X5T_RFC9529,
     329                 :             :              test_edhoc_responder_x509_x5t_rfc9529);
     330                 :           1 : }
     331                 :             : 
     332                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_initiator_static_dh_kid_rfc9529)
     333                 :             : {
     334                 :           1 :         skip(TEST_EDHOC_INITIATOR_STATIC_DH_KID_RFC9529,
     335                 :             :              test_edhoc_initiator_static_dh_kid_rfc9529);
     336                 :           1 : }
     337                 :             : 
     338                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_responder_static_dh_kid_rfc9529)
     339                 :             : {
     340                 :           1 :         skip(TEST_EDHOC_RESPONDER_STATIC_DH_KID_RFC9529,
     341                 :             :              test_edhoc_responder_static_dh_kid_rfc9529);
     342                 :           1 : }
     343                 :             : 
     344                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_initiator_empty_c_r)
     345                 :             : {
     346                 :           1 :         skip(TEST_EDHOC_INITIATOR_EMPTY_C_R, test_edhoc_initiator_empty_c_r);
     347                 :           1 : }
     348                 :             : 
     349                 :           2 : ZTEST(uoscore_uedhoc, test_edhoc_responder_empty_c_r)
     350                 :             : {
     351                 :           1 :         skip(TEST_EDHOC_RESPONDER_EMPTY_C_R, test_edhoc_responder_empty_c_r);
     352                 :           1 : }
     353                 :             : 
     354                 :           2 : ZTEST(uoscore_uedhoc, t_kid_id_cred2kid)
     355                 :             : {
     356                 :           1 :         skip(T_KID_ID_CRED2KID, t_kid_id_cred2kid);
     357                 :           1 : }
     358                 :             : 
     359                 :           2 : ZTEST(uoscore_uedhoc, t_kid_plaintext_split)
     360                 :             : {
     361                 :           1 :         skip(T_KID_PLAINTEXT_SPLIT, t_kid_plaintext_split);
     362                 :           1 : }
     363                 :             : 
     364                 :           2 : ZTEST(uoscore_uedhoc, t_kid_retrieve_cred)
     365                 :             : {
     366                 :           1 :         skip(T_KID_RETRIEVE_CRED, t_kid_retrieve_cred);
     367                 :           1 : }
     368                 :             : 
     369                 :           2 : ZTEST(uoscore_uedhoc, t_retrieve_cred_uncompressed_g)
     370                 :             : {
     371                 :           1 :         skip(T_RETRIEVE_CRED_UNCOMPRESSED_G, t_retrieve_cred_uncompressed_g);
     372                 :           1 : }
     373                 :             : 
     374                 :             : /*
     375                 :             :  * In order to measure the latency of coap2oscore, oscore2coap, 
     376                 :             :  * edhoc_responder_run, edhoc_initiator_run you need one of the supported boards 
     377                 :             :  * by Zephyr OS, see https://docs.zephyrproject.org/latest/boards/index.html
     378                 :             :  * Make sure that MEASURE_LATENCY_ON is enabled in CMakeLists.txt
     379                 :             :  * Build flash the test project for your board e.g.,
     380                 :             :  * west build -b=nrf9160dk/nrf9160; west flash.
     381                 :             :  * make also sure that DEBUG_PRINT is disabled
     382                 :             :  */
     383                 :             : #ifdef MEASURE_LATENCY_ON
     384                 :             : ZTEST(uoscore_uedhoc, t800_oscore)
     385                 :             : {
     386                 :             :         skip(T800_OSCORE_LATENCY_TEST, t800_oscore_latency_test);
     387                 :             : }
     388                 :             : #endif /*MEASURE_LATENCY_ON*/
        

Generated by: LCOV version 2.0-1