linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 7/7] mgmt-tester: Make use of vhci_set_force_suspend/vhci_set_force_wakeup
Date: Thu, 14 Oct 2021 22:09:29 -0700	[thread overview]
Message-ID: <20211015050929.3130100-7-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20211015050929.3130100-1-luiz.dentz@gmail.com>

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

This replaces the direct setting debugfs to use vhci instance which
properly stores the controller index so it can be used even if there
are real controllers in the system.
---
 emulator/hciemu.c   |   8 ++++
 emulator/hciemu.h   |   1 +
 tools/mgmt-tester.c | 105 ++++++++++----------------------------------
 3 files changed, 33 insertions(+), 81 deletions(-)

diff --git a/emulator/hciemu.c b/emulator/hciemu.c
index 3557efc93..4752c8a4d 100644
--- a/emulator/hciemu.c
+++ b/emulator/hciemu.c
@@ -234,6 +234,14 @@ static bool create_vhci(struct hciemu *hciemu)
 	return true;
 }
 
+struct vhci *hciemu_get_vhci(struct hciemu *hciemu)
+{
+	if (!hciemu)
+		return NULL;
+
+	return hciemu->vhci;
+}
+
 struct hciemu_client *hciemu_get_client(struct hciemu *hciemu, int num)
 {
 	const struct queue_entry *entry;
diff --git a/emulator/hciemu.h b/emulator/hciemu.h
index 3d3d93b4b..338fa844d 100644
--- a/emulator/hciemu.h
+++ b/emulator/hciemu.h
@@ -45,6 +45,7 @@ typedef void (*hciemu_destroy_func_t)(void *user_data);
 bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback,
 			void *user_data, hciemu_destroy_func_t destroy);
 
+struct vhci *hciemu_get_vhci(struct hciemu *hciemu);
 struct bthost *hciemu_client_get_host(struct hciemu *hciemu);
 
 const char *hciemu_get_address(struct hciemu *hciemu);
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 8bddf6b03..62218b431 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -30,6 +30,7 @@
 #include "lib/l2cap.h"
 
 #include "monitor/bt.h"
+#include "emulator/vhci.h"
 #include "emulator/bthost.h"
 #include "emulator/hciemu.h"
 
@@ -313,62 +314,6 @@ struct generic_data {
 	uint8_t adv_data_len;
 };
 
-static int set_debugfs_force_suspend(int index, bool enable)
-{
-	int fd, n, err;
-	char val, path[64];
-
-	err = 0;
-
-	/* path for the debugfs file
-	 * /sys/kernel/debug/bluetooth/hciX/force_suspend
-	 */
-	memset(path, 0, sizeof(path));
-	sprintf(path, "/sys/kernel/debug/bluetooth/hci%d/force_suspend", index);
-
-	fd = open(path, O_RDWR);
-	if (fd < 0)
-		return -errno;
-
-	val = (enable) ? 'Y' : 'N';
-
-	n = write(fd, &val, sizeof(val));
-	if (n < (ssize_t) sizeof(val))
-		err = -errno;
-
-	close(fd);
-
-	return err;
-}
-
-static int set_debugfs_force_wakeup(int index, bool enable)
-{
-	int fd, n, err;
-	char val, path[64];
-
-	err = 0;
-
-	/* path for the debugfs file
-	 * /sys/kernel/debug/bluetooth/hciX/force_suspend
-	 */
-	memset(path, 0, sizeof(path));
-	sprintf(path, "/sys/kernel/debug/bluetooth/hci%d/force_wakeup", index);
-
-	fd = open(path, O_RDWR);
-	if (fd < 0)
-		return -errno;
-
-	val = (enable) ? 'Y' : 'N';
-
-	n = write(fd, &val, sizeof(val));
-	if (n < (ssize_t) sizeof(val))
-		err = -errno;
-
-	close(fd);
-
-	return err;
-}
-
 static const uint8_t set_exp_feat_param_debug[] = {
 	0x1c, 0xda, 0x47, 0x1c, 0x48, 0x6c, 0x01, 0xab, /* UUID - Debug */
 	0x9f, 0x46, 0xec, 0xb9, 0x30, 0x25, 0x99, 0xd4,
@@ -10512,12 +10457,12 @@ static const struct generic_data suspend_resume_success_1 = {
 
 static void test_suspend_resume_success_1(const void *test_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Triggers the suspend */
-	suspend = true;
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
@@ -10535,12 +10480,12 @@ static const struct generic_data suspend_resume_success_2 = {
 
 static void test_suspend_resume_success_2(const void *test_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Triggers the suspend */
-	suspend = true;
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
@@ -10548,8 +10493,7 @@ static void test_suspend_resume_success_2(const void *test_data)
 	}
 
 	/* Triggers the resume */
-	suspend = false;
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, false);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
@@ -10586,12 +10530,12 @@ static void setup_suspend_resume_success_3(const void *test_data)
 
 static void test_suspend_resume_success_3(const void *test_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Triggers the suspend */
-	suspend = true;
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
@@ -10635,15 +10579,15 @@ static void setup_suspend_resume_success_4(const void *test_data)
 
 static void test_suspend_resume_success_4(const void *test_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	test_command_generic(test_data);
 
 	/* Triggers the suspend */
-	suspend = true;
 	tester_print("Set the system into Suspend via force_suspend");
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
@@ -10664,13 +10608,13 @@ static const struct generic_data suspend_resume_success_5 = {
 
 static void trigger_force_suspend(void *user_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Triggers the suspend */
-	suspend = true;
 	tester_print("Set the system into Suspend via force_suspend");
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		return;
@@ -10679,13 +10623,13 @@ static void trigger_force_suspend(void *user_data)
 
 static void trigger_force_resume(void *user_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Triggers the suspend */
-	suspend = false;
 	tester_print("Set the system into Resume via force_suspend");
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_suspend(vhci, false);
 	if (err) {
 		tester_warn("Unable to disable the force_suspend");
 		return;
@@ -10720,12 +10664,12 @@ static const struct generic_data suspend_resume_success_7 = {
 
 static void test_suspend_resume_success_7(const void *test_data)
 {
-	bool suspend;
+	struct test_data *data = tester_get_data();
+	struct vhci *vhci = hciemu_get_vhci(data->hciemu);
 	int err;
 
 	/* Set Force Wakeup */
-	suspend = true;
-	err = set_debugfs_force_wakeup(0, suspend);
+	err = vhci_set_force_wakeup(vhci, true);
 	if (err) {
 		tester_warn("Unable to enable the force_wakeup");
 		tester_test_failed();
@@ -10733,8 +10677,7 @@ static void test_suspend_resume_success_7(const void *test_data)
 	}
 
 	/* Triggers the suspend */
-	suspend = true;
-	err = set_debugfs_force_suspend(0, suspend);
+	err = vhci_set_force_wakeup(vhci, false);
 	if (err) {
 		tester_warn("Unable to enable the force_suspend");
 		tester_test_failed();
-- 
2.31.1


  parent reply	other threads:[~2021-10-15  5:09 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15  5:09 [PATCH BlueZ 1/7] monitor: Add packet definitions for MSFT extension Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 2/7] monitor: Make use of MSFT packet definitions Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 3/7] vhci: Read the controller index Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 4/7] vhci: Use io.h instead of mainloop.h Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 5/7] hciemu: Use vhci_open to instanciate a vhci btdev Luiz Augusto von Dentz
2021-10-15  5:09 ` [PATCH BlueZ 6/7] vhci: Add functions to interface with debugfs Luiz Augusto von Dentz
2021-10-15  5:09 ` Luiz Augusto von Dentz [this message]
2021-10-15  5:36 ` [BlueZ,1/7] monitor: Add packet definitions for MSFT extension bluez.test.bot
2021-10-15 20:10   ` Luiz Augusto von Dentz
     [not found] ` <CAGPPCLDFYFeiwfiyRX=6PquYYQ-Fp_LpN4Gw2745jyWzQKEBRQ@mail.gmail.com>
2021-10-18 16:24   ` [PATCH BlueZ 1/7] " Luiz Augusto von Dentz
2021-10-18 20:05     ` Luiz Augusto von Dentz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211015050929.3130100-7-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --subject='Re: [PATCH BlueZ 7/7] mgmt-tester: Make use of vhci_set_force_suspend/vhci_set_force_wakeup' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).