2022-06-11 11:39:12 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HID driver for UC-Logic devices not fully compliant with HID standard
|
|
|
|
*
|
|
|
|
* Copyright (c) 2022 José Expósito <jose.exposito89@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kunit/test.h>
|
|
|
|
#include "./hid-uclogic-rdesc.h"
|
|
|
|
|
|
|
|
struct uclogic_template_case {
|
|
|
|
const char *name;
|
|
|
|
const __u8 *template;
|
|
|
|
size_t template_size;
|
|
|
|
const s32 *param_list;
|
|
|
|
size_t param_num;
|
|
|
|
const __u8 *expected;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const s32 params_pen_all[UCLOGIC_RDESC_PH_ID_NUM] = {
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA,
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0xCC,
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0xDD,
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0xEE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const s32 params_pen_some[] = {
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xAA,
|
|
|
|
[UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0xBB,
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:13 +00:00
|
|
|
static const s32 params_frame_all[UCLOGIC_RDESC_PH_ID_NUM] = {
|
|
|
|
[UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0xFF,
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:12 +00:00
|
|
|
static const __u8 template_empty[] = { };
|
|
|
|
static const __u8 template_small[] = { 0x00 };
|
|
|
|
static const __u8 template_no_ph[] = { 0xAA, 0xFE, 0xAA, 0xED, 0x1D };
|
|
|
|
|
|
|
|
static const __u8 template_pen_ph_end[] = {
|
|
|
|
0xAA, 0xBB, UCLOGIC_RDESC_PEN_PH_HEAD
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:13 +00:00
|
|
|
static const __u8 template_btn_ph_end[] = {
|
|
|
|
0xAA, 0xBB, UCLOGIC_RDESC_FRAME_PH_BTN_HEAD
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:12 +00:00
|
|
|
static const __u8 template_pen_all_params[] = {
|
|
|
|
UCLOGIC_RDESC_PEN_PH(X_LM),
|
|
|
|
0x47, UCLOGIC_RDESC_PEN_PH(X_PM),
|
|
|
|
0x27, UCLOGIC_RDESC_PEN_PH(Y_LM),
|
|
|
|
UCLOGIC_RDESC_PEN_PH(Y_PM),
|
|
|
|
0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const __u8 expected_pen_all_params[] = {
|
|
|
|
0xAA, 0x00, 0x00, 0x00,
|
|
|
|
0x47, 0xBB, 0x00, 0x00, 0x00,
|
|
|
|
0x27, 0xCC, 0x00, 0x00, 0x00,
|
|
|
|
0xDD, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0xEE, 0x00, 0x00, 0x00,
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:13 +00:00
|
|
|
static const __u8 template_frame_all_params[] = {
|
|
|
|
0x01, 0x02,
|
|
|
|
UCLOGIC_RDESC_FRAME_PH_BTN,
|
|
|
|
0x99,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const __u8 expected_frame_all_params[] = {
|
|
|
|
0x01, 0x02,
|
|
|
|
0x2A, 0xFF, 0x00,
|
|
|
|
0x99,
|
|
|
|
};
|
|
|
|
|
2022-06-11 11:39:12 +00:00
|
|
|
static const __u8 template_pen_some_params[] = {
|
|
|
|
0x01, 0x02,
|
|
|
|
UCLOGIC_RDESC_PEN_PH(X_LM),
|
|
|
|
0x03, UCLOGIC_RDESC_PEN_PH(X_PM),
|
|
|
|
0x04, 0x05,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const __u8 expected_pen_some_params[] = {
|
|
|
|
0x01, 0x02,
|
|
|
|
0xAA, 0x00, 0x00, 0x00,
|
|
|
|
0x03, 0xBB, 0x00, 0x00, 0x00,
|
|
|
|
0x04, 0x05,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const __u8 template_params_none[] = {
|
|
|
|
0x27, UCLOGIC_RDESC_PEN_PH(Y_LM),
|
|
|
|
UCLOGIC_RDESC_PEN_PH(Y_PM),
|
|
|
|
0x00, UCLOGIC_RDESC_PEN_PH(PRESSURE_LM),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct uclogic_template_case uclogic_template_cases[] = {
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "empty_template",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_empty,
|
|
|
|
.template_size = sizeof(template_empty),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = template_empty,
|
|
|
|
},
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "template_smaller_than_the_placeholder",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_small,
|
|
|
|
.template_size = sizeof(template_small),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = template_small,
|
|
|
|
},
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "no_placeholder",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_no_ph,
|
|
|
|
.template_size = sizeof(template_no_ph),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = template_no_ph,
|
|
|
|
},
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "pen_placeholder_at_the_end_without_id",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_pen_ph_end,
|
|
|
|
.template_size = sizeof(template_pen_ph_end),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = template_pen_ph_end,
|
|
|
|
},
|
2022-06-11 11:39:13 +00:00
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "frame_button_placeholder_at_the_end_without_id",
|
2022-06-11 11:39:13 +00:00
|
|
|
.template = template_btn_ph_end,
|
|
|
|
.template_size = sizeof(template_btn_ph_end),
|
|
|
|
.param_list = params_frame_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_frame_all),
|
|
|
|
.expected = template_btn_ph_end,
|
|
|
|
},
|
2022-06-11 11:39:12 +00:00
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "all_params_present_in_the_pen_template",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_pen_all_params,
|
|
|
|
.template_size = sizeof(template_pen_all_params),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = expected_pen_all_params,
|
|
|
|
},
|
2022-06-11 11:39:13 +00:00
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "all_params_present_in_the_frame_template",
|
2022-06-11 11:39:13 +00:00
|
|
|
.template = template_frame_all_params,
|
|
|
|
.template_size = sizeof(template_frame_all_params),
|
|
|
|
.param_list = params_frame_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_frame_all),
|
|
|
|
.expected = expected_frame_all_params,
|
|
|
|
},
|
2022-06-11 11:39:12 +00:00
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "some_params_present_in_the_pen_template_with_complete_param_list",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_pen_some_params,
|
|
|
|
.template_size = sizeof(template_pen_some_params),
|
|
|
|
.param_list = params_pen_all,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_all),
|
|
|
|
.expected = expected_pen_some_params,
|
|
|
|
},
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "some_params_present_in_the_pen_template_with_incomplete_param_list",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_pen_some_params,
|
|
|
|
.template_size = sizeof(template_pen_some_params),
|
|
|
|
.param_list = params_pen_some,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_some),
|
|
|
|
.expected = expected_pen_some_params,
|
|
|
|
},
|
|
|
|
{
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "no_params_present_in_the_template",
|
2022-06-11 11:39:12 +00:00
|
|
|
.template = template_params_none,
|
|
|
|
.template_size = sizeof(template_params_none),
|
|
|
|
.param_list = params_pen_some,
|
|
|
|
.param_num = ARRAY_SIZE(params_pen_some),
|
|
|
|
.expected = template_params_none,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void uclogic_template_case_desc(struct uclogic_template_case *t,
|
|
|
|
char *desc)
|
|
|
|
{
|
|
|
|
strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
KUNIT_ARRAY_PARAM(uclogic_template, uclogic_template_cases,
|
|
|
|
uclogic_template_case_desc);
|
|
|
|
|
2022-11-10 17:49:55 +00:00
|
|
|
static void hid_test_uclogic_template(struct kunit *test)
|
2022-06-11 11:39:12 +00:00
|
|
|
{
|
|
|
|
__u8 *res;
|
|
|
|
const struct uclogic_template_case *params = test->param_value;
|
|
|
|
|
|
|
|
res = uclogic_rdesc_template_apply(params->template,
|
|
|
|
params->template_size,
|
|
|
|
params->param_list,
|
|
|
|
params->param_num);
|
|
|
|
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, res);
|
2022-12-26 12:57:36 +00:00
|
|
|
KUNIT_EXPECT_MEMEQ(test, res, params->expected, params->template_size);
|
2022-06-11 11:39:12 +00:00
|
|
|
kfree(res);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct kunit_case hid_uclogic_rdesc_test_cases[] = {
|
2022-11-10 17:49:55 +00:00
|
|
|
KUNIT_CASE_PARAM(hid_test_uclogic_template, uclogic_template_gen_params),
|
2022-06-11 11:39:12 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct kunit_suite hid_uclogic_rdesc_test_suite = {
|
2022-08-15 14:29:49 +00:00
|
|
|
.name = "hid_uclogic_rdesc_test",
|
2022-06-11 11:39:12 +00:00
|
|
|
.test_cases = hid_uclogic_rdesc_test_cases,
|
|
|
|
};
|
|
|
|
|
|
|
|
kunit_test_suite(hid_uclogic_rdesc_test_suite);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("KUnit tests for the UC-Logic driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");
|