Skip to content

Commit

Permalink
[nrf fromtree] tests: bsim: bluetooth: host: gatt: add authorization …
Browse files Browse the repository at this point in the history
…callback API test

Added a new BabbleSim test that validates the authorization callback API
from the Bluetooth GATT header.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
(cherry picked from commit a369eb7)
  • Loading branch information
kapi-no authored and rlubos committed Jan 23, 2024
1 parent e537e00 commit e4e6dc8
Show file tree
Hide file tree
Showing 9 changed files with 870 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/bsim/bluetooth/host/compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ app=tests/bsim/bluetooth/host/att/sequential/dut compile
app=tests/bsim/bluetooth/host/att/sequential/tester compile
app=tests/bsim/bluetooth/host/att/long_read compile

app=tests/bsim/bluetooth/host/gatt/authorization compile
app=tests/bsim/bluetooth/host/gatt/caching compile
app=tests/bsim/bluetooth/host/gatt/general compile
app=tests/bsim/bluetooth/host/gatt/notify compile
Expand Down
14 changes: 14 additions & 0 deletions tests/bsim/bluetooth/host/gatt/authorization/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20.0)

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

FILE(GLOB app_sources src/*.c)
target_sources(app PRIVATE ${app_sources} )

zephyr_include_directories(
${BSIM_COMPONENTS_PATH}/libUtilv1/src/
${BSIM_COMPONENTS_PATH}/libPhyComv1/src/
)
7 changes: 7 additions & 0 deletions tests/bsim/bluetooth/host/gatt/authorization/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_BT=y
CONFIG_BT_DEVICE_NAME="GATT tester"
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CENTRAL=y
CONFIG_BT_GATT_CLIENT=y
CONFIG_BT_GATT_AUTHORIZATION_CUSTOM=y
CONFIG_BT_ATT_PREPARE_COUNT=3
20 changes: 20 additions & 0 deletions tests/bsim/bluetooth/host/gatt/authorization/src/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "common.h"

void test_tick(bs_time_t HW_device_time)
{
if (bst_result != Passed) {
FAIL("test failed (not passed after %i seconds)\n", WAIT_TIME);
}
}

void test_init(void)
{
bst_ticker_set_next_tick_absolute(WAIT_TIME);
bst_result = In_progress;
}
73 changes: 73 additions & 0 deletions tests/bsim/bluetooth/host/gatt/authorization/src/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Common functions and helpers for BSIM GATT tests
*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>

#include "bs_types.h"
#include "bs_tracing.h"
#include "time_machine.h"
#include "bstests.h"

#include <zephyr/types.h>
#include <stddef.h>
#include <errno.h>

#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/hci.h>
#include <zephyr/bluetooth/conn.h>
#include <zephyr/bluetooth/uuid.h>
#include <zephyr/bluetooth/gatt.h>

extern enum bst_result_t bst_result;

#define WAIT_TIME (30 * 1e6) /*seconds*/

#define CREATE_FLAG(flag) static atomic_t flag = (atomic_t)false
#define SET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)true)
#define UNSET_FLAG(flag) (void)atomic_set(&flag, (atomic_t)false)
#define WAIT_FOR_FLAG(flag) \
while (!(bool)atomic_get(&flag)) { \
(void)k_sleep(K_MSEC(1)); \
}

#define FAIL(...) \
do { \
bst_result = Failed; \
bs_trace_error_time_line(__VA_ARGS__); \
} while (0)

#define PASS(...) \
do { \
bst_result = Passed; \
bs_trace_info_time(1, __VA_ARGS__); \
} while (0)

#define CHRC_SIZE 10

#define TEST_SERVICE_UUID \
BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x00, 0x00)

#define TEST_UNHANDLED_CHRC_UUID \
BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFD, 0x00)

#define TEST_UNAUTHORIZED_CHRC_UUID \
BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFE, 0x00)

#define TEST_AUTHORIZED_CHRC_UUID \
BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0x00)

#define TEST_CP_CHRC_UUID \
BT_UUID_DECLARE_128(0x01, 0x23, 0x45, 0x67, 0x89, 0x01, 0x02, 0x03, \
0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xF0, 0x00)

void test_tick(bs_time_t HW_device_time);
void test_init(void);
Loading

0 comments on commit e4e6dc8

Please sign in to comment.