Skip to content

Commit

Permalink
Bluetooth: tests: Add tests for L2CAP
Browse files Browse the repository at this point in the history
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
Vudentz authored and jhedberg committed Jun 24, 2019
1 parent 72b05f3 commit 2dc2d9c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/bluetooth/l2cap/CMakeLists.txt
@@ -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})
11 changes: 11 additions & 0 deletions tests/bluetooth/l2cap/prj.conf
@@ -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
78 changes: 78 additions & 0 deletions tests/bluetooth/l2cap/src/main.c
@@ -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);
}
4 changes: 4 additions & 0 deletions tests/bluetooth/l2cap/testcase.yaml
@@ -0,0 +1,4 @@
tests:
bluetooth.gatt:
platform_whitelist: native_posix qemu_x86 qemu_cortex_m3
tags: bluetooth l2cap

0 comments on commit 2dc2d9c

Please sign in to comment.