Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bluetooth: tests: Add tests for L2CAP
This adds initial test for L2CAP APIs that don't require a connection thus can be run without any extra setup. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.13.1) | ||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) | ||
project(bluetooth_gatt) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CONFIG_TEST=y | ||
CONFIG_ZTEST=y | ||
|
||
CONFIG_BT=y | ||
CONFIG_BT_CTLR=n | ||
CONFIG_BT_NO_DRIVER=y | ||
|
||
CONFIG_BT_DEBUG_LOG=y | ||
CONFIG_BT_PERIPHERAL=y | ||
CONFIG_BT_SMP=y | ||
CONFIG_BT_L2CAP_DYNAMIC_CHANNEL=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* main.c - Application main entry point */ | ||
|
||
/* | ||
* Copyright (c) 2019 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr.h> | ||
#include <stddef.h> | ||
#include <ztest.h> | ||
|
||
#include <bluetooth/buf.h> | ||
#include <bluetooth/bluetooth.h> | ||
#include <bluetooth/l2cap.h> | ||
|
||
static int l2cap_accept(struct bt_conn *conn, struct bt_l2cap_chan **chan) | ||
{ | ||
return -ENOSYS; | ||
} | ||
|
||
static struct bt_l2cap_server test_server = { | ||
.accept = l2cap_accept, | ||
}; | ||
|
||
static struct bt_l2cap_server test_fixed_server = { | ||
.accept = l2cap_accept, | ||
.psm = 0x007f, | ||
}; | ||
|
||
static struct bt_l2cap_server test_dyn_server = { | ||
.accept = l2cap_accept, | ||
.psm = 0x00ff, | ||
}; | ||
|
||
static struct bt_l2cap_server test_inv_server = { | ||
.accept = l2cap_accept, | ||
.psm = 0xffff, | ||
}; | ||
|
||
void test_l2cap_register(void) | ||
{ | ||
/* Attempt to register server with PSM auto allocation */ | ||
zassert_false(bt_l2cap_server_register(&test_server), | ||
"Test server registration failed"); | ||
|
||
/* Attempt to register server with fixed PSM */ | ||
zassert_false(bt_l2cap_server_register(&test_fixed_server), | ||
"Test fixed PSM server registration failed"); | ||
|
||
/* Attempt to register server with dynamic PSM */ | ||
zassert_false(bt_l2cap_server_register(&test_dyn_server), | ||
"Test dynamic PSM server registration failed"); | ||
|
||
/* Attempt to register server with invalid PSM */ | ||
zassert_true(bt_l2cap_server_register(&test_inv_server), | ||
"Test invalid PSM server registration succeeded"); | ||
|
||
/* Attempt to re-register server with PSM auto allocation */ | ||
zassert_true(bt_l2cap_server_register(&test_server), | ||
"Test server duplicate succeeded"); | ||
|
||
/* Attempt to re-register server with fixed PSM */ | ||
zassert_true(bt_l2cap_server_register(&test_fixed_server), | ||
"Test fixed PSM server duplicate succeeded"); | ||
|
||
/* Attempt to re-register server with dynamic PSM */ | ||
zassert_true(bt_l2cap_server_register(&test_dyn_server), | ||
"Test dynamic PSM server duplicate succeeded"); | ||
} | ||
|
||
/*test case main entry*/ | ||
void test_main(void) | ||
{ | ||
ztest_test_suite(test_l2cap, | ||
ztest_unit_test(test_l2cap_register)); | ||
ztest_run_test_suite(test_l2cap); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
tests: | ||
bluetooth.gatt: | ||
platform_whitelist: native_posix qemu_x86 qemu_cortex_m3 | ||
tags: bluetooth l2cap |