From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ RESEND 2/4] unit/test-hfp: Add SLC connection test
Date: Tue, 19 Aug 2025 15:33:19 +0200 [thread overview]
Message-ID: <20250819133321.382279-2-frederic.danis@collabora.com> (raw)
In-Reply-To: <20250819133321.382279-1-frederic.danis@collabora.com>
This adds minimal packet exchange to test the SLC establishment.
---
unit/test-hfp.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index b4af99d53..2ea77e210 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -104,6 +104,14 @@ struct test_data {
data.test_handler = test_hf_handler; \
} while (0)
+static void print_debug(const char *str, void *user_data)
+{
+ const char *prefix = user_data;
+
+ if (tester_use_debug())
+ tester_debug("%s%s", prefix, str);
+}
+
static void test_free(gconstpointer user_data)
{
const struct test_data *data = user_data;
@@ -680,6 +688,110 @@ static void test_hf_robustness(gconstpointer data)
context_quit(context);
}
+#define MINIMAL_SLC_SESSION \
+ raw_pdu('\r', '\n', '+', 'B', 'R', 'S', 'F', ':', \
+ ' ', '0', '\r', '\n'), \
+ frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
+ raw_pdu('\r', '\n', '+', 'C', 'I', 'N', 'D', ':', ' '), \
+ frg_pdu('(', '\"', 's', 'e', 'r', 'v', 'i', 'c', 'e'), \
+ frg_pdu('\"', '(', '0', ',', '1', ')', ')', ','), \
+ frg_pdu('(', '\"', 'c', 'a', 'l', 'l', '\"'), \
+ frg_pdu('(', '0', ',', '1', ')', ')', ','), \
+ frg_pdu('(', '\"', 'c', 'a', 'l', 'l', 's', 'e', 't'), \
+ frg_pdu('u', 'p', '\"', ',', '(', '0', '-', '3', ')'), \
+ frg_pdu(')', ','), \
+ frg_pdu('(', '\"', 'c', 'a', 'l', 'l', 'h', 'e', 'l'), \
+ frg_pdu('d', '\"', ',', '(', '0', '-', '2', ')', ')'), \
+ frg_pdu(',', '(', '\"', 's', 'i', 'g', 'n', 'a', 'l'), \
+ frg_pdu('\"', '(', '0', '-', '5', ')', ')', ','), \
+ frg_pdu('(', '\"', 'r', 'o', 'a', 'm', '\"', ',', '('), \
+ frg_pdu('0', ',', '1', ')', ')', ','), \
+ frg_pdu('(', '\"', 'b', 'a', 't', 't', 'c', 'h', 'g'), \
+ frg_pdu('\"', '(', '0', '-', '5', ')', ')', ','), \
+ frg_pdu('\r', '\n'), \
+ frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
+ raw_pdu('\r', '\n', '+', 'C', 'I', 'N', 'D', ':', ' '), \
+ frg_pdu('0', ',', '0', ',', '0', ',', '0', ',', '5'), \
+ frg_pdu(',', '0', ',', '5', '\r', '\n'), \
+ frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \
+ raw_pdu('\r', '\n', 'O', 'K', '\r', '\n')
+
+static void hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
+ void *user_data)
+{
+ struct context *context = user_data;
+
+ g_assert_cmpint(res, ==, HFP_RESULT_OK);
+
+ context->data->response_func(res, cme_err, context);
+}
+
+static void hf_update_indicator(enum hfp_indicator indicator, uint32_t val,
+ void *user_data)
+{
+ switch (indicator) {
+ case HFP_INDICATOR_SERVICE:
+ g_assert_cmpint(val, ==, 1);
+ break;
+ case HFP_INDICATOR_CALL:
+ g_assert_cmpint(val, ==, 0);
+ break;
+ case HFP_INDICATOR_CALLSETUP:
+ g_assert_cmpint(val, ==, 0);
+ break;
+ case HFP_INDICATOR_CALLHELD:
+ g_assert_cmpint(val, ==, 0);
+ break;
+ case HFP_INDICATOR_SIGNAL:
+ g_assert_cmpint(val, ==, 5);
+ break;
+ case HFP_INDICATOR_ROAM:
+ g_assert_cmpint(val, ==, 0);
+ break;
+ case HFP_INDICATOR_BATTCHG:
+ g_assert_cmpint(val, ==, 5);
+ break;
+ case HFP_INDICATOR_LAST:
+ default:
+ tester_test_failed();
+ }
+}
+
+static struct hfp_hf_callbacks hf_session_callbacks = {
+ .session_ready = hf_session_ready_cb,
+ .update_indicator = hf_update_indicator,
+};
+
+static void test_hf_session_done(enum hfp_result res, enum hfp_error cme_err,
+ void *user_data)
+{
+ struct context *context = user_data;
+
+ hfp_hf_disconnect(context->hfp_hf);
+}
+
+static void test_hf_session(gconstpointer data)
+{
+ struct context *context = create_context(data);
+ bool ret;
+
+ context->hfp_hf = hfp_hf_new(context->fd_client);
+ g_assert(context->hfp_hf);
+
+ ret = hfp_hf_set_debug(context->hfp_hf, print_debug, "hfp-hf:", NULL);
+ g_assert(ret);
+
+ ret = hfp_hf_set_close_on_unref(context->hfp_hf, true);
+ g_assert(ret);
+
+ ret = hfp_hf_session_register(context->hfp_hf, &hf_session_callbacks,
+ context);
+ g_assert(ret);
+
+ ret = hfp_hf_session(context->hfp_hf);
+ g_assert(ret);
+}
+
int main(int argc, char *argv[])
{
tester_init(&argc, &argv);
@@ -850,5 +962,10 @@ int main(int argc, char *argv[])
frg_pdu('1', ',', '2', 'x', '\r', '\n'),
data_end());
+ define_hf_test("/hfp_hf/test_session_minimal", test_hf_session,
+ NULL, test_hf_session_done,
+ MINIMAL_SLC_SESSION,
+ data_end());
+
return tester_run();
}
--
2.43.0
next prev parent reply other threads:[~2025-08-19 13:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-19 13:33 [PATCH BlueZ RESEND 1/4] shared/hfp: Add HF SLC connection function Frédéric Danis
2025-08-19 13:33 ` Frédéric Danis [this message]
2025-08-19 13:33 ` [PATCH BlueZ RESEND 3/4] shared/hfp: Add +CIEV event support Frédéric Danis
2025-08-19 13:33 ` [PATCH BlueZ RESEND 4/4] unit/test-hfp: Add indicators tests for HF Frédéric Danis
2025-08-19 14:59 ` [BlueZ,RESEND,1/4] shared/hfp: Add HF SLC connection function bluez.test.bot
2025-08-19 21:13 ` [PATCH BlueZ RESEND 1/4] " 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=20250819133321.382279-2-frederic.danis@collabora.com \
--to=frederic.danis@collabora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox