Skip to content

Commit

Permalink
bluetooth: mesh: add unit tests for new sensor API
Browse files Browse the repository at this point in the history
This tests the new APIs in sensor.h/sensor_types.h:

  * For each sensor format, test `bt_mesh_sensor_value_to_micro`,
    `bt_mesh_sensor_value_to_float`, `bt_mesh_sensor_value_from_micro`
    and `bt_mesh_sensor_value_from_float` according to GSS. Tests min
    value, max value, values out of range, prohibited values and
    special values.
  * For each sensor type defined in `sensor_types.c`, test that:
      * Property ID lookup returns the correct sensor type.
      * During decoding, the raw data is partitioned correctly into
        `bt_mesh_sensor_value`s according to channel widths, and the
        correct format is pointed to in each value.
      * During encoding, the raw data is correctly added to the buffer
        according to channel widths.

Signed-off-by: Ludvig Jordet <[email protected]>
  • Loading branch information
ludvigsj authored and jfischer-no committed Feb 26, 2024
1 parent 2cce69b commit ffd08bb
Show file tree
Hide file tree
Showing 5 changed files with 1,035 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/subsys/bluetooth/mesh/sensor_subsys_new/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(bt_mesh_sensor_subsystem_new_test)

target_include_directories(app PUBLIC
${ZEPHYR_NRF_MODULE_DIR}/subsys/bluetooth/mesh
)

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE
${app_sources}
${ZEPHYR_NRF_MODULE_DIR}/subsys/bluetooth/mesh/sensor_types.c
${ZEPHYR_NRF_MODULE_DIR}/subsys/bluetooth/mesh/sensor.c
)

target_compile_options(app
PRIVATE
-DCONFIG_BT_MESH_MODEL_KEY_COUNT=5
-DCONFIG_BT_MESH_MODEL_GROUP_COUNT=5
-DCONFIG_BT_MESH_SENSOR_ALL_TYPES=1
-DCONFIG_BT_MESH_SENSOR_LABELS=1
-DCONFIG_BT_MESH_SENSOR_CHANNELS_MAX=5
-DCONFIG_BT_MESH_SENSOR_CHANNEL_ENCODED_SIZE_MAX=4
-DCONFIG_BT_LOG_LEVEL=0
-DCONFIG_BT_MESH_USES_TINYCRYPT
)

zephyr_linker_sources(SECTIONS sensor_types.ld)
10 changes: 10 additions & 0 deletions tests/subsys/bluetooth/mesh/sensor_subsys_new/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# Ztest configuration
CONFIG_ZTEST=y
CONFIG_CBPRINTF_FP_SUPPORT=y
CONFIG_NET_BUF=y
6 changes: 6 additions & 0 deletions tests/subsys/bluetooth/mesh/sensor_subsys_new/sensor_types.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SECTION_DATA_PROLOGUE(bt_mesh_sensor_types_sections,,SUBALIGN(4))
{
_bt_mesh_sensor_type_list_start = .;
KEEP(*(SORT_BY_NAME("._bt_mesh_sensor_type.static.*")));
_bt_mesh_sensor_type_list_end = .;
} GROUP_LINK_IN(ROMABLE_REGION)
Loading

0 comments on commit ffd08bb

Please sign in to comment.