public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/2] test-tester: This add tests for tester
Date: Fri,  5 Aug 2022 13:10:34 -0700	[thread overview]
Message-ID: <20220805201034.3838529-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20220805201034.3838529-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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


  reply	other threads:[~2022-08-05 20:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 20:10 [PATCH BlueZ 1/2] shared/tester: Add tester_setup_io Luiz Augusto von Dentz
2022-08-05 20:10 ` Luiz Augusto von Dentz [this message]
2022-08-05 21:06 ` [BlueZ,1/2] " bluez.test.bot
2022-08-05 23:00 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220805201034.3838529-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox