All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] unit: End to end FD passing test
@ 2016-05-06 10:18 Andrew Zaborowski
  2016-05-06 10:18 ` [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus Andrew Zaborowski
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Andrew Zaborowski @ 2016-05-06 10:18 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 9269 bytes --]

---
 Makefile.am                  |   3 +
 unit/test-dbus-message-fds.c | 384 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 387 insertions(+)
 create mode 100644 unit/test-dbus-message-fds.c

diff --git a/Makefile.am b/Makefile.am
index 3e8e3ef..aa99bdd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -140,6 +140,7 @@ dbus_tests = unit/test-kdbus \
 			unit/test-dbus \
 			unit/test-dbus-util \
 			unit/test-dbus-message \
+			unit/test-dbus-message-fds \
 			unit/test-dbus-service \
 			unit/test-dbus-watch \
 			unit/test-dbus-properties \
@@ -186,6 +187,8 @@ unit_test_dbus_LDADD = ell/libell-private.la
 
 unit_test_dbus_message_LDADD = ell/libell-private.la
 
+unit_test_dbus_message_fds_LDADD = ell/libell-private.la
+
 unit_test_dbus_util_LDADD = ell/libell-private.la
 
 unit_test_dbus_service_LDADD = ell/libell-private.la
diff --git a/unit/test-dbus-message-fds.c b/unit/test-dbus-message-fds.c
new file mode 100644
index 0000000..7e710cf
--- /dev/null
+++ b/unit/test-dbus-message-fds.c
@@ -0,0 +1,384 @@
+/*
+ *
+ *  Embedded Linux library
+ *
+ *  Copyright (C) 2016  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include <ell/ell.h>
+#include <ell/dbus-private.h>
+
+#define TEST_BUS_ADDRESS "unix:path=/tmp/ell-test-bus"
+
+static pid_t dbus_daemon_pid = -1;
+
+static int kdbus_fd = -1;
+
+static char bus_address[128];
+
+static bool start_dbus_daemon(void)
+{
+	char *prg_argv[6];
+	char *prg_envp[1];
+	pid_t pid;
+
+	prg_argv[0] = "/usr/bin/dbus-daemon";
+	prg_argv[1] = "--session";
+	prg_argv[2] = "--address=" TEST_BUS_ADDRESS;
+	prg_argv[3] = "--nopidfile";
+	prg_argv[4] = "--nofork";
+	prg_argv[5] = NULL;
+
+	prg_envp[0] = NULL;
+
+	l_info("launching dbus-daemon");
+
+	pid = fork();
+	if (pid < 0) {
+		l_error("failed to fork new process");
+		return false;
+	}
+
+	if (pid == 0) {
+		execve(prg_argv[0], prg_argv, prg_envp);
+		exit(EXIT_SUCCESS);
+	}
+
+	l_info("dbus-daemon process %d created", pid);
+
+	dbus_daemon_pid = pid;
+
+	strcpy(bus_address, TEST_BUS_ADDRESS);
+
+	return true;
+}
+
+static bool create_kdbus(void)
+{
+	char bus_name[64];
+
+	snprintf(bus_name, sizeof(bus_name), "%u-ell-test", getuid());
+
+	kdbus_fd = _dbus_kernel_create_bus(bus_name);
+	if (kdbus_fd < 0) {
+		l_warn("kdbus not available");
+		return false;
+	}
+
+	snprintf(bus_address, sizeof(bus_address),
+				"kernel:path=/dev/kdbus/%s/bus", bus_name);
+
+	return true;
+}
+
+static void signal_handler(struct l_signal *signal, uint32_t signo,
+							void *user_data)
+{
+	switch (signo) {
+	case SIGINT:
+	case SIGTERM:
+		l_info("Terminate");
+		l_main_quit();
+		break;
+	case SIGCHLD:
+		while (1) {
+			pid_t pid;
+			int status;
+
+			pid = waitpid(WAIT_ANY, &status, WNOHANG);
+			if (pid < 0 || pid == 0)
+				break;
+
+			l_info("process %d terminated with status=%d\n",
+								pid, status);
+
+			if (pid == dbus_daemon_pid) {
+				dbus_daemon_pid = -1;
+				l_main_quit();
+			}
+		}
+		break;
+	}
+}
+
+static struct l_dbus *dbus;
+
+struct dbus_test {
+	const char *name;
+	void (*start)(struct l_dbus *dbus, void *);
+	void *data;
+};
+
+static bool success;
+static struct l_queue *tests;
+static const struct l_queue_entry *current;
+
+static void test_add(const char *name,
+			void (*start)(struct l_dbus *dbus, void *),
+			void *test_data)
+{
+	struct dbus_test *test = l_new(struct dbus_test, 1);
+
+	test->name = name;
+	test->start = start;
+	test->data = test_data;
+
+	if (!tests)
+		tests = l_queue_new();
+
+	l_queue_push_tail(tests, test);
+}
+
+static void test_next()
+{
+	struct dbus_test *test;
+
+	if (current)
+		current = current->next;
+	else
+		current = l_queue_get_entries(tests);
+
+	if (!current) {
+		success = true;
+		l_main_quit();
+		return;
+	}
+
+	test = current->data;
+
+	l_info("TEST: %s", test->name);
+
+	test->start(dbus, test->data);
+}
+
+#define test_assert(cond)	\
+	do {	\
+		if (!(cond)) {	\
+			l_info("TEST FAILED in %s at %s:%i: %s",	\
+				__func__, __FILE__, __LINE__,	\
+				L_STRINGIFY(cond));	\
+			l_main_quit();	\
+			return;	\
+		}	\
+	} while (0)
+
+static void request_name_callback(struct l_dbus *dbus, bool success,
+					bool queued, void *user_data)
+{
+	l_info("request name result=%s",
+		success ? (queued ? "queued" : "success") : "failed");
+
+	test_next();
+}
+
+static void ready_callback(void *user_data)
+{
+	l_info("ready");
+
+	l_dbus_name_acquire(dbus, "org.test", false, false, false,
+				request_name_callback, NULL);
+}
+
+static void disconnect_callback(void *user_data)
+{
+	l_info("Disconnected from DBus");
+	l_main_quit();
+}
+
+static struct l_dbus_message *get_random_callback(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					void *user_data)
+{
+	struct l_dbus_message *reply;
+	int fd;
+
+	reply = l_dbus_message_new_method_return(message);
+
+	fd = open("/dev/random", O_RDONLY);
+	l_dbus_message_set_arguments(reply, "h", fd);
+	close(fd);
+
+	return reply;
+}
+
+static void setup_test_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_method(interface, "GetRandom", 0, get_random_callback,
+				"h", "", "randomfd");
+}
+
+static int count_fds(void)
+{
+	int fd;
+	int count = 0;
+
+	for (fd = 0; fd < FD_SETSIZE; fd++)
+		if (fcntl(fd, F_GETFL) != -1 || errno != EBADF)
+			count++;
+
+	return count;
+}
+
+static bool compare_failed;
+
+static void compare_files(int a, int b)
+{
+	struct stat sa, sb;
+
+	compare_failed = true;
+
+	test_assert(fstat(a, &sa) == 0);
+	test_assert(fstat(b, &sb) == 0);
+
+	test_assert(sa.st_dev == sb.st_dev);
+	test_assert(sa.st_ino == sb.st_ino);
+	test_assert(sa.st_rdev == sb.st_rdev);
+
+	compare_failed = false;
+}
+
+static int open_fds;
+
+static void get_random_idle_callback(void *user_data)
+{
+	test_assert(count_fds() == open_fds);
+
+	test_next();
+}
+
+static void get_random_return_callback(struct l_dbus_message *message,
+					void *user_data)
+{
+	int fd0, fd1;
+
+	test_assert(!l_dbus_message_get_error(message, NULL, NULL));
+
+	test_assert(l_dbus_message_get_arguments(message, "h", &fd1));
+
+	fd0 = open("/dev/random", O_RDONLY);
+	test_assert(fd0 != -1);
+
+	compare_files(fd0, fd1);
+	if (compare_failed)
+		return;
+
+	close(fd0);
+	close(fd1);
+
+	test_assert(l_idle_oneshot(get_random_idle_callback, NULL, NULL));
+}
+
+static void test_fd_passing_1(struct l_dbus *dbus, void *test_data)
+{
+	open_fds = count_fds();
+
+	l_dbus_method_call(dbus, "org.test", "/test", "org.test", "GetRandom",
+				NULL, get_random_return_callback, NULL, NULL);
+}
+
+static void test_run(void)
+{
+	success = false;
+
+	l_dbus_set_ready_handler(dbus, ready_callback, dbus, NULL);
+	l_dbus_set_disconnect_handler(dbus, disconnect_callback, NULL, NULL);
+
+	if (!l_dbus_register_interface(dbus, "org.test", setup_test_interface,
+					NULL, true)) {
+		l_info("Unable to register interface");
+		return;
+	}
+
+	if (!l_dbus_object_add_interface(dbus, "/test", "org.test", NULL)) {
+		l_info("Unable to instantiate interface");
+		return;
+	}
+
+	l_main_run();
+}
+
+int main(int argc, char *argv[])
+{
+	struct l_signal *signal;
+	sigset_t mask;
+	int i;
+
+	test_add("FD passing 1", test_fd_passing_1, NULL);
+
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGINT);
+	sigaddset(&mask, SIGTERM);
+	sigaddset(&mask, SIGCHLD);
+
+	signal = l_signal_create(&mask, signal_handler, NULL, NULL);
+
+	l_log_set_stderr();
+
+	if (!start_dbus_daemon())
+		return -1;
+
+	for (i = 0; i < 10; i++) {
+		usleep(200 * 1000);
+
+		dbus = l_dbus_new(bus_address);
+		if (dbus)
+			break;
+	}
+
+	test_run();
+
+	l_dbus_destroy(dbus);
+
+	kill(dbus_daemon_pid, SIGKILL);
+
+	if (!success)
+		goto done;
+
+	if (!create_kdbus())
+		goto done;
+
+	dbus = l_dbus_new(bus_address);
+
+	test_run();
+
+	l_dbus_destroy(dbus);
+
+	close(kdbus_fd);
+
+done:
+	l_signal_remove(signal);
+
+	l_queue_destroy(tests, l_free);
+
+	if (!success)
+		abort();
+
+	return 0;
+}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus
  2016-05-06 10:18 [PATCH] unit: End to end FD passing test Andrew Zaborowski
@ 2016-05-06 10:18 ` Andrew Zaborowski
  2016-05-06 15:51   ` Denis Kenzior
  2016-05-06 10:18 ` [PATCH 1/2] unit: Remove dbus watch tests using old API Andrew Zaborowski
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Zaborowski @ 2016-05-06 10:18 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 5529 bytes --]

Same as test-dbus-message-fds.
---
 unit/test-dbus-properties.c | 124 +++++++++++++++++++++++++-------------------
 1 file changed, 70 insertions(+), 54 deletions(-)

diff --git a/unit/test-dbus-properties.c b/unit/test-dbus-properties.c
index 3238cf6..6eae592 100644
--- a/unit/test-dbus-properties.c
+++ b/unit/test-dbus-properties.c
@@ -40,7 +40,7 @@ static int kdbus_fd = -1;
 
 static char bus_address[128];
 
-static void start_dbus_daemon(void)
+static bool start_dbus_daemon(void)
 {
 	char *prg_argv[6];
 	char *prg_envp[1];
@@ -60,7 +60,7 @@ static void start_dbus_daemon(void)
 	pid = fork();
 	if (pid < 0) {
 		l_error("failed to fork new process");
-		return;
+		return false;
 	}
 
 	if (pid == 0) {
@@ -73,9 +73,11 @@ static void start_dbus_daemon(void)
 	dbus_daemon_pid = pid;
 
 	strcpy(bus_address, TEST_BUS_ADDRESS);
+
+	return true;
 }
 
-static void create_kdbus(void)
+static bool create_kdbus(void)
 {
 	char bus_name[64];
 
@@ -84,11 +86,13 @@ static void create_kdbus(void)
 	kdbus_fd = _dbus_kernel_create_bus(bus_name);
 	if (kdbus_fd < 0) {
 		l_warn("kdbus not available");
-		return;
+		return false;
 	}
 
 	snprintf(bus_address, sizeof(bus_address),
 				"kernel:path=/dev/kdbus/%s/bus", bus_name);
+
+	return true;
 }
 
 static void signal_handler(struct l_signal *signal, uint32_t signo,
@@ -131,6 +135,7 @@ struct dbus_test {
 
 static bool success;
 static struct l_queue *tests;
+static const struct l_queue_entry *current;
 
 static void test_add(const char *name,
 			void (*start)(struct l_dbus *dbus, void *),
@@ -150,19 +155,24 @@ static void test_add(const char *name,
 
 static void test_next()
 {
-	struct dbus_test *test = l_queue_pop_head(tests);
+	struct dbus_test *test;
 
-	if (!test) {
+	if (current)
+		current = current->next;
+	else
+		current = l_queue_get_entries(tests);
+
+	if (!current) {
 		success = true;
 		l_main_quit();
 		return;
 	}
 
+	test = current->data;
+
 	l_info("TEST: %s", test->name);
 
 	test->start(dbus, test->data);
-
-	l_free(test);
 }
 
 #define test_assert(cond)	\
@@ -916,42 +926,9 @@ static void test_object_manager_signals(struct l_dbus *dbus, void *test_data)
 						NULL));
 }
 
-int main(int argc, char *argv[])
+static void test_run(void)
 {
-	struct l_signal *signal;
-	sigset_t mask;
-	int i;
-	bool kdbus = false;
-
-	for (i = 1; i < argc; i++) {
-		if (!strcmp(argv[i], "--kdbus"))
-			kdbus = true;
-	}
-
-	sigemptyset(&mask);
-	sigaddset(&mask, SIGINT);
-	sigaddset(&mask, SIGTERM);
-	sigaddset(&mask, SIGCHLD);
-
-	signal = l_signal_create(&mask, signal_handler, NULL, NULL);
-
-	l_log_set_stderr();
-
-	if (kdbus)
-		create_kdbus();
-	else
-		start_dbus_daemon();
-
-	if (!bus_address[0])
-		return -1;
-
-	for (i = 0; i < 10; i++) {
-		usleep(200 * 1000);
-
-		dbus = l_dbus_new(bus_address);
-		if (dbus)
-			break;
-	}
+	success = false;
 
 	l_dbus_set_ready_handler(dbus, ready_callback, dbus, NULL);
 	l_dbus_set_disconnect_handler(dbus, disconnect_callback, NULL, NULL);
@@ -959,18 +936,18 @@ int main(int argc, char *argv[])
 	if (!l_dbus_register_interface(dbus, "org.test", setup_test_interface,
 					NULL, true)) {
 		l_info("Unable to register interface");
-		goto done;
+		return;
 	}
 
 	if (!l_dbus_object_add_interface(dbus, "/test", "org.test", NULL)) {
 		l_info("Unable to instantiate interface");
-		goto done;
+		return;
 	}
 
 	if (!l_dbus_object_add_interface(dbus, "/test",
 				"org.freedesktop.DBus.Properties", NULL)) {
 		l_info("Unable to instantiate the properties interface");
-		goto done;
+		return;
 	}
 
 	l_dbus_add_signal_watch(dbus, "org.test", "/test", "org.test",
@@ -984,7 +961,7 @@ int main(int argc, char *argv[])
 
 	if (!l_dbus_object_manager_enable(dbus)) {
 		l_info("Unable to enable Object Manager");
-		goto done;
+		return;
 	}
 
 	l_dbus_add_signal_watch(dbus, "org.test", "/",
@@ -992,6 +969,15 @@ int main(int argc, char *argv[])
 				NULL, L_DBUS_MATCH_NONE,
 				om_signal_callback, NULL);
 
+	l_main_run();
+}
+
+int main(int argc, char *argv[])
+{
+	struct l_signal *signal;
+	sigset_t mask;
+	int i;
+
 	test_add("Legacy properties get", test_old_get, NULL);
 	test_add("Legacy properties set", test_old_set, NULL);
 	test_add("Legacy optional property", test_old_optional_get, NULL);
@@ -1003,21 +989,51 @@ int main(int argc, char *argv[])
 	test_add("org.freedesktop.DBus.ObjectManager signals",
 			test_object_manager_signals, NULL);
 
-	l_main_run();
+	sigemptyset(&mask);
+	sigaddset(&mask, SIGINT);
+	sigaddset(&mask, SIGTERM);
+	sigaddset(&mask, SIGCHLD);
 
-	l_queue_destroy(tests, l_free);
+	signal = l_signal_create(&mask, signal_handler, NULL, NULL);
+
+	l_log_set_stderr();
+
+	if (!start_dbus_daemon())
+		return -1;
+
+	for (i = 0; i < 10; i++) {
+		usleep(200 * 1000);
+
+		dbus = l_dbus_new(bus_address);
+		if (dbus)
+			break;
+	}
+
+	test_run();
 
-done:
 	l_dbus_destroy(dbus);
 
-	if (dbus_daemon_pid > 0)
-		kill(dbus_daemon_pid, SIGKILL);
+	kill(dbus_daemon_pid, SIGKILL);
 
-	if (kdbus_fd >= 0)
-		close(kdbus_fd);
+	if (!success)
+		goto done;
 
+	if (!create_kdbus())
+		goto done;
+
+	dbus = l_dbus_new(bus_address);
+
+	test_run();
+
+	l_dbus_destroy(dbus);
+
+	close(kdbus_fd);
+
+done:
 	l_signal_remove(signal);
 
+	l_queue_destroy(tests, l_free);
+
 	if (!success)
 		abort();
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 1/2] unit: Remove dbus watch tests using old API
  2016-05-06 10:18 [PATCH] unit: End to end FD passing test Andrew Zaborowski
  2016-05-06 10:18 ` [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus Andrew Zaborowski
@ 2016-05-06 10:18 ` Andrew Zaborowski
  2016-05-06 15:52   ` Denis Kenzior
  2016-05-06 10:18 ` [PATCH 2/2] dbus: Remove now unused filter logic Andrew Zaborowski
  2016-05-06 15:50 ` [PATCH] unit: End to end FD passing test Denis Kenzior
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Zaborowski @ 2016-05-06 10:18 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 7067 bytes --]

---
 unit/test-dbus-watch.c | 226 -------------------------------------------------
 1 file changed, 226 deletions(-)

diff --git a/unit/test-dbus-watch.c b/unit/test-dbus-watch.c
index 46acf06..6b7bcda 100644
--- a/unit/test-dbus-watch.c
+++ b/unit/test-dbus-watch.c
@@ -24,12 +24,8 @@
 #include <config.h>
 #endif
 
-#include <unistd.h>
 #include <stdlib.h>
-#include <sys/wait.h>
 #include <assert.h>
-#include <time.h>
-#include <stdio.h>
 
 #include <ell/ell.h>
 #include "ell/dbus-private.h"
@@ -38,213 +34,6 @@
 #define DBUS_SERVICE_DBUS	"org.freedesktop.DBus"
 #define DBUS_PATH_DBUS		"/org/freedesktop/DBus"
 #define DBUS_INTERFACE_DBUS	"org.freedesktop.DBus"
-#define DBUS_MAXIMUM_MATCH_RULE_LENGTH	1024
-
-struct watch_test {
-	const char *name;
-	const char *service;
-	const char *path;
-	const char *interface;
-	const char *method;
-	const char *expected;
-};
-
-static const struct watch_test match_test_1 = {
-	.name = ":1.101",
-	.service = DBUS_SERVICE_DBUS,
-	.path = DBUS_PATH_DBUS,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"sender='org.freedesktop.DBus',"
-		"path='/org/freedesktop/DBus',"
-		"interface='org.freedesktop.DBus',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.101'",
-};
-
-static const struct watch_test match_test_2 = {
-	.name = ":1.102",
-	.service = NULL,
-	.path = DBUS_PATH_DBUS,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"path='/org/freedesktop/DBus',"
-		"interface='org.freedesktop.DBus',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.102'",
-};
-
-static const struct watch_test match_test_3 = {
-	.name = ":1.102",
-	.service = DBUS_SERVICE_DBUS,
-	.path = NULL,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"sender='org.freedesktop.DBus',"
-		"interface='org.freedesktop.DBus',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.102'",
-};
-
-static const struct watch_test match_test_4 = {
-	.name = ":1.102",
-	.service = DBUS_SERVICE_DBUS,
-	.path = DBUS_PATH_DBUS,
-	.interface = NULL,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"sender='org.freedesktop.DBus',"
-		"path='/org/freedesktop/DBus',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.102'",
-};
-
-static const struct watch_test match_test_5 = {
-	.name = ":1.102",
-	.service = DBUS_SERVICE_DBUS,
-	.path = DBUS_PATH_DBUS,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = NULL,
-	.expected = "type='signal',"
-		"sender='org.freedesktop.DBus',"
-		"path='/org/freedesktop/DBus',"
-		"interface='org.freedesktop.DBus',"
-		"arg0=':1.102'",
-};
-
-static const struct watch_test match_test_6 = {
-	.name = NULL,
-	.service = DBUS_SERVICE_DBUS,
-	.path = DBUS_PATH_DBUS,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"sender='org.freedesktop.DBus',"
-		"path='/org/freedesktop/DBus',"
-		"interface='org.freedesktop.DBus',"
-		"member='NameOwnerChanged'",
-};
-
-static const struct watch_test match_test_7 = {
-	.name = ":1.101",
-	.service = NULL,
-	.path = NULL,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"interface='org.freedesktop.DBus',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.101'",
-};
-
-static const struct watch_test match_test_8 = {
-	.name = ":1.101",
-	.service = NULL,
-	.path = NULL,
-	.interface = NULL,
-	.method = "NameOwnerChanged",
-	.expected = "type='signal',"
-		"member='NameOwnerChanged',"
-		"arg0=':1.101'",
-};
-
-static const struct watch_test match_test_9 = {
-	.name = NULL,
-	.service = NULL,
-	.path = NULL,
-	.interface = NULL,
-	.method = NULL,
-	.expected = "type='signal'",
-};
-
-static struct watch_test disconnect_test = {
-	.name = ":101.1",
-	.service = DBUS_SERVICE_DBUS,
-	.path = DBUS_PATH_DBUS,
-	.interface = DBUS_INTERFACE_DBUS,
-	.method = "NameOwnerChanged",
-};
-
-static void test_match(const void *test_data)
-{
-	const struct watch_test *test = test_data;
-	struct dbus1_filter_data *data;
-	char rule[DBUS_MAXIMUM_MATCH_RULE_LENGTH];
-
-	data = _dbus1_filter_data_get(NULL,
-				NULL,
-				test->service,
-				test->path,
-				test->interface,
-				test->method,
-				test->name,
-				NULL,
-				NULL,
-				NULL);
-
-	_dbus1_filter_format_match(data, rule, sizeof(rule));
-
-	assert(strcmp(rule, test->expected) == 0);
-
-	_dbus1_filter_data_destroy(data);
-}
-
-static void disconnect_cb(struct l_dbus *dbus, void *user_data)
-{
-	int *count = user_data;
-
-	(*count)++;
-}
-
-static void send_filter_signal(struct dbus1_filter_data *data,
-			const char *name, const char *old, const char *new)
-{
-	struct l_dbus_message *message;
-
-	message = _dbus_message_new_signal(2,
-					DBUS_PATH_DBUS,
-					DBUS_INTERFACE_DBUS,
-					"NameOwnerChanged");
-	l_dbus_message_set_arguments(message, "sss", name, old, new);
-	_dbus_message_set_sender(message, DBUS_SERVICE_DBUS);
-	_dbus1_signal_dispatcher(message, data);
-	l_dbus_message_unref(message);
-}
-
-static void test_disconnect_watch(const void *test_data)
-{
-	const struct watch_test *test = test_data;
-	struct dbus1_filter_data *data;
-	int count = 0;
-
-	data = _dbus1_filter_data_get(NULL,
-				_dbus1_name_owner_changed_filter,
-				test->service,
-				test->path,
-				test->interface,
-				test->method,
-				test->name,
-				disconnect_cb,
-				&count,
-				NULL);
-
-	send_filter_signal(data, ":0.1", ":0.1", "");
-	assert(count == 0);
-
-	send_filter_signal(data, ":0.1", ":0.1", ":0.2");
-	assert(count == 0);
-
-	send_filter_signal(data, ":101.1", ":101.1", ":101.1");
-	assert(count == 0);
-
-	send_filter_signal(data, ":101.1", ":101.1", "");
-	assert(count == 1);
-
-	_dbus1_filter_data_destroy(data);
-}
 
 static void test_rule_to_str(const void *test_data)
 {
@@ -494,21 +283,6 @@ int main(int argc, char *argv[])
 {
 	l_test_init(&argc, &argv);
 
-	l_test_add("DBus filter NameOwnerChanged", test_match, &match_test_1);
-	l_test_add("DBus filter NULL service", test_match, &match_test_2);
-	l_test_add("DBus filter NULL path", test_match, &match_test_3);
-	l_test_add("DBus filter NULL interface", test_match, &match_test_4);
-	l_test_add("DBus filter NULL method", test_match, &match_test_5);
-	l_test_add("DBus filter NULL argument", test_match, &match_test_6);
-	l_test_add("DBus filter NULL service and path", test_match,
-								&match_test_7);
-	l_test_add("DBus filter NULL service, path and interface", test_match,
-								&match_test_8);
-	l_test_add("DBus filter NULL all fields", test_match, &match_test_9);
-
-	l_test_add("DBus disconnect watch", test_disconnect_watch,
-						&disconnect_test);
-
 	l_test_add("_dbus_filter_rule_to_str", test_rule_to_str, NULL);
 
 	l_test_add("DBus filter tree", test_filter_tree, NULL);
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] dbus: Remove now unused filter logic
  2016-05-06 10:18 [PATCH] unit: End to end FD passing test Andrew Zaborowski
  2016-05-06 10:18 ` [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus Andrew Zaborowski
  2016-05-06 10:18 ` [PATCH 1/2] unit: Remove dbus watch tests using old API Andrew Zaborowski
@ 2016-05-06 10:18 ` Andrew Zaborowski
  2016-05-06 15:53   ` Denis Kenzior
  2016-05-06 15:50 ` [PATCH] unit: End to end FD passing test Denis Kenzior
  3 siblings, 1 reply; 8+ messages in thread
From: Andrew Zaborowski @ 2016-05-06 10:18 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 5791 bytes --]

---
 ell/dbus-private.h |  20 -------
 ell/dbus.c         | 158 -----------------------------------------------------
 2 files changed, 178 deletions(-)

diff --git a/ell/dbus-private.h b/ell/dbus-private.h
index 88bea3c..919639b 100644
--- a/ell/dbus-private.h
+++ b/ell/dbus-private.h
@@ -332,23 +332,3 @@ char *_dbus_filter_rule_to_str(const struct _dbus_filter_condition *rule,
 				int rule_len);
 
 void _dbus_filter_dispatch(struct l_dbus_message *message, void *user_data);
-
-struct dbus1_filter_data;
-
-void _dbus1_filter_format_match(struct dbus1_filter_data *data, char *rule,
-								size_t size);
-
-struct dbus1_filter_data *_dbus1_filter_data_get(struct l_dbus *dbus,
-					l_dbus_message_func_t filter,
-					const char *sender,
-					const char *path,
-					const char *interface,
-					const char *member,
-					const char *argument,
-					l_dbus_watch_func_t disconnect_func,
-					void *user_data,
-					l_dbus_destroy_func_t destroy);
-void _dbus1_filter_data_destroy(void *user_data);
-void _dbus1_signal_dispatcher(struct l_dbus_message *message, void *user_data);
-void _dbus1_name_owner_changed_filter(struct l_dbus_message *message,
-							void *user_data);
diff --git a/ell/dbus.c b/ell/dbus.c
index 35378b2..7cb4740 100644
--- a/ell/dbus.c
+++ b/ell/dbus.c
@@ -130,23 +130,6 @@ struct signal_callback {
 	void *user_data;
 };
 
-struct dbus1_filter_data {
-	struct l_dbus *dbus;
-	char *sender;
-	char *path;
-	char *interface;
-	char *member;
-	char *argument;
-	void *user_data;
-	l_dbus_message_func_t handle_func;
-	l_dbus_destroy_func_t destroy_func;
-
-	l_dbus_watch_func_t connect_func;
-	l_dbus_watch_func_t disconnect_func;
-	char *owner;
-	uint32_t get_name_owner_id;
-};
-
 static void message_queue_destroy(void *data)
 {
 	struct message_callback *callback = data;
@@ -1757,147 +1740,6 @@ LIB_EXPORT bool l_dbus_object_manager_enable(struct l_dbus *dbus)
 						dbus);
 }
 
-void _dbus1_filter_format_match(struct dbus1_filter_data *data, char *rule,
-					size_t size)
-{
-	int offset;
-
-	offset = snprintf(rule, size, "type='signal'");
-
-	if (data->sender)
-		offset += snprintf(rule + offset, size - offset,
-				",sender='%s'", data->sender);
-	if (data->path)
-		offset += snprintf(rule + offset, size - offset,
-				",path='%s'", data->path);
-	if (data->interface)
-		offset += snprintf(rule + offset, size - offset,
-				",interface='%s'", data->interface);
-	if (data->member)
-		offset += snprintf(rule + offset, size - offset,
-				",member='%s'", data->member);
-	if (data->argument)
-		snprintf(rule + offset, size - offset,
-				",arg0='%s'", data->argument);
-}
-
-struct dbus1_filter_data *_dbus1_filter_data_get(struct l_dbus *dbus,
-					l_dbus_message_func_t filter,
-					const char *sender,
-					const char *path,
-					const char *interface,
-					const char *member,
-					const char *argument,
-					l_dbus_watch_func_t disconnect_func,
-					void *user_data,
-					l_dbus_destroy_func_t destroy)
-{
-	struct dbus1_filter_data *data;
-
-	data = l_new(struct dbus1_filter_data, 1);
-
-	data->dbus = dbus;
-	data->handle_func = filter;
-	data->sender = l_strdup(sender);
-	data->path = l_strdup(path);
-	data->interface = l_strdup(interface);
-	data->member = l_strdup(member);
-	data->argument = l_strdup(argument);
-	data->user_data = user_data;
-	data->destroy_func = destroy;
-
-	data->disconnect_func = disconnect_func;
-
-	return data;
-}
-
-void _dbus1_filter_data_destroy(void *user_data)
-{
-	struct dbus1_filter_data *data = user_data;
-
-	l_free(data->sender);
-	l_free(data->path);
-	l_free(data->interface);
-	l_free(data->member);
-	l_free(data->argument);
-
-	l_free(data->owner);
-
-	if (data->get_name_owner_id)
-		l_dbus_cancel(data->dbus, data->get_name_owner_id);
-
-	if (data->destroy_func)
-		data->destroy_func(data->user_data);
-
-	l_free(data);
-}
-
-void _dbus1_signal_dispatcher(struct l_dbus_message *message, void *user_data)
-{
-	struct dbus1_filter_data *data = user_data;
-	const char *sender, *path, *iface, *member;
-
-	if (_dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL)
-		return;
-
-	sender = l_dbus_message_get_sender(message);
-	if (!sender)
-		return;
-
-	if (data->sender && strcmp(sender, data->sender))
-		return;
-
-	path = l_dbus_message_get_path(message);
-	if (data->path && strcmp(path, data->path))
-		return;
-
-	iface = l_dbus_message_get_interface(message);
-	if (data->interface && strcmp(iface, data->interface))
-		return;
-
-	member = l_dbus_message_get_member(message);
-	if (data->member && strcmp(member, data->member))
-		return;
-
-	if (data->handle_func)
-		data->handle_func(message, data);
-}
-
-void _dbus1_name_owner_changed_filter(struct l_dbus_message *message,
-							void *user_data)
-{
-	struct dbus1_filter_data *data = user_data;
-	char *name, *old, *new;
-
-	if (!l_dbus_message_get_arguments(message, "sss",
-						&name, &old, &new))
-		return;
-
-	if (strcmp(name, data->argument))
-		return;
-
-	if (!data->owner) {
-		if (data->get_name_owner_id)
-			l_dbus_cancel(data->dbus, data->get_name_owner_id);
-
-		data->get_name_owner_id = 0;
-	} else {
-		if (!strcmp(data->owner, new))
-			return;
-	}
-
-	l_free(data->owner);
-	data->owner = l_strdup(new);
-
-	if (*new == '\0') {
-		if (data->disconnect_func)
-			data->disconnect_func(data->dbus, data->user_data);
-	} else {
-		if (data->connect_func)
-			data->connect_func(data->dbus, data->user_data);
-	}
-}
-
 LIB_EXPORT unsigned int l_dbus_add_disconnect_watch(struct l_dbus *dbus,
 					const char *name,
 					l_dbus_watch_func_t disconnect_func,
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] unit: End to end FD passing test
  2016-05-06 10:18 [PATCH] unit: End to end FD passing test Andrew Zaborowski
                   ` (2 preceding siblings ...)
  2016-05-06 10:18 ` [PATCH 2/2] dbus: Remove now unused filter logic Andrew Zaborowski
@ 2016-05-06 15:50 ` Denis Kenzior
  3 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2016-05-06 15:50 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 335 bytes --]

Hi Andrew,

On 05/06/2016 05:18 AM, Andrew Zaborowski wrote:
> ---
>   Makefile.am                  |   3 +
>   unit/test-dbus-message-fds.c | 384 +++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 387 insertions(+)
>   create mode 100644 unit/test-dbus-message-fds.c
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus
  2016-05-06 10:18 ` [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus Andrew Zaborowski
@ 2016-05-06 15:51   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2016-05-06 15:51 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

Hi Andrew,

On 05/06/2016 05:18 AM, Andrew Zaborowski wrote:
> Same as test-dbus-message-fds.
> ---
>   unit/test-dbus-properties.c | 124 +++++++++++++++++++++++++-------------------
>   1 file changed, 70 insertions(+), 54 deletions(-)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] unit: Remove dbus watch tests using old API
  2016-05-06 10:18 ` [PATCH 1/2] unit: Remove dbus watch tests using old API Andrew Zaborowski
@ 2016-05-06 15:52   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2016-05-06 15:52 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 238 bytes --]

Hi Andrew,

On 05/06/2016 05:18 AM, Andrew Zaborowski wrote:
> ---
>   unit/test-dbus-watch.c | 226 -------------------------------------------------
>   1 file changed, 226 deletions(-)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] dbus: Remove now unused filter logic
  2016-05-06 10:18 ` [PATCH 2/2] dbus: Remove now unused filter logic Andrew Zaborowski
@ 2016-05-06 15:53   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2016-05-06 15:53 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

Hi Andrew,

On 05/06/2016 05:18 AM, Andrew Zaborowski wrote:
> ---
>   ell/dbus-private.h |  20 -------
>   ell/dbus.c         | 158 -----------------------------------------------------
>   2 files changed, 178 deletions(-)
>

Applied, thanks.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-06 15:53 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-06 10:18 [PATCH] unit: End to end FD passing test Andrew Zaborowski
2016-05-06 10:18 ` [PATCH] unit: Try dbus-properties tests on Dbus1 and kdbus Andrew Zaborowski
2016-05-06 15:51   ` Denis Kenzior
2016-05-06 10:18 ` [PATCH 1/2] unit: Remove dbus watch tests using old API Andrew Zaborowski
2016-05-06 15:52   ` Denis Kenzior
2016-05-06 10:18 ` [PATCH 2/2] dbus: Remove now unused filter logic Andrew Zaborowski
2016-05-06 15:53   ` Denis Kenzior
2016-05-06 15:50 ` [PATCH] unit: End to end FD passing test Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.