summaryrefslogtreecommitdiff
path: root/mesh/main.c
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2021-03-19 13:38:24 -0700
committerBrian Gix <brian.gix@intel.com>2021-04-10 10:28:14 -0700
commitc4cfcf085ce40af2e90f44f47eff333ef2f670a9 (patch)
tree04fec0b5d714c3a5edb09ee9d9112f1ee1c01d26 /mesh/main.c
parent9be85f867856195e16c9b94b605f65f6389eda33 (diff)
downloadbluez-c4cfcf085ce40af2e90f44f47eff333ef2f670a9.tar.gz
mesh: Add unit test IO
This adds a new type of mesh IO that is used for non-interactive testing. The new io option can be specified on command line as: --io unit:<socket_name> When the bluetooth-meshd daemon starts with the "unit" IO type, the daemon opens a socket (fd to open is provided after "unit:" in <socket_name>). The communication with the daemon is done either through the loop-back using mesh DBus-based APIs or the specified named socket.
Diffstat (limited to 'mesh/main.c')
-rw-r--r--mesh/main.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/mesh/main.c b/mesh/main.c
index 4356e3f65..1b466598b 100644
--- a/mesh/main.c
+++ b/mesh/main.c
@@ -61,7 +61,7 @@ static void usage(void)
"\t--help Show %s information\n", __func__);
fprintf(stderr,
"io:\n"
- "\t([hci]<index> | generic[:[hci]<index>])\n"
+ "\t([hci]<index> | generic[:[hci]<index>] | unit:<fd_path>)\n"
"\t\tUse generic HCI io on interface hci<index>, or the first\n"
"\t\tavailable one\n");
}
@@ -77,6 +77,7 @@ static void mesh_ready_callback(void *user_data, bool success)
{
struct l_dbus *dbus = user_data;
+ l_info("mesh_ready_callback");
if (!success) {
l_error("Failed to start mesh");
l_main_quit();
@@ -92,10 +93,8 @@ static void mesh_ready_callback(void *user_data, bool success)
static void request_name_callback(struct l_dbus *dbus, bool success,
bool queued, void *user_data)
{
- l_info("Request name %s",
- success ? "success": "failed");
-
- if (!success) {
+ if (!success && io_type != MESH_IO_TYPE_UNIT_TEST) {
+ l_info("Request name failed");
l_main_quit();
return;
}
@@ -159,6 +158,21 @@ static bool parse_io(const char *optarg, enum mesh_io_type *type, void **opts)
return true;
return false;
+
+ } else if (strstr(optarg, "unit") == optarg) {
+ char *test_path;
+
+ *type = MESH_IO_TYPE_UNIT_TEST;
+
+ optarg += strlen("unit");
+ if (*optarg != ':')
+ return false;
+
+ optarg++;
+ test_path = strdup(optarg);
+
+ *opts = test_path;
+ return true;
}
return false;
@@ -187,11 +201,19 @@ int main(int argc, char *argv[])
for (;;) {
int opt;
- opt = getopt_long(argc, argv, "i:s:c:ndbh", main_options, NULL);
+ opt = getopt_long(argc, argv, "u:i:s:c:ndbh", main_options,
+ NULL);
if (opt < 0)
break;
switch (opt) {
+ case 'u':
+ if (sscanf(optarg, "%d", &hci_index) == 1 ||
+ sscanf(optarg, "%d", &hci_index) == 1)
+ io = l_strdup_printf("unit:%d", hci_index);
+ else
+ io = l_strdup(optarg);
+ break;
case 'i':
if (sscanf(optarg, "hci%d", &hci_index) == 1 ||
sscanf(optarg, "%d", &hci_index) == 1)
@@ -261,11 +283,8 @@ int main(int argc, char *argv[])
status = l_main_run_with_signal(signal_handler, NULL);
done:
- if (io)
- l_free(io);
-
- if (io_opts)
- l_free(io_opts);
+ l_free(io);
+ l_free(io_opts);
mesh_cleanup();
l_dbus_destroy(dbus);