From f08baa97bc187a1bf73a58f21b5d72925c8a40e0 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 12 Dec 2024 17:14:51 +0000 Subject: [PATCH 1/4] linker: undefine the no-ops dt macros at the end of the file Undefine the DT_NODE_HAS_STATUS and DT_NODE_HAS_STATUS_OKAY no nop at the end of the file so other uses can include devicetree.h without generating a compiler warning. Signed-off-by: Fabio Baltieri --- include/zephyr/linker/linker-defs.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/zephyr/linker/linker-defs.h b/include/zephyr/linker/linker-defs.h index 9c795ae78517ae..14bbc250f4c7f3 100644 --- a/include/zephyr/linker/linker-defs.h +++ b/include/zephyr/linker/linker-defs.h @@ -28,7 +28,7 @@ /* We need to dummy out DT_NODE_HAS_STATUS when building the unittests. * Including devicetree.h would require generating dummy header files * to match what gen_defines creates, so it's easier to just dummy out - * DT_NODE_HAS_STATUS. + * DT_NODE_HAS_STATUS. These are undefined at the end of the file. */ #ifdef ZTEST_UNITTEST #define DT_NODE_HAS_STATUS(node, status) 0 @@ -359,4 +359,9 @@ extern char lnkr_ondemand_rodata_size[]; #endif /* CONFIG_LINKER_USE_ONDEMAND_SECTION */ #endif /* ! _ASMLANGUAGE */ +#ifdef ZTEST_UNITTEST +#undef DT_NODE_HAS_STATUS +#undef DT_NODE_HAS_STATUS_OKAY +#endif + #endif /* ZEPHYR_INCLUDE_LINKER_LINKER_DEFS_H_ */ From c43290c24d951fbc37a2585d6449048aecef30fe Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 12 Dec 2024 17:05:02 +0000 Subject: [PATCH 2/4] tests: fix various unit tests warnings Fix various unit test build warnings, unused variables, set but unused variables, wrong types etc... Signed-off-by: Fabio Baltieri --- tests/bluetooth/audio/bap_broadcast_source/src/main.c | 2 +- .../audio/cap_commander/src/test_broadcast_reception.c | 3 +-- .../audio/cap_commander/uut/bap_broadcast_assistant.c | 3 --- tests/bluetooth/audio/codec/src/main.c | 4 ++-- tests/bluetooth/controller/ctrl_phy_update/src/main.c | 3 --- tests/bluetooth/host/conn/mocks/scan.c | 1 + tests/unit/pot/nhpot.cpp | 2 +- 7 files changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/bluetooth/audio/bap_broadcast_source/src/main.c b/tests/bluetooth/audio/bap_broadcast_source/src/main.c index 38a2b0a6e5061b..31396ba9cfefab 100644 --- a/tests/bluetooth/audio/bap_broadcast_source/src/main.c +++ b/tests/bluetooth/audio/bap_broadcast_source/src/main.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include diff --git a/tests/bluetooth/audio/cap_commander/src/test_broadcast_reception.c b/tests/bluetooth/audio/cap_commander/src/test_broadcast_reception.c index 61827719bb5fd7..b23af0654721f0 100644 --- a/tests/bluetooth/audio/cap_commander/src/test_broadcast_reception.c +++ b/tests/bluetooth/audio/cap_commander/src/test_broadcast_reception.c @@ -104,13 +104,12 @@ static void cap_commander_test_broadcast_reception_before(void *f) static void cap_commander_test_broadcast_reception_after(void *f) { struct cap_commander_test_broadcast_reception_fixture *fixture = f; - int err; bt_cap_commander_unregister_cb(&mock_cap_commander_cb); bt_bap_broadcast_assistant_unregister_cb(&fixture->broadcast_assistant_cb); /* We need to cleanup since the CAP commander remembers state */ - err = bt_cap_commander_cancel(); + (void)bt_cap_commander_cancel(); for (size_t i = 0; i < ARRAY_SIZE(fixture->conns); i++) { mock_bt_conn_disconnected(&fixture->conns[i], BT_HCI_ERR_REMOTE_USER_TERM_CONN); diff --git a/tests/bluetooth/audio/cap_commander/uut/bap_broadcast_assistant.c b/tests/bluetooth/audio/cap_commander/uut/bap_broadcast_assistant.c index 8331c292e0c998..3ea01833905cb0 100644 --- a/tests/bluetooth/audio/cap_commander/uut/bap_broadcast_assistant.c +++ b/tests/bluetooth/audio/cap_commander/uut/bap_broadcast_assistant.c @@ -182,14 +182,11 @@ int bt_bap_broadcast_assistant_set_broadcast_code( struct bt_conn *conn, uint8_t src_id, const uint8_t broadcast_code[BT_ISO_BROADCAST_CODE_SIZE]) { - struct bap_broadcast_assistant_instance *inst; struct bt_bap_broadcast_assistant_cb *listener, *next; int err; zassert_not_null(conn, "conn is NULL"); - inst = inst_by_conn(conn); - zassert_equal(src_id, RANDOM_SRC_ID, "Invalid src_id"); err = strncmp((const char *)broadcast_code, BROADCAST_CODE, sizeof(BROADCAST_CODE)); diff --git a/tests/bluetooth/audio/codec/src/main.c b/tests/bluetooth/audio/codec/src/main.c index a3a189e86ca280..fcddfbb0523221 100644 --- a/tests/bluetooth/audio/codec/src/main.c +++ b/tests/bluetooth/audio/codec/src/main.c @@ -659,7 +659,7 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cfg_meta_set_lang) struct bt_audio_codec_cfg codec_cfg = BT_AUDIO_CODEC_CFG( BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')}); - char new_expected_data[] = "deu"; + const uint8_t new_expected_data[] = "deu"; char expected_data[] = "eng"; const uint8_t *lang; int ret; @@ -1701,7 +1701,7 @@ ZTEST(audio_codec_test_suite, test_bt_audio_codec_cap_meta_set_lang) struct bt_audio_codec_cap codec_cap = BT_AUDIO_CODEC_CAP( BT_HCI_CODING_FORMAT_LC3, 0x0000, 0x0000, {}, {BT_AUDIO_CODEC_DATA(BT_AUDIO_METADATA_TYPE_LANG, 'e', 'n', 'g')}); - char new_expected_data[] = "deu"; + const uint8_t new_expected_data[] = "deu"; char expected_data[] = "eng"; const uint8_t *lang; int ret; diff --git a/tests/bluetooth/controller/ctrl_phy_update/src/main.c b/tests/bluetooth/controller/ctrl_phy_update/src/main.c index 5951b685932b95..9a4c3d078d5c25 100644 --- a/tests/bluetooth/controller/ctrl_phy_update/src/main.c +++ b/tests/bluetooth/controller/ctrl_phy_update/src/main.c @@ -589,13 +589,10 @@ ZTEST(phy_periph, test_phy_update_periph_loc_invalid_central) { uint8_t err; struct node_tx *tx; - struct node_rx_pdu *ntf; struct pdu_data_llctrl_phy_req req = { .rx_phys = PHY_2M, .tx_phys = PHY_2M }; uint16_t instant; struct pdu_data_llctrl_conn_param_req conn_param_req = { }; - struct node_rx_pu pu = { .status = BT_HCI_ERR_SUCCESS }; - struct pdu_data_llctrl_phy_upd_ind phy_update_ind = { .c_to_p_phy = PHY_2M, .p_to_c_phy = PHY_2M }; diff --git a/tests/bluetooth/host/conn/mocks/scan.c b/tests/bluetooth/host/conn/mocks/scan.c index 6ccccd7bb88426..1359f5396060e9 100644 --- a/tests/bluetooth/host/conn/mocks/scan.c +++ b/tests/bluetooth/host/conn/mocks/scan.c @@ -5,6 +5,7 @@ */ #include +#include #include "scan.h" diff --git a/tests/unit/pot/nhpot.cpp b/tests/unit/pot/nhpot.cpp index 469072b7276a69..1a8385d270c0d6 100644 --- a/tests/unit/pot/nhpot.cpp +++ b/tests/unit/pot/nhpot.cpp @@ -39,7 +39,7 @@ ZTEST(pot, test_constexpr_NHPOT) zassert_equal(0, NHPOT(UINT64_MAX)); zassert_equal(64, val); - zassert_equal(64, nhpot(42)); + zassert_equal(64ULL, nhpot(42ULL)); zassert_equal(BIT64(33), val64); zassert_equal(BIT64(33), nhpot(42 + BIT64(32))); } From f38ddbb60e6620052e6c9653be2d59250b437301 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 12 Dec 2024 19:58:16 +0000 Subject: [PATCH 3/4] unittest: set -Wno-format-zero-length This flag is set on other compiler as well for normal builds, and suppresses a warning for empty print, which is apparently quite common. The unit test build uses its own flags so set it there as well to get the same behavior as with the rest of the code base. Signed-off-by: Fabio Baltieri --- cmake/modules/unittest.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/modules/unittest.cmake b/cmake/modules/unittest.cmake index 6565e89aec53a7..5bb6fb30c1340f 100644 --- a/cmake/modules/unittest.cmake +++ b/cmake/modules/unittest.cmake @@ -112,6 +112,7 @@ target_compile_options(test_interface INTERFACE ${EXTRA_CFLAGS_AS_LIST} $<$:${EXTRA_CXXFLAGS_AS_LIST}> $<$:${EXTRA_AFLAGS_AS_LIST}> + -Wno-format-zero-length ) target_link_options(testbinary PRIVATE From 3e31c8a9b78bc9a65ae087c6ad21bacf08a42959 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 12 Dec 2024 16:21:44 +0000 Subject: [PATCH 4/4] unittest: add COMPILER_WARNINGS_AS_ERRORS handling Add a check to set the warnings_as_errors flags in unit tests if CONFIG_COMPILER_WARNINGS_AS_ERRORS is specified, this should catch warnings in unit test twister runs. Signed-off-by: Fabio Baltieri --- cmake/modules/unittest.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmake/modules/unittest.cmake b/cmake/modules/unittest.cmake index 5bb6fb30c1340f..d981559ea65fd0 100644 --- a/cmake/modules/unittest.cmake +++ b/cmake/modules/unittest.cmake @@ -131,6 +131,10 @@ if(CONFIG_COVERAGE) target_link_libraries(testbinary PRIVATE $) endif() +if (CONFIG_COMPILER_WARNINGS_AS_ERRORS) + target_compile_options(test_interface INTERFACE $) +endif() + if(LIBS) message(FATAL_ERROR "This variable is not supported, see SOURCES instead") endif()