All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/9] unit/test-crc: Use tester framework
@ 2015-04-10 14:05 Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 2/9] unit/test-crypto: " Luiz Augusto von Dentz
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 Makefile.am     |  2 +-
 unit/test-crc.c | 37 ++++++++++++++++++-------------------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 2a1fe76..f9f26aa 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -282,7 +282,7 @@ unit_test_textfile_LDADD = @GLIB_LIBS@
 unit_tests += unit/test-crc
 
 unit_test_crc_SOURCES = unit/test-crc.c monitor/crc.h monitor/crc.c
-unit_test_crc_LDADD = @GLIB_LIBS@
+unit_test_crc_LDADD = src/libshared-glib.la @GLIB_LIBS@
 
 unit_tests += unit/test-crypto
 
diff --git a/unit/test-crc.c b/unit/test-crc.c
index db40dc9..791fa51 100644
--- a/unit/test-crc.c
+++ b/unit/test-crc.c
@@ -26,6 +26,7 @@
 #endif
 
 #include "monitor/crc.h"
+#include "src/shared/tester.h"
 
 #include <glib.h>
 
@@ -160,35 +161,33 @@ static void test_crc(gconstpointer data)
 	crc = crc24_calculate(crc_init, test_data->packet + 4,
 						test_data->size - 7);
 
-	if (g_test_verbose())
-		g_print("CRC: 0x%6.6x, Calculated: 0x%6.6x\n",
-						crc_value, crc);
+	tester_debug("CRC: 0x%6.6x, Calculated: 0x%6.6x", crc_value, crc);
 
 	g_assert(crc_value == crc);
 
 	rev = crc24_reverse(crc_value, test_data->packet + 4,
 						test_data->size - 7);
 
-	if (g_test_verbose())
-		g_print("Preset: 0x%6.6x, Calculated: 0x%6.6x\n",
-						crc_init, rev);
+	tester_debug("Preset: 0x%6.6x, Calculated: 0x%6.6x", crc_init, rev);
 
 	g_assert(crc_init == rev);
+
+	tester_test_passed();
 }
 
 int main(int argc, char *argv[])
 {
-	g_test_init(&argc, &argv, NULL);
-
-	g_test_add_data_func("/crc/1", &crc_1, test_crc);
-	g_test_add_data_func("/crc/2", &crc_2, test_crc);
-	g_test_add_data_func("/crc/3", &crc_3, test_crc);
-	g_test_add_data_func("/crc/4", &crc_4, test_crc);
-	g_test_add_data_func("/crc/5", &crc_5, test_crc);
-	g_test_add_data_func("/crc/6", &crc_6, test_crc);
-	g_test_add_data_func("/crc/7", &crc_7, test_crc);
-	g_test_add_data_func("/crc/8", &crc_8, test_crc);
-	g_test_add_data_func("/crc/9", &crc_9, test_crc);
-
-	return g_test_run();
+	tester_init(&argc, &argv);
+
+	tester_add("/crc/1", &crc_1, NULL, test_crc, NULL);
+	tester_add("/crc/2", &crc_2, NULL, test_crc, NULL);
+	tester_add("/crc/3", &crc_3, NULL, test_crc, NULL);
+	tester_add("/crc/4", &crc_4, NULL, test_crc, NULL);
+	tester_add("/crc/5", &crc_5, NULL, test_crc, NULL);
+	tester_add("/crc/6", &crc_6, NULL, test_crc, NULL);
+	tester_add("/crc/7", &crc_7, NULL, test_crc, NULL);
+	tester_add("/crc/8", &crc_8, NULL, test_crc, NULL);
+	tester_add("/crc/9", &crc_9, NULL, test_crc, NULL);
+
+	return tester_run();
 }
-- 
2.1.0


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

* [PATCH BlueZ 2/9] unit/test-crypto: Use tester framework
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 3/9] unit/test-ecc: " Luiz Augusto von Dentz
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 unit/test-crypto.c | 35 ++++++++++++++++-------------------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/unit/test-crypto.c b/unit/test-crypto.c
index fd2ea78..5fb1c64 100644
--- a/unit/test-crypto.c
+++ b/unit/test-crypto.c
@@ -26,6 +26,8 @@
 #endif
 
 #include "src/shared/crypto.h"
+#include "src/shared/util.h"
+#include "src/shared/tester.h"
 
 #include <string.h>
 #include <glib.h>
@@ -107,14 +109,9 @@ static const struct test_data test_data_4 = {
 	.t = t_msg_4
 };
 
-static void print_buf(const uint8_t *t, uint8_t len)
+static void print_debug(const char *str, void *user_data)
 {
-	int i;
-
-	for (i = 0; i < len; i++)
-		g_print("0x%02x, ", t[i]);
-
-	g_print("\n");
+	tester_debug("%s", str);
 }
 
 static bool result_compare(const uint8_t exp[12], uint8_t res[12])
@@ -136,14 +133,14 @@ static void test_sign(gconstpointer data)
 	if (!bt_crypto_sign_att(crypto, key, d->msg, d->msg_len, 0, t))
 		g_assert(true);
 
-	if (g_test_verbose()) {
-		g_print("Result T: ");
-		print_buf(t, 12);
-		g_print("Expected T:");
-		print_buf(d->t, 12);
-	}
+	tester_debug("Result T:");
+	util_hexdump(' ', t, 12, print_debug, NULL);
+	tester_debug("Expected T:");
+	util_hexdump(' ', d->t, 12, print_debug, NULL);
 
 	g_assert(result_compare(d->t, t));
+
+	tester_test_passed();
 }
 
 int main(int argc, char *argv[])
@@ -154,14 +151,14 @@ int main(int argc, char *argv[])
 	if (!crypto)
 		return 0;
 
-	g_test_init(&argc, &argv, NULL);
+	tester_init(&argc, &argv);
 
-	g_test_add_data_func("/crypto/sign_att_1", &test_data_1, test_sign);
-	g_test_add_data_func("/crypto/sign_att_2", &test_data_2, test_sign);
-	g_test_add_data_func("/crypto/sign_att_3", &test_data_3, test_sign);
-	g_test_add_data_func("/crypto/sign_att_4", &test_data_4, test_sign);
+	tester_add("/crypto/sign_att_1", &test_data_1, NULL, test_sign, NULL);
+	tester_add("/crypto/sign_att_2", &test_data_2, NULL, test_sign, NULL);
+	tester_add("/crypto/sign_att_3", &test_data_3, NULL, test_sign, NULL);
+	tester_add("/crypto/sign_att_4", &test_data_4, NULL, test_sign, NULL);
 
-	exit_status = g_test_run();
+	exit_status = tester_run();
 
 	bt_crypto_unref(crypto);
 
-- 
2.1.0


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

* [PATCH BlueZ 3/9] unit/test-ecc: Use tester framework
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 2/9] unit/test-crypto: " Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 4/9] unit/test-eir: " Luiz Augusto von Dentz
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 unit/test-ecc.c | 99 ++++++++++++++++++++++++---------------------------------
 1 file changed, 42 insertions(+), 57 deletions(-)

diff --git a/unit/test-ecc.c b/unit/test-ecc.c
index 8f80118..9b48d0b 100644
--- a/unit/test-ecc.c
+++ b/unit/test-ecc.c
@@ -37,33 +37,33 @@
 #include <fcntl.h>
 
 #include "src/shared/ecc.h"
+#include "src/shared/util.h"
+#include "src/shared/tester.h"
 
-static void vli_print(uint8_t *vli, size_t size)
+static void print_dump(const char *str, void *user_data)
 {
-	while (size) {
-		printf("%02X ", vli[size - 1]);
-		size--;
-	}
+	tester_debug("%s", str);
+}
+
+static void print_buf(const char *label, uint8_t *buf, size_t len)
+{
+	tester_debug("%s", label);
+
+	util_hexdump(' ', buf, len, print_dump, NULL);
 }
 
 #define PAIR_COUNT 200
 
-static void test_multi(void)
+static void test_multi(const void *data)
 {
 	uint8_t public1[64], public2[64];
 	uint8_t private1[32], private2[32];
 	uint8_t shared1[32], shared2[32];
 	int i;
 
-	if (g_test_verbose())
-		g_print("Testing %u random private key pairs", PAIR_COUNT);
+	tester_debug("Testing %u random private key pairs", PAIR_COUNT);
 
 	for (i = 0; i < PAIR_COUNT; i++) {
-		if (g_test_verbose()) {
-			printf(".");
-			fflush(stdout);
-		}
-
 		ecc_make_key(public1, private1);
 		ecc_make_key(public2, private2);
 
@@ -71,37 +71,20 @@ static void test_multi(void)
 		ecdh_shared_secret(public2, private1, shared2);
 
 		if (memcmp(shared1, shared2, sizeof(shared1)) != 0) {
-			printf("Shared secrets are not identical!\n");
-			printf("Shared secret 1 = ");
-			vli_print(shared1, sizeof(shared1));
-			printf("\n");
-			printf("Shared secret 2 = ");
-			vli_print(shared2, sizeof(shared2));
-			printf("\n");
-			printf("Private key 1 = ");
-			vli_print(private1, sizeof(private1));
-			printf("\n");
-			printf("Private key 2 = ");
-			vli_print(private2, sizeof(private2));
-			printf("\n");
+			tester_debug("Shared secrets are not identical!\n");
+			print_buf("Shared secret 1 = ", shared1,
+							sizeof(shared1));
+			print_buf("Shared secret 2 = ", shared2,
+							sizeof(shared2));
+			print_buf("Private key 1 = ", private1,
+							sizeof(private1));
+			print_buf("Private key 2 = ", private2,
+							sizeof(private2));
 			g_assert_not_reached();
 		}
 	}
 
-	if (g_test_verbose())
-		printf("\n");
-}
-
-static void print_buf(const char *label, uint8_t *buf, size_t len)
-{
-	size_t i;
-
-	printf("%s ", label);
-
-	for (i = 0; i < len; i++)
-		printf("%02x", buf[i]);
-
-	printf("\n");
+	tester_test_passed();
 }
 
 static int test_sample(uint8_t priv_a[32], uint8_t priv_b[32],
@@ -121,27 +104,23 @@ static int test_sample(uint8_t priv_a[32], uint8_t priv_b[32],
 	}
 
 	if (memcmp(dhkey_a, dhkey, 32)) {
-		if (g_test_verbose())
-			printf("DHKey A doesn't match!\n");
+		tester_debug("DHKey A doesn't match!");
 		fails++;
 	} else {
-		if (g_test_verbose())
-			printf("DHKey A matches :)\n");
+		tester_debug("DHKey A matches :)");
 	}
 
 	if (memcmp(dhkey_b, dhkey, 32)) {
-		if (g_test_verbose())
-			printf("DHKey B doesn't match!\n");
+		tester_debug("DHKey B doesn't match!");
 		fails++;
 	} else {
-		if (g_test_verbose())
-			printf("DHKey B matches :)\n");
+		tester_debug("DHKey B matches :)");
 	}
 
 	return fails;
 }
 
-static void test_sample_1(void)
+static void test_sample_1(const void *data)
 {
 	uint8_t priv_a[32] = {	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
 				0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
@@ -183,9 +162,11 @@ static void test_sample_1(void)
 	fails = test_sample(priv_a, priv_b, pub_a, pub_b, dhkey);
 
 	g_assert(fails == 0);
+
+	tester_test_passed();
 }
 
-static void test_sample_2(void)
+static void test_sample_2(const void *data)
 {
 	uint8_t priv_a[32] = {	0x63, 0x76, 0x45, 0xd0, 0xf7, 0x73, 0xac, 0xb7,
 				0xff, 0xdd, 0x03, 0x72, 0xb9, 0x72, 0x85, 0xb4,
@@ -227,9 +208,11 @@ static void test_sample_2(void)
 	fails = test_sample(priv_a, priv_b, pub_a, pub_b, dhkey);
 
 	g_assert(fails == 0);
+
+	tester_test_passed();
 }
 
-static void test_sample_3(void)
+static void test_sample_3(const void *data)
 {
 	uint8_t priv_a[32] = {	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
 				0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
@@ -256,17 +239,19 @@ static void test_sample_3(void)
 	fails = test_sample(priv_a, priv_a, pub_a, pub_a, dhkey);
 
 	g_assert(fails == 0);
+
+	tester_test_passed();
 }
 
 int main(int argc, char *argv[])
 {
-	g_test_init(&argc, &argv, NULL);
+	tester_init(&argc, &argv);
 
-	g_test_add_func("/ecdh/multi", test_multi);
+	tester_add("/ecdh/multi", NULL, NULL, test_multi, NULL);
 
-	g_test_add_func("/ecdh/sample/1", test_sample_1);
-	g_test_add_func("/ecdh/sample/2", test_sample_2);
-	g_test_add_func("/ecdh/sample/3", test_sample_3);
+	tester_add("/ecdh/sample/1", NULL, NULL, test_sample_1, NULL);
+	tester_add("/ecdh/sample/2", NULL, NULL, test_sample_2, NULL);
+	tester_add("/ecdh/sample/3", NULL, NULL, test_sample_3, NULL);
 
-	return g_test_run();
+	return tester_run();
 }
-- 
2.1.0


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

* [PATCH BlueZ 4/9] unit/test-eir: Use tester framework
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 2/9] unit/test-crypto: " Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 3/9] unit/test-ecc: " Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 5/9] unit/test-gdbus-client: " Luiz Augusto von Dentz
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 Makefile.am     |  3 ++-
 unit/test-eir.c | 78 +++++++++++++++++++++++++++++++--------------------------
 2 files changed, 45 insertions(+), 36 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index f9f26aa..b0292e7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -267,7 +267,8 @@ AM_CPPFLAGS = -I$(builddir)/lib
 unit_tests += unit/test-eir
 
 unit_test_eir_SOURCES = unit/test-eir.c src/eir.c src/uuid-helper.c
-unit_test_eir_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@
+unit_test_eir_LDADD = src/libshared-glib.la lib/libbluetooth-internal.la \
+								@GLIB_LIBS@
 
 unit_tests += unit/test-uuid
 
diff --git a/unit/test-eir.c b/unit/test-eir.c
index 043634b..d5216f6 100644
--- a/unit/test-eir.c
+++ b/unit/test-eir.c
@@ -33,6 +33,8 @@
 #include "lib/hci.h"
 #include "lib/sdp.h"
 
+#include <src/shared/tester.h>
+
 #include "src/eir.h"
 
 struct test_data {
@@ -527,41 +529,41 @@ static const struct test_data citizen_scan_test = {
 	.uuid = citizen_scan_uuid,
 };
 
-static void test_basic(void)
+static void test_basic(const void *data)
 {
-	struct eir_data data;
+	struct eir_data eir;
 	unsigned char buf[HCI_MAX_EIR_LENGTH];
 
 	memset(buf, 0, sizeof(buf));
-	memset(&data, 0, sizeof(data));
+	memset(&eir, 0, sizeof(eir));
 
-	eir_parse(&data, buf, HCI_MAX_EIR_LENGTH);
-	g_assert(data.services == NULL);
-	g_assert(data.name == NULL);
+	eir_parse(&eir, buf, HCI_MAX_EIR_LENGTH);
+	g_assert(eir.services == NULL);
+	g_assert(eir.name == NULL);
+
+	eir_data_free(&eir);
 
-	eir_data_free(&data);
+	tester_test_passed();
 }
 
 static void test_parsing(gconstpointer data)
 {
 	const struct test_data *test = data;
 	struct eir_data eir;
+	GSList *list;
 
 	memset(&eir, 0, sizeof(eir));
 
 	eir_parse(&eir, test->eir_data, test->eir_size);
 
-	if (g_test_verbose() == TRUE) {
-		GSList *list;
+	tester_debug("Flags: %d", eir.flags);
+	tester_debug("Name: %s", eir.name);
+	tester_debug("TX power: %d", eir.tx_power);
 
-		g_print("Flags: %d\n", eir.flags);
-		g_print("Name: %s\n", eir.name);
-		g_print("TX power: %d\n", eir.tx_power);
+	for (list = eir.services; list; list = list->next) {
+		char *uuid_str = list->data;
 
-		for (list = eir.services; list; list = list->next) {
-			char *uuid_str = list->data;
-			g_print("UUID: %s\n", uuid_str);
-		}
+		tester_debug("UUID: %s", uuid_str);
 	}
 
 	g_assert(eir.flags == test->flags);
@@ -589,27 +591,33 @@ static void test_parsing(gconstpointer data)
 	}
 
 	eir_data_free(&eir);
+
+	tester_test_passed();
 }
 
 int main(int argc, char *argv[])
 {
-	g_test_init(&argc, &argv, NULL);
-
-	g_test_add_func("/eir/basic", test_basic);
-
-	g_test_add_data_func("/eir/macbookair", &macbookair_test, test_parsing);
-	g_test_add_data_func("/eir/iphone5", &iphone5_test, test_parsing);
-	g_test_add_data_func("/eir/ipadmini", &ipadmini_test, test_parsing);
-	g_test_add_data_func("/eir/sl400h", &gigaset_sl400h_test, test_parsing);
-	g_test_add_data_func("/eir/sl910", &gigaset_sl910_test, test_parsing);
-	g_test_add_data_func("/eir/bh907", &nokia_bh907_test, test_parsing);
-	g_test_add_data_func("/eir/fuelband", &fuelband_test, test_parsing);
-	g_test_add_data_func("/ad/bluesc", &bluesc_test, test_parsing);
-	g_test_add_data_func("/ad/wahooscale", &wahoo_scale_test, test_parsing);
-	g_test_add_data_func("/ad/mioalpha", &mio_alpha_test, test_parsing);
-	g_test_add_data_func("/ad/cookoo", &cookoo_test, test_parsing);
-	g_test_add_data_func("/ad/citizen1", &citizen_adv_test, test_parsing);
-	g_test_add_data_func("/ad/citizen2", &citizen_scan_test, test_parsing);
-
-	return g_test_run();
+	tester_init(&argc, &argv);
+
+	tester_add("/eir/basic", NULL, NULL, test_basic, NULL);
+
+	tester_add("/eir/macbookair", &macbookair_test, NULL, test_parsing,
+									NULL);
+	tester_add("/eir/iphone5", &iphone5_test, NULL, test_parsing, NULL);
+	tester_add("/eir/ipadmini", &ipadmini_test, NULL, test_parsing, NULL);
+	tester_add("/eir/sl400h", &gigaset_sl400h_test, NULL, test_parsing,
+									NULL);
+	tester_add("/eir/sl910", &gigaset_sl910_test, NULL, test_parsing, NULL);
+	tester_add("/eir/bh907", &nokia_bh907_test, NULL, test_parsing, NULL);
+	tester_add("/eir/fuelband", &fuelband_test, NULL, test_parsing, NULL);
+	tester_add("/ad/bluesc", &bluesc_test, NULL, test_parsing, NULL);
+	tester_add("/ad/wahooscale", &wahoo_scale_test, NULL, test_parsing,
+									NULL);
+	tester_add("/ad/mioalpha", &mio_alpha_test, NULL, test_parsing, NULL);
+	tester_add("/ad/cookoo", &cookoo_test, NULL, test_parsing, NULL);
+	tester_add("/ad/citizen1", &citizen_adv_test, NULL, test_parsing, NULL);
+	tester_add("/ad/citizen2", &citizen_scan_test, NULL, test_parsing,
+									NULL);
+
+	return tester_run();
 }
-- 
2.1.0


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

* [PATCH BlueZ 5/9] unit/test-gdbus-client: Use tester framework
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2015-04-10 14:05 ` [PATCH BlueZ 4/9] unit/test-eir: " Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 6/9] gdbus: Close private connection if setup fails Luiz Augusto von Dentz
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 Makefile.am              |   2 +-
 unit/test-gdbus-client.c | 261 +++++++++++++----------------------------------
 2 files changed, 70 insertions(+), 193 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index b0292e7..0acc042 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -354,7 +354,7 @@ unit_tests += unit/test-gdbus-client
 
 unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
 unit_test_gdbus_client_LDADD = gdbus/libgdbus-internal.la \
-				@GLIB_LIBS@ @DBUS_LIBS@
+				src/libshared-glib.la @GLIB_LIBS@ @DBUS_LIBS@
 
 unit_tests += unit/test-gobex-header unit/test-gobex-packet unit/test-gobex \
 			unit/test-gobex-transfer unit/test-gobex-apparam
diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index ad426fe..5d8bbf2 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -29,12 +29,13 @@
 
 #include "gdbus/gdbus.h"
 
+#include "src/shared/tester.h"
+
 #define SERVICE_NAME "org.bluez.unit.test-gdbus-client"
 #define SERVICE_NAME1 "org.bluez.unit.test-gdbus-client1"
 #define SERVICE_PATH "/org/bluez/unit/test_gdbus_client"
 
 struct context {
-	GMainLoop *main_loop;
 	DBusConnection *dbus_conn;
 	GDBusClient *dbus_client;
 	GDBusProxy *proxy;
@@ -60,25 +61,16 @@ static struct context *create_context(void)
 	struct context *context = g_new0(struct context, 1);
 	DBusError err;
 
-	context->main_loop = g_main_loop_new(NULL, FALSE);
-	if (context->main_loop == NULL) {
-		g_free(context);
-		return NULL;
-	}
-
 	dbus_error_init(&err);
 
 	context->dbus_conn = g_dbus_setup_private(DBUS_BUS_SESSION,
 							SERVICE_NAME, &err);
 	if (context->dbus_conn == NULL) {
 		if (dbus_error_is_set(&err)) {
-			if (g_test_verbose())
-				g_printerr("D-Bus setup failed: %s\n",
-								err.message);
+			tester_debug("D-Bus setup failed: %s", err.message);
 			dbus_error_free(&err);
 		}
 
-		g_main_loop_unref(context->main_loop);
 		g_free(context);
 		return NULL;
 	}
@@ -97,17 +89,20 @@ static void destroy_context(struct context *context)
 	if (context == NULL)
 		return;
 
+	tester_test_passed();
+
 	if (context->timeout_source > 0)
 		g_source_remove(context->timeout_source);
 
 	g_dbus_detach_object_manager(context->dbus_conn);
 
+	g_dbus_unregister_interface(context->dbus_conn,
+					SERVICE_PATH, SERVICE_NAME);
+
 	dbus_connection_flush(context->dbus_conn);
 	dbus_connection_close(context->dbus_conn);
 	dbus_connection_unref(context->dbus_conn);
 
-	g_main_loop_unref(context->main_loop);
-
 	g_free(context->data);
 	g_free(context);
 }
@@ -116,8 +111,7 @@ static gboolean timeout_handler(gpointer user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("timeout triggered\n");
+	tester_debug("timeout triggered");
 
 	context->timeout_source = 0;
 
@@ -130,8 +124,7 @@ static void connect_handler(DBusConnection *connection, void *user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("service connected\n");
+	tester_debug("service connected");
 
 	g_dbus_client_unref(context->dbus_client);
 }
@@ -140,13 +133,12 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("service disconnected\n");
+	tester_debug("service disconnected");
 
-	g_main_loop_quit(context->main_loop);
+	destroy_context(context);
 }
 
-static void simple_client(void)
+static void simple_client(const void *data)
 {
 	struct context *context = create_context();
 
@@ -160,13 +152,9 @@ static void simple_client(void)
 						connect_handler, context);
 	g_dbus_client_set_disconnect_watch(context->dbus_client,
 						disconnect_handler, context);
-
-	g_main_loop_run(context->main_loop);
-
-	destroy_context(context);
 }
 
-static void client_connect_disconnect(void)
+static void client_connect_disconnect(const void *data)
 {
 	struct context *context = create_context();
 
@@ -187,13 +175,6 @@ static void client_connect_disconnect(void)
 
 	context->timeout_source = g_timeout_add_seconds(10, timeout_handler,
 								context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void append_variant(DBusMessageIter *iter, int type, void *val)
@@ -256,9 +237,7 @@ static void proxy_get_dict(GDBusProxy *proxy, void *user_data)
 	const char *string;
 	dbus_bool_t boolean;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "Dict", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY);
@@ -307,7 +286,7 @@ static void proxy_get_dict(GDBusProxy *proxy, void *user_data)
 	g_dbus_client_unref(context->dbus_client);
 }
 
-static void client_get_dict_property(void)
+static void client_get_dict_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable dict_properties[] = {
@@ -330,13 +309,6 @@ static void client_get_dict_property(void)
 						disconnect_handler, context);
 	g_dbus_client_set_proxy_handlers(context->dbus_client, proxy_get_dict,
 						NULL, NULL, context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void proxy_get_string(GDBusProxy *proxy, void *user_data)
@@ -345,9 +317,7 @@ static void proxy_get_string(GDBusProxy *proxy, void *user_data)
 	DBusMessageIter iter;
 	const char *string;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "String", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
@@ -368,7 +338,7 @@ static gboolean get_string(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
-static void client_get_string_property(void)
+static void client_get_string_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -392,13 +362,6 @@ static void client_get_string_property(void)
 						disconnect_handler, context);
 	g_dbus_client_set_proxy_handlers(context->dbus_client, proxy_get_string,
 						NULL, NULL, context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void proxy_get_boolean(GDBusProxy *proxy, void *user_data)
@@ -407,9 +370,7 @@ static void proxy_get_boolean(GDBusProxy *proxy, void *user_data)
 	DBusMessageIter iter;
 	dbus_bool_t value;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "Boolean", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_BOOLEAN);
@@ -430,7 +391,7 @@ static gboolean get_boolean(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
-static void client_get_boolean_property(void)
+static void client_get_boolean_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable boolean_properties[] = {
@@ -454,13 +415,6 @@ static void client_get_boolean_property(void)
 						NULL, NULL, context);
 	g_dbus_client_set_disconnect_watch(context->dbus_client,
 						disconnect_handler, context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void proxy_get_array(GDBusProxy *proxy, void *user_data)
@@ -469,9 +423,7 @@ static void proxy_get_array(GDBusProxy *proxy, void *user_data)
 	DBusMessageIter iter, entry;
 	const char *value1, *value2;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "Array", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY);
@@ -507,7 +459,7 @@ static gboolean get_array(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
-static void client_get_array_property(void)
+static void client_get_array_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable array_properties[] = {
@@ -530,13 +482,6 @@ static void client_get_array_property(void)
 						NULL, NULL, context);
 	g_dbus_client_set_disconnect_watch(context->dbus_client,
 						disconnect_handler, context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void proxy_get_uint64(GDBusProxy *proxy, void *user_data)
@@ -545,9 +490,7 @@ static void proxy_get_uint64(GDBusProxy *proxy, void *user_data)
 	DBusMessageIter iter;
 	guint64 value;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "Number", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_UINT64);
@@ -568,7 +511,7 @@ static gboolean get_uint64(const GDBusPropertyTable *property,
 	return TRUE;
 }
 
-static void client_get_uint64_property(void)
+static void client_get_uint64_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable uint64_properties[] = {
@@ -592,13 +535,6 @@ static void client_get_uint64_property(void)
 						NULL, NULL, context);
 	g_dbus_client_set_disconnect_watch(context->dbus_client,
 						disconnect_handler, context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void property_set_success(const DBusError *err, void *user_data)
@@ -611,9 +547,7 @@ static void proxy_set_string(GDBusProxy *proxy, void *user_data)
 	DBusMessageIter iter;
 	const char *string;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_get_property(proxy, "String", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
@@ -634,8 +568,7 @@ static void property_string_changed(GDBusProxy *proxy, const char *name,
 	struct context *context = user_data;
 	const char *string;
 
-	if (g_test_verbose())
-		g_print("property %s changed\n", name);
+	tester_debug("property %s changed", name);
 
 	g_assert(g_strcmp0(name, "String") == 0);
 	g_assert(dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING);
@@ -667,7 +600,7 @@ static void set_string(const GDBusPropertyTable *property,
 	g_dbus_pending_property_success(id);
 }
 
-static void client_set_string_property(void)
+static void client_set_string_property(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -692,13 +625,6 @@ static void client_set_string_property(void)
 	g_dbus_client_set_proxy_handlers(context->dbus_client, proxy_set_string,
 						NULL, property_string_changed,
 						context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static gboolean string_exists(const GDBusPropertyTable *property, void *data)
@@ -712,8 +638,7 @@ static gboolean timeout_test(gpointer user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("timeout triggered\n");
+	tester_debug("timeout triggered");
 
 	context->timeout_source = 0;
 
@@ -742,16 +667,14 @@ static void proxy_string_changed(GDBusProxy *proxy, void *user_data)
 	struct context *context = user_data;
 	DBusMessageIter iter;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(!g_dbus_proxy_get_property(proxy, "String", &iter));
 
 	g_idle_add(emit_string_change, context);
 }
 
-static void client_string_changed(void)
+static void client_string_changed(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -776,13 +699,6 @@ static void client_string_changed(void)
 						proxy_string_changed, NULL,
 						property_string_changed,
 						context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void property_check_order(const DBusError *err, void *user_data)
@@ -807,9 +723,7 @@ static void proxy_check_order(GDBusProxy *proxy, void *user_data)
 	struct context *context = user_data;
 	const char *string;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	context->proxy = proxy;
 	string = "value1";
@@ -819,7 +733,7 @@ static void proxy_check_order(GDBusProxy *proxy, void *user_data)
 					NULL));
 }
 
-static void client_check_order(void)
+static void client_check_order(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -844,32 +758,22 @@ static void client_check_order(void)
 	g_dbus_client_set_proxy_handlers(context->dbus_client,
 						proxy_check_order, NULL, NULL,
 						context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(context->dbus_conn,
-					SERVICE_PATH, SERVICE_NAME);
-
-	destroy_context(context);
 }
 
 static void proxy_removed(GDBusProxy *proxy, void *user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("proxy removed\n");
+	tester_debug("proxy removed");
 
-	g_main_loop_quit(context->main_loop);
+	destroy_context(context);
 }
 
 static void proxy_set_removed(GDBusProxy *proxy, void *user_data)
 {
 	struct context *context = user_data;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_set_removed_watch(proxy, proxy_removed, context));
 
@@ -880,7 +784,7 @@ static void proxy_set_removed(GDBusProxy *proxy, void *user_data)
 								SERVICE_NAME);
 }
 
-static void client_proxy_removed(void)
+static void client_proxy_removed(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -902,13 +806,9 @@ static void client_proxy_removed(void)
 	g_dbus_client_set_proxy_handlers(context->dbus_client,
 						proxy_set_removed, NULL, NULL,
 						context);
-
-	g_main_loop_run(context->main_loop);
-
-	destroy_context(context);
 }
 
-static void client_no_object_manager(void)
+static void client_no_object_manager(const void *data)
 {
 	struct context *context = create_context();
 	DBusConnection *conn;
@@ -945,17 +845,6 @@ static void client_no_object_manager(void)
 						NULL, NULL, context);
 
 	g_assert(!g_dbus_proxy_get_property(context->proxy, "String", &iter));
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_proxy_unref(context->proxy);
-	g_dbus_unregister_interface(conn, SERVICE_PATH, SERVICE_NAME1);
-
-	dbus_connection_flush(conn);
-	dbus_connection_close(conn);
-	dbus_connection_unref(conn);
-
-	destroy_context(context);
 }
 
 static void proxy_force_disconnect(GDBusProxy *proxy, void *user_data)
@@ -963,9 +852,7 @@ static void proxy_force_disconnect(GDBusProxy *proxy, void *user_data)
 	struct context *context = user_data;
 	DBusConnection *conn = context->data;
 
-	if (g_test_verbose())
-		g_print("proxy %s found\n",
-					g_dbus_proxy_get_interface(proxy));
+	tester_debug("proxy %s found", g_dbus_proxy_get_interface(proxy));
 
 	g_assert(g_dbus_proxy_set_removed_watch(proxy, proxy_removed, context));
 
@@ -977,7 +864,7 @@ static void proxy_force_disconnect(GDBusProxy *proxy, void *user_data)
 	context->data = NULL;
 }
 
-static void client_force_disconnect(void)
+static void client_force_disconnect(const void *data)
 {
 	struct context *context = create_context();
 	DBusConnection *conn;
@@ -1007,14 +894,6 @@ static void client_force_disconnect(void)
 	g_dbus_client_set_proxy_handlers(context->dbus_client,
 					proxy_force_disconnect, NULL, NULL,
 					context);
-
-	g_main_loop_run(context->main_loop);
-
-	g_dbus_unregister_interface(conn, SERVICE_PATH, SERVICE_NAME1);
-	g_dbus_detach_object_manager(conn);
-	dbus_connection_unref(conn);
-
-	destroy_context(context);
 }
 
 static void client_ready_watch(GDBusClient *client, void *user_data)
@@ -1035,10 +914,10 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
 	 */
 	g_assert(context->client_ready == FALSE);
 
-	g_main_loop_quit(context->main_loop);
+	destroy_context(context);
 }
 
-static void client_ready(void)
+static void client_ready(const void *data)
 {
 	struct context *context = create_context();
 	static const GDBusPropertyTable string_properties[] = {
@@ -1061,53 +940,51 @@ static void client_ready(void)
 								context);
 	g_dbus_client_set_proxy_handlers(context->dbus_client,
 						proxy_added, NULL, NULL, context);
-
-	g_main_loop_run(context->main_loop);
-
-	destroy_context(context);
 }
 
 int main(int argc, char *argv[])
 {
-	g_test_init(&argc, &argv, NULL);
+	tester_init(&argc, &argv);
 
-	g_test_add_func("/gdbus/simple_client", simple_client);
+	tester_add("/gdbus/simple_client", NULL, NULL, simple_client, NULL);
 
-	g_test_add_func("/gdbus/client_connect_disconnect",
-						client_connect_disconnect);
+	tester_add("/gdbus/client_connect_disconnect", NULL, NULL,
+					client_connect_disconnect, NULL);
 
-	g_test_add_func("/gdbus/client_get_string_property",
-						client_get_string_property);
+	tester_add("/gdbus/client_get_string_property", NULL, NULL,
+					client_get_string_property, NULL);
 
-	g_test_add_func("/gdbus/client_get_boolean_property",
-						client_get_boolean_property);
+	tester_add("/gdbus/client_get_boolean_property", NULL, NULL,
+					client_get_boolean_property, NULL);
 
-	g_test_add_func("/gdbus/client_get_uint64_property",
-						client_get_uint64_property);
+	tester_add("/gdbus/client_get_uint64_property", NULL, NULL,
+					client_get_uint64_property, NULL);
 
-	g_test_add_func("/gdbus/client_get_array_property",
-						client_get_array_property);
+	tester_add("/gdbus/client_get_array_property", NULL, NULL,
+					client_get_array_property, NULL);
 
-	g_test_add_func("/gdbus/client_get_dict_property",
-						client_get_dict_property);
+	tester_add("/gdbus/client_get_dict_property", NULL, NULL,
+					client_get_dict_property, NULL);
 
-	g_test_add_func("/gdbus/client_set_string_property",
-						client_set_string_property);
+	tester_add("/gdbus/client_set_string_property", NULL, NULL,
+					client_set_string_property, NULL);
 
-	g_test_add_func("/gdbus/client_string_changed",
-						client_string_changed);
+	tester_add("/gdbus/client_string_changed", NULL, NULL,
+					client_string_changed, NULL);
 
-	g_test_add_func("/gdbus/client_check_order", client_check_order);
+	tester_add("/gdbus/client_check_order", NULL, NULL, client_check_order,
+					NULL);
 
-	g_test_add_func("/gdbus/client_proxy_removed", client_proxy_removed);
+	tester_add("/gdbus/client_proxy_removed", NULL, NULL,
+					client_proxy_removed, NULL);
 
-	g_test_add_func("/gdbus/client_no_object_manager",
-						client_no_object_manager);
+	tester_add("/gdbus/client_no_object_manager", NULL, NULL,
+					client_no_object_manager, NULL);
 
-	g_test_add_func("/gdbus/client_force_disconnect",
-						client_force_disconnect);
+	tester_add("/gdbus/client_force_disconnect", NULL, NULL,
+					client_force_disconnect, NULL);
 
-	g_test_add_func("/gdbus/client_ready", client_ready);
+	tester_add("/gdbus/client_ready", NULL, NULL, client_ready, NULL);
 
-	return g_test_run();
+	return tester_run();
 }
-- 
2.1.0


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

* [PATCH BlueZ 6/9] gdbus: Close private connection if setup fails
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2015-04-10 14:05 ` [PATCH BlueZ 5/9] unit/test-gdbus-client: " Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:05 ` [PATCH BlueZ 7/9] unit/test-gdbus-client: Fix test client_no_object_manager Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

Private connection should be properly closed with dbus_connection_close
otherwise libdbus exits with the following error:

  'The last reference on a connection was dropped without closing the
   connection. This is a bug in an application. See
   dbus_connection_unref() documentation for details. Most likely, the
   application was supposed to call dbus_connection_close(), since this
   is a private connection.'
---
 gdbus/mainloop.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gdbus/mainloop.c b/gdbus/mainloop.c
index 3e88eac..b90a844 100644
--- a/gdbus/mainloop.c
+++ b/gdbus/mainloop.c
@@ -322,6 +322,7 @@ DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
 		return NULL;
 
 	if (setup_bus(conn, name, error) == FALSE) {
+		dbus_connection_close(conn);
 		dbus_connection_unref(conn);
 		return NULL;
 	}
-- 
2.1.0


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

* [PATCH BlueZ 7/9] unit/test-gdbus-client: Fix test client_no_object_manager
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (4 preceding siblings ...)
  2015-04-10 14:05 ` [PATCH BlueZ 6/9] gdbus: Close private connection if setup fails Luiz Augusto von Dentz
@ 2015-04-10 14:05 ` Luiz Augusto von Dentz
  2015-04-10 14:06 ` [PATCH BlueZ 8/9] unit/test-gdbus-client: Fix memory leak Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:05 UTC (permalink / raw)
  To: linux-bluetooth

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

This test creates a second connection without using the one created by
create_context and doesn't disconnect making test client_force_disconnect
fail.
---
 unit/test-gdbus-client.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index 5d8bbf2..51cf8b4 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -811,7 +811,6 @@ static void client_proxy_removed(const void *data)
 static void client_no_object_manager(const void *data)
 {
 	struct context *context = create_context();
-	DBusConnection *conn;
 	DBusMessageIter iter;
 	static const GDBusPropertyTable string_properties[] = {
 		{ "String", "s", get_string, set_string, string_exists },
@@ -821,25 +820,22 @@ static void client_no_object_manager(const void *data)
 	if (context == NULL)
 		return;
 
-	conn = g_dbus_setup_private(DBUS_BUS_SESSION, SERVICE_NAME1, NULL);
-	g_assert(conn != NULL);
-
 	context->data = g_strdup("value");
 
-	g_dbus_register_interface(conn,
-				SERVICE_PATH, SERVICE_NAME1,
+	g_dbus_register_interface(context->dbus_conn,
+				SERVICE_PATH, SERVICE_NAME,
 				methods, signals, string_properties,
 				context, NULL);
 
 	context->dbus_client = g_dbus_client_new_full(context->dbus_conn,
-						SERVICE_NAME1, SERVICE_PATH,
+						SERVICE_NAME, SERVICE_PATH,
 						NULL);
 
 	g_dbus_client_set_disconnect_watch(context->dbus_client,
 						disconnect_handler, context);
 
 	context->proxy = g_dbus_proxy_new(context->dbus_client, SERVICE_PATH,
-								SERVICE_NAME1);
+								SERVICE_NAME);
 
 	g_dbus_client_set_proxy_handlers(context->dbus_client, proxy_get_string,
 						NULL, NULL, context);
-- 
2.1.0


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

* [PATCH BlueZ 8/9] unit/test-gdbus-client: Fix memory leak
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (5 preceding siblings ...)
  2015-04-10 14:05 ` [PATCH BlueZ 7/9] unit/test-gdbus-client: Fix test client_no_object_manager Luiz Augusto von Dentz
@ 2015-04-10 14:06 ` Luiz Augusto von Dentz
  2015-04-10 14:06 ` [PATCH BlueZ 9/9] unit/test-gdbus-client: Fix memory leak on client_no_object_manager Luiz Augusto von Dentz
  2015-04-12 18:58 ` [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:06 UTC (permalink / raw)
  To: linux-bluetooth

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

This fixes leaking DBusConnection created by client_force_disconnect
causing the following trace:

40 bytes in 1 blocks are definitely lost in loss record 501 of 839
   at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x519D9E1: ??? (in /usr/lib64/libdbus-1.so.3.8.11)
   by 0x5191F94: ??? (in /usr/lib64/libdbus-1.so.3.8.11)
   by 0x517AC1A: ??? (in /usr/lib64/libdbus-1.so.3.8.11)
   by 0x517D754: ??? (in /usr/lib64/libdbus-1.so.3.8.11)
   by 0x51790FB: ??? (in /usr/lib64/libdbus-1.so.3.8.11)
   by 0x407739: g_dbus_setup_private (mainloop.c:314)
   by 0x404ECC: client_force_disconnect (test-gdbus-client.c:879)
   by 0x4108B2: run_callback (tester.c:413)
   by 0x4E7E7FA: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x4E7EB97: ??? (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x4E7EEC1: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.4200.2)
---
 unit/test-gdbus-client.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index 51cf8b4..ecbe51e 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -857,6 +857,7 @@ static void proxy_force_disconnect(GDBusProxy *proxy, void *user_data)
 
 	dbus_connection_flush(conn);
 	dbus_connection_close(conn);
+	dbus_connection_unref(conn);
 	context->data = NULL;
 }
 
-- 
2.1.0


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

* [PATCH BlueZ 9/9] unit/test-gdbus-client: Fix memory leak on client_no_object_manager
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (6 preceding siblings ...)
  2015-04-10 14:06 ` [PATCH BlueZ 8/9] unit/test-gdbus-client: Fix memory leak Luiz Augusto von Dentz
@ 2015-04-10 14:06 ` Luiz Augusto von Dentz
  2015-04-12 18:58 ` [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-10 14:06 UTC (permalink / raw)
  To: linux-bluetooth

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

When creating a proxy manually with g_dbus_proxy_new it has to be freed
with g_dbus_proxy_unref otherwise it leaks:

395 (80 direct, 315 indirect) bytes in 1 blocks are definitely lost in loss record 800 of 834
   at 0x4C29BCF: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
   by 0x4E84575: g_try_malloc0 (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x40E244: proxy_new (client.c:411)
   by 0x40F7FD: g_dbus_proxy_new (client.c:485)
   by 0x405844: client_no_object_manager (test-gdbus-client.c:837)
   by 0x410882: run_callback (tester.c:413)
   by 0x4E7E7FA: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x4E7EB97: ??? (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x4E7EEC1: g_main_loop_run (in /usr/lib64/libglib-2.0.so.0.4200.2)
   by 0x411CF1: tester_run (tester.c:831)
   by 0x4045E1: main (test-gdbus-client.c:986)
---
 unit/test-gdbus-client.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/unit/test-gdbus-client.c b/unit/test-gdbus-client.c
index ecbe51e..5a4b974 100644
--- a/unit/test-gdbus-client.c
+++ b/unit/test-gdbus-client.c
@@ -322,6 +322,11 @@ static void proxy_get_string(GDBusProxy *proxy, void *user_data)
 	g_assert(g_dbus_proxy_get_property(proxy, "String", &iter));
 	g_assert(dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_STRING);
 
+	if (context->proxy) {
+		g_assert(context->proxy == proxy);
+		g_dbus_proxy_unref(context->proxy);
+	}
+
 	dbus_message_iter_get_basic(&iter, &string);
 	g_assert_cmpstr(string, ==, "value");
 
-- 
2.1.0


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

* Re: [PATCH BlueZ 1/9] unit/test-crc: Use tester framework
  2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
                   ` (7 preceding siblings ...)
  2015-04-10 14:06 ` [PATCH BlueZ 9/9] unit/test-gdbus-client: Fix memory leak on client_no_object_manager Luiz Augusto von Dentz
@ 2015-04-12 18:58 ` Luiz Augusto von Dentz
  8 siblings, 0 replies; 10+ messages in thread
From: Luiz Augusto von Dentz @ 2015-04-12 18:58 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Fri, Apr 10, 2015 at 5:05 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
>  Makefile.am     |  2 +-
>  unit/test-crc.c | 37 ++++++++++++++++++-------------------
>  2 files changed, 19 insertions(+), 20 deletions(-)
>
> diff --git a/Makefile.am b/Makefile.am
> index 2a1fe76..f9f26aa 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -282,7 +282,7 @@ unit_test_textfile_LDADD = @GLIB_LIBS@
>  unit_tests += unit/test-crc
>
>  unit_test_crc_SOURCES = unit/test-crc.c monitor/crc.h monitor/crc.c
> -unit_test_crc_LDADD = @GLIB_LIBS@
> +unit_test_crc_LDADD = src/libshared-glib.la @GLIB_LIBS@
>
>  unit_tests += unit/test-crypto
>
> diff --git a/unit/test-crc.c b/unit/test-crc.c
> index db40dc9..791fa51 100644
> --- a/unit/test-crc.c
> +++ b/unit/test-crc.c
> @@ -26,6 +26,7 @@
>  #endif
>
>  #include "monitor/crc.h"
> +#include "src/shared/tester.h"
>
>  #include <glib.h>
>
> @@ -160,35 +161,33 @@ static void test_crc(gconstpointer data)
>         crc = crc24_calculate(crc_init, test_data->packet + 4,
>                                                 test_data->size - 7);
>
> -       if (g_test_verbose())
> -               g_print("CRC: 0x%6.6x, Calculated: 0x%6.6x\n",
> -                                               crc_value, crc);
> +       tester_debug("CRC: 0x%6.6x, Calculated: 0x%6.6x", crc_value, crc);
>
>         g_assert(crc_value == crc);
>
>         rev = crc24_reverse(crc_value, test_data->packet + 4,
>                                                 test_data->size - 7);
>
> -       if (g_test_verbose())
> -               g_print("Preset: 0x%6.6x, Calculated: 0x%6.6x\n",
> -                                               crc_init, rev);
> +       tester_debug("Preset: 0x%6.6x, Calculated: 0x%6.6x", crc_init, rev);
>
>         g_assert(crc_init == rev);
> +
> +       tester_test_passed();
>  }
>
>  int main(int argc, char *argv[])
>  {
> -       g_test_init(&argc, &argv, NULL);
> -
> -       g_test_add_data_func("/crc/1", &crc_1, test_crc);
> -       g_test_add_data_func("/crc/2", &crc_2, test_crc);
> -       g_test_add_data_func("/crc/3", &crc_3, test_crc);
> -       g_test_add_data_func("/crc/4", &crc_4, test_crc);
> -       g_test_add_data_func("/crc/5", &crc_5, test_crc);
> -       g_test_add_data_func("/crc/6", &crc_6, test_crc);
> -       g_test_add_data_func("/crc/7", &crc_7, test_crc);
> -       g_test_add_data_func("/crc/8", &crc_8, test_crc);
> -       g_test_add_data_func("/crc/9", &crc_9, test_crc);
> -
> -       return g_test_run();
> +       tester_init(&argc, &argv);
> +
> +       tester_add("/crc/1", &crc_1, NULL, test_crc, NULL);
> +       tester_add("/crc/2", &crc_2, NULL, test_crc, NULL);
> +       tester_add("/crc/3", &crc_3, NULL, test_crc, NULL);
> +       tester_add("/crc/4", &crc_4, NULL, test_crc, NULL);
> +       tester_add("/crc/5", &crc_5, NULL, test_crc, NULL);
> +       tester_add("/crc/6", &crc_6, NULL, test_crc, NULL);
> +       tester_add("/crc/7", &crc_7, NULL, test_crc, NULL);
> +       tester_add("/crc/8", &crc_8, NULL, test_crc, NULL);
> +       tester_add("/crc/9", &crc_9, NULL, test_crc, NULL);
> +
> +       return tester_run();
>  }
> --
> 2.1.0

Applied.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2015-04-12 18:58 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-10 14:05 [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 2/9] unit/test-crypto: " Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 3/9] unit/test-ecc: " Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 4/9] unit/test-eir: " Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 5/9] unit/test-gdbus-client: " Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 6/9] gdbus: Close private connection if setup fails Luiz Augusto von Dentz
2015-04-10 14:05 ` [PATCH BlueZ 7/9] unit/test-gdbus-client: Fix test client_no_object_manager Luiz Augusto von Dentz
2015-04-10 14:06 ` [PATCH BlueZ 8/9] unit/test-gdbus-client: Fix memory leak Luiz Augusto von Dentz
2015-04-10 14:06 ` [PATCH BlueZ 9/9] unit/test-gdbus-client: Fix memory leak on client_no_object_manager Luiz Augusto von Dentz
2015-04-12 18:58 ` [PATCH BlueZ 1/9] unit/test-crc: Use tester framework Luiz Augusto von Dentz

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.