Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/tools/testing/selftests/hid/tests/test_ite_keyboard.py
26308 views
1
#!/bin/env python3
2
# SPDX-License-Identifier: GPL-2.0
3
# -*- coding: utf-8 -*-
4
#
5
# Copyright (c) 2020 Benjamin Tissoires <[email protected]>
6
# Copyright (c) 2020 Red Hat, Inc.
7
#
8
9
from .test_keyboard import ArrayKeyboard, TestArrayKeyboard
10
from hidtools.util import BusType
11
12
import libevdev
13
import logging
14
from . import base
15
16
logger = logging.getLogger("hidtools.test.ite-keyboard")
17
18
KERNEL_MODULE = base.KernelModule("itetech", "hid_ite")
19
20
21
class KbdData(object):
22
pass
23
24
25
# The ITE keyboards have an issue regarding the Wifi key:
26
# nothing comes in when pressing the key, but we get a null
27
# event on the key release.
28
# This test covers this case.
29
class ITEKeyboard(ArrayKeyboard):
30
# fmt: off
31
report_descriptor = [
32
0x06, 0x85, 0xff, # Usage Page (Vendor Usage Page 0xff85)
33
0x09, 0x95, # Usage (Vendor Usage 0x95) 3
34
0xa1, 0x01, # Collection (Application) 5
35
0x85, 0x5a, # .Report ID (90) 7
36
0x09, 0x01, # .Usage (Vendor Usage 0x01) 9
37
0x15, 0x00, # .Logical Minimum (0) 11
38
0x26, 0xff, 0x00, # .Logical Maximum (255) 13
39
0x75, 0x08, # .Report Size (8) 16
40
0x95, 0x10, # .Report Count (16) 18
41
0xb1, 0x00, # .Feature (Data,Arr,Abs) 20
42
0xc0, # End Collection 22
43
0x05, 0x01, # Usage Page (Generic Desktop) 23
44
0x09, 0x06, # Usage (Keyboard) 25
45
0xa1, 0x01, # Collection (Application) 27
46
0x85, 0x01, # .Report ID (1) 29
47
0x75, 0x01, # .Report Size (1) 31
48
0x95, 0x08, # .Report Count (8) 33
49
0x05, 0x07, # .Usage Page (Keyboard) 35
50
0x19, 0xe0, # .Usage Minimum (224) 37
51
0x29, 0xe7, # .Usage Maximum (231) 39
52
0x15, 0x00, # .Logical Minimum (0) 41
53
0x25, 0x01, # .Logical Maximum (1) 43
54
0x81, 0x02, # .Input (Data,Var,Abs) 45
55
0x95, 0x01, # .Report Count (1) 47
56
0x75, 0x08, # .Report Size (8) 49
57
0x81, 0x03, # .Input (Cnst,Var,Abs) 51
58
0x95, 0x05, # .Report Count (5) 53
59
0x75, 0x01, # .Report Size (1) 55
60
0x05, 0x08, # .Usage Page (LEDs) 57
61
0x19, 0x01, # .Usage Minimum (1) 59
62
0x29, 0x05, # .Usage Maximum (5) 61
63
0x91, 0x02, # .Output (Data,Var,Abs) 63
64
0x95, 0x01, # .Report Count (1) 65
65
0x75, 0x03, # .Report Size (3) 67
66
0x91, 0x03, # .Output (Cnst,Var,Abs) 69
67
0x95, 0x06, # .Report Count (6) 71
68
0x75, 0x08, # .Report Size (8) 73
69
0x15, 0x00, # .Logical Minimum (0) 75
70
0x26, 0xff, 0x00, # .Logical Maximum (255) 77
71
0x05, 0x07, # .Usage Page (Keyboard) 80
72
0x19, 0x00, # .Usage Minimum (0) 82
73
0x2a, 0xff, 0x00, # .Usage Maximum (255) 84
74
0x81, 0x00, # .Input (Data,Arr,Abs) 87
75
0xc0, # End Collection 89
76
0x05, 0x0c, # Usage Page (Consumer Devices) 90
77
0x09, 0x01, # Usage (Consumer Control) 92
78
0xa1, 0x01, # Collection (Application) 94
79
0x85, 0x02, # .Report ID (2) 96
80
0x19, 0x00, # .Usage Minimum (0) 98
81
0x2a, 0x3c, 0x02, # .Usage Maximum (572) 100
82
0x15, 0x00, # .Logical Minimum (0) 103
83
0x26, 0x3c, 0x02, # .Logical Maximum (572) 105
84
0x75, 0x10, # .Report Size (16) 108
85
0x95, 0x01, # .Report Count (1) 110
86
0x81, 0x00, # .Input (Data,Arr,Abs) 112
87
0xc0, # End Collection 114
88
0x05, 0x01, # Usage Page (Generic Desktop) 115
89
0x09, 0x0c, # Usage (Wireless Radio Controls) 117
90
0xa1, 0x01, # Collection (Application) 119
91
0x85, 0x03, # .Report ID (3) 121
92
0x15, 0x00, # .Logical Minimum (0) 123
93
0x25, 0x01, # .Logical Maximum (1) 125
94
0x09, 0xc6, # .Usage (Wireless Radio Button) 127
95
0x95, 0x01, # .Report Count (1) 129
96
0x75, 0x01, # .Report Size (1) 131
97
0x81, 0x06, # .Input (Data,Var,Rel) 133
98
0x75, 0x07, # .Report Size (7) 135
99
0x81, 0x03, # .Input (Cnst,Var,Abs) 137
100
0xc0, # End Collection 139
101
0x05, 0x88, # Usage Page (Vendor Usage Page 0x88) 140
102
0x09, 0x01, # Usage (Vendor Usage 0x01) 142
103
0xa1, 0x01, # Collection (Application) 144
104
0x85, 0x04, # .Report ID (4) 146
105
0x19, 0x00, # .Usage Minimum (0) 148
106
0x2a, 0xff, 0xff, # .Usage Maximum (65535) 150
107
0x15, 0x00, # .Logical Minimum (0) 153
108
0x26, 0xff, 0xff, # .Logical Maximum (65535) 155
109
0x75, 0x08, # .Report Size (8) 158
110
0x95, 0x02, # .Report Count (2) 160
111
0x81, 0x02, # .Input (Data,Var,Abs) 162
112
0xc0, # End Collection 164
113
0x05, 0x01, # Usage Page (Generic Desktop) 165
114
0x09, 0x80, # Usage (System Control) 167
115
0xa1, 0x01, # Collection (Application) 169
116
0x85, 0x05, # .Report ID (5) 171
117
0x19, 0x81, # .Usage Minimum (129) 173
118
0x29, 0x83, # .Usage Maximum (131) 175
119
0x15, 0x00, # .Logical Minimum (0) 177
120
0x25, 0x01, # .Logical Maximum (1) 179
121
0x95, 0x08, # .Report Count (8) 181
122
0x75, 0x01, # .Report Size (1) 183
123
0x81, 0x02, # .Input (Data,Var,Abs) 185
124
0xc0, # End Collection 187
125
]
126
# fmt: on
127
128
def __init__(
129
self,
130
rdesc=report_descriptor,
131
name=None,
132
input_info=(BusType.USB, 0x06CB, 0x2968),
133
):
134
super().__init__(rdesc, name, input_info)
135
136
def event(self, keys, reportID=None, application=None):
137
application = application or "Keyboard"
138
return super().event(keys, reportID, application)
139
140
141
class TestITEKeyboard(TestArrayKeyboard):
142
kernel_modules = [KERNEL_MODULE]
143
144
def create_device(self):
145
return ITEKeyboard()
146
147
def test_wifi_key(self):
148
uhdev = self.uhdev
149
syn_event = self.syn_event
150
151
# the following sends a 'release' event on the Wifi key.
152
# the kernel is supposed to translate this into Wifi key
153
# down and up
154
r = [0x03, 0x00]
155
uhdev.call_input_event(r)
156
expected = [syn_event]
157
expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 1))
158
events = uhdev.next_sync_events()
159
self.debug_reports([r], uhdev, events)
160
self.assertInputEventsIn(expected, events)
161
162
expected = [syn_event]
163
expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 0))
164
# the kernel sends the two down/up key events in a batch, no need to
165
# call events = uhdev.next_sync_events()
166
self.debug_reports([], uhdev, events)
167
self.assertInputEventsIn(expected, events)
168
169