Skip to content

peer_manager: add unit tests and some fixes#808

Open
anhmolt wants to merge 12 commits into
nrfconnect:mainfrom
anhmolt:pm-unit-tests
Open

peer_manager: add unit tests and some fixes#808
anhmolt wants to merge 12 commits into
nrfconnect:mainfrom
anhmolt:pm-unit-tests

Conversation

@anhmolt
Copy link
Copy Markdown
Contributor

@anhmolt anhmolt commented Jun 2, 2026

Add initial peer manager unit tests.
Introduces some fixes to peer manager to allow unit tests to compile and to fix some issues that became apparent when starting unit testing.

anhmolt added 8 commits June 2, 2026 12:23
The __ALIGN macro defined in bm_zms.c is not used. Remove it
and add header for the __aligned macro, which is used in the
bm_zms.c file.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Swap nrf mdk __ALIGN macro for the zephyr __aligned macro to
align code.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
No need to round up to nearest word when storing bonding data.
The underlying storage now handles this.

Side note: The size of struct pm_peer_data_bonding in bytes
is currently divisible by 4 and therefore aligned. Therefore, the
round up macro currently does nothing here.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Use the standard inline keyword instead of the cmsis defined __INLINE.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
The module variables used by the peer ranks functionality
existed even when CONFIG_PM_PEER_RANKS was unset and nothing
was using them. Restructure the names to group them and place
them behind the CONFIG_PM_PEER_RANKS Kconfig option.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Calling pm_init() for a second time would not clear the
registered handler functions registered with pm_register().

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Fix an issue where calling pm_init two or more times would reset the
flag data in conn_state.c but not all flags in the peer manager
sub modules would be re-acquire correctly due to a check against
PM_CONN_STATE_USER_FLAG_INVALID.

Fix this and align how the flags are initialized.

Issue appeared and has existed since an internal copy of ble_conn_state
was added to peer_manager.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
The pm_address_resolve function should not return an nrf_error.
Change the value returned when the peer manager module is not
initialized to false.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
@anhmolt anhmolt requested review from a team and rghaddab as code owners June 2, 2026 11:00
@github-actions github-actions Bot added the doc-required PR must not be merged without tech writer approval. label Jun 2, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 2, 2026

You can find the documentation preview for this PR here.

Copy link
Copy Markdown
Contributor

@eivindj-nordic eivindj-nordic left a comment

Choose a reason for hiding this comment

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

Good cleanup! Have not looked at tests yet.

Fix an issue where the local_gatt_db_buf (in the
gscm_local_db_cache_apply function) was used after going out of scope.

This was not caught earlier because nothing was allocated on
the stack that could corrupt the data in local_gatt_db_buf before it
was used by the sd_ble_gatts_sys_attr_set SVC.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
anhmolt added 3 commits June 2, 2026 16:28
Add unit tests for the nrf_ble_lesc submodule of the peer_manager
library.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Add first set of unit tests for peer manager library.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Add more unit tests for peer manager. These have been
assisted with AI.

Signed-off-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-required PR must not be merged without tech writer approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants