From: Gustavo Padovan <gustavo@padovan.org>
To: linux-bluetooth@vger.kernel.org
Cc: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Subject: [PATCH 1/2] rctest: add automated test
Date: Thu, 30 Aug 2012 11:32:27 -0700 [thread overview]
Message-ID: <1346351548-5056-1-git-send-email-gustavo@padovan.org> (raw)
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
next reply other threads:[~2012-08-30 18:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-30 18:32 Gustavo Padovan [this message]
2012-08-30 18:32 ` [PATCH 2/2] rctest: add option to save received data to file Gustavo Padovan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346351548-5056-1-git-send-email-gustavo@padovan.org \
--to=gustavo@padovan.org \
--cc=gustavo.padovan@collabora.co.uk \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox