Commit graph

255 commits

Author SHA1 Message Date
Alberto Escolar Piedras
fba3f901ad tests/bluetooth/audio/cap_initiator: Be sure to free all malloc'ed memory
One of the tests is purposedly overwriting the stream pointer to NULL.
Which means it is lost and can't be free'd.
To avoid a memory leak warning, let's make sure we free it at the end
of each test by keeping the cap_streams ptr in the fixture.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-05-25 18:19:24 +02:00
Alberto Escolar Piedras
ab12d96334 tests/bluetooth/audio/bap_base: Free a malloc variable
To avoid a memory leak warning with valgrind.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-05-25 18:19:24 +02:00
Emil Gydesen
f825a8745f tests: Bluetooth: Audio: apply U suffix to unsigned integer literals
Apply the U suffix to unsigned integer literal constants used in
contexts involving unsigned types (uint8_t, uint16_t, uint32_t,
uint64_t, size_t, etc.) with coding guideline 40  which requires that
"A u or U suffix shall be applied to all integer constants that are
represented in an unsigned type".
In addition to this requirement, this commit also ads U to any unsigned
literal integer for the sake of completeness.

Changes are limited to literal values in assignments, initializations,
comparisons, and for-loop bounds where the context is unambiguously
unsigned.

Assisted-by: GitHub Copilot:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-19 12:53:46 +02:00
Emil Gydesen
f38c0cf7e5 tests: Bluetooth: CAP: Handover u->b unittests
Adds unittests for the handover from unicast to broadcast
APIs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 15:13:55 +01:00
Emil Gydesen
a2110e70fa Bluetooth: TBS: Rename features to optional opcodes
The characteristic name and definitions in the TBS spec for
the values are "optional opcodes" instead of "support features".

Additionally, the field is 16-bit, instead of the current 8-bit
in the register parameters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-18 10:14:52 +01:00
Emil Gydesen
0f653263ae tests: Bluetooth: Audio: Add missing error checks
Add missing error checks for any function calls in the
affected files, as that is required by the Zephyr coding guidelines.

Assisted-by: Copilot:claude-sonnet-4.6

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-15 12:57:17 +02:00
Emil Gydesen
418d6a7210 tests: Bluetooth: CCP: Server: Fix bad check for name
The provided name `inval_bearer_name` were not correctly set
as too long as it was not properly NULL terminated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-05 16:03:28 +01:00
Emil Gydesen
a89f48bcde tests: Bluetooth: Audio: add ARG_UNUSED to unused function parameters
Apply ARG_UNUSED() to unused function arguments as per the Zephyr
coding guidelines

Assisted-by: GitHub Copilot

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-05-04 22:08:20 +02:00
Emil Gydesen
e60165f45b Bluetooth: TBS: Add enum, move and rename TECHNOLOGY
The technology values defined in tbs.h are actually defined
in assigned numbers under the HFP. They have been moved to
the assigned_numbers.h file, and name to match the placement
in Assigned Numbers. They have been defined in an enum instead
of multiple #define's, to more easily refer to them.

The callback for reading technology was likewise updated to use
the new enum.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-30 13:59:23 -04:00
Emil Gydesen
028634623f Bluetooth: Audio: Add checks for UTF when getting broadcast name
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:22:20 +02:00
Emil Gydesen
a259ad8311 Bluetooth: Audio: Add checks for UTF when setting broadcast name
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:22:20 +02:00
Emil Gydesen
6548ed48af Bluetooth: CCP: Client: Add support for get bearer uci
Add support for getting the remote bearer UCI.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 17:21:17 +02:00
Emil Gydesen
7ac6f02ffb tests: Bluetooth: audio: replace implicit integer-to-boolean checks
MISRA-C requires essentially boolean types in control flow.
Convert all if/while conditions using err or ret
as implicit booleans to explicit comparisons:

- if (err)  -> if (err != 0)
- Same rules applied to while statements and ret variable

Also fix typos found during review:
- Fix "Failed to ser security level" -> "Failed to set security
  level" in pacs_notify_client_test.c (4 places) and
  csip_notify_client_test.c (2 places)
- Fix "Bluetoot" -> "Bluetooth" typo in media_controller_test.c
- Fix format/argument mismatch in bap_scan_delegator_test.c:
  add missing `i` argument to FAIL() call

Assisted-by: GitHub Copilot

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-27 14:22:32 +02:00
Emil Gydesen
a0a513667b Bluetooth: BAP/CAP: Make qos param const
Make the qos parameter of the BAP can CAP APIs const,
as they are now only used as one-time parameters, and not stored.
This also means that any uses of this can place the qos
parameter in the stack, rather than static memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-24 12:58:57 +02:00
Emil Gydesen
ce33df667f Bluetooth: CAP: Fix issue with aborting CAP commander procs
Fixed issue where an aborted CAP commander procedure would
never get past bt_cap_common_proc_all_handled and thus never
call the callback with an error, e.g. if the remote CAP
Acceptor rejects a request.

The fix required a significant refactor of the broadcast
part of the CAP commander, as it was fundamentally flawed.
The biggest change is that the implementation now uses both
the receive state notification as well as the write responses
to determine completeneess. Additionally, it also handles
notifications not initiated from our write requests, i.e.
it is now more similar to an event based procedure rather
than a linear one. This also means that when the callbacks
for the start and stop procedures are now called, we have
receive the events (notifications) from the remote CAP
acceptors that they are actually synced (or not synced) to
the broadcasts.

Since the broadcast reception start and stop now waits
for the receive state to be updated, a change in the
Handover implementation was also done.

To test the solution 2 new test cases were added,
and the existing tests were modified to allow for the
new expected behavior.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-16 11:37:24 -05:00
Emil Gydesen
9969e524ad Bluetooth: BAP: Make codec_cfg param const
Make the codec_cfg parameter of the BAP can CAP APIs const,
as they are now only used as one-time parameters, and not stored.
This also means that any uses of this can place the codec_cfg
parameter in the stack, rather than static memory.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:08:12 -04:00
Emil Gydesen
b1c2d5450e Bluetooth: BAP: Make bt_bap_stream.codec_cfg const
The pointer represent the codec configuration
for a stream based on the ASE or broadcast configuration,
and serves as a read-only value. Changing it to `const` makes
this more clear.

Some minor changes were done to existing code to help
support this change.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-04-14 22:08:12 -04:00
Emil Gydesen
2b198cf2cc Bluetooth: Audio: Make "foreach" functions consistent
Modify foreach functions in LE Audio to follow the same pattern:
Return true to continue iterating.
Return false to stop iterating.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-23 08:53:33 -04:00
Emil Gydesen
57155a5b2b tests: Bluetooth: Audio: Spring cleaning
Add missing header files, remove unused header files,
fix typos and missing static.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-20 18:18:55 +09:00
Kai Cheng
9906fdbe31 Bluetooth: Test: add dependency for bt_uuid_from_str unit tests
bt_uuid_from_str() uses hex2bin() from lib/utils/hex.c and
uuid_from_string() from lib/uuid/uuid.c. Add both dependencies
to each test CMakeLists.txt that compiles
subsys/bluetooth/host/uuid.c, fixing link failures on the
unit_testing platform.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-03-19 11:36:39 +00:00
Emil Gydesen
f8b573e7a3 Bluetooth: CCP: Modify get_bearer_uci to use output buffer
Modify bt_ccp_call_control_server_get_bearer_uci to
store the bearer UCI in an output buffer, instead of just
providing the pointer.

The reason for this is to make the result thread safe, and
avoid the user/application having a direct pointer to
internal storage.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-16 10:08:29 -04:00
Emil Gydesen
0e07f62e3a Bluetooth: CCP: Fix bad uses of TBS_MAX_PROVIDER_NAME_LENGTH
Several places used CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH
instead of
CONFIG_BT_CCP_CALL_CONTROL_SERVER_PROVIDER_NAME_MAX_LENGTH.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-04 14:34:10 +00:00
Emil Gydesen
f5f9a0e0f3 Bluetooth: CCP: Modify get_bearer_provider_name to use output buffer
Modify bt_ccp_call_control_server_get_bearer_provider_name to
store the bearer provider name in an output buffer, instead of just
providing the pointer.

The reason for this is to make the result thread safe, and
avoid the user/application having a direct pointer to
internal storage.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-03-04 14:34:10 +00:00
Emil Gydesen
3b93203348 tests: Bluetooth: Audio: Remove unused mocks
After the switch to the native_sim board instead of
the unit_testing board, we no longer need or use these
mocks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-02-20 10:08:34 +01:00
Emil Gydesen
9311480730 tests: Bluetooth: CAP: Fix issues in BAP BA mock
Fix wrong assignment to pa_sync_state.
Add missing call to recv_state_removed

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-02-19 10:00:45 -06:00
Emil Gydesen
309b5b3c01 Bluetooth: CAP: Add ep conn check in unicast audio start
Add check in valid_unicast_audio_start_param to verify
that the ep connection matches the member_conn.

Instead of declaring the endpoints in the unit tests, we
not define them in the mock unicast client and use the
discover function to get pointers.

This allows for a proper implementation of
bt_bap_unicast_client_has_ep as well as makes the tests more similar
to a normal application.

This change required a significant change in the unicast_stop
unit tests as well, which uncovered a small bug in the implementation.
The bug was fixed as part of this commit.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-02-17 10:31:09 +01:00
Emil Gydesen
5864564a46 Bluetooth: CCP: Add user_data to bt_ccp_call_control_client_cb
Add a user_data field to bt_ccp_call_control_client_cb. The
field is optional to enable via Kconfig. The field can be used
to provide additional context from the owner of the callback
structure, to the callbacks themselves.

This solves a memory use-after-free issue in the unit tests
where the values from the callback was accessed after they
were released, as the values were just stack allocated.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-02-10 10:51:43 +01:00
Alberto Escolar Piedras
ce7b62a55c tests: Bluetooth: ASCS: Fix link with CONFIG_NO_OPTIMIZATIONS
When this test is built with CONFIG_NO_OPTIMIZATIONS (which is the case
when building with CONFIG_COVERAGE) or when building with debug logging,
it fails to link due to lacking bt_uuid_str().
Let's include the corresponding file so it can link.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2026-02-04 15:17:55 +00:00
Emil Gydesen
d74f5d7d23 Bluetooth: Audio: depend on UTF8
Add a dependency for UTF8 for LE Audio. Since (nearly?) all
string in LE Audio are UTF8 and that the stack wants to be
able to check and validate strings coming both from remove
deviecs and from the application, it will depend on the utf8
API that is guarded by CONFIG_UTF8.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-01-20 13:20:52 +00:00
Emil Gydesen
f3b63a1bd6 Bluetooth: CCP: Server: Add support for get UCI
Add support for getting the UCI.
For now the UCI will be duplicated by the TBS
implementation, but will be optimizied in the future
so only one copy of the UCI exists.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2026-01-06 10:28:23 +01:00
Dima Kushchevskyi
e157c16fab tests: bluetooth: ascs: make callback expectation checks more generic
The existing ASCS test callback verification functions scale poorly and are
not easily reusable across different cases.

This change introduces a more generic approach to expectation checks by
adding `expect_bt_bap_unicast_server_cb_release_called(_expected_count,
_streams)` and similar functions, improving readability and maintainability
of ASCS unit tests.

Fixes #58034

Signed-off-by: Dima Kushchevskyi <d.kushchevskyi@sirinsoftware.com>
2025-12-19 10:20:14 +02:00
Biwen Li
b196917f6c tests: bluetooth: audio: ascs: fix build issues
Fix build issues,
- error: format %x expects argument of type
  unsigned int, but argument 7 has type ssize_t
  {aka long int} [-Werror=format=]
  zassert_false(ret < 0, "attr->read returned unexpected (err 0x%02x)"
  , BT_GATT_ERR(ret));

Signed-off-by: Biwen Li <biwen.li@nxp.com>
2025-12-18 12:06:06 +01:00
Sylvio Alves
f8d2e00a0e includes: remove duplicated entries in zephyr-tree
Remove duplicated #include directives within the same
preprocessor scope across the Zephyr tree.

Duplicates inside different #ifdef branches are preserved
as they may be intentional.

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
2025-12-17 13:57:38 -05:00
Piotr Kosycarz
9cd1247615 tests: bluetooth: audio: pacs: move native_sim to common
Move platform def into common section.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2025-12-03 10:38:37 -05:00
Piotr Kosycarz
20eabf354d tests: bluetooth: audio: ascs: set native_sim in common
Use native_sim for all configurations.

Signed-off-by: Piotr Kosycarz <piotr.kosycarz@nordicsemi.no>
2025-12-03 10:38:37 -05:00
Emil Gydesen
1d1f66c509 tests: Bluetooth: CCP: Modify server unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:21:21 +01:00
Emil Gydesen
522b8697b0 tests: Bluetooth: CCP: Modify client unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:21:11 +01:00
Emil Gydesen
96630fa564 tests: Bluetooth: CCID: Modify initiator unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:21:03 +01:00
Emil Gydesen
90b05da76a tests: Bluetooth: CAP: Modify commander unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:20:55 +01:00
Emil Gydesen
50a5cb3ec6 tests: Bluetooth: ASCS: Modify unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists,
and cleans up the code.
Since the kernel is actually running, we also need to support
that e.g. k_work items are actually scheduled, and that we have
to wait for them to finish. test_drain_syswq has been implemented
as a way to drain the system workqueue before we check for
callbacks or perform subsequent actions.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:20:48 +01:00
Emil Gydesen
540e6c6c75 tests: Bluetooth: BAP: Modify Broadcast unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists,
and moves the mock bap_broadcast_source.c file to the
correct location.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-02 11:20:40 +01:00
Emil Gydesen
f537b770e2 tests: Bluetooth: CAP: Unit tests: Delete group after creation
Some of the CAP initiator unit tests did not delete the group
after creation, even if they easily could.

Especially for test_initiator_unicast_group_add_streams it was
a problem, as the stream added was stack allocated, and by the
end of the test it was deallocated, causing issues when the
group was finally deleted in
cap_initiator_test_unicast_group_after.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-01 12:22:13 -05:00
Emil Gydesen
bfe66fc548 tests: Bluetooth: CAP: Modify initiator unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

To support mocking we cannot rely on the default
Kconfig options and values. The required Kconfig options
to satisfy dependencies are overridden in the Kconfig
file and the necessary Kconfig files are sourced.
We cannot enable e.g. CONFIG_BT as that would attempt
to pull in a lot of files we do not want in this test.

This commit also removes unused includes in the CMakelists

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-12-01 12:22:13 -05:00
Timothy Keys
c14dcaf199 bluetooth: host: Change uses of interval to interval_us
Since Shorter Connection Intervals changes the unit that connection
intervals can be represented in. It is necessary to change how
they are stored and represented.

This commit deprecates interval in favour of interval_us.

Remove use of interval in internal bt_conn struct since it is no longer
needed.

Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no>
2025-11-19 09:15:18 -05:00
Emil Gydesen
1c004a08c3 Bluetooth: CCP: Client: Add support for get provider name
Add support for getting the remote bearer provider
name.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-13 08:43:47 +02:00
Emil Gydesen
1e436f43d1 tests: Bluetooth: PACS: Modify unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-08 10:09:33 +02:00
Emil Gydesen
af00bc5a90 tests: Bluetooth: Codec: Modify unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-08 10:09:27 +02:00
Emil Gydesen
d9a691c2bf tests: Bluetooth: BAP: Modify BASE unittests to native_sim
Modify the unit tests to use the native_sim board instead of the
unit_testing board.
The native_sim board allows us to use the kernel in a more
regular way, while still being able to treat the tests as
unittest.

This commit also removes unused includes in the CMakelists.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-08 08:44:52 +02:00
Emil Gydesen
f0c6168e54 tests: Bluetooth: CAP: Update unicast audio start unittests
Update the CAP initiator audio start unittest.
The reason for this, is that the recent change to endpoints
means that we need to properly generate a BAP unicast group
and call bt_bap_stream_config, instead of trying to manage
the bap_iso values directly.

As part of updating this, the tests were also updated to
significantly reduce code duplication, but generating
a default start param that can easily be reused.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-03 12:51:45 +03:00
Emil Gydesen
c63ec6b5b0 tests: Bluetooth: Audio: Fix uninitalized value
copy may be uninitialzed in the default case, which causes some
compiler warnings/errors when returned and used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-10-02 15:15:17 +03:00