installed-fresh --input-fnkeys FLAGS (with --input) appends the guest boot-arg snap_i2c_fnkeys=FLAGS, which a SnapI2CHID built with SNAP_I2C_HID_FNKEYS (PROFILE=desktop-fnkeys) reads; other builds ignore it. The sets the kext would refuse are refused here: 0, bits above 0x1f, brightness encoding 3, the host Fn-lock (0x4) without translation (0x1), an encoding alone. Without the option the boot argument addition is unchanged. python3 tools/test-input-fnkeys.py: 4 tests OK; python3 tools/test-zone-log.py: 4 tests OK.
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: MIT
|
|
"""Host test for cycle.py installed-fresh --input-fnkeys. No A16 access.
|
|
|
|
Without the option the boot-argument addition is exactly what earlier attempts qualified; with it, it appends
|
|
snap_i2c_fnkeys=FLAGS (decimal, as XNU's boot-arg parser reads any number), and refuses what SnapI2CHID's
|
|
hid_fnkeys_init would refuse (drivers/snap-i2c-hid/src/hid-keyboard.h) and a run without the input AuxKC.
|
|
"""
|
|
import argparse
|
|
import importlib.util
|
|
import sys
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / 'tools'))
|
|
from cycle_lib import installed_fresh as fresh # noqa: E402
|
|
from cycle_lib.common import Refused # noqa: E402
|
|
|
|
spec = importlib.util.spec_from_file_location('cycle_cli', ROOT / 'tools/cycle.py')
|
|
cli = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(cli)
|
|
|
|
BASE = ' '.join([fresh.TIMESYNC_FLAG, fresh.COMPRESSOR_SW_FLAG])
|
|
|
|
|
|
def ns(**kw):
|
|
return argparse.Namespace(**kw)
|
|
|
|
|
|
class InputFnKeys(unittest.TestCase):
|
|
def test_default_unchanged(self):
|
|
self.assertEqual(fresh.boot_addition(ns()), BASE)
|
|
self.assertEqual(fresh.boot_addition(ns(input=True, input_fnkeys=None)), BASE)
|
|
|
|
def test_flags(self):
|
|
for flags in (0x1, 0x2, 0x3, 0x5, 0x7, 0x9, 0x13, 0x17):
|
|
self.assertEqual(fresh.boot_addition(ns(input=True, input_fnkeys=flags)), f'{BASE} snap_i2c_fnkeys={flags}')
|
|
self.assertEqual(fresh.boot_addition(ns(input=True, console=True, input_fnkeys=3)),
|
|
' '.join([BASE, fresh.CONSOLE_FLAG, 'snap_i2c_fnkeys=3']))
|
|
|
|
def test_refusals(self):
|
|
for flags in (0, -1, 0x20, 0x100, 0x19, 0x1f, 0x4, 0x6, 0x8, 0x10):
|
|
with self.assertRaises(Refused, msg=hex(flags)):
|
|
fresh.boot_addition(ns(input=True, input_fnkeys=flags))
|
|
with self.assertRaises(Refused):
|
|
fresh.boot_addition(ns(input_fnkeys=3))
|
|
|
|
def test_cli_reaches_args(self):
|
|
a = cli.parse(['installed-fresh', '--prefix', 'x', '--variant', 'fast', '--check', '--input', '--input-fnkeys',
|
|
'0x3'])
|
|
self.assertEqual(a.input_fnkeys, 3)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|