All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] test-runner: Add option to start emulator
@ 2022-02-28 23:27 Luiz Augusto von Dentz
  2022-03-01  0:35 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2022-02-28 23:27 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds an option (-l/--emulator) to start btvirt before processing
the command which is convenient to runs tools like bluetoothctl:

  sudo tools/test-runner -l -d -k <pathto/bzImage> --
  client/bluetoothctl power on
---
 tools/test-runner.c | 86 ++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 82 insertions(+), 4 deletions(-)

diff --git a/tools/test-runner.c b/tools/test-runner.c
index 71cc0d2df..e0e002dd6 100644
--- a/tools/test-runner.c
+++ b/tools/test-runner.c
@@ -47,6 +47,7 @@ static int test_argc;
 
 static bool run_auto = false;
 static bool start_dbus = false;
+static bool start_emulator = false;
 static bool start_monitor = false;
 static int num_devs = 0;
 static const char *qemu_binary = NULL;
@@ -249,9 +250,10 @@ static void start_qemu(void)
 				"acpi=off pci=noacpi noapic quiet ro init=%s "
 				"bluetooth.enable_ecred=1"
 				"TESTHOME=%s TESTDBUS=%u TESTMONITOR=%u "
-				"TESTDEVS=%d TESTAUTO=%u TESTARGS=\'%s\'",
+				"TESTEMULATOR=%u TESTDEVS=%d TESTAUTO=%u "
+				"TESTARGS=\'%s\'",
 				initcmd, cwd, start_dbus, start_monitor,
-				num_devs, run_auto, testargs);
+				start_emulator, num_devs, run_auto, testargs);
 
 	argv = alloca(sizeof(qemu_argv) +
 				(sizeof(char *) * (4 + (num_devs * 4))));
@@ -600,12 +602,64 @@ static pid_t start_btmon(const char *home)
 	return pid;
 }
 
+static const char *btvirt_table[] = {
+	"btvirt",
+	"emulator/btvirt",
+	"/usr/sbin/btvirt",
+	NULL
+};
+
+static pid_t start_btvirt(void)
+{
+	const char *btvirt = NULL;
+	char *argv[3], *envp[2];
+	pid_t pid;
+	int i;
+
+	for (i = 0; btvirt_table[i]; i++) {
+		struct stat st;
+
+		if (!stat(btvirt_table[i], &st)) {
+			btvirt = btvirt_table[i];
+			break;
+		}
+	}
+
+	if (!btvirt) {
+		fprintf(stderr, "Failed to locate btvirt binary\n");
+		return -1;
+	}
+
+	printf("Using %s\n", btvirt);
+
+	argv[0] = (char *) btvirt;
+	argv[1] = "-l";
+	argv[2] = NULL;
+
+	printf("Starting Emulator\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("Emulator process %d created\n", pid);
+
+	return pid;
+}
+
 static void run_command(char *cmdname, char *home)
 {
 	char *argv[9], *envp[3];
 	int pos = 0, idx = 0;
 	int serial_fd;
-	pid_t pid, dbus_pid, daemon_pid, monitor_pid;
+	pid_t pid, dbus_pid, daemon_pid, monitor_pid, emulator_pid;
 
 	if (num_devs) {
 		const char *node = "/dev/ttyS1";
@@ -635,6 +689,11 @@ static void run_command(char *cmdname, char *home)
 	else
 		monitor_pid = -1;
 
+	if (start_emulator)
+		emulator_pid = start_btvirt();
+	else
+		emulator_pid = -1;
+
 start_next:
 	if (run_auto) {
 		if (chdir(home + 5) < 0) {
@@ -735,6 +794,11 @@ start_next:
 			daemon_pid = -1;
 		}
 
+		if (corpse == emulator_pid) {
+			printf("Bluetooth emulator terminated\n");
+			emulator_pid = -1;
+		}
+
 		if (corpse == monitor_pid) {
 			printf("Bluetooth monitor terminated\n");
 			monitor_pid = -1;
@@ -755,6 +819,9 @@ start_next:
 	if (dbus_pid > 0)
 		kill(dbus_pid, SIGTERM);
 
+	if (emulator_pid > 0)
+		kill(dbus_pid, SIGTERM);
+
 	if (monitor_pid > 0)
 		kill(monitor_pid, SIGTERM);
 
@@ -822,6 +889,12 @@ static void run_tests(void)
 		start_monitor = true;
 	}
 
+	ptr = strstr(cmdline, "TESTEMULATOR=1");
+	if (ptr) {
+		printf("Emulator requested\n");
+		start_emulator = true;
+	}
+
 	ptr = strstr(cmdline, "TESTHOME=");
 	if (ptr) {
 		home = ptr + 4;
@@ -853,6 +926,7 @@ static const struct option main_options[] = {
 	{ "auto",    no_argument,       NULL, 'a' },
 	{ "unix",    no_argument,       NULL, 'u' },
 	{ "dbus",    no_argument,       NULL, 'd' },
+	{ "emulator", no_argument,      NULL, 'l' },
 	{ "monitor", no_argument,       NULL, 'm' },
 	{ "qemu",    required_argument, NULL, 'q' },
 	{ "kernel",  required_argument, NULL, 'k' },
@@ -875,7 +949,8 @@ int main(int argc, char *argv[])
 	for (;;) {
 		int opt;
 
-		opt = getopt_long(argc, argv, "audmq:k:vh", main_options, NULL);
+		opt = getopt_long(argc, argv, "audlmq:k:vh", main_options,
+								NULL);
 		if (opt < 0)
 			break;
 
@@ -889,6 +964,9 @@ int main(int argc, char *argv[])
 		case 'd':
 			start_dbus = true;
 			break;
+		case 'l':
+			start_emulator = true;
+			break;
 		case 'm':
 			start_monitor = true;
 			break;
-- 
2.35.1


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

* RE: [BlueZ] test-runner: Add option to start emulator
  2022-02-28 23:27 [PATCH BlueZ] test-runner: Add option to start emulator Luiz Augusto von Dentz
@ 2022-03-01  0:35 ` bluez.test.bot
  2022-03-02 23:22   ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 3+ messages in thread
From: bluez.test.bot @ 2022-03-01  0:35 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 2088 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=618913

---Test result---

Test Summary:
CheckPatch                    FAIL      1.54 seconds
GitLint                       PASS      1.05 seconds
Prep - Setup ELL              PASS      43.02 seconds
Build - Prep                  PASS      0.74 seconds
Build - Configure             PASS      8.82 seconds
Build - Make                  PASS      1440.03 seconds
Make Check                    PASS      11.46 seconds
Make Check w/Valgrind         PASS      446.11 seconds
Make Distcheck                PASS      231.77 seconds
Build w/ext ELL - Configure   PASS      8.81 seconds
Build w/ext ELL - Make        PASS      1433.12 seconds
Incremental Build with patchesPASS      0.00 seconds

Details
##############################
Test: CheckPatch - FAIL
Desc: Run checkpatch.pl script with rule in .checkpatch.conf
Output:
[BlueZ] test-runner: Add option to start emulator
ERROR:INITIALISED_STATIC: do not initialise statics to false
#98: FILE: tools/test-runner.c:50:
+static bool start_emulator = false;

WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const
#119: FILE: tools/test-runner.c:605:
+static const char *btvirt_table[] = {

/github/workspace/src/12763863.patch total: 1 errors, 1 warnings, 152 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

/github/workspace/src/12763863.patch has style problems, please review.

NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.




---
Regards,
Linux Bluetooth


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

* Re: [BlueZ] test-runner: Add option to start emulator
  2022-03-01  0:35 ` [BlueZ] " bluez.test.bot
@ 2022-03-02 23:22   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2022-03-02 23:22 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Mon, Feb 28, 2022 at 4:35 PM <bluez.test.bot@gmail.com> wrote:
>
> This is automated email and please do not reply to this email!
>
> Dear submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=618913
>
> ---Test result---
>
> Test Summary:
> CheckPatch                    FAIL      1.54 seconds
> GitLint                       PASS      1.05 seconds
> Prep - Setup ELL              PASS      43.02 seconds
> Build - Prep                  PASS      0.74 seconds
> Build - Configure             PASS      8.82 seconds
> Build - Make                  PASS      1440.03 seconds
> Make Check                    PASS      11.46 seconds
> Make Check w/Valgrind         PASS      446.11 seconds
> Make Distcheck                PASS      231.77 seconds
> Build w/ext ELL - Configure   PASS      8.81 seconds
> Build w/ext ELL - Make        PASS      1433.12 seconds
> Incremental Build with patchesPASS      0.00 seconds
>
> Details
> ##############################
> Test: CheckPatch - FAIL
> Desc: Run checkpatch.pl script with rule in .checkpatch.conf
> Output:
> [BlueZ] test-runner: Add option to start emulator
> ERROR:INITIALISED_STATIC: do not initialise statics to false
> #98: FILE: tools/test-runner.c:50:
> +static bool start_emulator = false;
>
> WARNING:STATIC_CONST_CHAR_ARRAY: static const char * array should probably be static const char * const
> #119: FILE: tools/test-runner.c:605:
> +static const char *btvirt_table[] = {
>
> /github/workspace/src/12763863.patch total: 1 errors, 1 warnings, 152 lines checked
>
> NOTE: For some of the reported defects, checkpatch may be able to
>       mechanically convert to the typical style using --fix or --fix-inplace.
>
> /github/workspace/src/12763863.patch has style problems, please review.
>
> NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO
>
> NOTE: If any of the errors are false positives, please report
>       them to the maintainer, see CHECKPATCH in MAINTAINERS.
>
>
>
>
> ---
> Regards,
> Linux Bluetooth
>
Pushed.

-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2022-03-02 23:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-28 23:27 [PATCH BlueZ] test-runner: Add option to start emulator Luiz Augusto von Dentz
2022-03-01  0:35 ` [BlueZ] " bluez.test.bot
2022-03-02 23:22   ` Luiz Augusto von Dentz

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.