From 2b7b142e97b42e08bf7386e2afe69dfa12306daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 16 Dec 2020 12:21:43 +0100 Subject: [PATCH] meson: make each dmidecode a separate test This allows them to be executed in parallel and also gives us better reporting. The dump files are renamed to avoid repeating "dmidecode-dump", since that string is already present in the subdirectory name. --- src/udev/meson.build | 26 +++++++++----- ...code-dump.bin => Lenovo-ThinkPad-X280.bin} | Bin ...p.bin.txt => Lenovo-ThinkPad-X280.bin.txt} | 0 ...-dump.bin => Lenovo-Thinkcentre-m720s.bin} | Bin ...n.txt => Lenovo-Thinkcentre-m720s.bin.txt} | 0 test/meson.build | 28 ++++++++++++--- test/udev-dmi-memory-id-test.sh | 34 ++++++------------ 7 files changed, 51 insertions(+), 37 deletions(-) rename test/dmidecode-dumps/{Lenovo-ThinkPad-X280-dmidecode-dump.bin => Lenovo-ThinkPad-X280.bin} (100%) rename test/dmidecode-dumps/{Lenovo-ThinkPad-X280-dmidecode-dump.bin.txt => Lenovo-ThinkPad-X280.bin.txt} (100%) rename test/dmidecode-dumps/{Lenovo-Thinkcentre-m720s-dmidecode-dump.bin => Lenovo-Thinkcentre-m720s.bin} (100%) rename test/dmidecode-dumps/{Lenovo-Thinkcentre-m720s-dmidecode-dump.bin.txt => Lenovo-Thinkcentre-m720s.bin.txt} (100%) diff --git a/src/udev/meson.build b/src/udev/meson.build index 0ed3b86135..5a1d2149d7 100644 --- a/src/udev/meson.build +++ b/src/udev/meson.build @@ -184,15 +184,23 @@ if dmi_arches.contains(host_machine.cpu_family()) endif foreach prog : udev_id_progs - executable(prog[0].split('/')[0], - prog, - include_directories : includes, - c_args : ['-DLOG_REALM=LOG_REALM_UDEV'], - dependencies : [versiondep], - link_with : udev_link_with, - install_rpath : udev_rpath, - install : true, - install_dir : udevlibexecdir) + name = prog[0].split('/')[0] + + exe = executable( + name, + prog, + include_directories : includes, + c_args : ['-DLOG_REALM=LOG_REALM_UDEV'], + dependencies : [versiondep], + link_with : udev_link_with, + install_rpath : udev_rpath, + install : true, + install_dir : udevlibexecdir) + + # TODO: let's use a dictionary instead as soon as we can depend on meson >= 0.47. + if name == 'dmi_memory_id' + dmi_memory_id_path = exe.full_path() + endif endforeach if install_sysconfdir diff --git a/test/dmidecode-dumps/Lenovo-ThinkPad-X280-dmidecode-dump.bin b/test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin similarity index 100% rename from test/dmidecode-dumps/Lenovo-ThinkPad-X280-dmidecode-dump.bin rename to test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin diff --git a/test/dmidecode-dumps/Lenovo-ThinkPad-X280-dmidecode-dump.bin.txt b/test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin.txt similarity index 100% rename from test/dmidecode-dumps/Lenovo-ThinkPad-X280-dmidecode-dump.bin.txt rename to test/dmidecode-dumps/Lenovo-ThinkPad-X280.bin.txt diff --git a/test/dmidecode-dumps/Lenovo-Thinkcentre-m720s-dmidecode-dump.bin b/test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin similarity index 100% rename from test/dmidecode-dumps/Lenovo-Thinkcentre-m720s-dmidecode-dump.bin rename to test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin diff --git a/test/dmidecode-dumps/Lenovo-Thinkcentre-m720s-dmidecode-dump.bin.txt b/test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin.txt similarity index 100% rename from test/dmidecode-dumps/Lenovo-Thinkcentre-m720s-dmidecode-dump.bin.txt rename to test/dmidecode-dumps/Lenovo-Thinkcentre-m720s.bin.txt diff --git a/test/meson.build b/test/meson.build index 3a930436f9..1e8a56aa90 100644 --- a/test/meson.build +++ b/test/meson.build @@ -124,6 +124,8 @@ else message('Skipping udev-test because perl is not available') endif +############################################################ + if conf.get('ENABLE_HWDB') == 1 hwdb_test_sh = find_program('hwdb-test.sh') if want_tests != 'false' @@ -133,11 +135,29 @@ if conf.get('ENABLE_HWDB') == 1 endif endif -if want_tests != false and dmi_arches.contains(host_machine.cpu_family()) +############################################################ + +if want_tests != 'false' and dmi_arches.contains(host_machine.cpu_family()) udev_dmi_memory_id_test = find_program('udev-dmi-memory-id-test.sh') - test('udev-dmi-memory-id-test', - udev_dmi_memory_id_test, - timeout : 90) + + if git.found() + out = run_command( + git, + '--git-dir=@0@/.git'.format(project_source_root), + 'ls-files', ':/test/dmidecode-dumps/*.bin') + else + out = run_command( + 'sh', '-c', 'ls @0@/test/dmidecode-dumps/*.bin'.format(project_source_root)) + endif + + foreach p : out.stdout().split() + source = join_paths(project_source_root, p) + name = 'dmidecode_' + p.split('/')[-1].split('.')[0] + + test(name, + udev_dmi_memory_id_test, + args : [dmi_memory_id_path, source, source + '.txt']) + endforeach endif subdir('fuzz') diff --git a/test/udev-dmi-memory-id-test.sh b/test/udev-dmi-memory-id-test.sh index 2b6dee5b74..e8b69245d8 100755 --- a/test/udev-dmi-memory-id-test.sh +++ b/test/udev-dmi-memory-id-test.sh @@ -1,31 +1,17 @@ #!/bin/sh # SPDX-License-Identifier: LGPL-2.1-or-later -# set -e -export SYSTEMD_LOG_LEVEL=info -ROOTDIR=$(dirname $(dirname $(readlink -f $0))) -UDEV_DMI_MEMORY_ID=./src/udev/dmi_memory_id +dmi_memory_id="$1" +input="$2" +expected="$3" -if [ ! -x "$UDEV_DMI_MEMORY_ID" ]; then - echo "$UDEV_DMI_MEMORY_ID does not exist, please build first" - exit 1 -fi +output=$(mktemp --tmpdir "test-udev-dmi-memory-id.XXXXXXXXXX") +trap "rm '$output'" EXIT INT QUIT PIPE -D=$(mktemp --tmpdir --directory "udev-dmi-memory-id.XXXXXXXXXX") -trap "rm -rf '$D'" EXIT INT QUIT PIPE - -for i in $ROOTDIR/test/dmidecode-dumps/*.bin ; do - $("$UDEV_DMI_MEMORY_ID" -F "$i" 2>&1 > "$D"/out.txt) && rc= || rc=$? - if [ -n "$rc" ]; then - echo "$UDEV_DMI_MEMORY_ID returned $rc" - exit $rc - fi - err=$(diff -u "$D"/out.txt "$i.txt" 2>&1) && rc= || rc=$? - if [ -n "$rc" ]; then - echo "Parsing DMI memory information from \"$i\" didn't match expected:" - echo "$err" - exit $rc - fi -done +( + set -x + "$dmi_memory_id" -F "$input" >$output + diff -u "$output" "$expected" +)