From patchwork Fri Mar 24 18:18:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 667017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93BB4C6FD20 for ; Fri, 24 Mar 2023 18:18:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231402AbjCXSSc (ORCPT ); Fri, 24 Mar 2023 14:18:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231656AbjCXSSU (ORCPT ); Fri, 24 Mar 2023 14:18:20 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C087F1025F for ; Fri, 24 Mar 2023 11:18:19 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id x4-20020a170902ec8400b001a1a5f6f272so1628960plg.1 for ; Fri, 24 Mar 2023 11:18:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679681899; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=tsPct1nXj3p0DgXEIXFQI0q4AZ/j9B3r7XwNOl9p7aE=; b=qLG8nRi+op0HZ5c4vOJoaX1K+Z8h1oxzbWu8PJbzU1hHkSINlSOtNy8sCHeZ6EgMDv WqbQO/PABnjCyi3i4A9LEPhGWpZcDdftwHVfqBADIUKvCxsG5khKSDGAe93yREW2utFf r0UDB/S1UA+AyI6/5qtfTdLT6XVSuzuKNNzA9PTqcluhpzCkVqgBAFoH8vWL98opwXMn NVnRanIrlgF1WVCHwPm++HhXt/6RqG7/XvDGgNHSVz3tu9C+fTf3M98CCMeYBdi67uNL IUdL9wWlDLwxQ+xjvxiEvHnML/ABr+HA0nIKDVgCAzirAwqyeaZnPtsfFtGrmSfxgSUM f39g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679681899; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=tsPct1nXj3p0DgXEIXFQI0q4AZ/j9B3r7XwNOl9p7aE=; b=HVN4orTzqz64/qre8ACqzUqzhaDmuNfDnUJ5stRELTiVZpNq+CRK8GfZibgsTaDZms xHbToYwmflLCQ0y1HgxF1qCF3EJSjhco6hoh7alvqTy3JqJQoT5GPGLpYLI3fa3QGRi7 n++41QRt/8o4rBAr9Zuuea59d1wudCoD1CgCTBaG2gA71hAK84SVtIku7Qtg4zqjheH3 cr9QPJVPpo+ZNbD9UCfF++v4jbuq22E70B6B8eQQUXS9MWTUepKam7AMFlHxVNFXwKxj H7V/L8OxgFOElqTAGK4f1oe7SvcwBm0+yPW9Ki0Gp/L5F0osDYxynSyM5mELH+1DGFsp 1vjw== X-Gm-Message-State: AAQBX9e9q4Aj5QqUxinHEfXbvcnO8agSTxVQkboVrAEt4c4JnTLvG73s FqPnq2yfUPv1fwLv3XsQYLrpSFcyK6GC7A== X-Google-Smtp-Source: AKy350YL9gkmqLhzmqBh+Dxr6chs1LRNZom/xqidZ0hDMNjK5QeDZGnp9v5S3p43NKxTX6CpBb4JkGMnWq6ZEA== X-Received: from mmandlik-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:2893]) (user=mmandlik job=sendgmr) by 2002:a63:4042:0:b0:50f:53aa:f662 with SMTP id n63-20020a634042000000b0050f53aaf662mr899613pga.5.1679681899054; Fri, 24 Mar 2023 11:18:19 -0700 (PDT) Date: Fri, 24 Mar 2023 11:18:15 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324111613.BlueZ.v4.1.I21ac5a143b0e42eef4ff71ef04ef0e53a294932a@changeid> Subject: [BlueZ PATCH v4 1/2] vhci: Add support to trigger devcoredump and read the dump file From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add vhci support to trigger the hci devcoredump by writing to force_devcoredump debugfs entry and read the generated devcoredump file. --- Changes in v4: - Split into two patches - vhci patch and mgmt-tester patch 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 ++ 2 files changed, 44 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 #include #include +#include #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); From patchwork Fri Mar 24 18:18:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manish Mandlik X-Patchwork-Id: 666674 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BF45C6FD20 for ; Fri, 24 Mar 2023 18:18:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231773AbjCXSSe (ORCPT ); Fri, 24 Mar 2023 14:18:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231966AbjCXSSa (ORCPT ); Fri, 24 Mar 2023 14:18:30 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A01D18B17 for ; Fri, 24 Mar 2023 11:18:21 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id y32-20020a634960000000b0050fa03fa554so983711pgk.1 for ; Fri, 24 Mar 2023 11:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1679681901; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=aSW5lVN/XdDnqsYnEdlvJ79vqtFaMV3jR95gfz5aEeg=; b=Dy3NhjDiXi4oiBF4Tnsprf/JOEIbUmTgkSnrcpUHd0skU6GPYbKoD5p5d61/8P+ytH PVS19xEOlnpdhjb6mhBLyvgn5Mqd7dqoN3NAqfYcUk142ez2T1s8hoOZulhAQ5Igehbj omKpZVKsrqM+lxRRBUgoHZE7sMYUmuNA7NdYOwsdsnfw57tu1dTZsB1DjJAxMnPc1jup IDTPPQJcU0u4QylXwCkvYkhLWyaBkD1Tzt3rxlMHSokGcLwII5w8Sv/X/2YraS21OyDm 2FFPQgv/QzPTopPYKdXu+ZFaqpvs1vn+g+ZYpIq2dh85qVq9rV4arYoyVAcB/cLp0zfs 0bYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679681901; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aSW5lVN/XdDnqsYnEdlvJ79vqtFaMV3jR95gfz5aEeg=; b=Bb12yLn8sTZyr8u18DJNj306UzfhdQqnDoO9M+8wDYNcBrtfVcfOQR/r9RLYFbBOWF GX/nzBNxabSCEjjFa+zh6WLxWPYfNp+cmOEGJrvfCoFc6+md/jcwsW3wowWcYP9XnhuF 6aZcbFt/e9DLm1wmX3wbEgq/bwQIPA0spqjZ4Rc6kkc5e3Ueog2yFhLdHdT9rCyqbFeN kO7R66/i8PfIMlVKqybLY97ECc3N87TYT5uxJ9k3M9VS5h6waXOXZfXVKTiJkNaIkR5n 2EkzhtObnSW1t0VFcznFzBLwTC7B7lSC7EXkolbDhl5dEd0X2Y2qS6vfOCutwRWHUNtj GDOA== X-Gm-Message-State: AAQBX9c2yQejvxxuckq/mIT3Uv3Pfrc5fiwSfM+J+/8uNKoUql7h//BW Z1FglXdemo7UDXo+/W+XgHeDpq3kBiN7jQ== X-Google-Smtp-Source: AKy350YQvBZ+RIYYu/aKFebCbJj4Bl1VbACugggNmrKeJ56LzKSgTIxfgBOSnEfAXKc6LpLgC9rI6fQwtzH9sQ== X-Received: from mmandlik-cloudtop.c.googlers.com ([fda3:e722:ac3:cc00:24:72f4:c0a8:2893]) (user=mmandlik job=sendgmr) by 2002:a17:90a:c095:b0:234:acfd:c8da with SMTP id o21-20020a17090ac09500b00234acfdc8damr1138137pjs.2.1679681900832; Fri, 24 Mar 2023 11:18:20 -0700 (PDT) Date: Fri, 24 Mar 2023 11:18:16 -0700 In-Reply-To: <20230324111613.BlueZ.v4.1.I21ac5a143b0e42eef4ff71ef04ef0e53a294932a@changeid> Mime-Version: 1.0 References: <20230324111613.BlueZ.v4.1.I21ac5a143b0e42eef4ff71ef04ef0e53a294932a@changeid> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog Message-ID: <20230324111613.BlueZ.v4.2.I6b8d9794fa661c63824306ccc8eecf6479040b1a@changeid> Subject: [BlueZ PATCH v4 2/2] mgmt-tester: Add devcoredump test From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: linux-bluetooth@vger.kernel.org, chromeos-bluetooth-upstreaming@chromium.org, Manish Mandlik Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org 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. --- Changes in v4: - New patch in the series tools/mgmt-tester.c | 78 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) 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(); }