From: Luiz Augusto von Dentz <[email protected]>
This adds tester_setup_io which can be used to add a PDU list in the
form of iovec.
---
src/shared/tester.c | 155 ++++++++++++++++++++++++++++++++++++++++++--
src/shared/tester.h | 12 ++++
2 files changed, 163 insertions(+), 4 deletions(-)
diff --git a/src/shared/tester.c b/src/shared/tester.c
index c07cbc11c..885b2591d 100644
--- a/src/shared/tester.c
+++ b/src/shared/tester.c
@@ -81,6 +81,8 @@ struct test_case {
enum test_result result;
enum test_stage stage;
const void *test_data;
+ const struct iovec *iov;
+ size_t iovcnt;
tester_data_func_t pre_setup_func;
tester_data_func_t setup_func;
tester_data_func_t test_func;
@@ -346,14 +348,20 @@ void tester_add(const char *name, const void *test_data,
teardown_func, NULL, 0, NULL, NULL);
}
-void *tester_get_data(void)
+static struct test_case *tester_get_test(void)
{
- struct test_case *test;
-
if (!test_current)
return NULL;
- test = test_current->data;
+ return test_current->data;
+}
+
+void *tester_get_data(void)
+{
+ struct test_case *test = tester_get_test();
+
+ if (!test)
+ return NULL;
return test->user_data;
}
@@ -859,6 +867,142 @@ void tester_init(int *argc, char ***argv)
test_current = NULL;
}
+static struct io *ios[2];
+
+static bool io_disconnected(struct io *io, void *user_data)
+{
+ if (io == ios[0]) {
+ io_destroy(ios[0]);
+ ios[0] = NULL;
+ } else if (io == ios[1]) {
+ io_destroy(ios[1]);
+ ios[1] = NULL;
+ }
+
+ return false;
+}
+
+static const struct iovec *test_get_iov(struct test_case *test)
+{
+ const struct iovec *iov;
+
+ if (!test || !test->iov || !test->iovcnt)
+ return NULL;
+
+ iov = test->iov;
+
+ test->iov++;
+ test->iovcnt--;
+
+ return iov;
+}
+
+static bool test_io_send(struct io *io, void *user_data)
+{
+ struct test_case *test = tester_get_test();
+ const struct iovec *iov = test_get_iov(test);
+ ssize_t len;
+
+ if (!iov)
+ return false;
+
+ len = io_send(io, iov, 1);
+
+ tester_monitor('<', 0x0004, 0x0000, iov->iov_base, len);
+
+ g_assert_cmpint(len, ==, iov->iov_len);
+
+ return false;
+}
+
+static bool test_io_recv(struct io *io, void *user_data)
+{
+ struct test_case *test = tester_get_test();
+ const struct iovec *iov = test_get_iov(test);
+ unsigned char buf[512];
+ int fd;
+ ssize_t len;
+
+ fd = io_get_fd(io);
+
+ len = read(fd, buf, sizeof(buf));
+
+ g_assert(len > 0);
+
+ tester_monitor('>', 0x0004, 0x0000, buf, len);
+
+ if (!iov)
+ return true;
+
+ g_assert_cmpint(len, ==, iov->iov_len);
+
+ g_assert(memcmp(buf, iov->iov_base, len) == 0);
+
+ if (test->iovcnt)
+ io_set_write_handler(io, test_io_send, NULL, NULL);
+
+ return true;
+}
+
+static void setup_io(void)
+{
+ int fd[2], err;
+
+ io_destroy(ios[0]);
+ io_destroy(ios[1]);
+
+ err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, fd);
+ if (err < 0) {
+ tester_warn("socketpair: %s (%d)", strerror(errno), errno);
+ return;
+ }
+
+ ios[0] = io_new(fd[0]);
+ if (!ios[0]) {
+ tester_warn("io_new: %p", ios[0]);
+ return;
+ }
+
+ io_set_close_on_destroy(ios[0], true);
+ io_set_disconnect_handler(ios[0], io_disconnected, NULL, NULL);
+
+ ios[1] = io_new(fd[1]);
+ if (!ios[1]) {
+ tester_warn("io_new: %p", ios[1]);
+ return;
+ }
+
+ io_set_close_on_destroy(ios[1], true);
+ io_set_disconnect_handler(ios[1], io_disconnected, NULL, NULL);
+ io_set_read_handler(ios[1], test_io_recv, NULL, NULL);
+}
+
+struct io *tester_setup_io(const struct iovec *iov, int iovcnt)
+{
+ struct test_case *test = tester_get_test();
+
+ if (!ios[0] || !ios[1]) {
+ setup_io();
+ if (!ios[0] || !ios[1]) {
+ tester_warn("Unable to setup IO");
+ return NULL;
+ }
+ }
+
+ test->iov = iov;
+ test->iovcnt = iovcnt;
+
+ return ios[0];
+}
+
+void tester_io_send(void)
+{
+ struct test_case *test = tester_get_test();
+
+ if (test->iovcnt)
+ io_set_write_handler(ios[1], test_io_send, NULL, NULL);
+}
+
int tester_run(void)
{
int ret;
@@ -879,5 +1023,8 @@ int tester_run(void)
if (option_monitor)
bt_log_close();
+ io_destroy(ios[0]);
+ io_destroy(ios[1]);
+
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
diff --git a/src/shared/tester.h b/src/shared/tester.h
index a304d89fe..f2590970e 100644
--- a/src/shared/tester.h
+++ b/src/shared/tester.h
@@ -11,6 +11,15 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#include "src/shared/io.h"
+
+#define data(args...) ((const unsigned char[]) { args })
+
+#define IOV_DATA(args...) \
+ { \
+ .iov_base = (void *)data(args), \
+ .iov_len = sizeof(data(args)), \
+ }
void tester_init(int *argc, char ***argv);
int tester_run(void);
@@ -66,3 +75,6 @@ typedef void (*tester_wait_func_t)(void *user_data);
void tester_wait(unsigned int seconds, tester_wait_func_t func,
void *user_data);
+
+struct io *tester_setup_io(const struct iovec *iov, int iovcnt);
+void tester_io_send(void);
--
2.37.1
From: Luiz Augusto von Dentz <[email protected]>
This adds tests for the tester itself:
> unit/test-tester
Test Summary
------------
/tester/basic Passed 0.000 seconds
/tester/setup_io Passed 0.000 seconds
/tester/io_send Passed 0.000 seconds
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0
Overall execution time: 0.000355 seconds
---
Makefile.am | 5 +++
unit/test-tester.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 97 insertions(+)
create mode 100644 unit/test-tester.c
diff --git a/Makefile.am b/Makefile.am
index cebe2f9df..960bf21bc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -408,6 +408,11 @@ EXTRA_DIST += tools/magic.btsnoop
AM_CPPFLAGS += $(DBUS_CFLAGS) $(GLIB_CFLAGS) -I$(builddir)/lib
+unit_tests += unit/test-tester
+
+unit_test_tester_SOURCES = unit/test-tester.c
+unit_test_tester_LDADD = src/libshared-glib.la lib/libbluetooth-internal.la \
+ $(GLIB_LIBS)
unit_tests += unit/test-eir
diff --git a/unit/test-tester.c b/unit/test-tester.c
new file mode 100644
index 000000000..7cdfc87b8
--- /dev/null
+++ b/unit/test-tester.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2022 Intel Corporation.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+
+#include <glib.h>
+
+#include "src/shared/util.h"
+#include "src/shared/tester.h"
+
+static void test_basic(const void *data)
+{
+ tester_test_passed();
+}
+
+static bool test_io_recv(struct io *io, void *user_data)
+{
+ const struct iovec *iov = user_data;
+ unsigned char buf[512];
+ int fd;
+ ssize_t len;
+
+ fd = io_get_fd(io);
+
+ len = read(fd, buf, sizeof(buf));
+
+ g_assert(len > 0);
+ g_assert_cmpint(len, ==, iov->iov_len);
+ g_assert(memcmp(buf, iov->iov_base, len) == 0);
+
+ tester_test_passed();
+
+ return false;
+}
+
+static const struct iovec iov[] = {
+ IOV_DATA(0x01),
+ IOV_DATA(0x01, 0x02),
+};
+
+static void test_setup_io(const void *data)
+{
+ struct io *io;
+ ssize_t len;
+
+ io = tester_setup_io(iov, ARRAY_SIZE(iov));
+ g_assert(io);
+
+ io_set_read_handler(io, test_io_recv, (void *)&iov[1], NULL);
+
+ len = io_send(io, (void *)&iov[0], 1);
+ g_assert_cmpint(len, ==, iov[0].iov_len);
+}
+
+static void test_io_send(const void *data)
+{
+ struct io *io;
+
+ io = tester_setup_io(iov, ARRAY_SIZE(iov));
+ g_assert(io);
+
+ io_set_read_handler(io, test_io_recv, (void *)&iov[0], NULL);
+
+ tester_io_send();
+}
+
+int main(int argc, char *argv[])
+{
+ tester_init(&argc, &argv);
+
+ tester_add("/tester/basic", NULL, NULL, test_basic, NULL);
+ tester_add("/tester/setup_io", NULL, NULL, test_setup_io, NULL);
+ tester_add("/tester/io_send", NULL, NULL, test_io_send, NULL);
+
+ return tester_run();
+}
+
--
2.37.1
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=665746
---Test result---
Test Summary:
CheckPatch PASS 3.05 seconds
GitLint PASS 2.09 seconds
Prep - Setup ELL PASS 26.88 seconds
Build - Prep PASS 0.79 seconds
Build - Configure PASS 8.52 seconds
Build - Make PASS 828.07 seconds
Make Check PASS 11.48 seconds
Make Check w/Valgrind PASS 284.37 seconds
Make Distcheck PASS 233.57 seconds
Build w/ext ELL - Configure PASS 8.72 seconds
Build w/ext ELL - Make PASS 81.50 seconds
Incremental Build w/ patches PASS 194.17 seconds
Scan Build PASS 581.41 seconds
---
Regards,
Linux Bluetooth
Hello:
This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <[email protected]>:
On Fri, 5 Aug 2022 13:10:33 -0700 you wrote:
> From: Luiz Augusto von Dentz <[email protected]>
>
> This adds tester_setup_io which can be used to add a PDU list in the
> form of iovec.
> ---
> src/shared/tester.c | 155 ++++++++++++++++++++++++++++++++++++++++++--
> src/shared/tester.h | 12 ++++
> 2 files changed, 163 insertions(+), 4 deletions(-)
Here is the summary with links:
- [BlueZ,1/2] shared/tester: Add tester_setup_io
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=2dfe29197435
- [BlueZ,2/2] test-tester: This add tests for tester
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f07b88abfb89
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html