mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2026-05-11 08:28:08 +02:00
remove create-misc-driver-test.py.in
This commit is contained in:
parent
aa9e4029d0
commit
4bed200a66
5 changed files with 64 additions and 154 deletions
|
|
@ -84,11 +84,17 @@ elif len(devices) > 1:
|
|||
test_name = driver_name
|
||||
if test_variant:
|
||||
test_name = driver_name + '-' + test_variant
|
||||
usb_device = devices[0].get_property('fpi-usb-device')
|
||||
bus_num = usb_device.get_bus()
|
||||
device_num = usb_device.get_address()
|
||||
misc_device = devices[0].get_property('fpi-udev-data-misc')
|
||||
if misc_device:
|
||||
device = misc_device
|
||||
print(f'### Detected misc device {device}')
|
||||
else:
|
||||
usb_device = devices[0].get_property('fpi-usb-device')
|
||||
bus_num = usb_device.get_bus()
|
||||
device_num = usb_device.get_address()
|
||||
device = f'/dev/bus/usb/{bus_num:03d}/{device_num:03d}'
|
||||
|
||||
print(f'### Detected USB device /dev/bus/usb/{bus_num:03d}/{device_num:03d}')
|
||||
print(f'### Detected USB device {device}')
|
||||
|
||||
# Make directory
|
||||
|
||||
|
|
@ -97,31 +103,32 @@ os.makedirs(test_dir, mode=0o775, exist_ok=True)
|
|||
|
||||
# Capture device info
|
||||
|
||||
args = ['umockdev-record', f'/dev/bus/usb/{bus_num:03d}/{device_num:03d}']
|
||||
args = ['umockdev-record', device]
|
||||
device_out = open(test_dir + '/device', 'w')
|
||||
process = subprocess.Popen(args, stdout=device_out)
|
||||
process.wait()
|
||||
|
||||
# Run capture
|
||||
# https://osqa-ask.wireshark.org/questions/53919/how-can-i-precisely-specify-a-usb-device-to-capture-with-tshark/
|
||||
if not misc_device:
|
||||
# Run capture
|
||||
# https://osqa-ask.wireshark.org/questions/53919/how-can-i-precisely-specify-a-usb-device-to-capture-with-tshark/
|
||||
|
||||
print(f'### Reseting USB port (as descriptors could be missing in the dump otherwise)')
|
||||
usb_device.open()
|
||||
usb_device.reset()
|
||||
usb_device.close()
|
||||
print(f'### Reseting USB port (as descriptors could be missing in the dump otherwise)')
|
||||
usb_device.open()
|
||||
usb_device.reset()
|
||||
usb_device.close()
|
||||
|
||||
print(f'### Starting USB capture on usbmon{bus_num}')
|
||||
capture_pid = os.fork()
|
||||
assert(capture_pid >= 0)
|
||||
print(f'### Starting USB capture on usbmon{bus_num}')
|
||||
capture_pid = os.fork()
|
||||
assert(capture_pid >= 0)
|
||||
|
||||
unfiltered_cap_path = os.path.join(tempfile.gettempdir(), 'capture-unfiltered.pcapng')
|
||||
if capture_pid == 0:
|
||||
os.setpgrp()
|
||||
args = ['tshark', '-q', '-i', f'usbmon{bus_num}', '-w', unfiltered_cap_path]
|
||||
os.execv(tshark, args)
|
||||
unfiltered_cap_path = os.path.join(tempfile.gettempdir(), 'capture-unfiltered.pcapng')
|
||||
if capture_pid == 0:
|
||||
os.setpgrp()
|
||||
args = ['tshark', '-q', '-i', f'usbmon{bus_num}', '-w', unfiltered_cap_path]
|
||||
os.execv(tshark, args)
|
||||
|
||||
# Wait 1 sec to settle (we can assume setpgrp happened)
|
||||
time.sleep(1)
|
||||
# Wait 1 sec to settle (we can assume setpgrp happened)
|
||||
time.sleep(1)
|
||||
|
||||
print('### Capturing fingerprint, please swipe or press your finger on the reader')
|
||||
cmd = ['python3', SRCDIR + '/tests/capture.py', test_dir + '/capture.png']
|
||||
|
|
@ -129,12 +136,16 @@ capture_file = 'capture.pcapng' # capture for "capture" test
|
|||
if os.path.exists(os.path.join(test_dir, "custom.py")):
|
||||
cmd = ['python3', os.path.join(test_dir, "custom.py")]
|
||||
capture_file = "custom.pcapng"
|
||||
if misc_device:
|
||||
capture_file = "custom.ioctl"
|
||||
cmd = ['umockdev-record', '--ioctl', f'{misc_device}={os.path.join(test_dir, capture_file)}'] + cmd
|
||||
|
||||
with subprocess.Popen(cmd) as capture_process:
|
||||
capture_process.wait()
|
||||
if capture_process.returncode != 0:
|
||||
print('Failed to capture fingerprint')
|
||||
os.killpg(capture_pid, signal.SIGKILL)
|
||||
if usb_device:
|
||||
os.killpg(capture_pid, signal.SIGKILL)
|
||||
sys.exit(1)
|
||||
|
||||
def t_waitpid(pid, timeout):
|
||||
|
|
@ -146,29 +157,30 @@ def t_waitpid(pid, timeout):
|
|||
|
||||
return r
|
||||
|
||||
os.kill(capture_pid, signal.SIGTERM)
|
||||
try:
|
||||
r = t_waitpid(capture_pid, 2)
|
||||
# Kill if nothing died
|
||||
if r[0] == 0:
|
||||
os.kill(capture_pid, signal.SIGKILL)
|
||||
except ChildProcessError:
|
||||
pass
|
||||
|
||||
try:
|
||||
while True:
|
||||
r = t_waitpid(-capture_pid, timeout=2)
|
||||
# Kill the process group, if nothing died (and there are children)
|
||||
if not misc_device:
|
||||
os.kill(capture_pid, signal.SIGTERM)
|
||||
try:
|
||||
r = t_waitpid(capture_pid, 2)
|
||||
# Kill if nothing died
|
||||
if r[0] == 0:
|
||||
os.killpg(capture_pid, signal.SIGKILL)
|
||||
except ChildProcessError:
|
||||
pass
|
||||
os.kill(capture_pid, signal.SIGKILL)
|
||||
except ChildProcessError:
|
||||
pass
|
||||
|
||||
# Filter the capture
|
||||
print(f'\n### Saving USB capture as test case {test_name}')
|
||||
args = ['tshark', '-r', unfiltered_cap_path, '-Y', f'usb.bus_id == {bus_num} and usb.device_address == {device_num}',
|
||||
'-w', os.path.join(test_dir, capture_file)]
|
||||
with subprocess.Popen(args, stderr=subprocess.DEVNULL) as filter_process:
|
||||
filter_process.wait()
|
||||
try:
|
||||
while True:
|
||||
r = t_waitpid(-capture_pid, timeout=2)
|
||||
# Kill the process group, if nothing died (and there are children)
|
||||
if r[0] == 0:
|
||||
os.killpg(capture_pid, signal.SIGKILL)
|
||||
except ChildProcessError:
|
||||
pass
|
||||
|
||||
# Filter the capture
|
||||
print(f'\n### Saving USB capture as test case {test_name}')
|
||||
args = ['tshark', '-r', unfiltered_cap_path, '-Y', f'usb.bus_id == {bus_num} and usb.device_address == {device_num}',
|
||||
'-w', os.path.join(test_dir, capture_file)]
|
||||
with subprocess.Popen(args, stderr=subprocess.DEVNULL) as filter_process:
|
||||
filter_process.wait()
|
||||
|
||||
print(f"\nDone! Don't forget to add {test_name} to tests/meson.build")
|
||||
|
|
|
|||
|
|
@ -1,99 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
BUILDDIR='@BUILDDIR@'
|
||||
SRCDIR='@SRCDIR@'
|
||||
|
||||
import os
|
||||
import sys
|
||||
library_path = BUILDDIR + '/libfprint/'
|
||||
|
||||
# Relaunch ourselves with a changed environment so
|
||||
# that we're loading the development version of libfprint
|
||||
if 'LD_LIBRARY_PATH' not in os.environ or not library_path in os.environ['LD_LIBRARY_PATH']:
|
||||
os.environ['LD_LIBRARY_PATH'] = library_path
|
||||
os.environ['GI_TYPELIB_PATH'] = f'{BUILDDIR}/libfprint/'
|
||||
os.environ['FP_DEVICE_EMULATION'] = '1'
|
||||
try:
|
||||
os.execv(sys.argv[0], sys.argv)
|
||||
except Exception as e:
|
||||
print('Could not run script with new library path')
|
||||
sys.exit(1)
|
||||
|
||||
import gi
|
||||
gi.require_version('FPrint', '2.0')
|
||||
from gi.repository import FPrint
|
||||
|
||||
import re
|
||||
import subprocess
|
||||
|
||||
def print_usage():
|
||||
print(f'Usage: {sys.argv[0]} driver [test-variant-name]')
|
||||
print('A test variant name is optional, and must be all lower case letters, or dashes, with no spaces')
|
||||
print(f'The captured data will be stored in {SRCDIR}/tests/[driver name]-[test variant name]')
|
||||
print(f'Create custom.py prior to execution for non image device tests.')
|
||||
|
||||
if len(sys.argv) > 3:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
driver_name = sys.argv[1]
|
||||
os.environ['FP_DRIVERS_ALLOWLIST'] = driver_name
|
||||
|
||||
test_variant = None
|
||||
if len(sys.argv) == 3:
|
||||
valid_re = re.compile('[a-z-]*')
|
||||
test_variant = sys.argv[2]
|
||||
if (not valid_re.match(test_variant) or
|
||||
test_variant.startswith('-') or
|
||||
test_variant.endswith('-')):
|
||||
print(f'Invalid variant name {test_variant}\n')
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
# Check that running as root
|
||||
|
||||
if os.geteuid() != 0:
|
||||
print(f'{sys.argv[0]} is expected to be run as root')
|
||||
sys.exit(1)
|
||||
|
||||
# Find the fingerprint reader
|
||||
ctx = FPrint.Context()
|
||||
ctx.enumerate()
|
||||
devices = ctx.get_devices()
|
||||
if len(devices) == 0:
|
||||
print('Could not find a supported fingerprint reader')
|
||||
sys.exit(1)
|
||||
elif len(devices) > 1:
|
||||
print('Capture requires a single supported fingerprint reader to be plugged in')
|
||||
sys.exit(1)
|
||||
|
||||
test_name = driver_name
|
||||
if test_variant:
|
||||
test_name = driver_name + '-' + test_variant
|
||||
misc_device = devices[0].get_property('fpi-udev-data-misc')
|
||||
|
||||
print(f'### Detected misc device {misc_device}')
|
||||
|
||||
# Make directory
|
||||
|
||||
test_dir = SRCDIR + '/tests/' + test_name
|
||||
os.makedirs(test_dir, mode=0o775, exist_ok=True)
|
||||
|
||||
# Capture device info
|
||||
|
||||
args = ['umockdev-record', misc_device]
|
||||
device_out = open(test_dir + '/device', 'w')
|
||||
process = subprocess.Popen(args, stdout=device_out)
|
||||
process.wait()
|
||||
|
||||
print('### Capturing fingerprint, please swipe or press your finger on the reader')
|
||||
capture_file = "custom.ioctl"
|
||||
cmd = ['umockdev-record', '--ioctl', f'{misc_device}={os.path.join(test_dir, capture_file)}', 'python3', os.path.join(test_dir, "custom.py")]
|
||||
|
||||
with subprocess.Popen(cmd) as capture_process:
|
||||
capture_process.wait()
|
||||
if capture_process.returncode != 0:
|
||||
print('Failed to capture fingerprint')
|
||||
sys.exit(1)
|
||||
|
||||
print(f"\nDone! Don't forget to add {test_name} to tests/meson.build")
|
||||
|
|
@ -13,9 +13,9 @@ CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000000000000
|
|||
CROS_EC_DEV_IOCXCMD_V2 48 010000000304000000000000300000000000000046504320090000001B020000010000009466000047524559A000A0000800FF0324140000050001000100000004000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000040000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 22 00000000070400000000000016000000000000007B630100C746020033AF0300FA095D6D040000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 22 0000000007040000000000001600000000000000309301001A47020039DF0300E9A0B112000000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000040000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 22 00000000070400000000000016000000000000007F630100A949020019B20300FBAA6D6D040000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 22 000000000704000000000000160000000000000029930100174902002DE10300AC88C512000000000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000080000000
|
||||
CROS_EC_DEV_IOCXCMD_V2 4 000000000204000004000000040000000000000000000000
|
||||
|
|
|
|||
|
|
@ -60,9 +60,9 @@ E: SUBSYSTEM=serial-base
|
|||
L: driver=../../../../../bus/serial-base/drivers/port
|
||||
A: power/autosuspend_delay_ms=500\n
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=19045089\n
|
||||
A: power/runtime_active_time=286257\n
|
||||
A: power/runtime_status=active\n
|
||||
A: power/runtime_suspended_time=1840\n
|
||||
A: power/runtime_suspended_time=3893\n
|
||||
|
||||
P: /devices/platform/AMDI0020:01/AMDI0020:01:0
|
||||
E: DEVTYPE=ctrl
|
||||
|
|
@ -70,9 +70,9 @@ E: DRIVER=ctrl
|
|||
E: SUBSYSTEM=serial-base
|
||||
L: driver=../../../../bus/serial-base/drivers/ctrl
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=19045095\n
|
||||
A: power/runtime_active_time=286264\n
|
||||
A: power/runtime_status=active\n
|
||||
A: power/runtime_suspended_time=1840\n
|
||||
A: power/runtime_suspended_time=3892\n
|
||||
|
||||
P: /devices/platform/AMDI0020:01
|
||||
E: DRIVER=dw-apb-uart
|
||||
|
|
@ -86,8 +86,8 @@ A: driver_override=(null)\n
|
|||
L: firmware_node=../../LNXSYSTM:00/LNXSYBUS:00/AMDI0020:01
|
||||
A: modalias=acpi:AMDI0020:\n
|
||||
A: power/control=auto\n
|
||||
A: power/runtime_active_time=19045115\n
|
||||
A: power/runtime_active_time=286263\n
|
||||
A: power/runtime_status=active\n
|
||||
A: power/runtime_suspended_time=1826\n
|
||||
A: power/runtime_suspended_time=3889\n
|
||||
L: software_node=../../../kernel/software_nodes/node1
|
||||
|
||||
|
|
|
|||
|
|
@ -69,9 +69,6 @@ if get_option('introspection')
|
|||
configure_file(configuration: conf,
|
||||
input: 'create-driver-test.py.in',
|
||||
output: 'create-driver-test.py')
|
||||
configure_file(configuration: conf,
|
||||
input: 'create-misc-driver-test.py.in',
|
||||
output: 'create-misc-driver-test.py')
|
||||
endif
|
||||
|
||||
env_parser_cmd = '''
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue