tests_kernel.test_mouse module — hid-tools documentation

# tests_kernel.test_mouse module

class BadReportDescriptorMouse(rdesc=[150, 1, 0, 6, 1, 0, 42, 144, 160, 39, 0, 0, 0, 0, 179, 129, 62, 37, 3, 27, 221, 232, 64, 80, 59, 93, 140, 61, 218], name=None, input_info=(3, 1118, 2010))

  Bases: `BaseMouse`

  This “device” was one autogenerated by syzbot. There are a lot of issues in it, and the most problematic is that it declares features that have no size.

  This leads to report->size being set to 0 and can mess up with usbhid internals. Fortunately, uhid merely passes the incoming buffer, without touching it so a buffer of size 0 will be translated to [] without triggering a kernel oops.

  Because the report descriptor is wrong, no input are created, and we need to tweak a little bit the parameters to make it look correct.

  get_evdev(application=None)
  is_ready()

    Returns whether a UHID device is ready. Can be overwritten in subclasses to add extra conditions on when to consider a UHID device ready. This can be:

    - we need to wait on different types of input devices to be ready (Touch Screen and Pen for example)

    - we need to have at least 4 LEDs present (len(self.uhdev.leds_classes) == 4)

    - or any other combinations

  next_sync_events(application=None)
  report_descriptor = [150, 1, 0, 6, 1, 0, 42, 144, 160, 39, 0, 0, 0, 0, 179, 129, 62, 37, 3, 27, 221, 232, 64, 80, 59, 93, 140, 61, 218]
  set_report(req, rnum, rtype, data)

    Callback invoked when a process calls SetReport on this UHID device.

    Return `0` on success or an errno on failure.

    The default method always returns `EIO` for a failure. Override this in your device if you want SetReport to succeed.

    Parameters:

      - req – the request identifier

      - rnum –

        ???

      - rtype – one of `UHID_FEATURE_REPORT`, `UHID_INPUT_REPORT`, or `UHID_OUTPUT_REPORT`

      - data (list) – a byte string with the data

class BadResolutionMultiplierMouse(rdesc=[5, 1, 9, 2, 161, 1, 5, 1, 9, 2, 161, 2, 133, 17, 9, 1, 161, 0, 5, 9, 25, 1, 41, 3, 149, 3, 117, 1, 37, 1, 129, 2, 149, 1, 129, 1, 9, 5, 129, 2, 149, 3, 129, 1, 5, 1, 9, 48, 9, 49, 149, 2, 117, 8, 21, 129, 37, 127, 129, 6, 161, 2, 133, 18, 9, 72, 149, 1, 117, 2, 21, 0, 37, 1, 53, 1, 69, 4, 177, 2, 53, 0, 69, 0, 117, 6, 177, 1, 133, 17, 9, 56, 21, 129, 37, 127, 117, 8, 129, 6, 192, 5, 12, 117, 8, 10, 56, 2, 129, 6, 192, 192, 192], name=None, input_info=None)

  Bases: `ResolutionMultiplierMouse`

  set_report(req, rnum, rtype, data)

    Callback invoked when a process calls SetReport on this UHID device.

    Return `0` on success or an errno on failure.

    The default method always returns `EIO` for a failure. Override this in your device if you want SetReport to succeed.

    Parameters:

      - req – the request identifier

      - rnum –

        ???

      - rtype – one of `UHID_FEATURE_REPORT`, `UHID_INPUT_REPORT`, or `UHID_OUTPUT_REPORT`

      - data (list) – a byte string with the data

class BaseMouse(rdesc, name=None, input_info=None)

  Bases: `UHIDTestDevice`

  create_report(x, y, buttons=None, wheels=None, reportID=None)

    Return an input report for this device.

    Parameters:

      - x – relative x

      - y – relative y

      - buttons – a (l, r, m) tuple of bools for the button states, where `None` is “leave unchanged”

      - wheels – a single value for the vertical wheel or a (vertical, horizontal) tuple for the two wheels

      - reportID – the numeric report ID for this report, if needed

  event(x, y, buttons=None, wheels=None)

    Send an input event on the default report ID.

    Parameters:

      - x – relative x

      - y – relative y

      - buttons – a (l, r, m) tuple of bools for the button states, where `None` is “leave unchanged”

      - wheels – a single value for the vertical wheel or a (vertical, horizontal) tuple for the two wheels

class BaseTest

  Bases: `object`

  class TestMouse

    Bases: `TestUhid`

    test_buttons()

      check for button reliability.

    test_relative()

      Check for relative events.

class ButtonMouse(rdesc=[5, 1, 9, 2, 161, 1, 9, 2, 161, 2, 9, 1, 161, 0, 5, 9, 25, 1, 41, 3, 21, 0, 37, 1, 117, 1, 149, 3, 129, 2, 117, 5, 149, 1, 129, 3, 5, 1, 9, 48, 9, 49, 21, 129, 37, 127, 117, 8, 149, 2, 129, 6, 192, 192, 192], name=None, input_info=None)

  Bases: `BaseMouse`

  fake_report(x, y, buttons)
  report_descriptor = [5, 1, 9, 2, 161, 1, 9, 2, 161, 2, 9, 1, 161, 0, 5, 9, 25, 1, 41, 3, 21, 0, 37, 1, 117, 1, 149, 3, 129, 2, 117, 5, 149, 1, 129, 3, 5, 1, 9, 48, 9, 49, 21, 129, 37, 127, 117, 8, 149, 2, 129, 6, 192, 192, 192]

exception InvalidHIDCommunication

  Bases: `Exception`

class MIDongleMIWirelessMouse(rdesc=[5, 1, 9, 2, 161, 1, 133, 1, 9, 1, 161, 0, 149, 5, 117, 1, 5, 9, 25, 1, 41, 5, 21, 0, 37, 1, 129, 2, 149, 1, 117, 3, 129, 1, 117, 8, 149, 1, 5, 1, 9, 56, 21, 129, 37, 127, 129, 6, 5, 12, 10, 56, 2, 149, 1, 129, 6, 192, 133, 2, 9, 1, 161, 0, 117, 12, 149, 2, 5, 1, 9, 48, 9, 49, 22, 1, 248, 38, 255, 7, 129, 6, 192, 192, 5, 12, 9, 1, 161, 1, 133, 3, 21, 0, 37, 1, 117, 1, 149, 1, 9, 205, 129, 6, 10, 131, 1, 129, 6, 9, 181, 129, 6, 9, 182, 129, 6, 9, 234, 129, 6, 9, 233, 129, 6, 10, 37, 2, 129, 6, 10, 36, 2, 129, 6, 192], name='uhid test MI Dongle MI Wireless Mouse', input_info=(BusType.USB, 10007, 59))

  Bases: `TwoWheelMouse`

  device_input_info = (BusType.USB, 10007, 59)
  device_name = 'uhid test MI Dongle MI Wireless Mouse'
  event(x, y, buttons=None, wheels=None)

    Send an input event on the default report ID.

    Parameters:

      - x – relative x

      - y – relative y

      - buttons – a (l, r, m) tuple of bools for the button states, where `None` is “leave unchanged”

      - wheels – a single value for the vertical wheel or a (vertical, horizontal) tuple for the two wheels

  report_descriptor = [5, 1, 9, 2, 161, 1, 133, 1, 9, 1, 161, 0, 149, 5, 117, 1, 5, 9, 25, 1, 41, 5, 21, 0, 37, 1, 129, 2, 149, 1, 117, 3, 129, 1, 117, 8, 149, 1, 5, 1, 9, 56, 21, 129, 37, 127, 129, 6, 5, 12, 10, 56, 2, 149, 1, 129, 6, 192, 133, 2, 9, 1, 161, 0, 117, 12, 149, 2, 5, 1, 9, 48, 9, 49, 22, 1, 248, 38, 255, 7, 129, 6, 192, 192, 5, 12, 9, 1, 161, 1, 133, 3, 21, 0, 37, 1, 117, 1, 149, 1, 9, 205, 129, 6, 10, 131, 1, 129, 6, 9, 181, 129, 6, 9, 182, 129, 6, 9, 234, 129, 6, 9, 233, 129, 6, 10, 37, 2, 129, 6, 10, 36, 2, 129, 6, 192]

class MouseData

  Bases: `object`

class ResolutionMultiplierHWheelMouse(rdesc=[5, 1, 9, 2, 161, 1, 5, 1, 9, 2, 161, 2, 133, 26, 9, 1, 161, 0, 5, 9, 25, 1, 41, 5, 149, 5, 117, 1, 21, 0, 37, 1, 129, 2, 117, 3, 149, 1, 129, 1, 5, 1, 9, 48, 9, 49, 149, 2, 117, 16, 22, 1, 128, 38, 255, 127, 129, 6, 161, 2, 133, 18, 9, 72, 149, 1, 117, 2, 21, 0, 37, 1, 53, 1, 69, 12, 177, 2, 133, 26, 9, 56, 53, 0, 69, 0, 149, 1, 117, 16, 22, 1, 128, 38, 255, 127, 129, 6, 192, 161, 2, 133, 18, 9, 72, 117, 2, 21, 0, 37, 1, 53, 1, 69, 12, 177, 2, 53, 0, 69, 0, 117, 4, 177, 1, 133, 26, 5, 12, 149, 1, 117, 16, 22, 1, 128, 38, 255, 127, 10, 56, 2, 129, 6, 192, 192, 192, 192], name=None, input_info=None)

  Bases: `TwoWheelMouse`

  report_descriptor = [5, 1, 9, 2, 161, 1, 5, 1, 9, 2, 161, 2, 133, 26, 9, 1, 161, 0, 5, 9, 25, 1, 41, 5, 149, 5, 117, 1, 21, 0, 37, 1, 129, 2, 117, 3, 149, 1, 129, 1, 5, 1, 9, 48, 9, 49, 149, 2, 117, 16, 22, 1, 128, 38, 255, 127, 129, 6, 161, 2, 133, 18, 9, 72, 149, 1, 117, 2, 21, 0, 37, 1, 53, 1, 69, 12, 177, 2, 133, 26, 9, 56, 53, 0, 69, 0, 149, 1, 117, 16, 22, 1, 128, 38, 255, 127, 129, 6, 192, 161, 2, 133, 18, 9, 72, 117, 2, 21, 0, 37, 1, 53, 1, 69, 12, 177, 2, 53, 0, 69, 0, 117, 4, 177, 1, 133, 26, 5, 12, 149, 1, 117, 16, 22, 1, 128, 38, 255, 127, 10, 56, 2, 129, 6, 192, 192, 192, 192]
  set_report(req, rnum, rtype, data)

    Callback invoked when a process calls SetReport on this UHID device.

    Return `0` on success or an errno on failure.

    The default method always returns `EIO` for a failure. Override this in your device if you want SetReport to succeed.

    Parameters:

      - req – the request identifier

      - rnum –

        ???

      - rtype – one of `UHID_FEATURE_REPORT`, `UHID_INPUT_REPORT`, or `UHID_OUTPUT_REPORT`

      - data (list) – a byte string with the data

class ResolutionMultiplierMouse(rdesc=[5, 1, 9, 2, 161, 1, 5, 1, 9, 2, 161, 2, 133, 17, 9, 1, 161, 0, 5, 9, 25, 1, 41, 3, 149, 3, 117, 1, 37, 1, 129, 2, 149, 1, 129, 1, 9, 5, 129, 2, 149, 3, 129, 1, 5, 1, 9, 48, 9, 49, 149, 2, 117, 8, 21, 129, 37, 127, 129, 6, 161, 2, 133, 18, 9, 72, 149, 1, 117, 2, 21, 0, 37, 1, 53, 1, 69, 4, 177, 2, 53, 0, 69, 0, 117, 6, 177, 1, 133, 17, 9, 56, 21, 129, 37, 127, 117, 8, 129, 6, 192, 5, 12, 117, 8, 10, 56, 2, 129, 6, 192, 192, 192], name=None, input_info=None)

  Bases: `TwoWheelMouse`

  report_descriptor = [5, 1, 9, 2, 161, 1, 5, 1, 9, 2, 161, 2, 133, 17, 9, 1, 161, 0, 5, 9, 25, 1, 41, 3, 149, 3, 117, 1, 37, 1, 129, 2, 149, 1, 129, 1, 9, 5, 129, 2, 149, 3, 129, 1, 5, 1, 9, 48, 9, 49, 149, 2, 117, 8, 21, 129, 37, 127, 129, 6, 161, 2, 133, 18, 9, 72, 149, 1, 117, 2, 21, 0, 37, 1, 53, 1, 69, 4, 177, 2, 53, 0, 69, 0, 117, 6, 177, 1, 133, 17, 9, 56, 21, 129, 37, 127, 117, 8, 129, 6, 192, 5, 12, 117, 8, 10, 56, 2, 129, 6, 192, 192, 192]
  set_report(req, rnum, rtype, data)

    Callback invoked when a process calls SetReport on this UHID device.

    Return `0` on success or an errno on failure.

    The default method always returns `EIO` for a failure. Override this in your device if you want SetReport to succeed.

    Parameters:

      - req – the request identifier

      - rnum –

        ???

      - rtype – one of `UHID_FEATURE_REPORT`, `UHID_INPUT_REPORT`, or `UHID_OUTPUT_REPORT`

      - data (list) – a byte string with the data

class TestBadReportDescriptorMouse

  Bases: `TestUhid`

  assertName(uhdev)
  create_device()

class TestBadResolutionMultiplierMouse

  Bases: `TestTwoWheelMouse`

  create_device()
  is_wheel_highres(uhdev)
  test_resolution_multiplier_wheel()

class TestMiMouse

  Bases: `TestWheelMouse`

  assertInputEvents(expected_events, effective_events)
  create_device()

class TestResolutionMultiplierHWheelMouse

  Bases: `TestResolutionMultiplierMouse`

  create_device()
  is_hwheel_highres(uhdev)
  test_ac_pan_with_multiplier()
  test_resolution_multiplier_ac_pan()

class TestResolutionMultiplierMouse

  Bases: `TestTwoWheelMouse`

  create_device()
  is_wheel_highres(uhdev)
  test_resolution_multiplier_wheel()
  test_wheel_with_multiplier()

class TestSimpleMouse

  Bases: `TestMouse`

  create_device()
  test_rdesc()

    Check that the testsuite actually manages to format the reports according to the report descriptors. No kernel device is used here

class TestTwoWheelMouse

  Bases: `TestWheelMouse`

  create_device()
  is_hwheel_highres(uhdev)
  test_ac_pan()

class TestWheelMouse

  Bases: `TestMouse`

  create_device()
  is_wheel_highres(uhdev)
  test_wheel()

class TwoWheelMouse(rdesc=[5, 1, 9, 2, 161, 1, 9, 1, 161, 0, 5, 9, 25, 1, 41, 16, 21, 0, 37, 1, 149, 16, 117, 1, 129, 2, 5, 1, 22, 1, 128, 38, 255, 127, 117, 16, 149, 2, 9, 48, 9, 49, 129, 6, 21, 129, 37, 127, 117, 8, 149, 1, 9, 56, 129, 6, 5, 12, 10, 56, 2, 149, 1, 129, 6, 192, 192], name=None, input_info=None)

  Bases: `WheelMouse`

  report_descriptor = [5, 1, 9, 2, 161, 1, 9, 1, 161, 0, 5, 9, 25, 1, 41, 16, 21, 0, 37, 1, 149, 16, 117, 1, 129, 2, 5, 1, 22, 1, 128, 38, 255, 127, 117, 16, 149, 2, 9, 48, 9, 49, 129, 6, 21, 129, 37, 127, 117, 8, 149, 1, 9, 56, 129, 6, 5, 12, 10, 56, 2, 149, 1, 129, 6, 192, 192]

class WheelMouse(rdesc=[5, 1, 9, 2, 161, 1, 5, 9, 25, 1, 41, 3, 21, 0, 37, 1, 149, 3, 117, 1, 129, 2, 149, 1, 117, 5, 129, 3, 5, 1, 9, 1, 161, 0, 9, 48, 9, 49, 21, 129, 37, 127, 117, 8, 149, 2, 129, 6, 192, 9, 56, 21, 129, 37, 127, 117, 8, 149, 1, 129, 6, 192], name=None, input_info=None)

  Bases: `ButtonMouse`

  report_descriptor = [5, 1, 9, 2, 161, 1, 5, 9, 25, 1, 41, 3, 21, 0, 37, 1, 149, 3, 117, 1, 129, 2, 149, 1, 117, 5, 129, 3, 5, 1, 9, 1, 161, 0, 9, 48, 9, 49, 21, 129, 37, 127, 117, 8, 149, 2, 129, 6, 192, 9, 56, 21, 129, 37, 127, 117, 8, 149, 1, 129, 6, 192]