All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tools/rfcomm-tester: Add bind after connected test case
@ 2014-02-13 14:11 Andrzej Kaczmarek
  2014-02-20  7:40 ` Andrzej Kaczmarek
  2014-03-03 14:52 ` Johan Hedberg
  0 siblings, 2 replies; 3+ messages in thread
From: Andrzej Kaczmarek @ 2014-02-13 14:11 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

This testcase will check if it's possible to bind socket on the same
channel number as used by some other socket connected to remote device.
---
 tools/rfcomm-tester.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c
index 44df7e7..c6aa8c7 100644
--- a/tools/rfcomm-tester.c
+++ b/tools/rfcomm-tester.c
@@ -56,6 +56,7 @@ struct test_data {
 struct rfcomm_client_data {
 	uint8_t server_channel;
 	uint8_t client_channel;
+	uint8_t bind_channel;
 	int expected_connect_err;
 };
 
@@ -300,6 +301,12 @@ const struct rfcomm_client_data connect_nval = {
 	.expected_connect_err = -ECONNREFUSED
 };
 
+const struct rfcomm_client_data connect_bind_success = {
+	.server_channel = 0x0c,
+	.client_channel = 0x0c,
+	.bind_channel = 0x0c
+};
+
 const struct rfcomm_server_data listen_success = {
 	.server_channel = 0x0c,
 	.client_channel = 0x0c,
@@ -371,6 +378,7 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond,
 {
 	struct test_data *data = tester_get_data();
 	const struct rfcomm_client_data *client_data = data->test_data;
+	const uint8_t *master_addr;
 	socklen_t len = sizeof(int);
 	int sk, err, sk_err;
 
@@ -389,10 +397,24 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond,
 		return false;
 	}
 
-	if (err < 0)
+	if (!client_data->bind_channel) {
+		if (err < 0)
+			tester_test_failed();
+		else
+			tester_test_passed();
+		return false;
+	}
+
+	master_addr = hciemu_get_master_bdaddr(data->hciemu);
+	sk = create_rfcomm_sock((bdaddr_t *) master_addr,
+						client_data->bind_channel);
+	if (sk < 0) {
 		tester_test_failed();
-	else
+	} else {
+		close(sk);
 		tester_test_passed();
+	}
+
 
 	return false;
 }
@@ -546,6 +568,9 @@ int main(int argc, char *argv[])
 					setup_powered_server, test_server);
 	test_rfcomm("Basic RFCOMM Socket Server - Conn Refused", &listen_nval,
 					setup_powered_server, test_server);
+	test_rfcomm("Basic RFCOMM Socket Server - Bind Connected",
+			&connect_bind_success, setup_powered_client,
+								test_connect);
 
 	return tester_run();
 }
-- 
1.8.5.4


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

* Re: [PATCH] tools/rfcomm-tester: Add bind after connected test case
  2014-02-13 14:11 [PATCH] tools/rfcomm-tester: Add bind after connected test case Andrzej Kaczmarek
@ 2014-02-20  7:40 ` Andrzej Kaczmarek
  2014-03-03 14:52 ` Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Andrzej Kaczmarek @ 2014-02-20  7:40 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On 13 February 2014 15:11, Andrzej Kaczmarek
<andrzej.kaczmarek@tieto.com> wrote:
> This testcase will check if it's possible to bind socket on the same
> channel number as used by some other socket connected to remote device.

ping...?

BR,
Andrzej

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

* Re: [PATCH] tools/rfcomm-tester: Add bind after connected test case
  2014-02-13 14:11 [PATCH] tools/rfcomm-tester: Add bind after connected test case Andrzej Kaczmarek
  2014-02-20  7:40 ` Andrzej Kaczmarek
@ 2014-03-03 14:52 ` Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2014-03-03 14:52 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth

Hi Andrzej,

On Thu, Feb 13, 2014, Andrzej Kaczmarek wrote:
> This testcase will check if it's possible to bind socket on the same
> channel number as used by some other socket connected to remote device.
> ---
>  tools/rfcomm-tester.c | 29 +++++++++++++++++++++++++++--
>  1 file changed, 27 insertions(+), 2 deletions(-)

Sorry for not getting around to this one earlier.

> @@ -389,10 +397,24 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond,
>  		return false;
>  	}
>  
> -	if (err < 0)
> +	if (!client_data->bind_channel) {
> +		if (err < 0)
> +			tester_test_failed();
> +		else
> +			tester_test_passed();
> +		return false;
> +	}
> +
> +	master_addr = hciemu_get_master_bdaddr(data->hciemu);
> +	sk = create_rfcomm_sock((bdaddr_t *) master_addr,
> +						client_data->bind_channel);
> +	if (sk < 0) {
>  		tester_test_failed();
> -	else
> +	} else {
> +		close(sk);
>  		tester_test_passed();
> +	}
> +
>  
>  	return false;
>  }

Considering that rc_connect_cb is a generic function used by many test
cases I find it strange to add this much extra code for it for a single
special case which is only needed by a single test case. I'd rather have
this in a separate function.

Either reuse the existing test_connect() and add a way to specify (in
the test case declaration) a custom function to pass to g_io_add_watch()
or then create completely new test function from scratch. This will help
avoid confusion when someone tries to understand what all the other
tests which do not need this extra hack are trying to do.

Johan

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

end of thread, other threads:[~2014-03-03 14:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-02-13 14:11 [PATCH] tools/rfcomm-tester: Add bind after connected test case Andrzej Kaczmarek
2014-02-20  7:40 ` Andrzej Kaczmarek
2014-03-03 14:52 ` Johan Hedberg

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.