All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tedd Ho-Jeong An <hj.tedd.an@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [BlueZ PATCH] tools: userchan-tester: Add test case for the closing channel
Date: Thu, 19 Aug 2021 22:07:05 -0700	[thread overview]
Message-ID: <20210820050705.76853-1-hj.tedd.an@gmail.com> (raw)

From: Tedd Ho-Jeong An <tedd.an@intel.com>

This patch adds a test casse for checking the controller power state
after closing the user channel.

When the user channel is closed, the controller should be powered down
state.
---
 tools/userchan-tester.c | 69 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/tools/userchan-tester.c b/tools/userchan-tester.c
index c17644fb8..095ef2689 100644
--- a/tools/userchan-tester.c
+++ b/tools/userchan-tester.c
@@ -40,6 +40,8 @@ struct test_data {
 	enum hciemu_type hciemu_type;
 	const void *test_data;
 	unsigned int remove_id;
+	struct bt_hci *hci;
+	uint32_t current_settings;
 };
 
 static void mgmt_debug(const char *str, void *user_data)
@@ -81,6 +83,8 @@ static void read_info_callback(uint8_t status, uint16_t length,
 	tester_print("  Name: %s", rp->name);
 	tester_print("  Short name: %s", rp->short_name);
 
+	data->current_settings = current_settings;
+
 	if (strcmp(hciemu_get_address(data->hciemu), addr)) {
 		tester_pre_setup_failed();
 		return;
@@ -291,6 +295,68 @@ static void test_open_failed(const void *test_data)
 	tester_test_failed();
 }
 
+static void close_read_info_callback(uint8_t status, uint16_t length,
+					const void *param, void *user_data)
+{
+	const struct mgmt_rp_read_info *rp = param;
+	uint32_t current_settings;
+
+	tester_print("Read Info callback");
+	tester_print("  Status: 0x%02x", status);
+
+	if (status || !param) {
+		tester_test_failed();
+		return;
+	}
+
+	current_settings = btohl(rp->current_settings);
+	if (current_settings & MGMT_SETTING_POWERED) {
+		tester_print("Controller is powered");
+		tester_test_failed();
+		return;
+	}
+
+	tester_test_passed();
+}
+
+static void setup_channel_open(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	/* Check power off */
+	if (data->current_settings & MGMT_SETTING_POWERED) {
+		tester_print("Controller is powered");
+		tester_setup_failed();
+		return;
+	}
+
+	/* Open Channel */
+	data->hci = bt_hci_new_user_channel(data->mgmt_index);
+	if (!data->hci) {
+		mgmt_unregister(data->mgmt, data->remove_id);
+		data->remove_id = 0;
+
+		tester_setup_failed();
+		return;
+	}
+
+	tester_print("User Channel Opened");
+
+	tester_setup_complete();
+}
+
+static void test_close_success(const void *test_data)
+{
+	struct test_data *data = tester_get_data();
+
+	tester_print("Close User Channel");
+	bt_hci_unref(data->hci);
+
+	/* Check if power is off */
+	mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL,
+					close_read_info_callback, NULL, NULL);
+}
+
 #define test_user(name, data, setup, func) \
 	do { \
 		struct test_data *user; \
@@ -316,6 +382,9 @@ int main(int argc, char *argv[])
 					setup_powered, test_open_failed);
 	test_user("User channel open - Power Toggle Success", INT_TO_PTR(true),
 					toggle_powered, test_open_success);
+	test_user("User channel close - Success", NULL,
+					setup_channel_open, test_close_success);
+
 
 	return tester_run();
 }
-- 
2.25.1


             reply	other threads:[~2021-08-20  5:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  5:07 Tedd Ho-Jeong An [this message]
2021-08-20  5:35 ` [BlueZ] tools: userchan-tester: Add test case for the closing channel bluez.test.bot
2021-09-17 20:32   ` Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2021-08-20  4:56 [BlueZ PATCH] " Tedd Ho-Jeong An

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=20210820050705.76853-1-hj.tedd.an@gmail.com \
    --to=hj.tedd.an@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.