From 4278c4b5fb1feb9e0011190c5e1c5c860a7afe99 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Fri, 13 Nov 2020 15:07:03 -0800 Subject: [PATCH] test-runner: Add option to start monitor This adds an option (-m/--monitor) to start btmon before the command running the command/tester which is convenient when a tests results in HCI traffic which are decoded by hciemu as it only prints the hexdump. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- tools/test-runner.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index c8b94f5..d035bd3 100755 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -46,6 +46,7 @@ static int test_argc; static bool run_auto = false; static bool start_dbus = false; +static bool start_monitor = false; static int num_devs = 0; static const char *qemu_binary = NULL; static const char *kernel_image = NULL; @@ -244,9 +245,10 @@ static void start_qemu(void) "rootfstype=9p " "rootflags=trans=virtio,version=9p2000.L " "acpi=off pci=noacpi noapic quiet ro init=%s " - "TESTHOME=%s TESTDBUS=%u TESTDEVS=%d " - "TESTAUTO=%u TESTARGS=\'%s\'", initcmd, cwd, - start_dbus, num_devs, run_auto, testargs); + "TESTHOME=%s TESTDBUS=%u TESTMONITOR=%u " + "TESTDEVS=%d TESTAUTO=%u TESTARGS=\'%s\'", + initcmd, cwd, start_dbus, start_monitor, + num_devs, run_auto, testargs); argv = alloca(sizeof(qemu_argv) + (sizeof(char *) * (4 + (num_devs * 4)))); @@ -531,6 +533,63 @@ static const char *test_table[] = { NULL }; +static const char *monitor_table[] = { + "btmon", + "monitor/btmon", + "/usr/sbin/btmon", + NULL +}; + +static pid_t start_btmon(const char *home) +{ + const char *monitor = NULL; + char *argv[3], *envp[2]; + pid_t pid; + int i; + + if (chdir(home + 5) < 0) { + perror("Failed to change home directory for monitor"); + return -1; + } + + for (i = 0; monitor_table[i]; i++) { + struct stat st; + + if (!stat(monitor_table[i], &st)) { + monitor = monitor_table[i]; + break; + } + } + + if (!monitor) { + fprintf(stderr, "Failed to locate Monitor binary\n"); + return -1; + } + + printf("Using Monitor %s\n", monitor); + + argv[0] = (char *) monitor; + argv[1] = "-t"; + argv[2] = NULL; + + printf("Starting Monitor\n"); + + pid = fork(); + if (pid < 0) { + perror("Failed to fork new process"); + return -1; + } + + if (pid == 0) { + execve(argv[0], argv, envp); + exit(EXIT_SUCCESS); + } + + printf("Monitor process %d created\n", pid); + + return pid; +} + static void run_command(char *cmdname, char *home) { #ifdef TIZEN_FEATURE_BLUEZ_MODIFY @@ -540,7 +599,7 @@ static void run_command(char *cmdname, char *home) #endif int pos = 0, idx = 0; int serial_fd; - pid_t pid, dbus_pid, daemon_pid; + pid_t pid, dbus_pid, daemon_pid, monitor_pid; if (num_devs) { const char *node = "/dev/ttyS1"; @@ -565,6 +624,11 @@ static void run_command(char *cmdname, char *home) daemon_pid = -1; } + if (start_monitor) + monitor_pid = start_btmon(home); + else + monitor_pid = -1; + start_next: if (run_auto) { if (chdir(home + 5) < 0) { @@ -665,12 +729,19 @@ start_next: daemon_pid = -1; } + if (corpse == monitor_pid) { + printf("Bluetooth monitor terminated\n"); + monitor_pid = -1; + } + if (corpse == pid) { if (!run_auto) { if (daemon_pid > 0) kill(daemon_pid, SIGTERM); if (dbus_pid > 0) kill(dbus_pid, SIGTERM); + if (monitor_pid > 0) + kill(monitor_pid, SIGTERM); } break; } @@ -739,6 +810,12 @@ static void run_tests(void) start_dbus = true; } + ptr = strstr(cmdline, "TESTMONITOR=1"); + if (ptr) { + printf("Monitor requested\n"); + start_monitor = true; + } + ptr = strstr(cmdline, "TESTHOME="); if (ptr) { home = ptr + 4; @@ -758,6 +835,7 @@ static void usage(void) printf("Options:\n" "\t-a, --auto Find tests and run them\n" "\t-d, --dbus Start D-Bus daemon\n" + "\t-m, --monitor Start btmon\n" "\t-u, --unix [path] Provide serial device\n" "\t-q, --qemu QEMU binary\n" "\t-k, --kernel Kernel image (bzImage)\n" @@ -769,6 +847,7 @@ static const struct option main_options[] = { { "auto", no_argument, NULL, 'a' }, { "unix", no_argument, NULL, 'u' }, { "dbus", no_argument, NULL, 'd' }, + { "monitor", no_argument, NULL, 'm' }, { "qemu", required_argument, NULL, 'q' }, { "kernel", required_argument, NULL, 'k' }, { "version", no_argument, NULL, 'v' }, @@ -790,7 +869,7 @@ int main(int argc, char *argv[]) for (;;) { int opt; - opt = getopt_long(argc, argv, "audq:k:vh", main_options, NULL); + opt = getopt_long(argc, argv, "audmq:k:vh", main_options, NULL); if (opt < 0) break; @@ -804,6 +883,9 @@ int main(int argc, char *argv[]) case 'd': start_dbus = true; break; + case 'm': + start_monitor = true; + break; case 'q': qemu_binary = optarg; break; -- 2.7.4