* [PATCHv2 2/6] android/avctp: Add UNIT INFO command request
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
@ 2014-02-21 15:23 ` Andrei Emeltchenko
2014-02-23 11:57 ` Luiz Augusto von Dentz
2014-02-21 15:23 ` [PATCHv2 3/6] android/avrcp: Implement avrcp_get_avctp Andrei Emeltchenko
` (4 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-21 15:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/avctp.c | 13 +++++++++++++
android/avctp.h | 3 +++
2 files changed, 16 insertions(+)
diff --git a/android/avctp.c b/android/avctp.c
index 1e414d1..57a8c23 100644
--- a/android/avctp.c
+++ b/android/avctp.c
@@ -1266,6 +1266,19 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
func, user_data);
}
+int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
+ void *user_data)
+{
+ uint8_t operands[5];
+
+ memset(operands, 0xFF, sizeof(operands));
+
+ return avctp_send_req(session, AVC_CTYPE_STATUS,
+ AVC_SUBUNIT_UNIT, AVC_OP_UNITINFO,
+ operands, sizeof(operands),
+ func, user_data);
+}
+
unsigned int avctp_register_passthrough_handler(struct avctp *session,
avctp_passthrough_cb cb,
void *user_data)
diff --git a/android/avctp.h b/android/avctp.h
index dfa0ca6..7496e53 100644
--- a/android/avctp.h
+++ b/android/avctp.h
@@ -46,6 +46,7 @@
/* subunits of interest */
#define AVC_SUBUNIT_PANEL 0x09
+#define AVC_SUBUNIT_UNIT 0x1f
/* operands in passthrough commands */
#define AVC_SELECT 0x00
@@ -170,3 +171,5 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
int avctp_send_browsing_req(struct avctp *session,
uint8_t *operands, size_t operand_count,
avctp_browsing_rsp_cb func, void *user_data);
+int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
+ void *user_data);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCHv2 2/6] android/avctp: Add UNIT INFO command request
2014-02-21 15:23 ` [PATCHv2 2/6] android/avctp: Add UNIT INFO command request Andrei Emeltchenko
@ 2014-02-23 11:57 ` Luiz Augusto von Dentz
2014-02-24 6:54 ` Andrei Emeltchenko
0 siblings, 1 reply; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-23 11:57 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
Hi Andrei,
On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
> android/avctp.c | 13 +++++++++++++
> android/avctp.h | 3 +++
> 2 files changed, 16 insertions(+)
>
> diff --git a/android/avctp.c b/android/avctp.c
> index 1e414d1..57a8c23 100644
> --- a/android/avctp.c
> +++ b/android/avctp.c
> @@ -1266,6 +1266,19 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
> func, user_data);
> }
>
> +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
> + void *user_data)
> +{
> + uint8_t operands[5];
> +
> + memset(operands, 0xFF, sizeof(operands));
> +
> + return avctp_send_req(session, AVC_CTYPE_STATUS,
> + AVC_SUBUNIT_UNIT, AVC_OP_UNITINFO,
> + operands, sizeof(operands),
> + func, user_data);
> +}
> +
> unsigned int avctp_register_passthrough_handler(struct avctp *session,
> avctp_passthrough_cb cb,
> void *user_data)
> diff --git a/android/avctp.h b/android/avctp.h
> index dfa0ca6..7496e53 100644
> --- a/android/avctp.h
> +++ b/android/avctp.h
> @@ -46,6 +46,7 @@
>
> /* subunits of interest */
> #define AVC_SUBUNIT_PANEL 0x09
> +#define AVC_SUBUNIT_UNIT 0x1f
>
> /* operands in passthrough commands */
> #define AVC_SELECT 0x00
> @@ -170,3 +171,5 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
> int avctp_send_browsing_req(struct avctp *session,
> uint8_t *operands, size_t operand_count,
> avctp_browsing_rsp_cb func, void *user_data);
> +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
> + void *user_data);
> --
> 1.8.3.2
This probably needs to be internal and sent automatically once
connected specially if it is for a mandatory test.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCHv2 2/6] android/avctp: Add UNIT INFO command request
2014-02-23 11:57 ` Luiz Augusto von Dentz
@ 2014-02-24 6:54 ` Andrei Emeltchenko
2014-02-24 8:28 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-24 6:54 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
Hi Luiz,
On Sun, Feb 23, 2014 at 01:57:05PM +0200, Luiz Augusto von Dentz wrote:
> Hi Andrei,
>
> On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
> <andrei.emeltchenko@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > ---
> > android/avctp.c | 13 +++++++++++++
> > android/avctp.h | 3 +++
> > 2 files changed, 16 insertions(+)
> >
> > diff --git a/android/avctp.c b/android/avctp.c
> > index 1e414d1..57a8c23 100644
> > --- a/android/avctp.c
> > +++ b/android/avctp.c
> > @@ -1266,6 +1266,19 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
> > func, user_data);
> > }
> >
> > +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
> > + void *user_data)
> > +{
> > + uint8_t operands[5];
> > +
> > + memset(operands, 0xFF, sizeof(operands));
> > +
> > + return avctp_send_req(session, AVC_CTYPE_STATUS,
> > + AVC_SUBUNIT_UNIT, AVC_OP_UNITINFO,
> > + operands, sizeof(operands),
> > + func, user_data);
> > +}
> > +
> > unsigned int avctp_register_passthrough_handler(struct avctp *session,
> > avctp_passthrough_cb cb,
> > void *user_data)
> > diff --git a/android/avctp.h b/android/avctp.h
> > index dfa0ca6..7496e53 100644
> > --- a/android/avctp.h
> > +++ b/android/avctp.h
> > @@ -46,6 +46,7 @@
> >
> > /* subunits of interest */
> > #define AVC_SUBUNIT_PANEL 0x09
> > +#define AVC_SUBUNIT_UNIT 0x1f
> >
> > /* operands in passthrough commands */
> > #define AVC_SELECT 0x00
> > @@ -170,3 +171,5 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
> > int avctp_send_browsing_req(struct avctp *session,
> > uint8_t *operands, size_t operand_count,
> > avctp_browsing_rsp_cb func, void *user_data);
> > +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
> > + void *user_data);
> > --
> > 1.8.3.2
>
> This probably needs to be internal and sent automatically once
> connected specially if it is for a mandatory test.
So what do you propose with this case? Make it private and send this
command in avrcp_new() ?
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCHv2 2/6] android/avctp: Add UNIT INFO command request
2014-02-24 6:54 ` Andrei Emeltchenko
@ 2014-02-24 8:28 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-24 8:28 UTC (permalink / raw)
To: Andrei Emeltchenko, Luiz Augusto von Dentz,
linux-bluetooth@vger.kernel.org
Hi Andrei,
On Mon, Feb 24, 2014 at 8:54 AM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> Hi Luiz,
>
> On Sun, Feb 23, 2014 at 01:57:05PM +0200, Luiz Augusto von Dentz wrote:
>> Hi Andrei,
>>
>> On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
>> <andrei.emeltchenko@gmail.com> wrote:
>> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>> >
>> > ---
>> > android/avctp.c | 13 +++++++++++++
>> > android/avctp.h | 3 +++
>> > 2 files changed, 16 insertions(+)
>> >
>> > diff --git a/android/avctp.c b/android/avctp.c
>> > index 1e414d1..57a8c23 100644
>> > --- a/android/avctp.c
>> > +++ b/android/avctp.c
>> > @@ -1266,6 +1266,19 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
>> > func, user_data);
>> > }
>> >
>> > +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
>> > + void *user_data)
>> > +{
>> > + uint8_t operands[5];
>> > +
>> > + memset(operands, 0xFF, sizeof(operands));
>> > +
>> > + return avctp_send_req(session, AVC_CTYPE_STATUS,
>> > + AVC_SUBUNIT_UNIT, AVC_OP_UNITINFO,
>> > + operands, sizeof(operands),
>> > + func, user_data);
>> > +}
>> > +
>> > unsigned int avctp_register_passthrough_handler(struct avctp *session,
>> > avctp_passthrough_cb cb,
>> > void *user_data)
>> > diff --git a/android/avctp.h b/android/avctp.h
>> > index dfa0ca6..7496e53 100644
>> > --- a/android/avctp.h
>> > +++ b/android/avctp.h
>> > @@ -46,6 +46,7 @@
>> >
>> > /* subunits of interest */
>> > #define AVC_SUBUNIT_PANEL 0x09
>> > +#define AVC_SUBUNIT_UNIT 0x1f
>> >
>> > /* operands in passthrough commands */
>> > #define AVC_SELECT 0x00
>> > @@ -170,3 +171,5 @@ int avctp_send_vendordep_req(struct avctp *session, uint8_t code,
>> > int avctp_send_browsing_req(struct avctp *session,
>> > uint8_t *operands, size_t operand_count,
>> > avctp_browsing_rsp_cb func, void *user_data);
>> > +int avctp_send_unit_info_req(struct avctp *session, avctp_rsp_cb func,
>> > + void *user_data);
>> > --
>> > 1.8.3.2
>>
>> This probably needs to be internal and sent automatically once
>> connected specially if it is for a mandatory test.
>
> So what do you propose with this case? Make it private and send this
> command in avrcp_new() ?
If it is mandatory, yes we should do it automatically, perhaps we can
trigger it with passthrough registration.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCHv2 3/6] android/avrcp: Implement avrcp_get_avctp
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
2014-02-21 15:23 ` [PATCHv2 2/6] android/avctp: Add UNIT INFO command request Andrei Emeltchenko
@ 2014-02-21 15:23 ` Andrei Emeltchenko
2014-02-23 11:54 ` Luiz Augusto von Dentz
2014-02-21 15:23 ` [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers Andrei Emeltchenko
` (3 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-21 15:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/avrcp-lib.c | 5 +++++
android/avrcp-lib.h | 3 +++
2 files changed, 8 insertions(+)
diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index ef48fa7..9180abd 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -39,6 +39,11 @@ struct avrcp {
struct avctp *session;
};
+struct avctp *avrcp_get_avctp(struct avrcp *session)
+{
+ return session->session;
+}
+
void avrcp_shutdown(struct avrcp *session)
{
if (session->session)
diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
index 7955d56..7bd8b25 100644
--- a/android/avrcp-lib.h
+++ b/android/avrcp-lib.h
@@ -21,8 +21,11 @@
*
*/
+struct avrcp;
+
typedef void (*avrcp_destroy_cb_t) (void *user_data);
+struct avctp *avrcp_get_avctp(struct avrcp *session);
struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
void avrcp_shutdown(struct avrcp *session);
void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
--
1.8.3.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCHv2 3/6] android/avrcp: Implement avrcp_get_avctp
2014-02-21 15:23 ` [PATCHv2 3/6] android/avrcp: Implement avrcp_get_avctp Andrei Emeltchenko
@ 2014-02-23 11:54 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-23 11:54 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
Hi Andrei,
On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ---
> android/avrcp-lib.c | 5 +++++
> android/avrcp-lib.h | 3 +++
> 2 files changed, 8 insertions(+)
>
> diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
> index ef48fa7..9180abd 100644
> --- a/android/avrcp-lib.c
> +++ b/android/avrcp-lib.c
> @@ -39,6 +39,11 @@ struct avrcp {
> struct avctp *session;
> };
>
> +struct avctp *avrcp_get_avctp(struct avrcp *session)
> +{
> + return session->session;
> +}
> +
> void avrcp_shutdown(struct avrcp *session)
> {
> if (session->session)
> diff --git a/android/avrcp-lib.h b/android/avrcp-lib.h
> index 7955d56..7bd8b25 100644
> --- a/android/avrcp-lib.h
> +++ b/android/avrcp-lib.h
> @@ -21,8 +21,11 @@
> *
> */
>
> +struct avrcp;
> +
> typedef void (*avrcp_destroy_cb_t) (void *user_data);
>
> +struct avctp *avrcp_get_avctp(struct avrcp *session);
> struct avrcp *avrcp_new(int fd, size_t imtu, size_t omtu, uint16_t version);
> void avrcp_shutdown(struct avrcp *session);
> void avrcp_set_destroy_cb(struct avrcp *session, avrcp_destroy_cb_t cb,
> --
> 1.8.3.2
Not sure if you have seem my patch-set, this probably conflict with it
and a rather not have the AVCTP exposed.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
2014-02-21 15:23 ` [PATCHv2 2/6] android/avctp: Add UNIT INFO command request Andrei Emeltchenko
2014-02-21 15:23 ` [PATCHv2 3/6] android/avrcp: Implement avrcp_get_avctp Andrei Emeltchenko
@ 2014-02-21 15:23 ` Andrei Emeltchenko
2014-02-24 6:55 ` Andrei Emeltchenko
2014-02-21 15:23 ` [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test Andrei Emeltchenko
` (2 subsequent siblings)
5 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-21 15:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/avrcp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/android/avrcp.c b/android/avrcp.c
index 8ac9e2f..acffd56 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -222,7 +222,7 @@ static sdp_record_t *avrcp_record(void)
features = sdp_data_alloc(SDP_UINT16, &feat);
sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
- sdp_set_info_attr(record, "AVRCP TG", 0, 0);
+ sdp_set_info_attr(record, "AVRCP TG", NULL, NULL);
sdp_data_free(psm);
sdp_data_free(version);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers
2014-02-21 15:23 ` [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers Andrei Emeltchenko
@ 2014-02-24 6:55 ` Andrei Emeltchenko
2014-02-24 12:31 ` Luiz Augusto von Dentz
0 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-24 6:55 UTC (permalink / raw)
To: linux-bluetooth
On Fri, Feb 21, 2014 at 05:23:48PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
ping
>
> ---
> android/avrcp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/android/avrcp.c b/android/avrcp.c
> index 8ac9e2f..acffd56 100644
> --- a/android/avrcp.c
> +++ b/android/avrcp.c
> @@ -222,7 +222,7 @@ static sdp_record_t *avrcp_record(void)
> features = sdp_data_alloc(SDP_UINT16, &feat);
> sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
>
> - sdp_set_info_attr(record, "AVRCP TG", 0, 0);
> + sdp_set_info_attr(record, "AVRCP TG", NULL, NULL);
>
> sdp_data_free(psm);
> sdp_data_free(version);
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers
2014-02-24 6:55 ` Andrei Emeltchenko
@ 2014-02-24 12:31 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-24 12:31 UTC (permalink / raw)
To: Andrei Emeltchenko, linux-bluetooth@vger.kernel.org
Hi Andrei,
On Mon, Feb 24, 2014 at 8:55 AM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> On Fri, Feb 21, 2014 at 05:23:48PM +0200, Andrei Emeltchenko wrote:
>> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> ping
>
>>
>> ---
>> android/avrcp.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/android/avrcp.c b/android/avrcp.c
>> index 8ac9e2f..acffd56 100644
>> --- a/android/avrcp.c
>> +++ b/android/avrcp.c
>> @@ -222,7 +222,7 @@ static sdp_record_t *avrcp_record(void)
>> features = sdp_data_alloc(SDP_UINT16, &feat);
>> sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features);
>>
>> - sdp_set_info_attr(record, "AVRCP TG", 0, 0);
>> + sdp_set_info_attr(record, "AVRCP TG", NULL, NULL);
>>
>> sdp_data_free(psm);
>> sdp_data_free(version);
>> --
>> 1.8.3.2
Applied, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
` (2 preceding siblings ...)
2014-02-21 15:23 ` [PATCHv2 4/6] android/avrcp: Use NULL for zero pointers Andrei Emeltchenko
@ 2014-02-21 15:23 ` Andrei Emeltchenko
2014-02-23 12:06 ` Luiz Augusto von Dentz
2014-02-21 15:23 ` [PATCHv2 6/6] unit/avrcp: Add /TP/ICC/BV-01-I/TG test Andrei Emeltchenko
2014-02-24 7:09 ` [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
5 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-21 15:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that the Controller can collect information of Target
by UNIT INFO command.
---
unit/test-avrcp.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index f1c0f46..2cb28b1 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -242,6 +242,37 @@ static void test_dummy(gconstpointer data)
destroy_context(context);
}
+static void execute_context(struct context *context)
+{
+ g_main_loop_run(context->main_loop);
+
+ if (context->source > 0)
+ g_source_remove(context->source);
+
+ avrcp_shutdown(context->session);
+
+ g_main_loop_unref(context->main_loop);
+
+ test_free(context->data);
+ g_free(context);
+}
+
+static void test_client(gconstpointer data)
+{
+ struct context *context = create_context(0x0100, data);
+ struct avctp *session = avrcp_get_avctp(context->session);
+ int ret = 0;
+
+ if (g_str_equal(context->data->test_name, "/TP/ICC/BV-01-I/CT"))
+ ret = avctp_send_unit_info_req(session, NULL, NULL);
+
+ DBG("ret = %d", ret);
+
+ g_assert(!ret);
+
+ execute_context(context);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -261,5 +292,11 @@ int main(int argc, char *argv[])
define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
+ /* Information collection for control tests */
+
+ define_test("/TP/ICC/BV-01-I/CT", test_client,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0xf8, 0x30,
+ 0xff, 0xff, 0xff, 0xff, 0xff));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test
2014-02-21 15:23 ` [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test Andrei Emeltchenko
@ 2014-02-23 12:06 ` Luiz Augusto von Dentz
2014-02-24 7:03 ` Andrei Emeltchenko
0 siblings, 1 reply; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-23 12:06 UTC (permalink / raw)
To: Andrei Emeltchenko; +Cc: linux-bluetooth@vger.kernel.org
HI Andrei,
On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Test verifies that the Controller can collect information of Target
> by UNIT INFO command.
> ---
> unit/test-avrcp.c | 37 +++++++++++++++++++++++++++++++++++++
> 1 file changed, 37 insertions(+)
>
> diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
> index f1c0f46..2cb28b1 100644
> --- a/unit/test-avrcp.c
> +++ b/unit/test-avrcp.c
> @@ -242,6 +242,37 @@ static void test_dummy(gconstpointer data)
> destroy_context(context);
> }
>
> +static void execute_context(struct context *context)
> +{
> + g_main_loop_run(context->main_loop);
> +
> + if (context->source > 0)
> + g_source_remove(context->source);
> +
> + avrcp_shutdown(context->session);
> +
> + g_main_loop_unref(context->main_loop);
> +
> + test_free(context->data);
> + g_free(context);
> +}
> +
> +static void test_client(gconstpointer data)
> +{
> + struct context *context = create_context(0x0100, data);
> + struct avctp *session = avrcp_get_avctp(context->session);
> + int ret = 0;
> +
> + if (g_str_equal(context->data->test_name, "/TP/ICC/BV-01-I/CT"))
> + ret = avctp_send_unit_info_req(session, NULL, NULL);
> +
> + DBG("ret = %d", ret);
> +
> + g_assert(!ret);
> +
> + execute_context(context);
> +}
> +
> int main(int argc, char *argv[])
> {
> g_test_init(&argc, &argv, NULL);
> @@ -261,5 +292,11 @@ int main(int argc, char *argv[])
> define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
> define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
>
> + /* Information collection for control tests */
> +
> + define_test("/TP/ICC/BV-01-I/CT", test_client,
> + raw_pdu(0x00, 0x11, 0x0e, 0x01, 0xf8, 0x30,
> + 0xff, 0xff, 0xff, 0xff, 0xff));
> +
> return g_test_run();
> }
> --
> 1.8.3.2
There is no such test in the test spec, there is only TP/ICC/BV-01-I,
perhaps you adding CT yourself just to be able to define the same test
for the TG but in that case I think it is better to separate with
different macros e.g. define_test_ct prefixing with "CT" to make
better distinction and don't mess with test names otherwise we may
confuse people looking at those tests.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test
2014-02-23 12:06 ` Luiz Augusto von Dentz
@ 2014-02-24 7:03 ` Andrei Emeltchenko
0 siblings, 0 replies; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-24 7:03 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth@vger.kernel.org
Hi Luiz,
On Sun, Feb 23, 2014 at 02:06:59PM +0200, Luiz Augusto von Dentz wrote:
> HI Andrei,
>
> On Fri, Feb 21, 2014 at 5:23 PM, Andrei Emeltchenko
> <andrei.emeltchenko@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > Test verifies that the Controller can collect information of Target
> > by UNIT INFO command.
> > ---
> > unit/test-avrcp.c | 37 +++++++++++++++++++++++++++++++++++++
> > 1 file changed, 37 insertions(+)
> >
> > diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
> > index f1c0f46..2cb28b1 100644
> > --- a/unit/test-avrcp.c
> > +++ b/unit/test-avrcp.c
> > @@ -242,6 +242,37 @@ static void test_dummy(gconstpointer data)
> > destroy_context(context);
> > }
> >
> > +static void execute_context(struct context *context)
> > +{
> > + g_main_loop_run(context->main_loop);
> > +
> > + if (context->source > 0)
> > + g_source_remove(context->source);
> > +
> > + avrcp_shutdown(context->session);
> > +
> > + g_main_loop_unref(context->main_loop);
> > +
> > + test_free(context->data);
> > + g_free(context);
> > +}
> > +
> > +static void test_client(gconstpointer data)
> > +{
> > + struct context *context = create_context(0x0100, data);
> > + struct avctp *session = avrcp_get_avctp(context->session);
> > + int ret = 0;
> > +
> > + if (g_str_equal(context->data->test_name, "/TP/ICC/BV-01-I/CT"))
> > + ret = avctp_send_unit_info_req(session, NULL, NULL);
> > +
> > + DBG("ret = %d", ret);
> > +
> > + g_assert(!ret);
> > +
> > + execute_context(context);
> > +}
> > +
> > int main(int argc, char *argv[])
> > {
> > g_test_init(&argc, &argv, NULL);
> > @@ -261,5 +292,11 @@ int main(int argc, char *argv[])
> > define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
> > define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
> >
> > + /* Information collection for control tests */
> > +
> > + define_test("/TP/ICC/BV-01-I/CT", test_client,
> > + raw_pdu(0x00, 0x11, 0x0e, 0x01, 0xf8, 0x30,
> > + 0xff, 0xff, 0xff, 0xff, 0xff));
> > +
> > return g_test_run();
> > }
> > --
> > 1.8.3.2
>
> There is no such test in the test spec, there is only TP/ICC/BV-01-I,
> perhaps you adding CT yourself just to be able to define the same test
> for the TG but in that case I think it is better to separate with
> different macros e.g. define_test_ct prefixing with "CT" to make
> better distinction and don't mess with test names otherwise we may
> confuse people looking at those tests.
Sorry don't get it. How we might confuse people with it? Anybody who
looked at least once to the spec wouldn't be confused, and others do not
care.
Anyway please propose any way I will follow example.
BTW: What is really confusing are names in pts-avrcp.txt. They are
almost completely different like for the case above:
"TC_TG_ICC_BV_01_I"
Best regards
Andrei Emeltchenko
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCHv2 6/6] unit/avrcp: Add /TP/ICC/BV-01-I/TG test
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
` (3 preceding siblings ...)
2014-02-21 15:23 ` [PATCHv2 5/6] unit/avrcp: Add /TP/ICC/BV-01-I/CT test Andrei Emeltchenko
@ 2014-02-21 15:23 ` Andrei Emeltchenko
2014-02-24 7:09 ` [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
5 siblings, 0 replies; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-21 15:23 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Test verifies that the Target responds to UNIT INFO command initiated by
Controller.
---
unit/test-avrcp.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
index 2cb28b1..0e7de96 100644
--- a/unit/test-avrcp.c
+++ b/unit/test-avrcp.c
@@ -273,6 +273,15 @@ static void test_client(gconstpointer data)
execute_context(context);
}
+static void test_server(gconstpointer data)
+{
+ struct context *context = create_context(0x0100, data);
+
+ g_idle_add(send_pdu, context);
+
+ execute_context(context);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
@@ -298,5 +307,11 @@ int main(int argc, char *argv[])
raw_pdu(0x00, 0x11, 0x0e, 0x01, 0xf8, 0x30,
0xff, 0xff, 0xff, 0xff, 0xff));
+ define_test("/TP/ICC/BV-01-I/TG", test_server,
+ raw_pdu(0x00, 0x11, 0x0e, 0x01, 0xf8, 0x30,
+ 0xff, 0xff, 0xff, 0xff, 0xff),
+ raw_pdu(0x02, 0x11, 0x0e, 0x0c, 0xf8, 0x30,
+ 0x07, 0x48, 0xff, 0xff, 0xff));
+
return g_test_run();
}
--
1.8.3.2
^ permalink raw reply related [flat|nested] 16+ messages in thread* Re: [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile
2014-02-21 15:23 [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
` (4 preceding siblings ...)
2014-02-21 15:23 ` [PATCHv2 6/6] unit/avrcp: Add /TP/ICC/BV-01-I/TG test Andrei Emeltchenko
@ 2014-02-24 7:09 ` Andrei Emeltchenko
2014-02-24 8:25 ` Luiz Augusto von Dentz
5 siblings, 1 reply; 16+ messages in thread
From: Andrei Emeltchenko @ 2014-02-24 7:09 UTC (permalink / raw)
To: linux-bluetooth
On Fri, Feb 21, 2014 at 05:23:45PM +0200, Andrei Emeltchenko wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> The tests verifies connection establishment for control.
ping
> ---
> Makefile.am | 9 ++
> unit/test-avrcp.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 274 insertions(+)
> create mode 100644 unit/test-avrcp.c
>
> diff --git a/Makefile.am b/Makefile.am
> index 11f2aa1..5fe58eb 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -282,6 +282,15 @@ unit_test_avctp_SOURCES = unit/test-avctp.c \
> android/avctp.c android/avctp.h
> unit_test_avctp_LDADD = @GLIB_LIBS@
>
> +unit_tests += unit/test-avrcp
> +
> +unit_test_avrcp_SOURCES = unit/test-avrcp.c \
> + src/shared/util.h src/shared/util.c \
> + src/log.h src/log.c \
> + android/avctp.c android/avctp.h \
> + android/avrcp-lib.c android/avrcp-lib.h
> +unit_test_avrcp_LDADD = @GLIB_LIBS@ lib/libbluetooth-internal.la
> +
> unit_tests += unit/test-gdbus-client
>
> unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
> diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
> new file mode 100644
> index 0000000..f1c0f46
> --- /dev/null
> +++ b/unit/test-avrcp.c
> @@ -0,0 +1,265 @@
> +/*
> + *
> + * BlueZ - Bluetooth protocol stack for Linux
> + *
> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> + *
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <unistd.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <inttypes.h>
> +#include <string.h>
> +#include <fcntl.h>
> +#include <sys/socket.h>
> +
> +#include <glib.h>
> +
> +#include "src/shared/util.h"
> +#include "src/log.h"
> +#include "lib/bluetooth.h"
> +
> +#include "android/avctp.h"
> +#include "android/avrcp-lib.h"
> +
> +struct test_pdu {
> + bool valid;
> + bool fragmented;
> + const uint8_t *data;
> + size_t size;
> +};
> +
> +struct test_data {
> + char *test_name;
> + struct test_pdu *pdu_list;
> +};
> +
> +struct context {
> + GMainLoop *main_loop;
> + struct avrcp *session;
> + guint source;
> + guint process;
> + int fd;
> + unsigned int pdu_offset;
> + const struct test_data *data;
> +};
> +
> +#define data(args...) ((const unsigned char[]) { args })
> +
> +#define raw_pdu(args...) \
> + { \
> + .valid = true, \
> + .data = data(args), \
> + .size = sizeof(data(args)), \
> + }
> +
> +#define frg_pdu(args...) \
> + { \
> + .valid = true, \
> + .fragmented = true, \
> + .data = data(args), \
> + .size = sizeof(data(args)), \
> + }
> +
> +#define define_test(name, function, args...) \
> + do { \
> + const struct test_pdu pdus[] = { \
> + args, { } \
> + }; \
> + static struct test_data data; \
> + data.test_name = g_strdup(name); \
> + data.pdu_list = g_malloc(sizeof(pdus)); \
> + memcpy(data.pdu_list, pdus, sizeof(pdus)); \
> + g_test_add_data_func(name, &data, function); \
> + } while (0)
> +
> +static void test_debug(const char *str, void *user_data)
> +{
> + const char *prefix = user_data;
> +
> + g_print("%s%s\n", prefix, str);
> +}
> +
> +static void test_free(gconstpointer user_data)
> +{
> + const struct test_data *data = user_data;
> +
> + g_free(data->test_name);
> + g_free(data->pdu_list);
> +}
> +
> +static gboolean context_quit(gpointer user_data)
> +{
> + struct context *context = user_data;
> +
> + if (context->process > 0)
> + g_source_remove(context->process);
> +
> + g_main_loop_quit(context->main_loop);
> +
> + return FALSE;
> +}
> +
> +static gboolean send_pdu(gpointer user_data)
> +{
> + struct context *context = user_data;
> + const struct test_pdu *pdu;
> + ssize_t len;
> +
> + pdu = &context->data->pdu_list[context->pdu_offset++];
> +
> + len = write(context->fd, pdu->data, pdu->size);
> +
> + if (g_test_verbose())
> + util_hexdump('<', pdu->data, len, test_debug, "AVRCP: ");
> +
> + g_assert_cmpint(len, ==, pdu->size);
> +
> + if (pdu->fragmented)
> + return send_pdu(user_data);
> +
> + context->process = 0;
> + return FALSE;
> +}
> +
> +static void context_process(struct context *context)
> +{
> + if (!context->data->pdu_list[context->pdu_offset].valid) {
> + context_quit(context);
> + return;
> + }
> +
> + context->process = g_idle_add(send_pdu, context);
> +}
> +
> +static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
> + gpointer user_data)
> +{
> + struct context *context = user_data;
> + const struct test_pdu *pdu;
> + unsigned char buf[512];
> + ssize_t len;
> + int fd;
> +
> + pdu = &context->data->pdu_list[context->pdu_offset++];
> +
> + if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
> + context->source = 0;
> + g_print("%s: cond %x\n", __func__, cond);
> + return FALSE;
> + }
> +
> + fd = g_io_channel_unix_get_fd(channel);
> +
> + len = read(fd, buf, sizeof(buf));
> +
> + g_assert(len > 0);
> +
> + if (g_test_verbose())
> + util_hexdump('>', buf, len, test_debug, "AVRCP: ");
> +
> + g_assert_cmpint(len, ==, pdu->size);
> +
> + g_assert(memcmp(buf, pdu->data, pdu->size) == 0);
> +
> + if (!pdu->fragmented)
> + context_process(context);
> +
> + return TRUE;
> +}
> +
> +static struct context *create_context(uint16_t version, gconstpointer data)
> +{
> + struct context *context = g_new0(struct context, 1);
> + GIOChannel *channel;
> + int err, sv[2];
> +
> + context->main_loop = g_main_loop_new(NULL, FALSE);
> + g_assert(context->main_loop);
> +
> + err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
> + g_assert(err == 0);
> +
> + context->session = avrcp_new(sv[0], 672, 672, version);
> + g_assert(context->session != NULL);
> +
> + channel = g_io_channel_unix_new(sv[1]);
> +
> + g_io_channel_set_close_on_unref(channel, TRUE);
> + g_io_channel_set_encoding(channel, NULL, NULL);
> + g_io_channel_set_buffered(channel, FALSE);
> +
> + context->source = g_io_add_watch(channel,
> + G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
> + test_handler, context);
> + g_assert(context->source > 0);
> +
> + g_io_channel_unref(channel);
> +
> + context->fd = sv[1];
> + context->data = data;
> +
> + return context;
> +}
> +
> +static void destroy_context(struct context *context)
> +{
> + if (context->source > 0)
> + g_source_remove(context->source);
> +
> + avrcp_shutdown(context->session);
> +
> + g_main_loop_unref(context->main_loop);
> +
> + test_free(context->data);
> + g_free(context);
> +}
> +
> +static void test_dummy(gconstpointer data)
> +{
> + struct context *context = create_context(0x0100, data);
> +
> + destroy_context(context);
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + g_test_init(&argc, &argv, NULL);
> +
> + if (g_test_verbose())
> + __btd_log_init("*", 0);
> +
> + /* Connection Establishment for Control tests */
> +
> + /*
> + * Tests are checking connection establishement and release
> + * for control channel. Since we are connected through socketpair
> + * the tests are dummy
> + */
> + define_test("/TP/CEC/BV-01-I", test_dummy, raw_pdu(0x00));
> + define_test("/TP/CEC/BV-02-I", test_dummy, raw_pdu(0x00));
> + define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
> + define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
> +
> + return g_test_run();
> +}
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile
2014-02-24 7:09 ` [PATCHv2 1/6] unit/avrcp: First unit test for AVRCP profile Andrei Emeltchenko
@ 2014-02-24 8:25 ` Luiz Augusto von Dentz
0 siblings, 0 replies; 16+ messages in thread
From: Luiz Augusto von Dentz @ 2014-02-24 8:25 UTC (permalink / raw)
To: Andrei Emeltchenko, linux-bluetooth@vger.kernel.org
Hi Andrei,
On Mon, Feb 24, 2014 at 9:09 AM, Andrei Emeltchenko
<andrei.emeltchenko@gmail.com> wrote:
> On Fri, Feb 21, 2014 at 05:23:45PM +0200, Andrei Emeltchenko wrote:
>> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>>
>> The tests verifies connection establishment for control.
>
> ping
>
>
>> ---
>> Makefile.am | 9 ++
>> unit/test-avrcp.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 274 insertions(+)
>> create mode 100644 unit/test-avrcp.c
>>
>> diff --git a/Makefile.am b/Makefile.am
>> index 11f2aa1..5fe58eb 100644
>> --- a/Makefile.am
>> +++ b/Makefile.am
>> @@ -282,6 +282,15 @@ unit_test_avctp_SOURCES = unit/test-avctp.c \
>> android/avctp.c android/avctp.h
>> unit_test_avctp_LDADD = @GLIB_LIBS@
>>
>> +unit_tests += unit/test-avrcp
>> +
>> +unit_test_avrcp_SOURCES = unit/test-avrcp.c \
>> + src/shared/util.h src/shared/util.c \
>> + src/log.h src/log.c \
>> + android/avctp.c android/avctp.h \
>> + android/avrcp-lib.c android/avrcp-lib.h
>> +unit_test_avrcp_LDADD = @GLIB_LIBS@ lib/libbluetooth-internal.la
>> +
>> unit_tests += unit/test-gdbus-client
>>
>> unit_test_gdbus_client_SOURCES = unit/test-gdbus-client.c
>> diff --git a/unit/test-avrcp.c b/unit/test-avrcp.c
>> new file mode 100644
>> index 0000000..f1c0f46
>> --- /dev/null
>> +++ b/unit/test-avrcp.c
>> @@ -0,0 +1,265 @@
>> +/*
>> + *
>> + * BlueZ - Bluetooth protocol stack for Linux
>> + *
>> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
>> + *
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; if not, write to the Free Software
>> + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
>> + *
>> + */
>> +
>> +#ifdef HAVE_CONFIG_H
>> +#include <config.h>
>> +#endif
>> +
>> +#include <unistd.h>
>> +#include <stdlib.h>
>> +#include <stdbool.h>
>> +#include <inttypes.h>
>> +#include <string.h>
>> +#include <fcntl.h>
>> +#include <sys/socket.h>
>> +
>> +#include <glib.h>
>> +
>> +#include "src/shared/util.h"
>> +#include "src/log.h"
>> +#include "lib/bluetooth.h"
>> +
>> +#include "android/avctp.h"
>> +#include "android/avrcp-lib.h"
>> +
>> +struct test_pdu {
>> + bool valid;
>> + bool fragmented;
>> + const uint8_t *data;
>> + size_t size;
>> +};
>> +
>> +struct test_data {
>> + char *test_name;
>> + struct test_pdu *pdu_list;
>> +};
>> +
>> +struct context {
>> + GMainLoop *main_loop;
>> + struct avrcp *session;
>> + guint source;
>> + guint process;
>> + int fd;
>> + unsigned int pdu_offset;
>> + const struct test_data *data;
>> +};
>> +
>> +#define data(args...) ((const unsigned char[]) { args })
>> +
>> +#define raw_pdu(args...) \
>> + { \
>> + .valid = true, \
>> + .data = data(args), \
>> + .size = sizeof(data(args)), \
>> + }
>> +
>> +#define frg_pdu(args...) \
>> + { \
>> + .valid = true, \
>> + .fragmented = true, \
>> + .data = data(args), \
>> + .size = sizeof(data(args)), \
>> + }
>> +
>> +#define define_test(name, function, args...) \
>> + do { \
>> + const struct test_pdu pdus[] = { \
>> + args, { } \
>> + }; \
>> + static struct test_data data; \
>> + data.test_name = g_strdup(name); \
>> + data.pdu_list = g_malloc(sizeof(pdus)); \
>> + memcpy(data.pdu_list, pdus, sizeof(pdus)); \
>> + g_test_add_data_func(name, &data, function); \
>> + } while (0)
>> +
>> +static void test_debug(const char *str, void *user_data)
>> +{
>> + const char *prefix = user_data;
>> +
>> + g_print("%s%s\n", prefix, str);
>> +}
>> +
>> +static void test_free(gconstpointer user_data)
>> +{
>> + const struct test_data *data = user_data;
>> +
>> + g_free(data->test_name);
>> + g_free(data->pdu_list);
>> +}
>> +
>> +static gboolean context_quit(gpointer user_data)
>> +{
>> + struct context *context = user_data;
>> +
>> + if (context->process > 0)
>> + g_source_remove(context->process);
>> +
>> + g_main_loop_quit(context->main_loop);
>> +
>> + return FALSE;
>> +}
>> +
>> +static gboolean send_pdu(gpointer user_data)
>> +{
>> + struct context *context = user_data;
>> + const struct test_pdu *pdu;
>> + ssize_t len;
>> +
>> + pdu = &context->data->pdu_list[context->pdu_offset++];
>> +
>> + len = write(context->fd, pdu->data, pdu->size);
>> +
>> + if (g_test_verbose())
>> + util_hexdump('<', pdu->data, len, test_debug, "AVRCP: ");
>> +
>> + g_assert_cmpint(len, ==, pdu->size);
>> +
>> + if (pdu->fragmented)
>> + return send_pdu(user_data);
>> +
>> + context->process = 0;
>> + return FALSE;
>> +}
>> +
>> +static void context_process(struct context *context)
>> +{
>> + if (!context->data->pdu_list[context->pdu_offset].valid) {
>> + context_quit(context);
>> + return;
>> + }
>> +
>> + context->process = g_idle_add(send_pdu, context);
>> +}
>> +
>> +static gboolean test_handler(GIOChannel *channel, GIOCondition cond,
>> + gpointer user_data)
>> +{
>> + struct context *context = user_data;
>> + const struct test_pdu *pdu;
>> + unsigned char buf[512];
>> + ssize_t len;
>> + int fd;
>> +
>> + pdu = &context->data->pdu_list[context->pdu_offset++];
>> +
>> + if (cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) {
>> + context->source = 0;
>> + g_print("%s: cond %x\n", __func__, cond);
>> + return FALSE;
>> + }
>> +
>> + fd = g_io_channel_unix_get_fd(channel);
>> +
>> + len = read(fd, buf, sizeof(buf));
>> +
>> + g_assert(len > 0);
>> +
>> + if (g_test_verbose())
>> + util_hexdump('>', buf, len, test_debug, "AVRCP: ");
>> +
>> + g_assert_cmpint(len, ==, pdu->size);
>> +
>> + g_assert(memcmp(buf, pdu->data, pdu->size) == 0);
>> +
>> + if (!pdu->fragmented)
>> + context_process(context);
>> +
>> + return TRUE;
>> +}
>> +
>> +static struct context *create_context(uint16_t version, gconstpointer data)
>> +{
>> + struct context *context = g_new0(struct context, 1);
>> + GIOChannel *channel;
>> + int err, sv[2];
>> +
>> + context->main_loop = g_main_loop_new(NULL, FALSE);
>> + g_assert(context->main_loop);
>> +
>> + err = socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv);
>> + g_assert(err == 0);
>> +
>> + context->session = avrcp_new(sv[0], 672, 672, version);
>> + g_assert(context->session != NULL);
>> +
>> + channel = g_io_channel_unix_new(sv[1]);
>> +
>> + g_io_channel_set_close_on_unref(channel, TRUE);
>> + g_io_channel_set_encoding(channel, NULL, NULL);
>> + g_io_channel_set_buffered(channel, FALSE);
>> +
>> + context->source = g_io_add_watch(channel,
>> + G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
>> + test_handler, context);
>> + g_assert(context->source > 0);
>> +
>> + g_io_channel_unref(channel);
>> +
>> + context->fd = sv[1];
>> + context->data = data;
>> +
>> + return context;
>> +}
>> +
>> +static void destroy_context(struct context *context)
>> +{
>> + if (context->source > 0)
>> + g_source_remove(context->source);
>> +
>> + avrcp_shutdown(context->session);
>> +
>> + g_main_loop_unref(context->main_loop);
>> +
>> + test_free(context->data);
>> + g_free(context);
>> +}
>> +
>> +static void test_dummy(gconstpointer data)
>> +{
>> + struct context *context = create_context(0x0100, data);
>> +
>> + destroy_context(context);
>> +}
>> +
>> +int main(int argc, char *argv[])
>> +{
>> + g_test_init(&argc, &argv, NULL);
>> +
>> + if (g_test_verbose())
>> + __btd_log_init("*", 0);
>> +
>> + /* Connection Establishment for Control tests */
>> +
>> + /*
>> + * Tests are checking connection establishement and release
>> + * for control channel. Since we are connected through socketpair
>> + * the tests are dummy
>> + */
>> + define_test("/TP/CEC/BV-01-I", test_dummy, raw_pdu(0x00));
>> + define_test("/TP/CEC/BV-02-I", test_dummy, raw_pdu(0x00));
>> + define_test("/TP/CRC/BV-01-I", test_dummy, raw_pdu(0x00));
>> + define_test("/TP/CRC/BV-02-I", test_dummy, raw_pdu(0x00));
>> +
>> + return g_test_run();
>> +}
>> --
>> 1.8.3.2
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
Applied, thanks.
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 16+ messages in thread