* [PATCH -v3 1/2] rctest: add automated test
@ 2012-08-31 20:50 Gustavo Padovan
2012-08-31 20:50 ` [PATCH -v3 2/2] rctest: add option to save received data to file Gustavo Padovan
2012-10-08 3:50 ` [PATCH -v4 1/2] rctest: add automated test Gustavo Padovan
0 siblings, 2 replies; 6+ messages in thread
From: Gustavo Padovan @ 2012-08-31 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
adds -a option to enable automated tests. We use the -i option to define
the receiving side and the -a define the sending side:
./rctest -i hci0 -a hci1
---
test/rctest.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index f82d2cc..0c645b7 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -55,7 +55,8 @@ enum {
DUMP,
CONNECT,
CRECV,
- LSEND
+ LSEND,
+ AUTO,
};
static unsigned char *buf;
@@ -72,6 +73,7 @@ static unsigned long delay = 0;
/* Default addr and channel */
static bdaddr_t bdaddr;
+static bdaddr_t auto_bdaddr;
static uint16_t uuid = 0x0000;
static uint8_t channel = 10;
@@ -162,7 +164,11 @@ static int do_connect(const char *svr)
/* Bind to local address */
memset(&addr, 0, sizeof(addr));
addr.rc_family = AF_BLUETOOTH;
- bacpy(&addr.rc_bdaddr, &bdaddr);
+
+ if (bacmp(&auto_bdaddr, BDADDR_ANY))
+ bacpy(&addr.rc_bdaddr, &auto_bdaddr);
+ else
+ bacpy(&addr.rc_bdaddr, &bdaddr);
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
syslog(LOG_ERR, "Can't bind socket: %s (%d)",
@@ -591,6 +597,23 @@ static void multi_connect_mode(int argc, char *argv[])
}
}
+static void automated_send_recv()
+{
+ int sk;
+ char device[18];
+
+ if (fork()) {
+ do_listen(recv_mode);
+ } else {
+ ba2str(&bdaddr, device);
+
+ sk = do_connect(device);
+ if (sk < 0)
+ exit(1);
+ send_mode(sk);
+ }
+}
+
static void usage(void)
{
printf("rctest - RFCOMM testing\n"
@@ -604,7 +627,8 @@ static void usage(void)
"\t-u connect and receive\n"
"\t-n connect and be silent\n"
"\t-c connect, disconnect, connect, ...\n"
- "\t-m multiple connects\n");
+ "\t-m multiple connects\n"
+ "\t-a automated test (receive hcix as parameter)\n");
printf("Options:\n"
"\t[-b bytes] [-i device] [-P channel] [-U uuid]\n"
@@ -628,8 +652,9 @@ int main(int argc, char *argv[])
int opt, sk, mode = RECV, need_addr = 0;
bacpy(&bdaddr, BDADDR_ANY);
+ bacpy(&auto_bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -668,6 +693,15 @@ int main(int argc, char *argv[])
need_addr = 1;
break;
+ case 'a':
+ mode = AUTO;
+
+ if (!strncasecmp(optarg, "hci", 3))
+ hci_devba(atoi(optarg + 3), &auto_bdaddr);
+ else
+ str2ba(optarg, &auto_bdaddr);
+ break;
+
case 'b':
data_size = atoi(optarg);
break;
@@ -804,6 +838,10 @@ int main(int argc, char *argv[])
exit(1);
dump_mode(sk);
break;
+
+ case AUTO:
+ automated_send_recv();
+ break;
}
syslog(LOG_INFO, "Exit");
--
1.7.11.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -v3 2/2] rctest: add option to save received data to file
2012-08-31 20:50 [PATCH -v3 1/2] rctest: add automated test Gustavo Padovan
@ 2012-08-31 20:50 ` Gustavo Padovan
2012-09-03 12:01 ` Johan Hedberg
2012-10-08 3:50 ` [PATCH -v4 1/2] rctest: add automated test Gustavo Padovan
1 sibling, 1 reply; 6+ messages in thread
From: Gustavo Padovan @ 2012-08-31 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
works only for automated test option for now
---
test/rctest.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 54 insertions(+), 3 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index 0c645b7..57d092a 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -78,6 +78,8 @@ static uint16_t uuid = 0x0000;
static uint8_t channel = 10;
static char *filename = NULL;
+static char *savefile = NULL;
+static int save_fd = -1;
static int master = 0;
static int auth = 0;
@@ -448,6 +450,25 @@ static void dump_mode(int sk)
syslog(LOG_INFO, "Received %d bytes", len);
}
+static void save_mode(int sk)
+{
+ int len, ret;
+ char *b;
+
+ b = malloc(data_size);
+ if (!b) {
+ syslog(LOG_ERR, "Failed to open file to save recv data");
+ return;
+ }
+
+ syslog(LOG_INFO, "Receiving ...");
+ while ((len = read(sk, b, data_size)) > 0) {
+ ret = write(save_fd, b, len);
+ if (ret < 0)
+ return;
+ }
+}
+
static void recv_mode(int sk)
{
struct timeval tv_beg, tv_end, tv_diff;
@@ -603,7 +624,20 @@ static void automated_send_recv()
char device[18];
if (fork()) {
- do_listen(recv_mode);
+ if (!savefile) {
+ do_listen(recv_mode);
+ return;
+ }
+
+ save_fd = open(savefile, O_CREAT | O_WRONLY,
+ S_IRUSR | S_IWUSR);
+ if (save_fd < 0)
+ syslog(LOG_ERR, "Failed to open file to save "
+ "recv data");
+
+ do_listen(save_mode);
+
+ close(save_fd);
} else {
ba2str(&bdaddr, device);
@@ -614,6 +648,15 @@ static void automated_send_recv()
}
}
+static void sig_child_exit(int code)
+{
+ syslog(LOG_INFO, "Exit");
+ exit(0);
+
+ if (save_fd >= 0)
+ close(save_fd);
+}
+
static void usage(void)
{
printf("rctest - RFCOMM testing\n"
@@ -635,6 +678,7 @@ static void usage(void)
"\t[-L seconds] enabled SO_LINGER option\n"
"\t[-W seconds] enable deferred setup\n"
"\t[-B filename] use data packets from file\n"
+ "\t[-O filename] save received data to file\n"
"\t[-N num] number of frames to send\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
@@ -654,7 +698,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
bacpy(&auto_bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:O:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -754,6 +798,10 @@ int main(int argc, char *argv[])
filename = strdup(optarg);
break;
+ case 'O':
+ savefile = strdup(optarg);
+ break;
+
case 'N':
num_frames = atoi(optarg);
break;
@@ -791,7 +839,10 @@ int main(int argc, char *argv[])
}
memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_IGN;
+ if (mode == AUTO)
+ sa.sa_handler = sig_child_exit;
+ else
+ sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_NOCLDSTOP;
sigaction(SIGCHLD, &sa, NULL);
--
1.7.11.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH -v3 2/2] rctest: add option to save received data to file
2012-08-31 20:50 ` [PATCH -v3 2/2] rctest: add option to save received data to file Gustavo Padovan
@ 2012-09-03 12:01 ` Johan Hedberg
0 siblings, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2012-09-03 12:01 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: linux-bluetooth, Gustavo Padovan
Hi Gustavo,
On Fri, Aug 31, 2012, Gustavo Padovan wrote:
> + if (save_fd < 0)
> + syslog(LOG_ERR, "Failed to open file to save "
> + "recv data");
Please don't split strings like this if not necessary. It makes greping
harder (you see something in the command output and try to locate it in
the source). Split after "LOG_ERR," instead.
> +static void sig_child_exit(int code)
> +{
> + syslog(LOG_INFO, "Exit");
> + exit(0);
> +
> + if (save_fd >= 0)
> + close(save_fd);
> +}
This doesn't look right as nothing after the exit() call will get
executed. I suppose you meant to ahve the save_fd closing before the
exit call?
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH -v4 1/2] rctest: add automated test
2012-08-31 20:50 [PATCH -v3 1/2] rctest: add automated test Gustavo Padovan
2012-08-31 20:50 ` [PATCH -v3 2/2] rctest: add option to save received data to file Gustavo Padovan
@ 2012-10-08 3:50 ` Gustavo Padovan
2012-10-08 3:50 ` [PATCH -v4 2/2] rctest: add option to save received data to file Gustavo Padovan
2012-10-12 14:58 ` [PATCH -v4 1/2] rctest: add automated test Johan Hedberg
1 sibling, 2 replies; 6+ messages in thread
From: Gustavo Padovan @ 2012-10-08 3:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
adds -a option to enable automated tests. We use the -i option to define
the receiving side and the -a define the sending side:
./rctest -i hci0 -a hci1
---
test/rctest.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index 2dd54de..d19e096 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -55,7 +55,8 @@ enum {
DUMP,
CONNECT,
CRECV,
- LSEND
+ LSEND,
+ AUTO,
};
static unsigned char *buf;
@@ -72,6 +73,7 @@ static unsigned long delay = 0;
/* Default addr and channel */
static bdaddr_t bdaddr;
+static bdaddr_t auto_bdaddr;
static uint16_t uuid = 0x0000;
static uint8_t channel = 10;
@@ -162,7 +164,11 @@ static int do_connect(const char *svr)
/* Bind to local address */
memset(&addr, 0, sizeof(addr));
addr.rc_family = AF_BLUETOOTH;
- bacpy(&addr.rc_bdaddr, &bdaddr);
+
+ if (bacmp(&auto_bdaddr, BDADDR_ANY))
+ bacpy(&addr.rc_bdaddr, &auto_bdaddr);
+ else
+ bacpy(&addr.rc_bdaddr, &bdaddr);
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
syslog(LOG_ERR, "Can't bind socket: %s (%d)",
@@ -592,6 +598,23 @@ static void multi_connect_mode(int argc, char *argv[])
}
}
+static void automated_send_recv()
+{
+ int sk;
+ char device[18];
+
+ if (fork()) {
+ do_listen(recv_mode);
+ } else {
+ ba2str(&bdaddr, device);
+
+ sk = do_connect(device);
+ if (sk < 0)
+ exit(1);
+ send_mode(sk);
+ }
+}
+
static void usage(void)
{
printf("rctest - RFCOMM testing\n"
@@ -605,7 +628,8 @@ static void usage(void)
"\t-u connect and receive\n"
"\t-n connect and be silent\n"
"\t-c connect, disconnect, connect, ...\n"
- "\t-m multiple connects\n");
+ "\t-m multiple connects\n"
+ "\t-a automated test (receive hcix as parameter)\n");
printf("Options:\n"
"\t[-b bytes] [-i device] [-P channel] [-U uuid]\n"
@@ -629,8 +653,9 @@ int main(int argc, char *argv[])
int opt, sk, mode = RECV, need_addr = 0;
bacpy(&bdaddr, BDADDR_ANY);
+ bacpy(&auto_bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmnb:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -669,6 +694,15 @@ int main(int argc, char *argv[])
need_addr = 1;
break;
+ case 'a':
+ mode = AUTO;
+
+ if (!strncasecmp(optarg, "hci", 3))
+ hci_devba(atoi(optarg + 3), &auto_bdaddr);
+ else
+ str2ba(optarg, &auto_bdaddr);
+ break;
+
case 'b':
data_size = atoi(optarg);
break;
@@ -805,6 +839,10 @@ int main(int argc, char *argv[])
exit(1);
dump_mode(sk);
break;
+
+ case AUTO:
+ automated_send_recv();
+ break;
}
syslog(LOG_INFO, "Exit");
--
1.7.11.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -v4 2/2] rctest: add option to save received data to file
2012-10-08 3:50 ` [PATCH -v4 1/2] rctest: add automated test Gustavo Padovan
@ 2012-10-08 3:50 ` Gustavo Padovan
2012-10-12 14:58 ` [PATCH -v4 1/2] rctest: add automated test Johan Hedberg
1 sibling, 0 replies; 6+ messages in thread
From: Gustavo Padovan @ 2012-10-08 3:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Gustavo Padovan
From: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
works only for automated test option for now
---
test/rctest.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 53 insertions(+), 3 deletions(-)
diff --git a/test/rctest.c b/test/rctest.c
index d19e096..ac341b0 100644
--- a/test/rctest.c
+++ b/test/rctest.c
@@ -78,6 +78,8 @@ static uint16_t uuid = 0x0000;
static uint8_t channel = 10;
static char *filename = NULL;
+static char *savefile = NULL;
+static int save_fd = -1;
static int master = 0;
static int auth = 0;
@@ -448,6 +450,25 @@ static void dump_mode(int sk)
syslog(LOG_INFO, "Received %d bytes", len);
}
+static void save_mode(int sk)
+{
+ int len, ret;
+ char *b;
+
+ b = malloc(data_size);
+ if (!b) {
+ syslog(LOG_ERR, "Failed to open file to save recv data");
+ return;
+ }
+
+ syslog(LOG_INFO, "Receiving ...");
+ while ((len = read(sk, b, data_size)) > 0) {
+ ret = write(save_fd, b, len);
+ if (ret < 0)
+ return;
+ }
+}
+
static void recv_mode(int sk)
{
struct timeval tv_beg, tv_end, tv_diff;
@@ -604,7 +625,19 @@ static void automated_send_recv()
char device[18];
if (fork()) {
- do_listen(recv_mode);
+ if (!savefile) {
+ do_listen(recv_mode);
+ return;
+ }
+
+ save_fd = open(savefile, O_CREAT | O_WRONLY,
+ S_IRUSR | S_IWUSR);
+ if (save_fd < 0)
+ syslog(LOG_ERR, "Failed to open file to save data");
+
+ do_listen(save_mode);
+
+ close(save_fd);
} else {
ba2str(&bdaddr, device);
@@ -615,6 +648,15 @@ static void automated_send_recv()
}
}
+static void sig_child_exit(int code)
+{
+ if (save_fd >= 0)
+ close(save_fd);
+
+ syslog(LOG_INFO, "Exit");
+ exit(0);
+}
+
static void usage(void)
{
printf("rctest - RFCOMM testing\n"
@@ -636,6 +678,7 @@ static void usage(void)
"\t[-L seconds] enabled SO_LINGER option\n"
"\t[-W seconds] enable deferred setup\n"
"\t[-B filename] use data packets from file\n"
+ "\t[-O filename] save received data to file\n"
"\t[-N num] number of frames to send\n"
"\t[-C num] send num frames before delay (default = 1)\n"
"\t[-D milliseconds] delay after sending num frames (default = 0)\n"
@@ -655,7 +698,7 @@ int main(int argc, char *argv[])
bacpy(&bdaddr, BDADDR_ANY);
bacpy(&auto_bdaddr, BDADDR_ANY);
- while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:N:MAESL:W:C:D:Y:T")) != EOF) {
+ while ((opt=getopt(argc,argv,"rdscuwmna:b:i:P:U:B:O:N:MAESL:W:C:D:Y:T")) != EOF) {
switch (opt) {
case 'r':
mode = RECV;
@@ -755,6 +798,10 @@ int main(int argc, char *argv[])
filename = strdup(optarg);
break;
+ case 'O':
+ savefile = strdup(optarg);
+ break;
+
case 'N':
num_frames = atoi(optarg);
break;
@@ -792,7 +839,10 @@ int main(int argc, char *argv[])
}
memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_IGN;
+ if (mode == AUTO)
+ sa.sa_handler = sig_child_exit;
+ else
+ sa.sa_handler = SIG_IGN;
sa.sa_flags = SA_NOCLDSTOP;
sigaction(SIGCHLD, &sa, NULL);
--
1.7.11.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH -v4 1/2] rctest: add automated test
2012-10-08 3:50 ` [PATCH -v4 1/2] rctest: add automated test Gustavo Padovan
2012-10-08 3:50 ` [PATCH -v4 2/2] rctest: add option to save received data to file Gustavo Padovan
@ 2012-10-12 14:58 ` Johan Hedberg
1 sibling, 0 replies; 6+ messages in thread
From: Johan Hedberg @ 2012-10-12 14:58 UTC (permalink / raw)
To: Gustavo Padovan; +Cc: linux-bluetooth, Gustavo Padovan
Hi Gustavo,
On Mon, Oct 08, 2012, Gustavo Padovan wrote:
> adds -a option to enable automated tests. We use the -i option to define
> the receiving side and the -a define the sending side:
>
> ./rctest -i hci0 -a hci1
> ---
> test/rctest.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 42 insertions(+), 4 deletions(-)
Both patches have been applied. Thanks.
Johan
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-10-12 14:58 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-31 20:50 [PATCH -v3 1/2] rctest: add automated test Gustavo Padovan
2012-08-31 20:50 ` [PATCH -v3 2/2] rctest: add option to save received data to file Gustavo Padovan
2012-09-03 12:01 ` Johan Hedberg
2012-10-08 3:50 ` [PATCH -v4 1/2] rctest: add automated test Gustavo Padovan
2012-10-08 3:50 ` [PATCH -v4 2/2] rctest: add option to save received data to file Gustavo Padovan
2012-10-12 14:58 ` [PATCH -v4 1/2] rctest: add automated test Johan Hedberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).