keyboard

Source code: keyboard.py

Tests keyboard functionality.

Description

This test check basic keyboard functionality by asking operator to press each keys on keyboard once at a time.

The layout of the keyboard is derived from vpd ‘region’ value, and can be overwritten by argument layout.

If allow_multi_keys is True, the operator can press multiple keys at once to speed up the testing.

If sequential_press or strict_sequential_press is True, the operator have to press each key in order from top-left to bottom-right. Additionally, if strict_sequential_press is True, the test would fail if the operator press the wrong key.

A dict repeat_times can be specified to indicate number of times each key have to be pressed before the key is marked as checked.

The test would fail after timeout_secs seconds.

Test Procedure

  1. The test shows an image of the keyboard, and each key labeled with how many times it need to be pressed.

  2. Operator press each key the number of times needed, and keys on UI would be marked as such.

  3. The test pass when all keys have been pressed for the number of times needed, or fail after timeout_secs seconds.

Dependency

Depends on ‘evdev’ module to monitor key presses.

Examples

To test keyboard functionality, add this into test list:

{
  "pytest_name": "keyboard"
}

To test keyboard functionality, allow multiple keys to be pressed at once, and have a timeout of 10 seconds, add this into test list:

{
  "pytest_name": "keyboard",
  "args": {
    "allow_multi_keys": true,
    "timeout_secs": 10
  }
}

To test keyboard functionality, ask operator to press keys in order, skip keycode [4, 5, 6], have keycode 3 be pressed 5 times, and other keys be pressed 2 times to pass, add this into test list:

{
  "pytest_name": "keyboard",
  "args": {
    "sequential_press": true,
    "skip_keycodes": [4, 5, 6],
    "repeat_times": {
      "3": 5,
      "default": 2
    }
  }
}

To test keyboard functionality, ask operator to press keys in order (and fail the test if wrong key is pressed), and set keyboard layout to ISO, add this into test list:

{
  "pytest_name": "keyboard",
  "args": {
    "strict_sequential_press": true,
    "layout": "ISO"
  }
}

To test keyboard functionality, ask operator to press [2,3] and [4,5] at the same time, and have a timeout of 300 seconds, add this into test list:

{
  "pytest_name": "keyboard",
  "args": {
    "key_combinations": [[2, 3], [4, 5]],
    "timeout_secs": 300
  }
}

Test Arguments

Name

Type

Description

allow_multi_keys

bool

(optional; default: False) Allow multiple keys pressed simultaneously. (Less strictly checking with shorter cycle time)

multi_keys_delay

int, float

(optional; default: 0) When allow_multi_keys is False, do not fail the test if the delay between the consecutivepresses is more than multi_keys_delay seconds.

layout

str, None

(optional; default: None) Use specified layout other than derived from VPD. If None, the layout from the VPD is used.

timeout_secs

int

(optional; default: 30) Timeout for the test.

sequential_press

bool

(optional; default: False) Indicate whether keycodes need to be pressed sequentially or not.

strict_sequential_press

bool

(optional; default: False) Indicate whether keycodes need to be pressed strictly sequentially or not.

board

str

(optional; default: '') If presents, in filename, the board name is appended after layout.

device_filter

int, str, None

(optional; default: None) If present, the input event ID or a substring of the input device name specifying which keyboard to test.

key_order

list

(optional; default: []) Specify the sequential order of the keys to press. Will use the order in .layout files if it is not specified.

fn_keycodes

list, None

(optional; default: None) The keycodes in the first row, esc and power/lock key are excluded.

last_fn_keycode

int

(optional; default: 142) The keycode of the last fn key in the first row. Note that it should be a lock or a power key

replacement_keymap

dict

(optional; default: {}) Deprecated, please use fn_keycodes

has_power_key

bool

(optional; default: True) If True, the last key in the first row will be a power key, otherwise it will be a lock key.

skip_keycodes

list

(optional; default: []) Keycodes to skip

skip_power_key

bool

(optional; default: False) Deprecated, please use skip_keycodes.

detect_long_press

bool

(optional; default: False) Detect long press event. Usually for detecting bluetooth keyboard disconnection.

repeat_times

dict

(optional; default: {}) A dict object {key_code: times} to specify number of presses required for keys specified in key code, e.g. {"28": 3, "57": 5}, then ENTER (28) shall be pressed 3 times while SPACE (57) shall be pressed 5 times. If you want all keys to be pressed twice, you can do: {"default": 2}. You can find keycode mappings in /usr/include/linux/input.h

has_numpad

bool

(optional; default: False) The keyboard has a number pad or not.

vivaldi_keyboard

bool

(optional; default: True) Get function keys map from sysfs.

key_combinations

list

(optional; default: []) The element in the list is a list of key codes, and these keys should be held at the same time to pass the test. It is recommended to test 8 keys at once.