Commit bfff0f9f authored by Aleksander Wasaznik's avatar Aleksander Wasaznik Committed by Carles Cufi
Browse files

Bluetooth: Host: Tests: Move testlib to common



This is the first patch with the goal of establishing a common library
for Bluetooth utilities that are commonly used for setup in Bluetooth
Host tests. The ultimate goal is to remove redundant (near) copies of
these utilities and other more ad-hoc solutions.

This patch moves one instance of testlib (from
tests/bsim/bluetooth/host/att/long_read) to
tests/bluetooth/common/testlib and makes it a proper CMake library.

The long_read test is updated to link to the new CMake library.

Further changes and de-duplication will come in later patches.

Signed-off-by: default avatarAleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
parent 133f20ab
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

add_library(testlib)

target_link_libraries(testlib PUBLIC
  kernel
  subsys__bluetooth__host
  zephyr_interface
)

target_include_directories(testlib PUBLIC
  include
)

target_sources(testlib PRIVATE
  src/adv.c
  src/att_read.c
  src/att_write.c
  src/connect.c
  src/conn_wait.c
  src/scan.c
  src/security.c
)
+12 −0
Original line number Diff line number Diff line
@@ -2,6 +2,11 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ADV_H_
#define ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ADV_H_

#include <zephyr/bluetooth/bluetooth.h>

int bt_testlib_adv_conn(struct bt_conn **conn, int id, uint32_t adv_options);

#endif /* ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ADV_H_ */
+8 −3
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_READ_H_
#define ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_READ_H_

#include <stdint.h>
#include <zephyr/bluetooth/gatt.h>

@@ -20,7 +23,7 @@ int bt_testlib_att_read_by_handle_sync(struct net_buf_simple *result_data, uint1
				       enum bt_att_chan_opt bearer, uint16_t handle,
				       uint16_t offset);

int btt_gatt_long_read(struct net_buf_simple *result_data, uint16_t *result_size,
int bt_testlib_gatt_long_read(struct net_buf_simple *result_data, uint16_t *result_size,
			      struct bt_conn *conn, enum bt_att_chan_opt bearer, uint16_t handle,
			      uint16_t offset);

@@ -37,3 +40,5 @@ int bt_testlib_gatt_discover_characteristic(uint16_t *const result_value_handle,
					    uint16_t *const result_def_handle, struct bt_conn *conn,
					    const struct bt_uuid *uuid, uint16_t start_handle,
					    uint16_t svc_end_handle);

#endif /* ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_READ_H_ */
+5 −0
Original line number Diff line number Diff line
@@ -2,8 +2,13 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_WRITE_H_
#define ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_WRITE_H_

#include <stdint.h>
#include <zephyr/bluetooth/gatt.h>

int bt_testlib_att_write(struct bt_conn *conn, enum bt_att_chan_opt bearer, uint16_t handle,
			 const uint8_t *data, uint16_t size);

#endif /* ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_ATT_WRITE_H_ */
+5 −0
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_CONN_REF_H_
#define ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_CONN_REF_H_

#include <zephyr/sys/atomic_builtin.h>
#include <zephyr/bluetooth/conn.h>

@@ -35,3 +38,5 @@ void bt_testlib_conn_unref(struct bt_conn **connp)
	__ASSERT_NO_MSG(conn);
	bt_conn_unref(conn);
}

#endif /* ZEPHYR_TESTS_BLUETOOTH_COMMON_TESTLIB_INCLUDE_TESTLIB_CONN_REF_H_ */
Loading