1 // SPDX-License-Identifier: GPL-2.0+
4 * HID driver for UC-Logic devices not fully compliant with HID standard
6 * Copyright (c) 2022 José Expósito <jose.exposito89@gmail.com>
9 #include <kunit/test.h>
10 #include "./hid-uclogic-params.h"
11 #include "./hid-uclogic-rdesc.h"
13 #define MAX_STR_DESC_SIZE 14
15 struct uclogic_parse_ugee_v2_desc_case {
18 const __u8 str_desc[MAX_STR_DESC_SIZE];
20 const s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
21 enum uclogic_params_frame_type frame_type;
24 static struct uclogic_parse_ugee_v2_desc_case uclogic_parse_ugee_v2_desc_cases[] = {
26 .name = "invalid_str_desc",
31 .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS,
34 .name = "resolution_with_value_0",
47 [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB270,
48 [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0,
49 [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7710,
50 [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0,
51 [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF,
52 [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08,
54 .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS,
56 /* XP-PEN Deco L str_desc: Frame with 8 buttons */
58 .name = "frame_type_buttons",
71 [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB270,
72 [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2320,
73 [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7710,
74 [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x1770,
75 [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF,
76 [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08,
78 .frame_type = UCLOGIC_PARAMS_FRAME_BUTTONS,
80 /* PARBLO A610 PRO str_desc: Frame with 9 buttons and dial */
82 .name = "frame_type_dial",
95 [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xC796,
96 [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2749,
97 [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x7CF9,
98 [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x1899,
99 [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF,
100 [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x09,
102 .frame_type = UCLOGIC_PARAMS_FRAME_DIAL,
104 /* XP-PEN Deco Pro S str_desc: Frame with 8 buttons and mouse */
106 .name = "frame_type_mouse",
119 [UCLOGIC_RDESC_PEN_PH_ID_X_LM] = 0xB3C8,
120 [UCLOGIC_RDESC_PEN_PH_ID_X_PM] = 0x2363,
121 [UCLOGIC_RDESC_PEN_PH_ID_Y_LM] = 0x6534,
122 [UCLOGIC_RDESC_PEN_PH_ID_Y_PM] = 0x13EC,
123 [UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM] = 0x1FFF,
124 [UCLOGIC_RDESC_FRAME_PH_ID_UM] = 0x08,
126 .frame_type = UCLOGIC_PARAMS_FRAME_MOUSE,
130 static void uclogic_parse_ugee_v2_desc_case_desc(struct uclogic_parse_ugee_v2_desc_case *t,
133 strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
136 KUNIT_ARRAY_PARAM(uclogic_parse_ugee_v2_desc, uclogic_parse_ugee_v2_desc_cases,
137 uclogic_parse_ugee_v2_desc_case_desc);
139 static void hid_test_uclogic_parse_ugee_v2_desc(struct kunit *test)
142 s32 desc_params[UCLOGIC_RDESC_PH_ID_NUM];
143 enum uclogic_params_frame_type frame_type;
144 const struct uclogic_parse_ugee_v2_desc_case *params = test->param_value;
146 res = uclogic_params_parse_ugee_v2_desc(params->str_desc,
147 params->str_desc_size,
149 ARRAY_SIZE(desc_params),
151 KUNIT_ASSERT_EQ(test, res, params->res);
156 KUNIT_EXPECT_EQ(test,
157 params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM],
158 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_LM]);
159 KUNIT_EXPECT_EQ(test,
160 params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM],
161 desc_params[UCLOGIC_RDESC_PEN_PH_ID_X_PM]);
162 KUNIT_EXPECT_EQ(test,
163 params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM],
164 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_LM]);
165 KUNIT_EXPECT_EQ(test,
166 params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM],
167 desc_params[UCLOGIC_RDESC_PEN_PH_ID_Y_PM]);
168 KUNIT_EXPECT_EQ(test,
169 params->desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM],
170 desc_params[UCLOGIC_RDESC_PEN_PH_ID_PRESSURE_LM]);
171 KUNIT_EXPECT_EQ(test,
172 params->desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM],
173 desc_params[UCLOGIC_RDESC_FRAME_PH_ID_UM]);
174 KUNIT_EXPECT_EQ(test, params->frame_type, frame_type);
177 static void hid_test_uclogic_params_cleanup_event_hooks(struct kunit *test)
180 struct uclogic_params p = {0, };
182 res = uclogic_params_ugee_v2_init_event_hooks(NULL, &p);
183 KUNIT_ASSERT_EQ(test, res, 0);
185 /* Check that the function can be called repeatedly */
186 for (n = 0; n < 4; n++) {
187 uclogic_params_cleanup_event_hooks(&p);
188 KUNIT_EXPECT_PTR_EQ(test, p.event_hooks, NULL);
192 static struct kunit_case hid_uclogic_params_test_cases[] = {
193 KUNIT_CASE_PARAM(hid_test_uclogic_parse_ugee_v2_desc,
194 uclogic_parse_ugee_v2_desc_gen_params),
195 KUNIT_CASE(hid_test_uclogic_params_cleanup_event_hooks),
199 static struct kunit_suite hid_uclogic_params_test_suite = {
200 .name = "hid_uclogic_params_test",
201 .test_cases = hid_uclogic_params_test_cases,
204 kunit_test_suite(hid_uclogic_params_test_suite);
206 MODULE_DESCRIPTION("KUnit tests for the UC-Logic driver");
207 MODULE_LICENSE("GPL");
208 MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");