From 20e8355c014aff0308b5762a822d99c4b8279dd0 Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Tue, 21 Sep 2021 19:06:15 +0200 Subject: [PATCH] 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. --- tests/README.md | 22 +++++++++++++--------- tests/create-driver-test.py.in | 11 +++++++++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tests/README.md b/tests/README.md index d04915a..3012cbc 100644 --- a/tests/README.md +++ b/tests/README.md @@ -3,20 +3,23 @@ `umockdev` tests use fingerprint devices mocked by [`umockdev` toolchain][umockdev]. -This document describes how to create a 'capture' test: a test that -captures a picture of a fingerprint from the device (mocked by -`umockdev`) and compares it with the standard one. +This document describes how to create test cases (for USB devices). Many of +these tests are tests for image devices, where a single image is captured +and stored. 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` script, capture it and store the capture to `custom.pcapng`. -'Capture' Test Creation ------------------------ -A new 'capture' test is created by means of `capture.py` script: +'capture' and 'custom' Test Creation +------------------------------------ + +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 - 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 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. -**Note.** To avoid submitting a real fingerprint, the side of finger, -arm, or anything else producing an image with the device can be used. +**Note.** To avoid submitting a real fingerprint when creating a 'capture' test, +the side of finger, arm, or anything else producing an image with the device +can be used. Possible Issues diff --git a/tests/create-driver-test.py.in b/tests/create-driver-test.py.in index 70b48f5..3eabb78 100755 --- a/tests/create-driver-test.py.in +++ b/tests/create-driver-test.py.in @@ -37,6 +37,7 @@ 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() @@ -118,7 +119,13 @@ if capture_pid == 0: time.sleep(1) 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() if capture_process.returncode != 0: print('Failed to capture fingerprint') @@ -155,7 +162,7 @@ except ChildProcessError: # 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', test_dir + '/capture.pcapng'] + '-w', os.path.join(test_dir, capture_file)] with subprocess.Popen(args, stderr=subprocess.DEVNULL) as filter_process: filter_process.wait()