Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth: controller: Llcp update unittests #52894

Merged
merged 1 commit into from
Jan 20, 2023

Conversation

kruithofa
Copy link
Collaborator

@kruithofa kruithofa commented Dec 8, 2022

Update to the feature exchange unit tests

  • use the new ZTEST API
  • use the Zephyr Kconfig settings (and a prj.conf file), getting rid of the hack of having an include file for KConfig settings.
  • specify the helper functions and the mocks as a library instead of including them as a file list

Looking for feedback, in particular if we should have a file unit_sources.txt, and include that in each of the unit-tests (as per this PR), or copy the contents of this file to each CMakelists.txt in each unit-test.

fixes #52626

Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this improvement, some minor nits and question / proposals regarding some of the choices made.

Overall impression is that this is a nice improvement 👍

# some of the control procedures in the BT LL depend on
# the following configs been set
config SOC_COMPATIBLE_NRF
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to redefine the type here.
Actually not specifying the type not only minimize the file but also has the benefit of easily discover if the real symbol is renamed / removed.

Ref: https://docs.zephyrproject.org/latest/build/kconfig/tips.html#common-kconfig-shorthands

Suggested change
bool

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know this, but makes sense. A cleanup of other Kconfig files may be required then, for example in tests/bluetooth/df/* (where this was copied from)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifying the type has been removed from all other places as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cleanup of other Kconfig files may be required then, for example in tests/bluetooth/df/* (where this was copied from)

Yes, there's a bit of whack-a-mole here, because developers naturally copies files / code snippes around and adjust.

Thanks for cleaning up.

default y

config SOC_SERIES_NRFX
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

default y

config BT_CTLR_PHY_UPDATE_SUPPORT
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

default y

config ENTROPY_NRF_FORCE_ALT
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

default n

config DT_HAS_NORDIC_NRF_RNG_ENABLED
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

# Common include directories and source files for bluetooth unit tests
#

include_directories(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why exactly is include_directories() used here ?
cause in this particular case then those include paths will only be applied to testbinary afaict.

Generally target_include_directories() is recommended.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a uut library removes the need for this file

@@ -15,6 +15,14 @@ config BT_CTLR_PHY_UPDATE_SUPPORT
bool
default y

config BT_CTLR_PHY_CODED_SUPPORT
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

default y

config BT_CTLR_PHY_2M_SUPPORT
bool
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool

Comment on lines 12 to 19
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
${ZEPHYR_BASE}/subsys/bluetooth/controller/util
${ZEPHYR_BASE}/subsys/bluetooth/controller
${ZEPHYR_BASE}/subsys/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic/lll
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic
${ZEPHYR_BASE}/include/zephyr/bluetooth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those are also exported by the mocks library.

are both really needed or could there be a single interface library that both the mock and the testbinary can link to ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer listing the required include directories explicitly for each library; however the list was too large, so the list will be reduced to only the absolutely minimum required include directories
Arguably the directory 'common' should be renamed 'helper', but that will have to be part of a separate PR, where we move the unittests for the controller to a more logical place

Comment on lines 61 to 65
add_definitions(-include kconfig.h)
if(KCONFIG_OVERRIDE_FILE)
add_definitions(-include ${KCONFIG_OVERRIDE_FILE})
endif()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have kconfig support in unittesting so I don't think we should be using this Kconfig override principle.
We should be able to handle this properly in Kconfig files directly, so that unittests are following same pattern as samples.

Please let me know if there are reasons when the common Kconfig approach cannot be used.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agreed, and the reason for this PR is so that we can get rid of this hack. It is left here because the other unittests rely on this. Once this PR is approved (meaning that we agree on how the framework for the unittests for the controller should be) we can create another PR updating all the other unittests and getting rid of this hack. See #35099

@kruithofa kruithofa force-pushed the llcp_update_unittests branch 2 times, most recently from 049e545 to ff07730 Compare December 22, 2022 12:28
@kruithofa kruithofa requested a review from tejlmand December 22, 2022 12:49
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Definitely improved, making other things easier to spot.

#

add_library(mocks STATIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/src/kernel.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for full path, relative sources are picked up relative to CMAKE_CURRENT_SOURCE_DIR, so this is sufficient here and below:

  src/kernel.c

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done



target_include_directories(mocks PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can be reduced to

Suggested change
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
include

as that include folder is below the CMAKE_CURRENT_SOURCE_DIR.
This also makes it clearer to the reader which folders are local to the mock lib, and which folders are picked up externally (as they use abs path)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,35 @@
#
# CMakeLists.txt file for creating of mocks library.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

target_include_directories(uut PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line indicates that this library depends on the mock library created.

Should there be a target_link_libraries(uut PUBLIC mocks) here ?
That would ensure the include path gets inherited correctly, as well as generally making sense as I believe the sources in uut actually links to functions provided my the mock lib.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed; that makes the CMakeLists.txt in the ctrl_feature_exchange cleaner as well

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so because you now link to the mocks library, then this line can be removed because it is inherited.

Suggested change
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is still here.
The mock_ctrl/include is an include native to the mock library, so it should be inherited.

The other includes, those with ${ZEPHYR_BASE}/subsys/bluetooth are not native to the mock library (they are rightfully native to the bluetooth controller library which we are not linking directly).
Therefor the ${ZEPHYR_BASE}/subsys/bluetooth are acceptable not to inherit, but the mock include must be inherited. The uut itself should not know about internals of the mock lib.

@kruithofa kruithofa force-pushed the llcp_update_unittests branch 5 times, most recently from 2dc3e63 to 802eabf Compare January 9, 2023 14:04
@kruithofa kruithofa requested a review from tejlmand January 9, 2023 15:12
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, also some minor nits.

)

target_include_directories(uut PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so because you now link to the mocks library, then this line can be removed because it is inherited.

Suggested change
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include

Comment on lines 30 to 35
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
${ZEPHYR_BASE}/subsys/bluetooth/controller
${ZEPHYR_BASE}/subsys/bluetooth
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw
${ZEPHYR_BASE}/subsys/bluetooth/controller/ll_sw/nordic
${ZEPHYR_BASE}/include/zephyr/bluetooth
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Those include paths are also defined by the mocks library, which in practice means you can remove them from here.

But as the uut library refers to source files directly in the bluetooth controller library then it also make sense to keep those includes explicitly here, as well as in the mocks lib.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer listing them here explicitly, due to the direct reference to bluetooth controller files

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consequence is however that we also need to leave the ${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include in place to ensure that we include the mock include-files.
i.e. either we remove all include paths, or we leave all of them as is

${ZEPHYR_BASE}/include/zephyr/bluetooth
)

add_subdirectory(${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl mocks)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment for future reference.

This is not ideal, as we should strive to have a straight forward CMake hierarchy.
But as this is an improvement on the overall test structure, then it is accepted in this case.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #53741 for followup

#
# SPDX-License-Identifier: Apache-2.0
#
# CMakeLists.txt file for creating of mocks library.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust, this file doesn't create the mocks library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@carlescufi
Copy link
Member

@tejlmand please take another look

)

target_include_directories(uut PUBLIC
${ZEPHYR_BASE}/tests/bluetooth/controller/mock_ctrl/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line is still here.
The mock_ctrl/include is an include native to the mock library, so it should be inherited.

The other includes, those with ${ZEPHYR_BASE}/subsys/bluetooth are not native to the mock library (they are rightfully native to the bluetooth controller library which we are not linking directly).
Therefor the ${ZEPHYR_BASE}/subsys/bluetooth are acceptable not to inherit, but the mock include must be inherited. The uut itself should not know about internals of the mock lib.


target_include_directories(mocks PUBLIC
include
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as you have decided that test lib themselves should not inherit includes under ${ZEPHYR_BASE}/subsys/bluetooth, then those should be made PRIVATE as to avoid mix of principles.

Suggested change
${ZEPHYR_BASE}/subsys/bluetooth/controller/include
PRIVATE
${ZEPHYR_BASE}/subsys/bluetooth/controller/include

Update the unittests for feature exchange to use the new ZTEST API
Here we only update the feature exchange procedure. The remaining
unittests will be done in a next PR

Mocks, helper routines and the Unit Under Test are splitted out as
a library instead of adding them to the file list

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
@kruithofa kruithofa force-pushed the llcp_update_unittests branch from dc70d3c to 9767788 Compare January 17, 2023 10:38
@kruithofa kruithofa requested a review from tejlmand January 17, 2023 11:20
Copy link
Collaborator

@tejlmand tejlmand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the effort.

@carlescufi
Copy link
Member

@thoh-ot @erbr-ot could you please review this one?

Copy link
Collaborator

@erbr-ot erbr-ot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good - thanks, Andries!
One nit-pick - the tittle of the PR could reflect this is feature exchange only.

@carlescufi carlescufi merged commit f0c610c into zephyrproject-rtos:main Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve LLCP unit tests
7 participants