tests: Detect pcap vs. ioctl recording and run correct one

This commit is contained in:
Benjamin Berg 2021-06-16 10:53:34 +02:00
parent c989cc4b95
commit daaafc80c3

View file

@ -17,6 +17,8 @@ try:
if version < (0, 13, 2): if version < (0, 13, 2):
print('umockdev is too old for test to be reliable, expect random failures!') print('umockdev is too old for test to be reliable, expect random failures!')
print('Please update umockdev to at least 0.13.2.') print('Please update umockdev to at least 0.13.2.')
pcap_supported = version >= (0, 15, 6) or os.getenv('CI_COMMIT_SHA') is not None
except FileNotFoundError: except FileNotFoundError:
print('umockdev-run not found, skipping test!') print('umockdev-run not found, skipping test!')
print('Please install umockdev.') print('Please install umockdev.')
@ -55,14 +57,31 @@ def cmp_pngs(png_a, png_b):
def get_umockdev_runner(ioctl_basename): def get_umockdev_runner(ioctl_basename):
ioctl = os.path.join(ddir, "{}.ioctl".format(ioctl_basename)) ioctl = os.path.join(ddir, "{}.ioctl".format(ioctl_basename))
device = os.path.join(ddir, "device") pcap = os.path.join(ddir, "{}.pcapng".format(ioctl_basename))
dev = open(ioctl).readline().strip()
assert dev.startswith('@DEV ')
dev = dev[5:]
umockdev = ['umockdev-run', '-d', device, device = os.path.join(ddir, "device")
'-i', "%s=%s" % (dev, ioctl),
'--'] if os.path.exists(pcap):
p = open(device).readline().strip()
assert p.startswith('P: ')
syspath = '/sys' + p[3:]
umockdev = ['umockdev-run', '-d', device,
'-p', "%s=%s" % (syspath, pcap),
'--']
# Skip test if we detect too old umockdev for pcap replay
if not pcap_supported:
sys.exit(77)
else:
dev = open(ioctl).readline().strip()
assert dev.startswith('@DEV ')
dev = dev[5:]
umockdev = ['umockdev-run', '-d', device,
'-i', "%s=%s" % (dev, ioctl),
'--']
wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER') wrapper = os.getenv('LIBFPRINT_TEST_WRAPPER')
return umockdev + (wrapper.split(' ') if wrapper else []) + [sys.executable] return umockdev + (wrapper.split(' ') if wrapper else []) + [sys.executable]