All of lore.kernel.org
 help / color / mirror / Atom feed
* [BlueZ PATCH v3] mgmt-tester: Add devcoredump test
@ 2023-03-24 17:22 Manish Mandlik
  2023-03-24 17:34 ` Luiz Augusto von Dentz
  2023-03-24 18:45 ` [BlueZ,v3] " bluez.test.bot
  0 siblings, 2 replies; 3+ messages in thread
From: Manish Mandlik @ 2023-03-24 17:22 UTC (permalink / raw)
  To: marcel, luiz.dentz
  Cc: chromeos-bluetooth-upstreaming, linux-bluetooth, Manish Mandlik

Add mgmt-tester test for hci devcoredump. This test triggers the
devcoredump with a test data and verifies the generated devcoredump
file for the test data and correct devcoredump header fields.

Signed-off-by: Manish Mandlik <mmandlik@google.com>
---

Changes in v3:
- Fix compiler warning for signed comparision in test_hci_devcd()

Changes in v2:
- Rename function names to *_devcd

 emulator/vhci.c     | 42 ++++++++++++++++++++++++
 emulator/vhci.h     |  2 ++
 tools/mgmt-tester.c | 78 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+)

diff --git a/emulator/vhci.c b/emulator/vhci.c
index a12b11e0f..1676f1697 100644
--- a/emulator/vhci.c
+++ b/emulator/vhci.c
@@ -22,6 +22,7 @@
 #include <sys/uio.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <dirent.h>
 
 #include "lib/bluetooth.h"
 #include "lib/hci.h"
@@ -32,6 +33,7 @@
 #include "vhci.h"
 
 #define DEBUGFS_PATH "/sys/kernel/debug/bluetooth"
+#define DEVCORE_PATH "/sys/class/devcoredump"
 
 struct vhci {
 	enum btdev_type type;
@@ -267,3 +269,43 @@ int vhci_set_force_static_address(struct vhci *vhci, bool enable)
 	return vhci_debugfs_write(vhci, "force_static_address", &val,
 							sizeof(val));
 }
+
+int vhci_force_devcd(struct vhci *vhci, void *data, size_t len)
+{
+	return vhci_debugfs_write(vhci, "force_devcoredump", data, len);
+}
+
+int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size)
+{
+	DIR *dir;
+	struct dirent *entry;
+	char filename[PATH_MAX];
+	int fd;
+	int count;
+
+	dir = opendir(DEVCORE_PATH);
+	if (dir == NULL)
+		return -errno;
+
+	while ((entry = readdir(dir)) != NULL) {
+		if (strstr(entry->d_name, "devcd"))
+			break;
+	}
+
+	if (entry == NULL) {
+		closedir(dir);
+		return -ENOENT;
+	}
+
+	sprintf(filename, DEVCORE_PATH "/%s/data", entry->d_name);
+	fd  = open(filename, O_RDONLY);
+	if (fd < 0) {
+		closedir(dir);
+		return -errno;
+	}
+
+	count = read(fd, buf, size);
+	close(fd);
+
+	return count;
+}
diff --git a/emulator/vhci.h b/emulator/vhci.h
index 6da56cb58..5dd28b627 100644
--- a/emulator/vhci.h
+++ b/emulator/vhci.h
@@ -29,3 +29,5 @@ int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode);
 int vhci_set_aosp_capable(struct vhci *vhci, bool enable);
 int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode);
 int vhci_set_force_static_address(struct vhci *vhci, bool enable);
+int vhci_force_devcd(struct vhci *vhci, void *data, size_t len);
+int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size);
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index a56c38173..838ae5d2b 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -12511,6 +12511,77 @@ static void test_suspend_resume_success_10(const void *test_data)
 	tester_wait(2, trigger_force_resume, NULL);
 }
 
+#define MAX_COREDUMP_BUF_LEN	512
+#define MAX_COREDUMP_LINE_LEN	40
+
+static void test_hci_devcd(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
+	char buf[MAX_COREDUMP_BUF_LEN] = {0};
+	char delim[] = "\n";
+	char *line;
+	char *saveptr;
+	unsigned int i = 0;
+
+	char dump_data[] = "test data";
+	char expected[][MAX_COREDUMP_LINE_LEN] = {
+		"Bluetooth devcoredump",
+		"State: 2",
+		"Controller Name: vhci_ctrl",
+		"Firmware Version: vhci_fw",
+		"Driver: vhci_drv",
+		"Vendor: vhci",
+		"--- Start dump ---",
+	};
+
+	/* Triggers the devcoredump */
+	if (vhci_force_devcd(vhci, dump_data, sizeof(dump_data))) {
+		tester_warn("Unable to set force_devcoredump");
+		tester_test_failed();
+		return;
+	}
+
+	/* Read the generated devcoredump file */
+	if (vhci_read_devcd(vhci, buf, sizeof(buf)) <= 0) {
+		tester_warn("Unable to read devcoredump");
+		tester_test_failed();
+		return;
+	}
+
+	/* Verify if all devcoredump header fields are present */
+	line = strtok_r(buf, delim, &saveptr);
+	while (i < ARRAY_SIZE(expected)) {
+		if (!line || strcmp(line, expected[i])) {
+			tester_warn("Incorrect coredump data: %s (expected %s)",
+				    line, expected[i]);
+			tester_test_failed();
+			return;
+		}
+
+		if (!strcmp(line, "State: 2")) {
+			/* After updating the devcoredump state, the HCI
+			 * devcoredump API adds a `\0` at the end. Skip it
+			 * before reading the next line.
+			 */
+			saveptr++;
+		}
+
+		line = strtok_r(NULL, delim, &saveptr);
+		i++;
+	}
+
+	/* Verify the devcoredump data */
+	if (!line || strcmp(line, dump_data)) {
+		tester_warn("Incorrect coredump data: %s (expected %s)", line,
+			    dump_data);
+		tester_test_failed();
+		return;
+	}
+
+	tester_test_passed();
+}
+
 int main(int argc, char *argv[])
 {
 	tester_init(&argc, &argv);
@@ -14651,5 +14722,12 @@ int main(int argc, char *argv[])
 				setup_ll_privacy_add_device,
 				test_command_generic);
 
+	/* HCI devcoredump
+	 * Setup : Power on
+	 * Run: Trigger devcoredump via force_devcoredump
+	 * Expect: Devcoredump is generated with correct data
+	 */
+	test_bredrle("HCI devcoredump", NULL, NULL, test_hci_devcd);
+
 	return tester_run();
 }
-- 
2.40.0.348.gf938b09366-goog


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

* Re: [BlueZ PATCH v3] mgmt-tester: Add devcoredump test
  2023-03-24 17:22 [BlueZ PATCH v3] mgmt-tester: Add devcoredump test Manish Mandlik
@ 2023-03-24 17:34 ` Luiz Augusto von Dentz
  2023-03-24 18:45 ` [BlueZ,v3] " bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2023-03-24 17:34 UTC (permalink / raw)
  To: Manish Mandlik; +Cc: marcel, chromeos-bluetooth-upstreaming, linux-bluetooth

Hi Manish,

On Fri, Mar 24, 2023 at 10:22 AM Manish Mandlik <mmandlik@google.com> wrote:
>
> Add mgmt-tester test for hci devcoredump. This test triggers the
> devcoredump with a test data and verifies the generated devcoredump
> file for the test data and correct devcoredump header fields.
>
> Signed-off-by: Manish Mandlik <mmandlik@google.com>
> ---
>
> Changes in v3:
> - Fix compiler warning for signed comparision in test_hci_devcd()
>
> Changes in v2:
> - Rename function names to *_devcd
>
>  emulator/vhci.c     | 42 ++++++++++++++++++++++++
>  emulator/vhci.h     |  2 ++
>  tools/mgmt-tester.c | 78 +++++++++++++++++++++++++++++++++++++++++++++

Looks like you forgot to split the vhci changes.

>  3 files changed, 122 insertions(+)
>
> diff --git a/emulator/vhci.c b/emulator/vhci.c
> index a12b11e0f..1676f1697 100644
> --- a/emulator/vhci.c
> +++ b/emulator/vhci.c
> @@ -22,6 +22,7 @@
>  #include <sys/uio.h>
>  #include <fcntl.h>
>  #include <unistd.h>
> +#include <dirent.h>
>
>  #include "lib/bluetooth.h"
>  #include "lib/hci.h"
> @@ -32,6 +33,7 @@
>  #include "vhci.h"
>
>  #define DEBUGFS_PATH "/sys/kernel/debug/bluetooth"
> +#define DEVCORE_PATH "/sys/class/devcoredump"
>
>  struct vhci {
>         enum btdev_type type;
> @@ -267,3 +269,43 @@ int vhci_set_force_static_address(struct vhci *vhci, bool enable)
>         return vhci_debugfs_write(vhci, "force_static_address", &val,
>                                                         sizeof(val));
>  }
> +
> +int vhci_force_devcd(struct vhci *vhci, void *data, size_t len)
> +{
> +       return vhci_debugfs_write(vhci, "force_devcoredump", data, len);
> +}
> +
> +int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size)
> +{
> +       DIR *dir;
> +       struct dirent *entry;
> +       char filename[PATH_MAX];
> +       int fd;
> +       int count;
> +
> +       dir = opendir(DEVCORE_PATH);
> +       if (dir == NULL)
> +               return -errno;
> +
> +       while ((entry = readdir(dir)) != NULL) {
> +               if (strstr(entry->d_name, "devcd"))
> +                       break;
> +       }
> +
> +       if (entry == NULL) {
> +               closedir(dir);
> +               return -ENOENT;
> +       }
> +
> +       sprintf(filename, DEVCORE_PATH "/%s/data", entry->d_name);
> +       fd  = open(filename, O_RDONLY);
> +       if (fd < 0) {
> +               closedir(dir);
> +               return -errno;
> +       }
> +
> +       count = read(fd, buf, size);
> +       close(fd);
> +
> +       return count;
> +}
> diff --git a/emulator/vhci.h b/emulator/vhci.h
> index 6da56cb58..5dd28b627 100644
> --- a/emulator/vhci.h
> +++ b/emulator/vhci.h
> @@ -29,3 +29,5 @@ int vhci_set_msft_opcode(struct vhci *vhci, uint16_t opcode);
>  int vhci_set_aosp_capable(struct vhci *vhci, bool enable);
>  int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode);
>  int vhci_set_force_static_address(struct vhci *vhci, bool enable);
> +int vhci_force_devcd(struct vhci *vhci, void *data, size_t len);
> +int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size);
> diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
> index a56c38173..838ae5d2b 100644
> --- a/tools/mgmt-tester.c
> +++ b/tools/mgmt-tester.c
> @@ -12511,6 +12511,77 @@ static void test_suspend_resume_success_10(const void *test_data)
>         tester_wait(2, trigger_force_resume, NULL);
>  }
>
> +#define MAX_COREDUMP_BUF_LEN   512
> +#define MAX_COREDUMP_LINE_LEN  40
> +
> +static void test_hci_devcd(const void *test_data)
> +{
> +       struct test_data *data = tester_get_data();
> +       struct vhci *vhci = hciemu_get_vhci(data->hciemu);
> +       char buf[MAX_COREDUMP_BUF_LEN] = {0};
> +       char delim[] = "\n";
> +       char *line;
> +       char *saveptr;
> +       unsigned int i = 0;
> +
> +       char dump_data[] = "test data";
> +       char expected[][MAX_COREDUMP_LINE_LEN] = {
> +               "Bluetooth devcoredump",
> +               "State: 2",
> +               "Controller Name: vhci_ctrl",
> +               "Firmware Version: vhci_fw",
> +               "Driver: vhci_drv",
> +               "Vendor: vhci",
> +               "--- Start dump ---",
> +       };
> +
> +       /* Triggers the devcoredump */
> +       if (vhci_force_devcd(vhci, dump_data, sizeof(dump_data))) {
> +               tester_warn("Unable to set force_devcoredump");
> +               tester_test_failed();
> +               return;
> +       }
> +
> +       /* Read the generated devcoredump file */
> +       if (vhci_read_devcd(vhci, buf, sizeof(buf)) <= 0) {
> +               tester_warn("Unable to read devcoredump");
> +               tester_test_failed();
> +               return;
> +       }
> +
> +       /* Verify if all devcoredump header fields are present */
> +       line = strtok_r(buf, delim, &saveptr);
> +       while (i < ARRAY_SIZE(expected)) {
> +               if (!line || strcmp(line, expected[i])) {
> +                       tester_warn("Incorrect coredump data: %s (expected %s)",
> +                                   line, expected[i]);
> +                       tester_test_failed();
> +                       return;
> +               }
> +
> +               if (!strcmp(line, "State: 2")) {
> +                       /* After updating the devcoredump state, the HCI
> +                        * devcoredump API adds a `\0` at the end. Skip it
> +                        * before reading the next line.
> +                        */
> +                       saveptr++;
> +               }
> +
> +               line = strtok_r(NULL, delim, &saveptr);
> +               i++;
> +       }
> +
> +       /* Verify the devcoredump data */
> +       if (!line || strcmp(line, dump_data)) {
> +               tester_warn("Incorrect coredump data: %s (expected %s)", line,
> +                           dump_data);
> +               tester_test_failed();
> +               return;
> +       }
> +
> +       tester_test_passed();
> +}
> +
>  int main(int argc, char *argv[])
>  {
>         tester_init(&argc, &argv);
> @@ -14651,5 +14722,12 @@ int main(int argc, char *argv[])
>                                 setup_ll_privacy_add_device,
>                                 test_command_generic);
>
> +       /* HCI devcoredump
> +        * Setup : Power on
> +        * Run: Trigger devcoredump via force_devcoredump
> +        * Expect: Devcoredump is generated with correct data
> +        */
> +       test_bredrle("HCI devcoredump", NULL, NULL, test_hci_devcd);
> +
>         return tester_run();
>  }
> --
> 2.40.0.348.gf938b09366-goog
>


-- 
Luiz Augusto von Dentz

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

* RE: [BlueZ,v3] mgmt-tester: Add devcoredump test
  2023-03-24 17:22 [BlueZ PATCH v3] mgmt-tester: Add devcoredump test Manish Mandlik
  2023-03-24 17:34 ` Luiz Augusto von Dentz
@ 2023-03-24 18:45 ` bluez.test.bot
  1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2023-03-24 18:45 UTC (permalink / raw)
  To: linux-bluetooth, mmandlik

[-- Attachment #1: Type: text/plain, Size: 948 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=733636

---Test result---

Test Summary:
CheckPatch                    PASS      0.70 seconds
GitLint                       PASS      0.38 seconds
BuildEll                      PASS      32.39 seconds
BluezMake                     PASS      1002.32 seconds
MakeCheck                     PASS      12.50 seconds
MakeDistcheck                 PASS      181.00 seconds
CheckValgrind                 PASS      295.50 seconds
CheckSmatch                   PASS      391.26 seconds
bluezmakeextell               PASS      118.25 seconds
IncrementalBuild              PASS      812.47 seconds
ScanBuild                     PASS      1230.99 seconds



---
Regards,
Linux Bluetooth


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

end of thread, other threads:[~2023-03-24 18:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-24 17:22 [BlueZ PATCH v3] mgmt-tester: Add devcoredump test Manish Mandlik
2023-03-24 17:34 ` Luiz Augusto von Dentz
2023-03-24 18:45 ` [BlueZ,v3] " bluez.test.bot

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.