Path: blob/master/tools/testing/selftests/hid/tests/test_ite_keyboard.py
26308 views
#!/bin/env python31# SPDX-License-Identifier: GPL-2.02# -*- coding: utf-8 -*-3#4# Copyright (c) 2020 Benjamin Tissoires <[email protected]>5# Copyright (c) 2020 Red Hat, Inc.6#78from .test_keyboard import ArrayKeyboard, TestArrayKeyboard9from hidtools.util import BusType1011import libevdev12import logging13from . import base1415logger = logging.getLogger("hidtools.test.ite-keyboard")1617KERNEL_MODULE = base.KernelModule("itetech", "hid_ite")181920class KbdData(object):21pass222324# The ITE keyboards have an issue regarding the Wifi key:25# nothing comes in when pressing the key, but we get a null26# event on the key release.27# This test covers this case.28class ITEKeyboard(ArrayKeyboard):29# fmt: off30report_descriptor = [310x06, 0x85, 0xff, # Usage Page (Vendor Usage Page 0xff85)320x09, 0x95, # Usage (Vendor Usage 0x95) 3330xa1, 0x01, # Collection (Application) 5340x85, 0x5a, # .Report ID (90) 7350x09, 0x01, # .Usage (Vendor Usage 0x01) 9360x15, 0x00, # .Logical Minimum (0) 11370x26, 0xff, 0x00, # .Logical Maximum (255) 13380x75, 0x08, # .Report Size (8) 16390x95, 0x10, # .Report Count (16) 18400xb1, 0x00, # .Feature (Data,Arr,Abs) 20410xc0, # End Collection 22420x05, 0x01, # Usage Page (Generic Desktop) 23430x09, 0x06, # Usage (Keyboard) 25440xa1, 0x01, # Collection (Application) 27450x85, 0x01, # .Report ID (1) 29460x75, 0x01, # .Report Size (1) 31470x95, 0x08, # .Report Count (8) 33480x05, 0x07, # .Usage Page (Keyboard) 35490x19, 0xe0, # .Usage Minimum (224) 37500x29, 0xe7, # .Usage Maximum (231) 39510x15, 0x00, # .Logical Minimum (0) 41520x25, 0x01, # .Logical Maximum (1) 43530x81, 0x02, # .Input (Data,Var,Abs) 45540x95, 0x01, # .Report Count (1) 47550x75, 0x08, # .Report Size (8) 49560x81, 0x03, # .Input (Cnst,Var,Abs) 51570x95, 0x05, # .Report Count (5) 53580x75, 0x01, # .Report Size (1) 55590x05, 0x08, # .Usage Page (LEDs) 57600x19, 0x01, # .Usage Minimum (1) 59610x29, 0x05, # .Usage Maximum (5) 61620x91, 0x02, # .Output (Data,Var,Abs) 63630x95, 0x01, # .Report Count (1) 65640x75, 0x03, # .Report Size (3) 67650x91, 0x03, # .Output (Cnst,Var,Abs) 69660x95, 0x06, # .Report Count (6) 71670x75, 0x08, # .Report Size (8) 73680x15, 0x00, # .Logical Minimum (0) 75690x26, 0xff, 0x00, # .Logical Maximum (255) 77700x05, 0x07, # .Usage Page (Keyboard) 80710x19, 0x00, # .Usage Minimum (0) 82720x2a, 0xff, 0x00, # .Usage Maximum (255) 84730x81, 0x00, # .Input (Data,Arr,Abs) 87740xc0, # End Collection 89750x05, 0x0c, # Usage Page (Consumer Devices) 90760x09, 0x01, # Usage (Consumer Control) 92770xa1, 0x01, # Collection (Application) 94780x85, 0x02, # .Report ID (2) 96790x19, 0x00, # .Usage Minimum (0) 98800x2a, 0x3c, 0x02, # .Usage Maximum (572) 100810x15, 0x00, # .Logical Minimum (0) 103820x26, 0x3c, 0x02, # .Logical Maximum (572) 105830x75, 0x10, # .Report Size (16) 108840x95, 0x01, # .Report Count (1) 110850x81, 0x00, # .Input (Data,Arr,Abs) 112860xc0, # End Collection 114870x05, 0x01, # Usage Page (Generic Desktop) 115880x09, 0x0c, # Usage (Wireless Radio Controls) 117890xa1, 0x01, # Collection (Application) 119900x85, 0x03, # .Report ID (3) 121910x15, 0x00, # .Logical Minimum (0) 123920x25, 0x01, # .Logical Maximum (1) 125930x09, 0xc6, # .Usage (Wireless Radio Button) 127940x95, 0x01, # .Report Count (1) 129950x75, 0x01, # .Report Size (1) 131960x81, 0x06, # .Input (Data,Var,Rel) 133970x75, 0x07, # .Report Size (7) 135980x81, 0x03, # .Input (Cnst,Var,Abs) 137990xc0, # End Collection 1391000x05, 0x88, # Usage Page (Vendor Usage Page 0x88) 1401010x09, 0x01, # Usage (Vendor Usage 0x01) 1421020xa1, 0x01, # Collection (Application) 1441030x85, 0x04, # .Report ID (4) 1461040x19, 0x00, # .Usage Minimum (0) 1481050x2a, 0xff, 0xff, # .Usage Maximum (65535) 1501060x15, 0x00, # .Logical Minimum (0) 1531070x26, 0xff, 0xff, # .Logical Maximum (65535) 1551080x75, 0x08, # .Report Size (8) 1581090x95, 0x02, # .Report Count (2) 1601100x81, 0x02, # .Input (Data,Var,Abs) 1621110xc0, # End Collection 1641120x05, 0x01, # Usage Page (Generic Desktop) 1651130x09, 0x80, # Usage (System Control) 1671140xa1, 0x01, # Collection (Application) 1691150x85, 0x05, # .Report ID (5) 1711160x19, 0x81, # .Usage Minimum (129) 1731170x29, 0x83, # .Usage Maximum (131) 1751180x15, 0x00, # .Logical Minimum (0) 1771190x25, 0x01, # .Logical Maximum (1) 1791200x95, 0x08, # .Report Count (8) 1811210x75, 0x01, # .Report Size (1) 1831220x81, 0x02, # .Input (Data,Var,Abs) 1851230xc0, # End Collection 187124]125# fmt: on126127def __init__(128self,129rdesc=report_descriptor,130name=None,131input_info=(BusType.USB, 0x06CB, 0x2968),132):133super().__init__(rdesc, name, input_info)134135def event(self, keys, reportID=None, application=None):136application = application or "Keyboard"137return super().event(keys, reportID, application)138139140class TestITEKeyboard(TestArrayKeyboard):141kernel_modules = [KERNEL_MODULE]142143def create_device(self):144return ITEKeyboard()145146def test_wifi_key(self):147uhdev = self.uhdev148syn_event = self.syn_event149150# the following sends a 'release' event on the Wifi key.151# the kernel is supposed to translate this into Wifi key152# down and up153r = [0x03, 0x00]154uhdev.call_input_event(r)155expected = [syn_event]156expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 1))157events = uhdev.next_sync_events()158self.debug_reports([r], uhdev, events)159self.assertInputEventsIn(expected, events)160161expected = [syn_event]162expected.append(libevdev.InputEvent(libevdev.EV_KEY.KEY_RFKILL, 0))163# the kernel sends the two down/up key events in a batch, no need to164# call events = uhdev.next_sync_events()165self.debug_reports([], uhdev, events)166self.assertInputEventsIn(expected, events)167168169