tests: Run custom.py from test creation helper when available
This allows creating tests both for image and non-image devices using the same script.
This commit is contained in:
parent
f579a77bfd
commit
20e8355c01
2 changed files with 22 additions and 11 deletions
|
@ -3,20 +3,23 @@
|
||||||
`umockdev` tests use fingerprint devices mocked by [`umockdev`
|
`umockdev` tests use fingerprint devices mocked by [`umockdev`
|
||||||
toolchain][umockdev].
|
toolchain][umockdev].
|
||||||
|
|
||||||
This document describes how to create a 'capture' test: a test that
|
This document describes how to create test cases (for USB devices). Many of
|
||||||
captures a picture of a fingerprint from the device (mocked by
|
these tests are tests for image devices, where a single image is captured
|
||||||
`umockdev`) and compares it with the standard one.
|
and stored.
|
||||||
|
|
||||||
Other kinds of `umockdev` tests can be created in a similar manner. For
|
Other kinds of `umockdev` tests can be created in a similar manner. For
|
||||||
match-on-chip devices you would instead create a test specific `custom.py`
|
match-on-chip devices you would instead create a test specific `custom.py`
|
||||||
script, capture it and store the capture to `custom.pcapng`.
|
script, capture it and store the capture to `custom.pcapng`.
|
||||||
|
|
||||||
'Capture' Test Creation
|
'capture' and 'custom' Test Creation
|
||||||
-----------------------
|
------------------------------------
|
||||||
A new 'capture' test is created by means of `capture.py` script:
|
|
||||||
|
For image devices the `capture.py` script will be used to capture one reference
|
||||||
|
image. If the driver is a non-image driver, then a `custom.py` script should be
|
||||||
|
created in advance, which will be run instead.
|
||||||
|
|
||||||
1. Make sure that libfprint is built with support for the device driver
|
1. Make sure that libfprint is built with support for the device driver
|
||||||
that you want to capture a test case for.
|
that you want to create a test case for.
|
||||||
|
|
||||||
2. From the build directory, run tests/create-driver-test.py as root. Note
|
2. From the build directory, run tests/create-driver-test.py as root. Note
|
||||||
that if you're capturing data for a driver which already has a test case
|
that if you're capturing data for a driver which already has a test case
|
||||||
|
@ -33,8 +36,9 @@ $ sudo tests/create-driver-test.py driver [variant]
|
||||||
|
|
||||||
5. Check whether `meson test` passes with this new test.
|
5. Check whether `meson test` passes with this new test.
|
||||||
|
|
||||||
**Note.** To avoid submitting a real fingerprint, the side of finger,
|
**Note.** To avoid submitting a real fingerprint when creating a 'capture' test,
|
||||||
arm, or anything else producing an image with the device can be used.
|
the side of finger, arm, or anything else producing an image with the device
|
||||||
|
can be used.
|
||||||
|
|
||||||
|
|
||||||
Possible Issues
|
Possible Issues
|
||||||
|
|
|
@ -37,6 +37,7 @@ def print_usage():
|
||||||
print(f'Usage: {sys.argv[0]} driver [test-variant-name]')
|
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('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'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:
|
if len(sys.argv) > 3:
|
||||||
print_usage()
|
print_usage()
|
||||||
|
@ -118,7 +119,13 @@ if capture_pid == 0:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print('### Capturing fingerprint, please swipe or press your finger on the reader')
|
print('### Capturing fingerprint, please swipe or press your finger on the reader')
|
||||||
with subprocess.Popen(['python3', SRCDIR + '/tests/capture.py', test_dir + '/capture.png']) as capture_process:
|
cmd = ['python3', SRCDIR + '/tests/capture.py', test_dir + '/capture.png']
|
||||||
|
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"
|
||||||
|
|
||||||
|
with subprocess.Popen(cmd) as capture_process:
|
||||||
capture_process.wait()
|
capture_process.wait()
|
||||||
if capture_process.returncode != 0:
|
if capture_process.returncode != 0:
|
||||||
print('Failed to capture fingerprint')
|
print('Failed to capture fingerprint')
|
||||||
|
@ -155,7 +162,7 @@ except ChildProcessError:
|
||||||
# Filter the capture
|
# Filter the capture
|
||||||
print(f'\n### Saving USB capture as test case {test_name}')
|
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}',
|
args = ['tshark', '-r', unfiltered_cap_path, '-Y', f'usb.bus_id == {bus_num} and usb.device_address == {device_num}',
|
||||||
'-w', test_dir + '/capture.pcapng']
|
'-w', os.path.join(test_dir, capture_file)]
|
||||||
with subprocess.Popen(args, stderr=subprocess.DEVNULL) as filter_process:
|
with subprocess.Popen(args, stderr=subprocess.DEVNULL) as filter_process:
|
||||||
filter_process.wait()
|
filter_process.wait()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue