Skip to content
Permalink
Browse files

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...
Vudentz authored and jhedberg committed Jun 18, 2019
1 parent 72b05f3 commit 2dc2d9cf00b800ae862c78133f2b35b073defb78
@@ -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})
@@ -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
@@ -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);
}
@@ -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.
You can’t perform that action at this time.