All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ RESEND 4/4] unit/test-hfp: Add indicators tests for HF
Date: Tue, 19 Aug 2025 15:33:21 +0200	[thread overview]
Message-ID: <20250819133321.382279-4-frederic.danis@collabora.com> (raw)
In-Reply-To: <20250819133321.382279-1-frederic.danis@collabora.com>

This adds the following tests:
- /HFP/HF/TRS/BV-01-C
  Verify that the HF accepts the registration status indication.
- /HFP/HF/PSI/BV-01-C
  Verify that the HF successfully receives the signal strength status of
  the AG.
- /HFP/HF/PSI/BV-02-C
  Verify that the HF successfully receives the roaming status of the AG.
- /HFP/HF/PSI/BV-03-C
  Verify that the HF successfully receives the battery level status of
  the AG.
---
 unit/test-hfp.c | 131 ++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 105 insertions(+), 26 deletions(-)

diff --git a/unit/test-hfp.c b/unit/test-hfp.c
index 2ea77e210..9be1b05ae 100644
--- a/unit/test-hfp.c
+++ b/unit/test-hfp.c
@@ -19,6 +19,11 @@
 #include "src/shared/tester.h"
 #include "src/shared/util.h"
 
+struct session {
+	bool completed;
+	guint step;
+};
+
 struct context {
 	guint watch_id;
 	int fd_server;
@@ -27,6 +32,7 @@ struct context {
 	struct hfp_hf *hfp_hf;
 	const struct test_data *data;
 	unsigned int pdu_offset;
+	struct session session;
 };
 
 struct test_pdu {
@@ -720,40 +726,75 @@ static void hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err,
 							void *user_data)
 {
 	struct context *context = user_data;
+	const char *test_name = context->data->test_name;
 
 	g_assert_cmpint(res, ==, HFP_RESULT_OK);
+	context->session.completed = true;
 
-	context->data->response_func(res, cme_err, context);
+	if (g_str_equal(test_name, "/hfp_hf/test_session_minimal"))
+		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();
+	struct context *context = user_data;
+	const char *test_name = context->data->test_name;
+
+	if (!context->session.completed) {
+		switch (indicator) {
+		case HFP_INDICATOR_SERVICE:
+			g_assert_cmpint(val, ==, 0);
+			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();
+		}
+		return;
+	}
+
+	if (g_str_equal(test_name, "/HFP/HF/TRS/BV-01-C")) {
+		context->session.step++;
+		g_assert_cmpint(indicator, ==, HFP_INDICATOR_SERVICE);
+		g_assert_cmpint(val, ==, context->session.step % 2);
+
+		if (context->session.step == 3)
+			context->data->response_func(HFP_RESULT_OK, 0,
+								context);
+	} else if (g_str_equal(test_name, "/HFP/HF/PSI/BV-01-C")) {
+		g_assert_cmpint(indicator, ==, HFP_INDICATOR_SIGNAL);
+		g_assert_cmpint(val, ==, 3);
+		context->data->response_func(HFP_RESULT_OK, 0, context);
+	} else if (g_str_equal(test_name, "/HFP/HF/PSI/BV-02-C")) {
+		context->session.step++;
+		g_assert_cmpint(indicator, ==, HFP_INDICATOR_ROAM);
+		g_assert_cmpint(val, ==, context->session.step % 2);
+
+		if (context->session.step == 2)
+			context->data->response_func(HFP_RESULT_OK, 0,
+								context);
+	} else if (g_str_equal(test_name, "/HFP/HF/PSI/BV-03-C")) {
+		g_assert_cmpint(indicator, ==, HFP_INDICATOR_BATTCHG);
+		g_assert_cmpint(val, ==, 3);
+		context->data->response_func(HFP_RESULT_OK, 0, context);
 	}
 }
 
@@ -967,5 +1008,43 @@ int main(int argc, char *argv[])
 			MINIMAL_SLC_SESSION,
 			data_end());
 
+	/* Transfer Registration Status - HF */
+	define_hf_test("/HFP/HF/TRS/BV-01-C", test_hf_session,
+			NULL, test_hf_session_done,
+			MINIMAL_SLC_SESSION,
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '1', ',', '1', '\r', '\n'),
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '1', ',', '0', '\r', '\n'),
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '1', ',', '1', '\r', '\n'),
+			data_end());
+
+	/* Transfer Signal Strength Indication - HF */
+	define_hf_test("/HFP/HF/PSI/BV-01-C", test_hf_session,
+			NULL, test_hf_session_done,
+			MINIMAL_SLC_SESSION,
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '5', ',', '3', '\r', '\n'),
+			data_end());
+
+	/* Transfer Roaming Status Indication - HF */
+	define_hf_test("/HFP/HF/PSI/BV-02-C", test_hf_session,
+			NULL, test_hf_session_done,
+			MINIMAL_SLC_SESSION,
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '6', ',', '1', '\r', '\n'),
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '6', ',', '0', '\r', '\n'),
+			data_end());
+
+	/* Transfer Battery Level Indication - HF */
+	define_hf_test("/HFP/HF/PSI/BV-03-C", test_hf_session,
+			NULL, test_hf_session_done,
+			MINIMAL_SLC_SESSION,
+			frg_pdu('\r', '\n', '+', 'C', 'I', 'E', 'V', ':'),
+			frg_pdu(' ', '7', ',', '3', '\r', '\n'),
+			data_end());
+
 	return tester_run();
 }
-- 
2.43.0


  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 ` [PATCH BlueZ RESEND 2/4] unit/test-hfp: Add SLC connection test Frédéric Danis
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 ` Frédéric Danis [this message]
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-4-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 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.