summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/ChangeLog376
-rw-r--r--tests/Makefile.am94
-rw-r--r--tests/alldts.c5
-rw-r--r--tests/backtrace.c61
-rwxr-xr-xtests/debuginfod-subr.sh170
-rw-r--r--tests/elfcopy.c2
-rw-r--r--tests/nvidia_extended_linemap_libdw.c166
-rwxr-xr-xtests/run-alldts.sh2
-rwxr-xr-xtests/run-debuginfod-archive-groom.sh166
-rwxr-xr-xtests/run-debuginfod-archive-rename.sh103
-rwxr-xr-xtests/run-debuginfod-archive-test.sh87
-rwxr-xr-xtests/run-debuginfod-artifact-running.sh119
-rwxr-xr-xtests/run-debuginfod-dlopen.sh91
-rwxr-xr-xtests/run-debuginfod-duplicate-urls.sh56
-rwxr-xr-xtests/run-debuginfod-extraction-passive.sh77
-rwxr-xr-xtests/run-debuginfod-extraction.sh106
-rwxr-xr-xtests/run-debuginfod-fd-prefetch-caches.sh66
-rwxr-xr-xtests/run-debuginfod-federation-link.sh164
-rwxr-xr-xtests/run-debuginfod-federation-metrics.sh210
-rwxr-xr-xtests/run-debuginfod-federation-sqlite.sh202
-rwxr-xr-xtests/run-debuginfod-file.sh41
-rwxr-xr-xtests/run-debuginfod-find.sh677
-rwxr-xr-xtests/run-debuginfod-malformed.sh111
-rwxr-xr-xtests/run-debuginfod-negative-cache.sh83
-rwxr-xr-xtests/run-debuginfod-no-urls.sh41
-rwxr-xr-xtests/run-debuginfod-percent-escape.sh60
-rwxr-xr-xtests/run-debuginfod-query-retry.sh35
-rwxr-xr-xtests/run-debuginfod-regex.sh101
-rwxr-xr-xtests/run-debuginfod-response-headers.sh100
-rwxr-xr-xtests/run-debuginfod-sizetime.sh82
-rwxr-xr-xtests/run-debuginfod-tmp-home.sh126
-rwxr-xr-xtests/run-debuginfod-webapi-concurrency.sh69
-rwxr-xr-xtests/run-debuginfod-writable.sh88
-rwxr-xr-xtests/run-debuginfod-x-forwarded-for.sh63
-rwxr-xr-xtests/run-large-elf-file.sh11
-rwxr-xr-xtests/run-nvidia-extended-linemap-libdw.sh60
-rwxr-xr-xtests/run-nvidia-extended-linemap-readelf.sh120
-rwxr-xr-xtests/run-readelf-d.sh7
-rwxr-xr-xtests/run-readelf-fat-lto.sh53
-rwxr-xr-xtests/run-readelf-multi-noline.sh170
-rwxr-xr-xtests/run-strip-largealign.sh35
-rwxr-xr-xtests/run-varlocs-vars.sh93
-rw-r--r--tests/show-die-info.c2
-rw-r--r--tests/testfile-dwarf5-fat-lto.o.bz2bin0 -> 3101 bytes
-rw-r--r--tests/testfile-largealign.o.bz2bin0 -> 183 bytes
-rw-r--r--tests/testfile-vars-clang-dwarf4-32.o.bz2bin0 -> 568 bytes
-rw-r--r--tests/testfile-vars-clang-dwarf4-64.o.bz2bin0 -> 605 bytes
-rw-r--r--tests/testfile-vars-clang-dwarf5-32.o.bz2bin0 -> 741 bytes
-rw-r--r--tests/testfile-vars-clang-dwarf5-64.o.bz2bin0 -> 761 bytes
-rw-r--r--tests/testfile-vars-gcc-dwarf4-32.o.bz2bin0 -> 660 bytes
-rw-r--r--tests/testfile-vars-gcc-dwarf4-64.o.bz2bin0 -> 691 bytes
-rw-r--r--tests/testfile-vars-gcc-dwarf5-32.o.bz2bin0 -> 728 bytes
-rw-r--r--tests/testfile-vars-gcc-dwarf5-64.o.bz2bin0 -> 768 bytes
-rwxr-xr-xtests/testfile_multi_noline.bz2bin0 -> 3155 bytes
-rw-r--r--tests/testfile_nvidia_linemap.bz2bin0 -> 2365 bytes
-rw-r--r--tests/varlocs.c11
57 files changed, 3851 insertions, 712 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index d0e83da2..99d04819 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -85,6 +85,7 @@
/next-files
/next-lines
/next_cfi
+/nvidia_extended_linemap_libdw
/peel_type
/rdwrmmap
/read_unaligned
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 38e92659..44b8df88 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,379 @@
+2022-04-24 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-webapi-concurrency.sh: Fix PR number in xfail.
+
+2022-04-23 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-webapi-concurrency.sh: Lower parallel lookups.
+
+2022-03-01 Di Chen <[email protected]>
+
+ * alldts.c (dtflags): Put DT_NULL last.
+ * run-alldts.sh: NULL comes last.
+ * run-readelf-d.sh: Adjust Dynamic entries, remove DT_NULL
+ padding.
+
+2022-04-14 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-federation-sqlite.sh: Don't try to corrupt
+ sqlite database.
+
+2022-04-13 Aaron Merey <[email protected]>
+
+ * Makefile.am (TESTS): Remove run-debuginfod-000-permission.sh
+ and add run-debuginfod-negative-cache.sh.
+ (EXTRA_DIST): Likewise.
+ * run-debuginfod-federation-link.sh: Update comments about
+ negative-hit file.
+ * run-debuginfod-federation-metrics.sh: Likewise.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+ * run-debuginfod-tmp-home.sh: Likewise.
+
+2022-03-20 Mark Wielaard <[email protected]>
+
+ * run-large-elf-file.sh: Check elf class of addsections binary.
+
+2021-12-17 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-query-retry.sh: Use /bin/sh instead of /bin/ls.
+
+2021-12-09 Frank Ch. Eigler <[email protected]>
+
+ * debuginfod-subr.sh (xfail): New proc.
+ * run-debuginfod-webapi-concurrency.sh: New test for -C.
+ * Makefile.am: List it.
+
+2021-12-04 Mark Wielaard <[email protected]>
+
+ * Makefile.am (EXTRA_NLIST_CFLAGS): New variable depends on
+ USE_ADDRESS_SANITIZER.
+ (test_nlist_CFLAGS): Add EXTRA_NLIST_CFLAGS.
+
+2021-12-04 Mark Wielaard <[email protected]>
+
+ * varlocs.c (dwarf_encoding_string): Return "<unknown encoding>" instead
+ of NULL.
+ (dwarf_tag_string): Return "<unknown tag>" instead of NULL.
+ (dwarf_attr_string): Return "<unknown attr>" instead of NULL.
+ (dwarf_form_string): Return "<unknown form>" instead of NULL.
+ (dwarf_opcode_string): Return "<unknown opcode>" instead of NULL.
+ (print_expr): Remove assert.
+
+2021-11-18 Mark Wielaard <[email protected]>
+
+ * Makefile.am (dwfl_proc_attach_LDFLAGS): Add -rdynamic.
+
+2021-11-11 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-000-permission.sh: Don't set DEBUGINFOD_TIMEOUT.
+ * run-debuginfod-archive-groom.sh: Likewise.
+ * run-debuginfod-archive-rename.sh: Likewise.
+ * run-debuginfod-archive-test.sh: Likewise.
+ * run-debuginfod-artifact-running.sh: Likewise.
+ * run-debuginfod-dlopen.sh: Likewise.
+ * run-debuginfod-extraction.sh: Likewise.
+ * run-debuginfod-federation-link.sh: Likewise.
+ * run-debuginfod-federation-metrics.sh: Likewise.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+ * run-debuginfod-malformed.sh: Likewise.
+ * run-debuginfod-tmp-home.sh: Likewise.
+ * run-debuginfod-writable.sh: Likewise.
+
+2021-11-05 Frank Ch. Eigler <[email protected]>
+
+ PR28430
+ * run-debuginfod-extraction-passive.sh: New test.
+ * Makefile.am (TESTS, EXTRA_DIST): Add it.
+
+2021-10-20 John M Mellor-Crummey <[email protected]>
+
+ * nvidia_extended_linemap_libdw.c: New file.
+ * run-nvidia-extended-linemap-libdw.sh: New test.
+ * run-nvidia-extended-linemap-readelf.sh: Likewise.
+ * testfile_nvidia_linemap.bz2: New test file.
+ * .gitignore: Add nvidia_extended_linemap_libdw.
+ * Makefile.am (check_PROGRAMS): Add nvidia_extended_linemap_libdw.
+ (TESTS): Add run-nvidia-extended-linemap-libdw.sh and
+ run-nvidia-extended-linemap-readelf.sh
+ (EXTRA_DIST): Likewise and testfile_nvidia_linemap.bz2.
+ (nvidia_extended_linemap_libdw_LDADD): New variable.
+
+2021-11-08 Mark Wielaard <[email protected]>
+
+ * Makefile.am (TESTS): Add run-readelf-fat-lto.sh.
+ (EXTRA_DIST): Add run-readelf-fat-lto.sh and
+ testfile-dwarf5-fat-lto.o.bz2.
+ * run-readelf-fat-lto.sh: New test.
+ * testfile-dwarf5-fat-lto.o.bz2: New test file.
+
+2021-11-04 Frank Ch. Eigler <[email protected]>
+
+ PR28514
+ * run-debuginfod-archive-groom.sh: Look for new groom metric.
+
+2021-10-23 Frank Ch. Eigler <[email protected]>
+
+ PR28240
+ * run-debuginfod-000-permission.sh, -writable.sh:
+ Correct negative-cache file permission checking.
+
+2021-10-06 Mark Wielaard <[email protected]>
+
+ * show-die-info.c (handle): Handle dwarf_attr_string returning NULL.
+
+2021-10-06 Di Chen <[email protected]>
+
+ PR28242
+ * run-debuginfod-000-permission.sh: Expect artifacttype metrics.
+
+2021-09-17 Noah Sanci <[email protected]>
+
+ * run-debuginfod-response-header.sh: removed checking for Connection
+ and Cache-Control in response headers.
+
+2021-09-08 Mark Wielaard <[email protected]>
+
+ * run-varlocs-vars.sh: New test.
+ * testfile-vars-clang-dwarf4-32.o.bz2: New test file.
+ * testfile-vars-clang-dwarf4-64.o.bz2: Likewise.
+ * testfile-vars-clang-dwarf5-32.o.bz2: Likewise.
+ * testfile-vars-clang-dwarf5-64.o.bz2: Likewise.
+ * testfile-vars-gcc-dwarf4-32.o.bz2: Likewise.
+ * testfile-vars-gcc-dwarf4-64.o.bz2: Likewise.
+ * testfile-vars-gcc-dwarf5-32.o.bz2: Likewise.
+ * testfile-vars-gcc-dwarf5-64.o.bz2: Likewise.
+ * Makefile.am (EXTRA_DIST): Add new test and test files.
+ (TESTS): Add run-varlocs-vars.sh.
+
+2021-09-09 Mark Wielaard <[email protected]>
+
+ * debuginfod-subr.sh: set -o functrace.
+ (cleanup): Disable trap 0.
+ (err): Disable trap ERR.
+ * run-debuginfod-fd-prefetch-caches.sh: Use || true when grep -c fails.
+
+2021-09-09 Mark Wielaard <[email protected]>
+
+ * debuginfod-subr.sh: set -o errtrace.
+ (cleanup): Don't fail kill or wait. Only trap on normal exit.
+ (err): Don't fail curl metrics. Call cleanup.
+ * run-debuginfod-federation-link.sh: Use separate client caches
+ for both servers and debuginfod client. Remove duplicate valgrind
+ disabling.
+ * run-debuginfod-federation-metrics.sh: Likewise.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+
+2021-09-13 Noah Sanci <[email protected]>
+
+ * Makefile.am: added run-debuginfod-percent-escape.sh to TESTS and
+ EXTRA_DIST.
+
+2021-09-06 Dmitry V. Levin <[email protected]>
+
+ * elfcopy.c (copy_elf): Remove cast of malloc return value.
+
+2021-09-07 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-archive-groom.sh: Wait for initial scan and groom
+ cycle before making any changes to the scan dirs.
+ * run-debuginfod-archive-rename.sh: Likewise.
+ * run-debuginfod-artifact-running.sh: Wait for initial scan cycle
+ before making any changes to the scan dirs.
+ * run-debuginfod-dlopen.sh: Likewise.
+ * run-debuginfod-extraction.sh: Likewise.
+ * run-debuginfod-federation-link.sh: Don't wait twice for the initial
+ scan.
+
+2021-09-06 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-archive-groom.sh: Wait for initial scan and groom
+ cycle.
+ * run-debuginfod-archive-rename.sh: Likewise.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+ * run-debuginfod-archive-test.sh: Wait for initial scan cycle.
+ * run-debuginfod-artifact-running.sh: Likewise.
+ * run-debuginfod-dlopen.sh: Likewise.
+ * run-debuginfod-extraction.sh: Likewise.
+ * run-debuginfod-federation-link.sh: Likewise.
+ * run-debuginfod-federation-metrics.sh: Likewise.
+ * run-debuginfod-malformed.sh: Likewise.
+ * run-debuginfod-regex.sh: Likewise.
+ * run-debuginfod-tmp-home.sh: Likewise.
+ * run-debuginfod-writable.sh: Likewise.
+
+2021-09-06 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-archive-groom.sh: Set DEBUGINFOD_URLS after starting
+ debuginfod server.
+ * run-debuginfod-archive-rename.sh: Likewise.
+ * run-debuginfod-federation-link.sh: Don't set DEBUGINFOD_URLS.
+ * run-debuginfod-federation-sqlite.sh: Likewise.
+ * run-debuginfod-federation-metrics.sh: Add comment why invalid
+ DEBUGINFOD_URLS is set.
+
+2021-09-06 Mark Wielaard <[email protected]>
+
+ * debuginfod-subr.sh (err): Change ports to port in for loop so both
+ PORT1 and PORT2 are used.
+ (get_ports): Simplify port selection by using for 50 for PORT1 and
+ second 50 for PORT2.
+
+2021-09-06 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-file.sh: Set DEBUGINFOD_CACHE_PATH. Export
+ correct DEBUGINFOD_URLS.
+ * run-debuginfod-query-retry.sh: Add DEBUGINFOD_CACHE_PATH
+ to env.
+
+2021-09-03 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-000-permission.sh: Set DEBUGINFOD_CACHE_PATH
+ and use an unique sqlite db.
+ * run-debuginfod-archive-groom.sh: Likewise.
+ * run-debuginfod-archive-test.sh: Likewise.
+ * run-debuginfod-dlopen.sh: Likewise.
+ * run-debuginfod-duplicate-urls.sh: Likewise.
+ * run-debuginfod-extraction.sh: Likewise.
+ * run-debuginfod-fd-prefetch-caches.sh: Likewise.
+ * run-debuginfod-malformed.sh: Likewise.
+ * run-debuginfod-sizetime.sh: Likewise.
+ * run-debuginfod-tmp-home.sh: Likewise.
+ * run-debuginfod-writable.sh: Likewise.
+
+2021-09-03 Mark Wielaard <[email protected]>
+
+ * debuginfod-subr.sh (EXTRA_DIST): Add debuginfod-subr.sh.
+
+2021-08-20 Noah Sanci <[email protected]>
+
+ * run-debuginfod-response-headers.sh: Ensures custom http response
+ headers are used and functional
+ * Makefile.am: Added the above new file to TESTS and EXTRA_DIST
+
+2021-08-28 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-find.sh: Use ":memory:" for the
+ forwarded-ttl-limit tests.
+
+2021-08-28 Mark Wielaard <[email protected]>
+
+ * run-debuginfod-find.sh: Use clean, separate databases for
+ forwarded-ttl-limit tests.
+
+2021-08-20 Di Chen <[email protected]>
+
+ * run-debuginfod-find.sh: Add test for X-Forwarded-For hops limit.
+
+2021-08-20 Noah Sanci <[email protected]>
+
+ * debuginfod-find.sh: Separated file into
+ run-debuginfod-000-permission.sh,
+ run-debuginfod-archive-groom.sh,
+ run-debuginfod-archive-rename.sh,
+ run-debuginfod-archive-test.sh,
+ run-debuginfod-artifact-running.sh,
+ run-debuginfod-dlopen.sh,
+ run-debuginfod-duplicate-urls.sh,
+ run-debuginfod-extraction.sh,
+ run-debuginfod-fd-prefetch-caches.sh,
+ run-debuginfod-federation-link.sh,
+ run-debuginfod-federation-metrics.sh,
+ run-debuginfod-federation-sqlite.sh,
+ run-debuginfod-file.sh,
+ run-debuginfod-malformed.sh,
+ run-debuginfod-no-urls.sh,
+ run-debuginfod-query-retry.sh,
+ run-debuginfod-regex.sh,
+ run-debuginfod-sizetime.sh,
+ run-debuginfod-tmp-home.sh,
+ run-debuginfod-x-forwarded.sh
+ and run-debuginfod-writable.sh.
+ All files source debuginfod-subr.sh and use the $base variable to find ports.
+ * tests/Makefile.am: Added the above new files to the test suite
+ * tests/debuginfod-subr.sh: Added some general functions for above tests
+
+2021-08-04 Mark Wielaard <[email protected]>
+
+ PR28190
+ * backtrace.c (callback_verify): Check for pthread_kill as first
+ frame. Change asserts to fprintf plus abort.
+
+2021-07-26 Noah Sanci <[email protected]>
+
+ PR27982
+ * run-debuginfod-find.sh: Added a test to ensure that
+ DEBUGINFOD_MAXSIZE and DEBUGINFOD_MAXTIME work properly
+ by searching server and client logs for prompts.
+
+2021-07-16 Noah Sanci <[email protected]>
+
+ PR28034
+ * run-debuginfod-percent-escape.sh: Added a test ensuring files with %
+ escapable characters in their paths are accessible.
+
+2021-07-21 Noah Sanci <[email protected]>
+
+ * run-debuginfod-find.sh: Properly kill $PID4 by waiting for it to
+ finish. Report $PORT3's metrics in err().
+
+2021-06-28 Noah Sanci <[email protected]>
+
+ PR25978
+ * run-debuginfod-find.sh: Test to ensure options
+ fdcache-prefetch-fds/mbs are set. Check that inc_metric works for lru
+ and prefetch cache metrics.
+
+2021-07-06 Alice Zhang <[email protected]>
+
+ PR27531
+ * run-debuginfod-find.sh: Add test case for retry mechanism.
+
+2021-07-01 Noah Sanci <[email protected]>
+
+ PR2711
+ * run-debuginfod-find.sh: Added test case for grooming the database
+ using regexes.
+
+2021-07-09 Noah Sanci <[email protected]>
+
+ PR27983
+ * run-debuginfod-find.sh: Wrote test to ensure duplicate urls are in
+ fact not checked.
+
+2021-07-08 Mark Wielaard <[email protected]>
+
+ * Makefile.am (EXTRA_DIST): Fix typo testfile-largealign.bz2 was
+ was missing .o.
+
+2021-06-09 Andrei Homescu <[email protected]>
+
+ * testfile-largealign.o.bz2: New test file.
+ * run-strip-largealign.sh: New test.
+ * Makefile.am (TESTS): Add run-strip-largealign.sh.
+ (EXTRA_DIST): Add run-strip-largealign.sh and
+ testfile-largealign.o.bz2
+
+2021-07-02 Mark Wielaard <[email protected]>
+
+ * run-debuginfo-find.sh: unset VALGRIND_CMD before testing debuginfod
+ client cache.
+
+2021-06-16 Frank Ch. Eigler <[email protected]>
+
+ * run-debuginfod-find.sh: Fix intermittent groom/stale failure,
+ due to SIGUSR1/SIGUSR2 races. Trace more.
+
+2021-06-15 Frank Ch. Eigler <[email protected]>
+
+ * run-debuginfod-find.sh (err): Elaborate. Use as the reliable
+ error-report triggering function, rather than "exit 1".
+
+2021-06-03 Frank Ch. Eigler <[email protected]>
+
+ PR27863
+ * run-debuginfod-find.sh: Test "after-you" queueing via flooding
+ with concurent curls.
+
2021-05-14 Frank Ch. Eigler <[email protected]>
PR27859
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6f19007a..75fbe799 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -61,6 +61,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \
dwelf_elf_e_machine_string \
getphdrnum leb128 read_unaligned \
msg_tst system-elf-libelf-test \
+ nvidia_extended_linemap_libdw \
$(asm_TESTS)
asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \
@@ -86,7 +87,13 @@ endif
# test_nlist checks its own symbol table, and expects various symbols
# to be in the order as specified in the source file. Explicitly set
-# minimal CFLAGS
+# minimal CFLAGS. But add address sanitizer if in use.
+if USE_ADDRESS_SANITIZER
+EXTRA_NLIST_CFLAGS=-fsanitize=address
+else
+EXTRA_NLIST_CFLAGS=
+endif
+
test-nlist$(EXEEXT): test-nlist.c
$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
$(AM_CPPFLAGS) $(CPPFLAGS) \
@@ -138,11 +145,11 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-low_high_pc.sh run-macro-test.sh run-elf_cntl_gelf_getshdr.sh \
run-test-archive64.sh run-readelf-vmcoreinfo.sh \
run-readelf-mixed-corenote.sh run-dwfllines.sh \
- run-readelf-variant.sh \
+ run-readelf-variant.sh run-readelf-fat-lto.sh \
run-dwfl-report-elf-align.sh run-addr2line-test.sh \
run-addr2line-i-test.sh run-addr2line-i-lex-test.sh \
run-addr2line-i-demangle-test.sh run-addr2line-alt-debugpath.sh \
- run-varlocs.sh run-exprlocs.sh run-funcretval.sh \
+ run-varlocs.sh run-exprlocs.sh run-varlocs-vars.sh run-funcretval.sh \
run-backtrace-native.sh run-backtrace-data.sh run-backtrace-dwarf.sh \
run-backtrace-native-biarch.sh run-backtrace-native-core.sh \
run-backtrace-native-core-biarch.sh run-backtrace-core-x86_64.sh \
@@ -157,6 +164,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
run-backtrace-demangle.sh run-stack-d-test.sh run-stack-i-test.sh \
run-stack-demangled-test.sh run-readelf-zx.sh run-readelf-zp.sh \
run-readelf-addr.sh run-readelf-str.sh \
+ run-readelf-multi-noline.sh \
run-readelf-types.sh \
run-readelf-dwz-multi.sh run-allfcts-multi.sh run-deleted.sh \
run-linkmap-cut.sh run-aggregate-size.sh run-peel-type.sh \
@@ -186,7 +194,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \
leb128 read_unaligned \
msg_tst system-elf-libelf-test \
$(asm_TESTS) run-disasm-bpf.sh run-low_high_pc-dw-form-indirect.sh \
- run-readelf-dw-form-indirect.sh
+ run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
+ run-readelf-dw-form-indirect.sh run-strip-largealign.sh
if !BIARCH
export ELFUTILS_DISABLE_BIARCH = 1
@@ -208,7 +217,31 @@ if DEBUGINFOD
check_PROGRAMS += debuginfod_build_id_find
# With the dummy delegation doesn't work
if !DUMMY_LIBDEBUGINFOD
-TESTS += run-debuginfod-find.sh
+TESTS += run-debuginfod-dlopen.sh \
+ run-debuginfod-artifact-running.sh \
+ run-debuginfod-fd-prefetch-caches.sh \
+ run-debuginfod-regex.sh \
+ run-debuginfod-duplicate-urls.sh \
+ run-debuginfod-file.sh \
+ run-debuginfod-sizetime.sh \
+ run-debuginfod-malformed.sh \
+ run-debuginfod-negative-cache.sh \
+ run-debuginfod-tmp-home.sh \
+ run-debuginfod-writable.sh \
+ run-debuginfod-no-urls.sh \
+ run-debuginfod-query-retry.sh \
+ run-debuginfod-extraction.sh \
+ run-debuginfod-archive-groom.sh \
+ run-debuginfod-archive-rename.sh \
+ run-debuginfod-archive-test.sh \
+ run-debuginfod-federation-sqlite.sh \
+ run-debuginfod-federation-link.sh \
+ run-debuginfod-federation-metrics.sh \
+ run-debuginfod-percent-escape.sh \
+ run-debuginfod-x-forwarded-for.sh \
+ run-debuginfod-response-headers.sh \
+ run-debuginfod-extraction-passive.sh \
+ run-debuginfod-webapi-concurrency.sh
endif
endif
@@ -277,7 +310,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfile21.bz2 testfile21.index.bz2 \
testfile22.bz2 testfile23.bz2 testfile24.bz2 testfile25.bz2 \
testfile26.bz2 testfile27.bz2 \
- coverage.sh test-subr.sh test-wrapper.sh \
+ coverage.sh test-subr.sh test-wrapper.sh debuginfod-subr.sh \
run-readelf-test1.sh run-readelf-test2.sh run-readelf-test3.sh \
run-readelf-test4.sh run-readelf-twofiles.sh \
run-bug1-test.sh testfile28.bz2 testfile28.rdwr.bz2 \
@@ -309,6 +342,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfile_multi.dwz.bz2 testfile_multi_main.bz2 \
testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \
run-readelf-addr.sh run-readelf-str.sh \
+ run-readelf-multi-noline.sh testfile_multi_noline.bz2 \
run-readelf-types.sh \
run-readelf-frames.sh \
run-readelf-n.sh \
@@ -353,6 +387,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfilebazminppc64.bz2 testfilebazminppc64_pl.bz2 \
testfilebazminppc64_plr.bz2 testfilebaztabppc64.bz2 \
run-readelf-variant.sh testfile-ada-variant.bz2 \
+ run-readelf-fat-lto.sh testfile-dwarf5-fat-lto.o.bz2 \
run-dwflsyms.sh \
run-unstrip-n.sh testcore-rtlib.bz2 testcore-rtlib-ppc.bz2 \
run-low_high_pc.sh testfile_low_high_pc.bz2 \
@@ -375,7 +410,16 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfileppc32.bz2 testfileppc64.bz2 \
testfiles390.bz2 testfiles390x.bz2 \
testfilearm.bz2 testfileaarch64.bz2 \
- run-varlocs.sh run-exprlocs.sh testfile-stridex.bz2 \
+ run-varlocs.sh run-exprlocs.sh run-varlocs-vars.sh \
+ testfile-vars-clang-dwarf4-32.o.bz2 \
+ testfile-vars-clang-dwarf4-64.o.bz2 \
+ testfile-vars-clang-dwarf5-32.o.bz2 \
+ testfile-vars-clang-dwarf5-64.o.bz2 \
+ testfile-vars-gcc-dwarf4-32.o.bz2 \
+ testfile-vars-gcc-dwarf4-64.o.bz2 \
+ testfile-vars-gcc-dwarf5-32.o.bz2 \
+ testfile-vars-gcc-dwarf5-64.o.bz2 \
+ testfile-stridex.bz2 \
testfile_const_type.c testfile_const_type.bz2 \
testfile_implicit_pointer.c testfile_implicit_pointer.bz2 \
testfile_parameter_ref.c testfile_parameter_ref.bz2 \
@@ -470,7 +514,31 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
run-elfclassify.sh run-elfclassify-self.sh \
run-disasm-riscv64.sh \
testfile-riscv64-dis1.o.bz2 testfile-riscv64-dis1.expect.bz2 \
- run-debuginfod-find.sh \
+ run-debuginfod-extraction.sh \
+ run-debuginfod-federation-link.sh \
+ run-debuginfod-federation-metrics.sh \
+ run-debuginfod-artifact-running.sh \
+ run-debuginfod-federation-sqlite.sh \
+ run-debuginfod-x-forwarded-for.sh \
+ run-debuginfod-fd-prefetch-caches.sh \
+ run-debuginfod-regex.sh \
+ run-debuginfod-duplicate-urls.sh \
+ run-debuginfod-file.sh \
+ run-debuginfod-sizetime.sh \
+ run-debuginfod-dlopen.sh \
+ run-debuginfod-malformed.sh \
+ run-debuginfod-negative-cache.sh \
+ run-debuginfod-tmp-home.sh \
+ run-debuginfod-writable.sh \
+ run-debuginfod-no-urls.sh \
+ run-debuginfod-query-retry.sh \
+ run-debuginfod-archive-groom.sh \
+ run-debuginfod-archive-rename.sh \
+ run-debuginfod-archive-test.sh \
+ run-debuginfod-percent-escape.sh \
+ run-debuginfod-response-headers.sh \
+ run-debuginfod-extraction-passive.sh \
+ run-debuginfod-webapi-concurrency.sh \
debuginfod-rpms/fedora30/hello2-1.0-2.src.rpm \
debuginfod-rpms/fedora30/hello2-1.0-2.x86_64.rpm \
debuginfod-rpms/fedora30/hello2-debuginfo-1.0-2.x86_64.rpm \
@@ -507,7 +575,10 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
testfile_pt_gnu_prop.bz2 testfile_pt_gnu_prop32.bz2 \
run-getphdrnum.sh testfile-phdrs.elf.bz2 \
run-test-includes.sh run-low_high_pc-dw-form-indirect.sh \
- run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2
+ run-readelf-dw-form-indirect.sh testfile-dw-form-indirect.bz2 \
+ run-nvidia-extended-linemap-libdw.sh run-nvidia-extended-linemap-readelf.sh \
+ testfile_nvidia_linemap.bz2 \
+ testfile-largealign.o.bz2 run-strip-largealign.sh
if USE_VALGRIND
@@ -570,7 +641,7 @@ scnnames_LDADD = $(libelf)
sectiondump_LDADD = $(libelf)
showptable_LDADD = $(libelf)
hash_LDADD = $(libelf)
-test_nlist_CFLAGS =-g -O0
+test_nlist_CFLAGS =-g -O0 $(EXTRA_NLIST_CFLAGS)
test_nlist_LDADD = $(libelf)
msg_tst_LDADD = $(libelf)
newscn_LDADD = $(libelf)
@@ -653,7 +724,7 @@ strptr_LDADD = $(libelf)
newdata_LDADD = $(libelf)
elfstrtab_LDADD = $(libelf)
dwfl_proc_attach_LDADD = $(libdw)
-dwfl_proc_attach_LDFLAGS = -pthread $(AM_LDFLAGS)
+dwfl_proc_attach_LDFLAGS = -pthread -rdynamic $(AM_LDFLAGS)
elfshphehdr_LDADD =$(libelf)
elfstrmerge_LDADD = $(libdw) $(libelf)
dwelfgnucompressed_LDADD = $(libelf) $(libdw)
@@ -681,6 +752,7 @@ dwelf_elf_e_machine_string_LDADD = $(libelf) $(libdw)
getphdrnum_LDADD = $(libelf) $(libdw)
leb128_LDADD = $(libelf) $(libdw)
read_unaligned_LDADD = $(libelf) $(libdw)
+nvidia_extended_linemap_libdw_LDADD = $(libelf) $(libdw)
# We want to test the libelf header against the system elf.h header.
# Don't include any -I CPPFLAGS. Except when we install our own elf.h.
diff --git a/tests/alldts.c b/tests/alldts.c
index 3e9f9fe6..d0fe4f24 100644
--- a/tests/alldts.c
+++ b/tests/alldts.c
@@ -44,7 +44,7 @@ main (void)
Dwelf_Strent *shstrtabse;
const Elf32_Sword dtflags[] =
{
- DT_NULL, DT_NEEDED, DT_PLTRELSZ, DT_PLTGOT,
+ DT_NEEDED, DT_PLTRELSZ, DT_PLTGOT,
DT_HASH, DT_STRTAB, DT_SYMTAB, DT_RELA,
DT_RELASZ, DT_RELAENT, DT_STRSZ, DT_SYMENT,
DT_INIT, DT_FINI, DT_SONAME, DT_RPATH,
@@ -61,7 +61,8 @@ main (void)
DT_GNU_LIBLIST, DT_CONFIG, DT_DEPAUDIT, DT_AUDIT,
DT_PLTPAD, DT_MOVETAB, DT_SYMINFO, DT_RELACOUNT,
DT_RELCOUNT, DT_FLAGS_1, DT_VERDEF, DT_VERDEFNUM,
- DT_VERNEED, DT_VERNEEDNUM, DT_AUXILIARY, DT_FILTER
+ DT_VERNEED, DT_VERNEEDNUM, DT_AUXILIARY, DT_FILTER,
+ DT_NULL
};
const int ndtflags = sizeof (dtflags) / sizeof (dtflags[0]);
diff --git a/tests/backtrace.c b/tests/backtrace.c
index 36c8b8c4..afc12fb9 100644
--- a/tests/backtrace.c
+++ b/tests/backtrace.c
@@ -97,6 +97,9 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
static bool reduce_frameno = false;
if (reduce_frameno)
frameno--;
+ static bool pthread_kill_seen = false;
+ if (pthread_kill_seen)
+ frameno--;
if (! use_raise_jmp_patching && frameno >= 2)
frameno += 2;
const char *symname2 = NULL;
@@ -107,11 +110,26 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
&& (strcmp (symname, "__kernel_vsyscall") == 0
|| strcmp (symname, "__libc_do_syscall") == 0))
reduce_frameno = true;
+ else if (! pthread_kill_seen && symname
+ && strstr (symname, "pthread_kill") != NULL)
+ pthread_kill_seen = true;
else
- assert (symname && strcmp (symname, "raise") == 0);
+ {
+ if (!symname || strcmp (symname, "raise") != 0)
+ {
+ fprintf (stderr,
+ "case 0: expected symname 'raise' got '%s'\n", symname);
+ abort ();
+ }
+ }
break;
case 1:
- assert (symname != NULL && strcmp (symname, "sigusr2") == 0);
+ if (symname == NULL || strcmp (symname, "sigusr2") != 0)
+ {
+ fprintf (stderr,
+ "case 1: expected symname 'sigusr2' got '%s'\n", symname);
+ abort ();
+ }
break;
case 2: // x86_64 only
/* __restore_rt - glibc maybe does not have to have this symbol. */
@@ -120,11 +138,21 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
if (use_raise_jmp_patching)
{
/* Verify we trapped on the very first instruction of jmp. */
- assert (symname != NULL && strcmp (symname, "jmp") == 0);
+ if (symname == NULL || strcmp (symname, "jmp") != 0)
+ {
+ fprintf (stderr,
+ "case 3: expected symname 'raise' got '%s'\n", symname);
+ abort ();
+ }
mod = dwfl_addrmodule (dwfl, pc - 1);
if (mod)
symname2 = dwfl_module_addrname (mod, pc - 1);
- assert (symname2 == NULL || strcmp (symname2, "jmp") != 0);
+ if (symname2 == NULL || strcmp (symname2, "jmp") != 0)
+ {
+ fprintf (stderr,
+ "case 3: expected symname2 'jmp' got '%s'\n", symname2);
+ abort ();
+ }
break;
}
FALLTHROUGH;
@@ -137,11 +165,22 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
duplicate_sigusr2 = true;
break;
}
- assert (symname != NULL && strcmp (symname, "stdarg") == 0);
+ if (symname == NULL || strcmp (symname, "stdarg") != 0)
+ {
+ fprintf (stderr,
+ "case 4: expected symname 'stdarg' got '%s'\n", symname);
+ abort ();
+ }
break;
case 5:
/* Verify we trapped on the very last instruction of child. */
- assert (symname != NULL && strcmp (symname, "backtracegen") == 0);
+ if (symname == NULL || strcmp (symname, "backtracegen") != 0)
+ {
+ fprintf (stderr,
+ "case 5: expected symname 'backtracegen' got '%s'\n",
+ symname);
+ abort ();
+ }
mod = dwfl_addrmodule (dwfl, pc);
if (mod)
symname2 = dwfl_module_addrname (mod, pc);
@@ -151,7 +190,15 @@ callback_verify (pid_t tid, unsigned frameno, Dwarf_Addr pc,
// instructions or even inserts some padding instructions at the end
// (which apparently happens on ppc64).
if (use_raise_jmp_patching)
- assert (symname2 == NULL || strcmp (symname2, "backtracegen") != 0);
+ {
+ if (symname2 != NULL && strcmp (symname2, "backtracegen") == 0)
+ {
+ fprintf (stderr,
+ "use_raise_jmp_patching didn't expect symname2 "
+ "'backtracegen'\n");
+ abort ();
+ }
+ }
break;
}
}
diff --git a/tests/debuginfod-subr.sh b/tests/debuginfod-subr.sh
new file mode 100755
index 00000000..0b59b5b8
--- /dev/null
+++ b/tests/debuginfod-subr.sh
@@ -0,0 +1,170 @@
+# Copyright (C) 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# sourced from run-debuginfod-*.sh tests (must be bash scripts)
+
+# We trap ERR and like commands that fail in function to also trap
+set -o functrace
+set -o errtrace
+
+. $srcdir/test-subr.sh # includes set -e
+
+type curl 2>/dev/null || (echo "need curl"; exit 77)
+type rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77)
+type cpio 2>/dev/null || (echo "need cpio"; exit 77)
+type bzcat 2>/dev/null || (echo "need bzcat"; exit 77)
+bsdtar --version | grep -q zstd && zstd=true || zstd=false
+echo "zstd=$zstd bsdtar=`bsdtar --version`"
+
+cleanup()
+{
+ # No more cleanups after this cleanup
+ trap - 0
+
+ if [ $PID1 -ne 0 ]; then kill $PID1 || : ; wait $PID1 || :; fi
+ if [ $PID2 -ne 0 ]; then kill $PID2 || : ; wait $PID2 || :; fi
+ rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp*
+ exit_cleanup
+}
+
+# clean up trash if we exit
+trap cleanup 0
+
+errfiles_list=
+err() {
+ # Don't trap any new errors from now on
+ trap - ERR
+
+ echo ERROR REPORTS
+ for port in $PORT1 $PORT2
+ do
+ echo ERROR REPORT $port metrics
+ curl -s http://127.0.0.1:$port/metrics || :
+ echo
+ done
+ for x in $errfiles_list
+ do
+ echo ERROR REPORT "$x"
+ cat $x
+ echo
+ done
+ cleanup
+ false # trigger set -e
+}
+trap err ERR
+
+errfiles() {
+ errfiles_list="$errfiles_list $*"
+}
+
+# We want to run debuginfod in the background. We also want to start
+# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff
+# that the testrun alias sets. But: we if we just use
+# testrun .../debuginfod
+# it runs in a subshell, with different pid, so not helpful.
+#
+# So we gather the LD_LIBRARY_PATH with this cunning trick:
+ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'`
+
+wait_ready()
+{
+ port=$1;
+ what=$2;
+ value=$3;
+ timeout=20;
+
+ echo "Wait $timeout seconds on $port for metric $what to change to $value"
+ while [ $timeout -gt 0 ]; do
+ mvalue="$(curl -s http://127.0.0.1:$port/metrics \
+ | grep "$what" | awk '{print $NF}')"
+ if [ -z "$mvalue" ]; then mvalue=0; fi
+ echo "metric $what: $mvalue"
+ if [ "$mvalue" -eq "$value" ]; then
+ break;
+ fi
+ sleep 0.5;
+ ((timeout--));
+ done;
+
+ if [ $timeout -eq 0 ]; then
+ echo "metric $what never changed to $value on port $port"
+ err
+ fi
+}
+
+archive_test() {
+ __BUILDID=$1
+ __SOURCEPATH=$2
+ __SOURCESHA1=$3
+
+ filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
+ buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
+ test $__BUILDID = $buildid
+ # check that timestamps are plausible - older than the near-present (tmpdir mtime)
+ test $filename -ot `pwd`
+
+ # run again to assure that fdcache is being enjoyed
+ filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
+ buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
+ test $__BUILDID = $buildid
+ test $filename -ot `pwd`
+
+ filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID`
+ buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
+ test $__BUILDID = $buildid
+ test $filename -ot `pwd`
+
+ if test "x$__SOURCEPATH" != "x"; then
+ filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH`
+ hash=`cat $filename | sha1sum | awk '{print $1}'`
+ test $__SOURCESHA1 = $hash
+ test $filename -ot `pwd`
+ fi
+}
+
+get_ports() {
+ while true; do
+ PORT1=`expr '(' $RANDOM % 50 ')' + $base`
+ ss -atn | fgrep ":$PORT1" || break
+ done
+# Some tests will use two servers, so assign the second var
+ while true; do
+ PORT2=`expr '(' $RANDOM % 50 ')' + $base + 50`
+ ss -atn | fgrep ":$PORT2" || break
+ done
+
+}
+
+VERBOSE=-vvv
+# We gather the LD_LIBRARY_PATH with this cunning trick:
+ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'`
+PORT1=0
+PORT2=0
+PID1=0
+PID2=0
+
+
+# run $1 as a sh -c command, invert result code
+xfail() {
+ if sh -c "$1"; then
+ false
+ else
+ true
+ fi
+}
diff --git a/tests/elfcopy.c b/tests/elfcopy.c
index 4542222e..10b2d362 100644
--- a/tests/elfcopy.c
+++ b/tests/elfcopy.c
@@ -194,7 +194,7 @@ copy_elf (const char *in, const char *out, bool use_mmap, bool reverse_offs)
exit (1);
}
- offs = (GElf_Off *) malloc (shnum * sizeof (GElf_Off));
+ offs = malloc (shnum * sizeof (GElf_Off));
if (offs == NULL)
{
printf ("couldn't allocate memory for offs\n");
diff --git a/tests/nvidia_extended_linemap_libdw.c b/tests/nvidia_extended_linemap_libdw.c
new file mode 100644
index 00000000..20d8d404
--- /dev/null
+++ b/tests/nvidia_extended_linemap_libdw.c
@@ -0,0 +1,166 @@
+/* Inspect nvidia extended linemap with dwarf_next_lines.
+ Copyright (C) 2002, 2004, 2018 Red Hat, Inc.
+ This file is part of elfutils.
+
+ This file is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ elfutils is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <fcntl.h>
+#include <inttypes.h>
+#include <libelf.h>
+#include ELFUTILS_HEADER(dw)
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+
+int
+main (int argc, char *argv[])
+{
+ int result = 0;
+ int cnt;
+
+ for (cnt = 1; cnt < argc; ++cnt)
+ {
+ int fd = open (argv[cnt], O_RDONLY);
+
+ Dwarf *dbg = dwarf_begin (fd, DWARF_C_READ);
+ if (dbg == NULL)
+ {
+ printf ("%s not usable: %s\n", argv[cnt], dwarf_errmsg (-1));
+ close (fd);
+ continue;
+ }
+
+ Dwarf_Off off;
+ Dwarf_Off next_off = 0;
+ Dwarf_CU *cu = NULL;
+ Dwarf_Lines *lb;
+ size_t nlb;
+ int res;
+ while ((res = dwarf_next_lines (dbg, off = next_off, &next_off, &cu,
+ NULL, NULL, &lb, &nlb)) == 0)
+ {
+ printf ("off = %" PRIu64 "\n", off);
+ printf (" %zu lines\n", nlb);
+
+ for (size_t i = 0; i < nlb; ++i)
+ {
+ Dwarf_Line *l = dwarf_onesrcline (lb, i);
+ if (l == NULL)
+ {
+ printf ("%s: cannot get individual line\n", argv[cnt]);
+ result = 1;
+ break;
+ }
+
+ Dwarf_Addr addr;
+ if (dwarf_lineaddr (l, &addr) != 0)
+ addr = 0;
+ const char *file = dwarf_linesrc (l, NULL, NULL);
+ int line;
+ if (dwarf_lineno (l, &line) != 0)
+ line = 0;
+
+ printf ("%" PRIx64 ": %s:%d:", (uint64_t) addr,
+ file ?: "???", line);
+
+ /* Getting the file path through the Dwarf_Files should
+ result in the same path. */
+ Dwarf_Files *files;
+ size_t idx;
+ if (dwarf_line_file (l, &files, &idx) != 0)
+ {
+ printf ("%s: cannot get file from line (%zd): %s\n",
+ argv[cnt], i, dwarf_errmsg (-1));
+ result = 1;
+ break;
+ }
+ const char *path = dwarf_filesrc (files, idx, NULL, NULL);
+ if ((path == NULL && file != NULL)
+ || (path != NULL && file == NULL)
+ || (strcmp (file, path) != 0))
+ {
+ printf ("%s: line %zd srcline (%s) != file srcline (%s)\n",
+ argv[cnt], i, file ?: "???", path ?: "???");
+ result = 1;
+ break;
+ }
+
+ int column;
+ if (dwarf_linecol (l, &column) != 0)
+ column = 0;
+ if (column >= 0)
+ printf ("%d:", column);
+
+ bool is_stmt;
+ if (dwarf_linebeginstatement (l, &is_stmt) != 0)
+ is_stmt = false;
+ bool end_sequence;
+ if (dwarf_lineendsequence (l, &end_sequence) != 0)
+ end_sequence = false;
+ bool basic_block;
+ if (dwarf_lineblock (l, &basic_block) != 0)
+ basic_block = false;
+ bool prologue_end;
+ if (dwarf_lineprologueend (l, &prologue_end) != 0)
+ prologue_end = false;
+ bool epilogue_begin;
+ if (dwarf_lineepiloguebegin (l, &epilogue_begin) != 0)
+ epilogue_begin = false;
+ printf (" is_stmt:%s, end_seq:%s, bb:%s, prologue:%s, epilogue:%s\n",
+ is_stmt ? "yes" : "no", end_sequence ? "yes" : "no",
+ basic_block ? "yes" : "no", prologue_end ? "yes" : "no",
+ epilogue_begin ? "yes" : "no");
+
+ Dwarf_Line* callee_context = l;
+ Dwarf_Line* caller_context = dwarf_linecontext (lb, l);
+ unsigned int depth = 0;
+ while (caller_context != NULL)
+ {
+ depth++;
+ for (unsigned int x = 0; x < depth; x++)
+ printf (" ");
+
+ const char *inlined_file = dwarf_linesrc (caller_context,
+ NULL, NULL);
+ int inlined_line;
+ if (dwarf_lineno (caller_context, &inlined_line) != 0)
+ inlined_line = 0;
+
+ printf ("%s inlined at %s:%d\n",
+ dwarf_linefunctionname(dbg, callee_context),
+ inlined_file ?: "???", inlined_line);
+
+ callee_context = caller_context;
+ caller_context = dwarf_linecontext (lb, callee_context);
+ }
+ }
+ }
+
+ if (res < 0)
+ {
+ printf ("dwarf_next_lines failed: %s\n", dwarf_errmsg (-1));
+ result = 1;
+ }
+
+ dwarf_end (dbg);
+ close (fd);
+ }
+
+ return result;
+}
diff --git a/tests/run-alldts.sh b/tests/run-alldts.sh
index 6a9a9ece..ce3630b0 100755
--- a/tests/run-alldts.sh
+++ b/tests/run-alldts.sh
@@ -27,7 +27,6 @@ testrun_compare ${abs_top_builddir}/src/readelf -d testfile-alldts <<\EOF
Dynamic segment contains 66 entries:
Addr: 0x000001a0 Offset: 0x000078 Link to section: [ 0] ''
Type Value
- NULL
NEEDED Shared library: [(null)]
PLTRELSZ 3735928559 (bytes)
PLTGOT 0xdeadbeef
@@ -93,6 +92,7 @@ Dynamic segment contains 66 entries:
VERNEEDNUM 3735928559
AUXILIARY 0xdeadbeef
FILTER 0xdeadbeef
+ NULL
EOF
exit 0
diff --git a/tests/run-debuginfod-archive-groom.sh b/tests/run-debuginfod-archive-groom.sh
new file mode 100755
index 00000000..e2c394ef
--- /dev/null
+++ b/tests/run-debuginfod-archive-groom.sh
@@ -0,0 +1,166 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8100
+get_ports
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+# Clean old dirictories
+mkdir R ${PWD}/F
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \
+ -F -R -d $DB -p $PORT1 -t0 -g0 -v R ${PWD}/F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# Be patient when run on a busy machine things might take a bit.
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# wait till the initial scan is done before triggering a new one
+# and before dropping new file into the scan dirs
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+# Same for the initial groom cycle, we don't want it to be done
+# half way initializing the file setup
+wait_ready $PORT1 'thread_work_total{role="groom"}' 1
+
+# Build a non-stripped binary
+echo "int main() { return 0; }" > ${PWD}/F/prog.c
+gcc -Wl,--build-id -g -o ${PWD}/F/prog ${PWD}/F/prog.c
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a ${PWD}/F/prog | grep 'Build ID' | cut -d ' ' -f 7`
+tempfiles ${PWD}/F/prog ${PWD}/F/prog.c
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+kill -USR1 $PID1
+# Now there should be 1 files in the index
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+tempfiles vlog3
+cp -rvp ${abs_srcdir}/debuginfod-tars Z
+kill -USR1 $PID1
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+########################################################################
+# All rpms need to be in the index, except the dummy permission-000 one
+rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
+wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
+txz=$(find Z -name \*tar.xz | wc -l)
+
+kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 4
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# Expect all source files found in the rpms (they are all called hello.c :)
+# We will need to extract all rpms (in their own directory) and could all
+# sources referenced in the .debug files.
+mkdir extracted
+cd extracted
+subdir=0;
+newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
+for i in $newrpms; do
+ subdir=$[$subdir+1];
+ mkdir $subdir;
+ cd $subdir;
+ ls -lah ../$i
+ rpm2cpio ../$i | cpio -ivd;
+ cd ..;
+done
+sourcefiles=$(find -name \*\\.debug \
+ | env LD_LIBRARY_PATH=$ldpath xargs \
+ ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
+ | grep mtime: | wc --lines)
+cd ..
+rm -rf extracted
+
+wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
+
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+
+# common source file sha1
+SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
+# fedora31
+if [ $zstd = true ]; then
+ # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
+ # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
+ archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
+ archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
+fi
+# fedora30
+archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
+archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
+# rhel7
+archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
+archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
+# rhel6
+archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
+archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
+RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir
+
+# Drop some of the artifacts, run a groom cycle; confirm that
+# debuginfod has forgotten them, but remembers others
+rm -r R/debuginfod-rpms/rhel6/*
+
+kill -USR2 $PID1 # groom cycle
+## 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2
+wait_ready $PORT1 'thread_work_total{role="groom"}' 2
+# Expect 4 rpms containing 2 buildids to be deleted by the groom
+wait_ready $PORT1 'groomed_total{decision="stale"}' 4
+# Expect no more groom actions pending
+wait_ready $PORT1 'thread_work_pending{role="groom"}' 0
+
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+
+# this is one of the buildids from the groom-deleted rpms
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
+
+# but this one was not deleted so should be still around
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID || true
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-archive-rename.sh b/tests/run-debuginfod-archive-rename.sh
new file mode 100755
index 00000000..a1a6cc1e
--- /dev/null
+++ b/tests/run-debuginfod-archive-rename.sh
@@ -0,0 +1,103 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8200
+get_ports
+DB=${PWD}/.debuginfod_tmp.sqlite
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+tempfiles $DEBUGINFOD_CACHE_PATH $DB
+# Clean old dirictories
+mkdir R ${PWD}/F
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \
+ -F -R -d $DB -p $PORT1 -t0 -g0 -v R ${PWD}/F > vlog$PORT1 2>&1 &
+
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# wait till the initial scan is done before triggering a new one
+# and before dropping new file into the scan dirs
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+# Same for the initial groom cycle, we don't want it to be done
+# half way initializing the file setup
+wait_ready $PORT1 'thread_work_total{role="groom"}' 1
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+kill -USR1 $PID1
+# Now there should be 1 files in the index
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# common source file sha1
+SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
+
+########################################################################
+## PR26810: Now rename some files in the R directory, then rescan, so
+# there are two copies of the same buildid in the index, one for the
+# no-longer-existing file name, and one under the new name.
+
+# run a groom cycle to force server to drop its fdcache
+kill -USR2 $PID1 # groom cycle
+wait_ready $PORT1 'thread_work_total{role="groom"}' 2
+# move it around a couple of times to make it likely to hit a nonexistent entry during iteration
+mv R/debuginfod-rpms/rhel7 R/debuginfod-rpms/rhel7renamed
+kill -USR1 $PID1 # scan cycle
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+mv R/debuginfod-rpms/rhel7renamed R/debuginfod-rpms/rhel7renamed2
+kill -USR1 $PID1 # scan cycle
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 4
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+mv R/debuginfod-rpms/rhel7renamed2 R/debuginfod-rpms/rhel7renamed3
+kill -USR1 $PID1 # scan cycle
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 5
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+
+# retest rhel7
+archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
+archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
+
+egrep '(libc.error.*rhel7)|(bc1febfd03ca)|(f0aa15b8aba)' vlog$PORT1
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0;
diff --git a/tests/run-debuginfod-archive-test.sh b/tests/run-debuginfod-archive-test.sh
new file mode 100755
index 00000000..5f24ea71
--- /dev/null
+++ b/tests/run-debuginfod-archive-test.sh
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+# find an unused port number
+mkdir R
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8300
+get_ports
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -R -p $PORT1 -d $DB -t0 -g0 -v R > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# And make sure first scan is done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+# Be patient when run on a busy machine things might take a bit.
+export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT1
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+kill -USR1 $PID1
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# common source file sha1
+SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
+# fedora31
+if [ $zstd = true ]; then
+ # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
+ # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
+ archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
+ archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
+fi
+# fedora30
+archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
+archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
+# rhel7
+archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
+archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
+# rhel6
+archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
+archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
+# arch
+#archive_test cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb /usr/src/debug/hello.c 7a1334e086b97e5f124003a6cfb3ed792d10cdf4
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-artifact-running.sh b/tests/run-debuginfod-artifact-running.sh
new file mode 100755
index 00000000..8b9aed37
--- /dev/null
+++ b/tests/run-debuginfod-artifact-running.sh
@@ -0,0 +1,119 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8400
+get_ports
+mkdir F
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+echo 'int main(int argc, char * argv){ return 0; }' > ${PWD}/prog.c
+gcc -Wl,--build-id -g -o prog ${PWD}/prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+tempfiles prog prog.debug prog.c
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog | grep 'Build ID' | cut -d ' ' -f 7`
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d $DB -F -p $PORT1 -t0 -g0 -v F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# And the initial scan should have been done before moving
+# files under the scan dirs.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+mv prog F
+mv prog.debug F
+tempfiles prog/F
+
+kill -USR1 $PID1
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# Add artifacts to the search paths and test whether debuginfod finds them while already running.
+# Build another, non-stripped binary
+echo "int main() { return 0; }" > ${PWD}/prog2.c
+tempfiles prog2.c
+gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
+#testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
+mv prog2 F
+#mv prog2.debug F
+tempfiles F/prog2 F/prog2.debug
+
+kill -USR1 $PID1
+# Now there should be 3 files in the index
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+
+# Test whether debuginfod-find is able to fetch those files.
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
+cmp $filename F/prog.debug
+
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
+cmp $filename F/prog
+
+# raw source filename
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
+cmp $filename ${PWD}/prog.c
+
+# and also the canonicalized one
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
+cmp $filename ${PWD}/prog.c
+
+# Rerun same tests for the prog2 binary
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
+cmp $filename F/prog2
+grep -q Progress vlog
+grep -q Downloaded.from vlog
+tempfiles vlog
+filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
+cmp $filename F/prog2
+grep -q 'Downloading.*http' vlog2
+tempfiles vlog2
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
+cmp $filename ${PWD}/prog2.c
+
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-dlopen.sh b/tests/run-debuginfod-dlopen.sh
new file mode 100755
index 00000000..7279b02e
--- /dev/null
+++ b/tests/run-debuginfod-dlopen.sh
@@ -0,0 +1,91 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+mkdir F
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8500
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod -F -R $VERBOSE -p $PORT1 -d $DB \
+ -t0 -g0 -v F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a'
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# Make sure the initial scan has finished.
+# Before moving files under the scan dirs.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+# We use -t0 and -g0 here to turn off time-based scanning & grooming.
+# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
+
+########################################################################
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
+tempfiles p+r%o\$g.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
+testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv p+r%o\$g F
+mv p+r%o\$g.debug F
+
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+
+# Test whether elfutils, via the debuginfod client library dlopen hooks,
+# is able to fetch debuginfo from the local debuginfod.
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/p+r%o\$g 1
+
+kill $PID1
+wait $PID1
+PID1=0
+
+exit 0
diff --git a/tests/run-debuginfod-duplicate-urls.sh b/tests/run-debuginfod-duplicate-urls.sh
new file mode 100755
index 00000000..50e39cb2
--- /dev/null
+++ b/tests/run-debuginfod-duplicate-urls.sh
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8600
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod \
+ $VERBOSE -F -p $PORT1 -t0 -g0 -d ${DB} F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+wait_ready $PORT1 'ready' 1
+
+########################################################################
+## PR27983
+# Ensure no duplicate urls are used in when querying servers for files
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+env DEBUGINFOD_URLS="http://127.0.0.1:$PORT1 http://127.0.0.1:$PORT1 http://127.0.0.1:$PORT1 http://127.0.0.1:7999" \
+ LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find -vvv executable 0 > vlog1 2>&1 || true
+tempfiles vlog1
+cat vlog1
+if [ $( grep -c 'duplicate url: http://127.0.0.1:'$PORT1'.*' vlog1 ) -ne 2 ]; then
+ echo "Duplicate servers remain";
+ err
+fi
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-extraction-passive.sh b/tests/run-debuginfod-extraction-passive.sh
new file mode 100755
index 00000000..c2724b58
--- /dev/null
+++ b/tests/run-debuginfod-extraction-passive.sh
@@ -0,0 +1,77 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+
+mkdir Z
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=11000
+get_ports
+
+DB=${PWD}/.debuginfod.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+cp -rvp ${abs_srcdir}/debuginfod-tars Z
+tempfiles Z
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d $DB -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT1 -t0 -g0 -v Z > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+wait_ready $PORT1 'ready' 1
+
+# Start second passive server with same database
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE --passive -d $DB -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT2 -v > vlog$PORT2 2>&1 &
+PID2=$!
+
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+
+wait_ready $PORT2 'ready' 1
+
+# Wait for first server to finish indexing
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# No similar metrics for the passive server
+! (curl http://localhost:$PORT2/metrics | egrep 'role="scan"|role="groom"|role="traverse"')
+
+# Confirm no active threads
+! (ps -q $PID2 -e -L -o '%p %c %a' | egrep 'scan|groom|traverse')
+
+# Do a random lookup via passive server
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://localhost:$PORT2 ${abs_builddir}/../debuginfod/debuginfod-find debuginfo cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb
+
+tempfiles $DB*
+
+kill $PID1
+wait $PID1
+PID1=0
+
+kill $PID2
+wait $PID2
+PID2=0
+
+exit 0
diff --git a/tests/run-debuginfod-extraction.sh b/tests/run-debuginfod-extraction.sh
new file mode 100755
index 00000000..a3722c90
--- /dev/null
+++ b/tests/run-debuginfod-extraction.sh
@@ -0,0 +1,106 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+mkdir R Z
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8700
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d $DB -F -R -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT1 -t0 -g0 -v R Z > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# Make sure the initial scan has finished before copying the new files in
+# We might remove some, which we don't want to be accidentially scanned.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+cp -rvp ${abs_srcdir}/debuginfod-tars Z
+
+kill -USR1 $PID1
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+# All rpms need to be in the index, except the dummy permission-000 one
+rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
+wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
+txz=$(find Z -name \*tar.xz | wc -l)
+wait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz
+tb2=$(find Z -name \*tar.bz2 | wc -l)
+wait_ready $PORT1 'scanned_files_total{source=".tar.bz2 archive"}' $tb2
+
+kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+# Expect all source files found in the rpms (they are all called hello.c :)
+# We will need to extract all rpms (in their own directory) and could all
+# sources referenced in the .debug files.
+mkdir extracted
+cd extracted
+subdir=0;
+newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
+for i in $newrpms; do
+ subdir=$[$subdir+1];
+ mkdir $subdir;
+ cd $subdir;
+ ls -lah ../$i
+ rpm2cpio ../$i | cpio -ivd;
+ cd ..;
+done
+sourcefiles=$(find -name \*\\.debug \
+ | env LD_LIBRARY_PATH=$ldpath xargs \
+ ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
+ | grep mtime: | wc --lines)
+cd ..
+rm -rf extracted
+
+wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-fd-prefetch-caches.sh b/tests/run-debuginfod-fd-prefetch-caches.sh
new file mode 100755
index 00000000..7fbf7b20
--- /dev/null
+++ b/tests/run-debuginfod-fd-prefetch-caches.sh
@@ -0,0 +1,66 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+FDCACHE_FDS=100
+FDCACHE_MBS=100
+PREFETCH_FDS=100
+PREFETCH_MBS=100
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8800
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+echo $PORT1
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -p $PORT1 -d $DB \
+ --fdcache-mbs=$FDCACHE_MDS --fdcache-fds=$FDCACHE_FDS --fdcache-prefetch-mbs=$PREFETCH_MBS \
+ --fdcache-prefetch-fds=$PREFETCH_FDS --fdcache-mintmp 0 -v -F F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+
+grep 'fdcache fds ' vlog$PORT1 #$FDCACHE_FDS
+grep 'fdcache mbs ' vlog$PORT1 #$FDCACHE_MBS
+grep 'prefetch fds ' vlog$PORT1 #$PREFETCH_FDS
+grep 'prefetch mbs ' vlog$PORT1 #$PREFETCH_MBS
+# search the vlog to find what metric counts should be and check the correct metrics
+# were incrimented
+enqueue_nr=$(grep -c 'interned.*front=1' vlog$PORT1 || true)
+wait_ready $PORT1 'fdcache_op_count{op="enqueue"}' $enqueue_nr
+evict_nr=$(grep -c 'evicted a=.*' vlog$PORT1 || true)
+wait_ready $PORT1 'fdcache_op_count{op="evict"}' $evict_nr
+prefetch_enqueue_nr=$(grep -c 'interned.*front=0' vlog$PORT1 || true)
+wait_ready $PORT1 'fdcache_op_count{op="prefetch_enqueue"}' $prefetch_enqueue_nr
+prefetch_evict_nr=$(grep -c 'evicted from prefetch a=.*front=0' vlog$PORT1 || true)
+wait_ready $PORT1 'fdcache_op_count{op="prefetch_evict"}' $prefetch_evict_nr
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-federation-link.sh b/tests/run-debuginfod-federation-link.sh
new file mode 100755
index 00000000..d7827436
--- /dev/null
+++ b/tests/run-debuginfod-federation-link.sh
@@ -0,0 +1,164 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+tempfiles $DB
+
+# Clean old dirictories
+mkdir D L F
+mkdir -p $DEBUGINFOD_CACHE_PATH
+# not tempfiles F R L D Z - they are directories which we clean up manually
+ln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8900
+get_ports
+# Launch server which will be unable to follow symlinks
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+wait_ready $PORT1 'ready' 1
+# Make sure initial scan was done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/prog.c
+tempfiles prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv prog F
+mv prog.debug F
+
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+wait_ready $PORT1 'thread_busy{role="http-buildid"}' 0
+wait_ready $PORT1 'thread_busy{role="http-metrics"}' 1
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
+mkdir -p $DEBUGINFOD_CACHE_PATH
+
+# NB: run in -L symlink-following mode for the L subdir
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D > vlog$PORT2 2>&1 &
+PID2=$!
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+tempfiles ${DB}_2
+
+wait_ready $PORT2 'ready' 1
+
+# Make sure initial scan was done
+wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
+kill -USR1 $PID2
+# Wait till both files are in the index.
+wait_ready $PORT2 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT2 'thread_busy{role="scan"}' 0
+
+wait_ready $PORT2 'thread_busy{role="http-buildid"}' 0
+wait_ready $PORT2 'thread_busy{role="http-metrics"}' 1
+
+# have clients contact the new server
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
+# Use fresh cache for debuginfod-find client requests
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
+mkdir -p $DEBUGINFOD_CACHE_PATH
+
+if type bsdtar 2>/dev/null; then
+ # copy in the deb files
+ cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
+ kill -USR1 $PID2
+ wait_ready $PORT2 'thread_work_total{role="traverse"}' 3
+ wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
+ wait_ready $PORT2 'thread_busy{role="scan"}' 0
+
+ # All debs need to be in the index
+ debs=$(find D -name \*.deb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
+ ddebs=$(find D -name \*.ddeb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
+
+ # ubuntu
+ archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
+fi
+
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# send a request to stress XFF and User-Agent federation relay;
+# we'll grep for the two patterns in vlog$PORT1
+curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
+
+grep UA:TESTCURL vlog$PORT1
+grep XFF:TESTXFF vlog$PORT1
+
+# confirm that first server can't resolve symlinked info in L/ but second can
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
+file L/foo
+file -L L/foo
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# test again with scheme free url
+export DEBUGINFOD_URLS=127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# test parallel queries in client
+rm -rf $DEBUGINFOD_CACHE_PATH
+export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
+
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
+
+kill $PID1
+kill $PID2
+wait $PID1
+wait $PID2
+PID1=0
+PID2=0
+
+exit 0
diff --git a/tests/run-debuginfod-federation-metrics.sh b/tests/run-debuginfod-federation-metrics.sh
new file mode 100755
index 00000000..3d716246
--- /dev/null
+++ b/tests/run-debuginfod-federation-metrics.sh
@@ -0,0 +1,210 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+export DEBUGINFOD_URLS='http://127.0.0.1:0' # Note invalid, will trigger error_count metric
+tempfiles $DB
+# Clean old dirictories
+mkdir D L F
+
+# not tempfiles F R L D Z - they are directories which we clean up manually
+ln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9000
+get_ports
+
+# Launch server which will be unable to follow symlinks
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+wait_ready $PORT1 'ready' 1
+
+# Wait till initial scan is done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+########################################################################
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/prog.c
+tempfiles prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv prog F
+mv prog.debug F
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+wait_ready $PORT1 'thread_busy{role="http-buildid"}' 0
+wait_ready $PORT1 'thread_busy{role="http-metrics"}' 1
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
+mkdir -p $DEBUGINFOD_CACHE_PATH
+# NB: run in -L symlink-following mode for the L subdir
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D > vlog$PORT2 2>&1 &
+PID2=$!
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+tempfiles ${DB}_2
+
+wait_ready $PORT2 'ready' 1
+wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT2 'thread_busy{role="scan"}' 0
+
+wait_ready $PORT2 'thread_busy{role="http-buildid"}' 0
+wait_ready $PORT2 'thread_busy{role="http-metrics"}' 1
+
+# have clients contact the new server
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
+# Use fresh cache for debuginfod-find client requests
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
+mkdir -p $DEBUGINFOD_CACHE_PATH
+
+if type bsdtar 2>/dev/null; then
+ # copy in the deb files
+ cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
+ kill -USR1 $PID2
+ wait_ready $PORT2 'thread_work_total{role="traverse"}' 2
+ wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
+ wait_ready $PORT2 'thread_busy{role="scan"}' 0
+
+ # All debs need to be in the index
+ debs=$(find D -name \*.deb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
+ ddebs=$(find D -name \*.ddeb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
+
+ # ubuntu
+ archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
+fi
+
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# send a request to stress XFF and User-Agent federation relay;
+# we'll grep for the two patterns in vlog$PORT1
+curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
+
+grep UA:TESTCURL vlog$PORT1
+grep XFF:TESTXFF vlog$PORT1
+
+# confirm that first server can't resolve symlinked info in L/ but second can
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
+file L/foo
+file -L L/foo
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# test again with scheme free url
+export DEBUGINFOD_URLS=127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+# test parallel queries in client
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
+mkdir -p $DEBUGINFOD_CACHE_PATH
+export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
+
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
+
+########################################################################
+# Fetch some metrics
+curl -s http://127.0.0.1:$PORT1/badapi
+curl -s http://127.0.0.1:$PORT1/metrics
+curl -s http://127.0.0.1:$PORT2/metrics
+curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*error'
+curl -s http://127.0.0.1:$PORT2/metrics | grep -q 'http_responses_total.*result.*upstream'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_count'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_sum'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_sum'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'fdcache_'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'error_count'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'traversed_total'
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'scanned_bytes_total'
+
+# And generate a few errors into the second debuginfod's logs, for analysis just below
+curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
+curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
+# NB: this error is used to seed the 404 failure for the survive-404 tests
+
+# Confirm bad artifact types are rejected without leaving trace
+curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true
+(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false
+
+# Confirm that reused curl connections survive 404 errors.
+# The rm's force an uncached fetch (in both servers and client cache)
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# Confirm that some debuginfod client pools are being used
+curl -s http://127.0.0.1:$PORT2/metrics | grep 'dc_pool_op.*reuse'
+
+# Trigger a flood of requests against the same archive content file.
+# Use a file that hasn't been previously extracted in to make it
+# likely that even this test debuginfod will experience concurrency
+# and impose some "after-you" delays.
+(for i in `seq 100`; do
+ curl -s http://127.0.0.1:$PORT1/buildid/87c08d12c78174f1082b7c888b3238219b0eb265/executable >/dev/null &
+ done;
+ wait)
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_after_you.*'
+# If we could guarantee some minimum number of seconds of CPU time, we
+# could assert that the after_you metrics show some nonzero amount of
+# waiting. A few hundred ms is typical on this developer's workstation.
+
+kill $PID1
+kill $PID2
+wait $PID1
+wait $PID2
+PID1=0
+PID2=0
+exit 0
+
diff --git a/tests/run-debuginfod-federation-sqlite.sh b/tests/run-debuginfod-federation-sqlite.sh
new file mode 100755
index 00000000..d9321526
--- /dev/null
+++ b/tests/run-debuginfod-federation-sqlite.sh
@@ -0,0 +1,202 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+tempfiles $DB
+
+# Clean old dirictories
+mkdir D L F
+# not tempfiles F R L D Z - they are directories which we clean up manually
+ln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test
+
+########################################################################
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/prog.c
+tempfiles prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv prog F
+mv prog.debug F
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9100
+get_ports
+# Launch server which will be unable to follow symlinks
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB} -F -U -t0 -g0 -p $PORT1 L D F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+wait_ready $PORT1 'ready' 1
+
+# Wait till initial scan is done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
+mkdir -p $DEBUGINFOD_CACHE_PATH
+# NB: run in -L symlink-following mode for the L subdir
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d ${DB}_2 -F -U -p $PORT2 -L L D F > vlog$PORT2 2>&1 &
+PID2=$!
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+tempfiles ${DB}_2
+wait_ready $PORT2 'ready' 1
+# Wait till initial scan is done
+wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
+# And initial groom cycle
+wait_ready $PORT1 'thread_work_total{role="groom"}' 1
+
+export DEBUGINFOD_URLS='http://127.0.0.1:'$PORT2
+# Use fresh cache for debuginfod-find client requests
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
+mkdir -p $DEBUGINFOD_CACHE_PATH
+
+if type bsdtar 2>/dev/null; then
+ # copy in the deb files
+ cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
+ kill -USR1 $PID2
+ wait_ready $PORT2 'thread_work_total{role="traverse"}' 2
+ wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
+ wait_ready $PORT2 'thread_busy{role="scan"}' 0
+
+ # All debs need to be in the index
+ debs=$(find D -name \*.deb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
+ ddebs=$(find D -name \*.ddeb | wc -l)
+ wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
+
+ # ubuntu
+ archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
+fi
+
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# send a request to stress XFF and User-Agent federation relay;
+# we'll grep for the two patterns in vlog$PORT1
+curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
+
+grep UA:TESTCURL vlog$PORT1
+grep XFF:TESTXFF vlog$PORT1
+
+# confirm that first server can't resolve symlinked info in L/ but second can
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
+file L/foo
+file -L L/foo
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+
+# test again with scheme free url
+export DEBUGINFOD_URLS=127.0.0.1:$PORT1
+rm -rf $DEBUGINFOD_CACHE_PATH
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop negative-hit file
+export DEBUGINFOD_URLS=127.0.0.1:$PORT2
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+# test parallel queries in client
+rm -rf $DEBUGINFOD_CACHE_PATH
+export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
+
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
+
+# And generate a few errors into the second debuginfod's logs, for analysis just below
+curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
+curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
+# NB: this error is used to seed the 404 failure for the survive-404 tests
+
+# Confirm bad artifact types are rejected without leaving trace
+curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true
+(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false
+
+# Confirm that reused curl connections survive 404 errors.
+# The rm's force an uncached fetch (in both servers and client cache)
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+rm -f .client_cache*/$BUILDID/debuginfo
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+# Trigger a flood of requests against the same archive content file.
+# Use a file that hasn't been previously extracted in to make it
+# likely that even this test debuginfod will experience concurrency
+# and impose some "after-you" delays.
+(for i in `seq 100`; do
+ curl -s http://127.0.0.1:$PORT1/buildid/87c08d12c78174f1082b7c888b3238219b0eb265/executable >/dev/null &
+ done;
+ wait)
+curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_after_you.*'
+# If we could guarantee some minimum number of seconds of CPU time, we
+# could assert that the after_you metrics show some nonzero amount of
+# waiting. A few hundred ms is typical on this developer's workstation.
+
+########################################################################
+# Trigger some some random activity, then trigger a clean shutdown.
+# We used to try to corrupt the database while the debuginfod server
+# was running and check it detected errors, but that was unreliably
+# and slightly dangerous since part of the database was already mapped
+# into memory.
+kill -USR1 $PID1
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+kill -USR2 $PID1
+wait_ready $PORT1 'thread_work_total{role="groom"}' 2
+curl -s http://127.0.0.1:$PORT1/buildid/beefbeefbeefd00dd00d/debuginfo > /dev/null || true
+
+kill -INT $PID1 $PID2
+wait $PID1 $PID2
+PID1=0
+PID2=0
+
+# Run the tests again without the servers running. The target file should
+# be found in the cache.
+
+tempfiles .debuginfod_*
+
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
+
+# check out the debuginfod logs for the new style status lines
+cat vlog$PORT2
+grep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog$PORT2
+grep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog$PORT2
+grep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog$PORT2
+grep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog$PORT2
+
+exit 0
diff --git a/tests/run-debuginfod-file.sh b/tests/run-debuginfod-file.sh
new file mode 100755
index 00000000..341bbc68
--- /dev/null
+++ b/tests/run-debuginfod-file.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+# Test fetching a file using file:// . No debuginfod server needs to be run for
+# this test.
+local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
+mkdir -p ${local_dir}
+echo "int main() { return 0; }" > ${local_dir}/main.c
+# first test that is doesn't work, when no DEBUGINFOD_URLS is set
+export DEBUGINFOD_URLS=""
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
+
+# Now test is with proper DEBUGINFOD_URLS
+export DEBUGINFOD_URLS="file://${PWD}/mocktree/"
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
+cmp $filename ${local_dir}/main.c
+
+exit 0
diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh
deleted file mode 100755
index 9183cccb..00000000
--- a/tests/run-debuginfod-find.sh
+++ /dev/null
@@ -1,677 +0,0 @@
-#!/usr/bin/env bash
-#
-# Copyright (C) 2019-2021 Red Hat, Inc.
-# This file is part of elfutils.
-#
-# This file is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3 of the License, or
-# (at your option) any later version.
-#
-# elfutils is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-. $srcdir/test-subr.sh # includes set -e
-
-type curl 2>/dev/null || (echo "need curl"; exit 77)
-type rpm2cpio 2>/dev/null || (echo "need rpm2cpio"; exit 77)
-type cpio 2>/dev/null || (echo "need cpio"; exit 77)
-type bzcat 2>/dev/null || (echo "need bzcat"; exit 77)
-bsdtar --version | grep -q zstd && zstd=true || zstd=false
-echo "zstd=$zstd bsdtar=`bsdtar --version`"
-
-# for test case debugging, uncomment:
-#set -x
-VERBOSE=-vvv
-
-DB=${PWD}/.debuginfod_tmp.sqlite
-tempfiles $DB
-export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
-
-PID1=0
-PID2=0
-PID3=0
-
-cleanup()
-{
- if [ $PID1 -ne 0 ]; then kill $PID1; wait $PID1; fi
- if [ $PID2 -ne 0 ]; then kill $PID2; wait $PID2; fi
- if [ $PID3 -ne 0 ]; then kill $PID3; wait $PID3; fi
-
- rm -rf F R D L Z ${PWD}/foobar ${PWD}/mocktree ${PWD}/.client_cache* ${PWD}/tmp*
- exit_cleanup
-}
-
-# clean up trash if we were aborted early
-trap cleanup 0 1 2 3 5 9 15
-
-errfiles_list=
-err() {
- for ports in $PORT1 $PORT2
- do
- echo $port metrics
- curl -s http://127.0.0.1:$port/metrics
- echo
- done
- for x in $errfiles_list
- do
- echo "$x"
- cat $x
- echo
- done
-}
-trap err ERR
-
-errfiles() {
- errfiles_list="$errfiles_list $*"
-}
-
-
-
-# find an unused port number
-while true; do
- PORT1=`expr '(' $RANDOM % 1000 ')' + 9000`
- ss -atn | fgrep ":$PORT1" || break
-done
-
-# We want to run debuginfod in the background. We also want to start
-# it with the same check/installcheck-sensitive LD_LIBRARY_PATH stuff
-# that the testrun alias sets. But: we if we just use
-# testrun .../debuginfod
-# it runs in a subshell, with different pid, so not helpful.
-#
-# So we gather the LD_LIBRARY_PATH with this cunning trick:
-ldpath=`testrun sh -c 'echo $LD_LIBRARY_PATH'`
-
-mkdir F R L D Z
-# not tempfiles F R L D Z - they are directories which we clean up manually
-ln -s ${abs_builddir}/dwfllines L/foo # any program not used elsewhere in this test
-
-wait_ready()
-{
- port=$1;
- what=$2;
- value=$3;
- timeout=20;
-
- echo "Wait $timeout seconds on $port for metric $what to change to $value"
- while [ $timeout -gt 0 ]; do
- mvalue="$(curl -s http://127.0.0.1:$port/metrics \
- | grep "$what" | awk '{print $NF}')"
- if [ -z "$mvalue" ]; then mvalue=0; fi
- echo "metric $what: $mvalue"
- if [ "$mvalue" -eq "$value" ]; then
- break;
- fi
- sleep 0.5;
- ((timeout--));
- done;
-
- if [ $timeout -eq 0 ]; then
- echo "metric $what never changed to $value on port $port"
- exit 1;
- fi
-}
-
-# create a bogus .rpm file to evoke a metric-visible error
-# Use a cyclic symlink instead of chmod 000 to make sure even root
-# would see an error (running the testsuite under root is NOT encouraged).
-ln -s R/nothing.rpm R/nothing.rpm
-
-env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -R -d $DB -p $PORT1 -t0 -g0 --fdcache-fds 1 --fdcache-mbs 2 --fdcache-mintmp 0 -Z .tar.xz -Z .tar.bz2=bzcat -v R F Z L > vlog$PORT1 2>&1 &
-PID1=$!
-tempfiles vlog$PORT1
-errfiles vlog$PORT1
-# Server must become ready
-wait_ready $PORT1 'ready' 1
-export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
-
-# Be patient when run on a busy machine things might take a bit.
-export DEBUGINFOD_TIMEOUT=10
-
-# Check thread comm names
-ps -q $PID1 -e -L -o '%p %c %a' | grep groom
-ps -q $PID1 -e -L -o '%p %c %a' | grep scan
-ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
-
-# We use -t0 and -g0 here to turn off time-based scanning & grooming.
-# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
-
-########################################################################
-
-# Compile a simple program, strip its debuginfo and save the build-id.
-# Also move the debuginfo into another directory so that elfutils
-# cannot find it without debuginfod.
-echo "int main() { return 0; }" > ${PWD}/prog.c
-tempfiles prog.c
-# Create a subdirectory to confound source path names
-mkdir foobar
-gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
-testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
-BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a prog | grep 'Build ID' | cut -d ' ' -f 7`
-
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
-mv prog F
-mv prog.debug F
-kill -USR1 $PID1
-# Wait till both files are in the index.
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-
-########################################################################
-
-# Test whether elfutils, via the debuginfod client library dlopen hooks,
-# is able to fetch debuginfo from the local debuginfod.
-testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
-
-########################################################################
-
-# PR25628
-rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
-
-# The query is designed to fail, while the 000-permission file should be created.
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
-if [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
- echo "could not find cache in $DEBUGINFOD_CACHE_PATH"
- exit 1
-fi
-
-if [ -r $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
- echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is readable"
- exit 1
-fi
-
-bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'`
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
-bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'`
-if [ "$bytecount_before" != "$bytecount_after" ]; then
- echo "http_responses_transfer_bytes_count{code="404"} has changed."
- exit 1
-fi
-
-# set cache_miss_s to 0 and sleep 1 to make the mtime expire.
-echo 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s
-sleep 1
-bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'`
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
-bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404"}'`
-if [ "$bytecount_before" == "$bytecount_after" ]; then
- echo "http_responses_transfer_bytes_count{code="404"} should be incremented."
- exit 1
-fi
-########################################################################
-
-# Test whether debuginfod-find is able to fetch those files.
-rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
-cmp $filename F/prog.debug
-if [ -w $filename ]; then
- echo "cache file writable, boo"
- exit 1
-fi
-
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable F/prog`
-cmp $filename F/prog
-
-# raw source filename
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/foobar///./../prog.c`
-cmp $filename ${PWD}/prog.c
-
-# and also the canonicalized one
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID ${PWD}/prog.c`
-cmp $filename ${PWD}/prog.c
-
-
-########################################################################
-
-# Test whether the cache default locations are correct
-
-mkdir tmphome
-
-# $HOME/.cache should be created.
-testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
- echo "could not find cache in $PWD/tmphome/.cache"
- exit 1
-fi
-
-# $HOME/.cache should be found.
-testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
-if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
- echo "could not find cache in $PWD/tmphome/.cache"
- exit 1
-fi
-
-# $XDG_CACHE_HOME should take priority over $HOME.cache.
-testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
- echo "could not find cache in $PWD/tmpxdg/"
- exit 1
-fi
-
-# A cache at the old default location ($HOME/.debuginfod_client_cache) should take
-# priority over $HOME/.cache, $XDG_CACHE_HOME.
-cp -r $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache
-
-# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
-mkdir tmphome/.debuginfod_client_cache/deadbeef
-echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo
-filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef`
-cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo
-
-# $DEBUGINFO_CACHE_PATH should take priority over all else.
-testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then
- echo "could not find cache in $PWD/tmpcache/"
- exit 1
-fi
-
-########################################################################
-
-# Add artifacts to the search paths and test whether debuginfod finds them while already running.
-
-# Build another, non-stripped binary
-echo "int main() { return 0; }" > ${PWD}/prog2.c
-tempfiles prog2.c
-gcc -Wl,--build-id -g -o prog2 ${PWD}/prog2.c
-BUILDID2=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a prog2 | grep 'Build ID' | cut -d ' ' -f 7`
-
-mv prog2 F
-kill -USR1 $PID1
-# Now there should be 3 files in the index
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 3
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-
-# Rerun same tests for the prog2 binary
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo $BUILDID2 2>vlog`
-cmp $filename F/prog2
-cat vlog
-grep -q Progress vlog
-grep -q Downloaded.from vlog
-tempfiles vlog
-filename=`testrun env DEBUGINFOD_PROGRESS=1 ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2 2>vlog2`
-cmp $filename F/prog2
-cat vlog2
-grep -q 'Downloading.*http' vlog2
-tempfiles vlog2
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $BUILDID2 ${PWD}/prog2.c`
-cmp $filename ${PWD}/prog2.c
-
-cp -rvp ${abs_srcdir}/debuginfod-rpms R
-if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
- rm -vrf R/debuginfod-rpms/fedora31
-fi
-
-cp -rvp ${abs_srcdir}/debuginfod-tars Z
-kill -USR1 $PID1
-# All rpms need to be in the index, except the dummy permission-000 one
-rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
-wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
-txz=$(find Z -name \*tar.xz | wc -l)
-wait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz
-tb2=$(find Z -name \*tar.bz2 | wc -l)
-wait_ready $PORT1 'scanned_files_total{source=".tar.bz2 archive"}' $tb2
-
-kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
-# Expect all source files found in the rpms (they are all called hello.c :)
-# We will need to extract all rpms (in their own directory) and could all
-# sources referenced in the .debug files.
-mkdir extracted
-cd extracted
-subdir=0;
-newrpms=$(find ../R -name \*\.rpm | grep -v nothing)
-for i in $newrpms; do
- subdir=$[$subdir+1];
- mkdir $subdir;
- cd $subdir;
- ls -lah ../$i
- rpm2cpio ../$i | cpio -ivd;
- cd ..;
-done
-sourcefiles=$(find -name \*\\.debug \
- | env LD_LIBRARY_PATH=$ldpath xargs \
- ${abs_top_builddir}/src/readelf --debug-dump=decodedline \
- | grep mtime: | wc --lines)
-cd ..
-rm -rf extracted
-
-wait_ready $PORT1 'found_sourcerefs_total{source=".rpm archive"}' $sourcefiles
-
-# Run a bank of queries against the debuginfod-rpms / debuginfod-debs test cases
-
-archive_test() {
- __BUILDID=$1
- __SOURCEPATH=$2
- __SOURCESHA1=$3
-
- filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
- buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
- test $__BUILDID = $buildid
- # check that timestamps are plausible - older than the near-present (tmpdir mtime)
- test $filename -ot `pwd`
-
- # run again to assure that fdcache is being enjoyed
- filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $__BUILDID`
- buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
- test $__BUILDID = $buildid
- test $filename -ot `pwd`
-
- filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $__BUILDID`
- buildid=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a $filename | grep 'Build ID' | cut -d ' ' -f 7`
- test $__BUILDID = $buildid
- test $filename -ot `pwd`
-
- if test "x$__SOURCEPATH" != "x"; then
- filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source $__BUILDID $__SOURCEPATH`
- hash=`cat $filename | sha1sum | awk '{print $1}'`
- test $__SOURCESHA1 = $hash
- test $filename -ot `pwd`
- fi
-}
-
-
-# common source file sha1
-SHA=f4a1a8062be998ae93b8f1cd744a398c6de6dbb1
-# fedora31
-if [ $zstd = true ]; then
- # fedora31 uses zstd compression on rpms, older rpm2cpio/libarchive can't handle it
- # and we're not using the fancy -Z '.rpm=(rpm2cpio|zstdcat)<' workaround in this testsuite
- archive_test 420e9e3308971f4b817cc5bf83928b41a6909d88 /usr/src/debug/hello3-1.0-2.x86_64/foobar////./../hello.c $SHA
- archive_test 87c08d12c78174f1082b7c888b3238219b0eb265 /usr/src/debug/hello3-1.0-2.x86_64///foobar/./..//hello.c $SHA
-fi
-# fedora30
-archive_test c36708a78618d597dee15d0dc989f093ca5f9120 /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
-archive_test 41a236eb667c362a1c4196018cc4581e09722b1b /usr/src/debug/hello2-1.0-2.x86_64/hello.c $SHA
-# rhel7
-archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
-archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
-# rhel6
-archive_test bbbf92ebee5228310e398609c23c2d7d53f6e2f9 /usr/src/debug/hello-1.0/hello.c $SHA
-archive_test d44d42cbd7d915bc938c81333a21e355a6022fb7 /usr/src/debug/hello-1.0/hello.c $SHA
-# arch
-archive_test cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb /usr/src/debug/hello.c 7a1334e086b97e5f124003a6cfb3ed792d10cdf4
-
-RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir, for a later test
-
-
-########################################################################
-
-# Drop some of the artifacts, run a groom cycle; confirm that
-# debuginfod has forgotten them, but remembers others
-
-rm -r R/debuginfod-rpms/rhel6/*
-kill -USR2 $PID1 # groom cycle
-# 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2
-wait_ready $PORT1 'thread_work_total{role="groom"}' 2
-# Expect 4 rpms containing 2 buildids to be deleted by the groom
-wait_ready $PORT1 'groomed_total{decision="stale"}' 4
-
-rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
-
-# this is one of the buildids from the groom-deleted rpms
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $RPM_BUILDID && false || true
-# but this one was not deleted so should be still around
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID2
-
-########################################################################
-
-# PR26810: Now rename some files in the R directory, then rescan, so
-# there are two copies of the same buildid in the index, one for the
-# no-longer-existing file name, and one under the new name.
-
-# run a groom cycle to force server to drop its fdcache
-kill -USR2 $PID1 # groom cycle
-wait_ready $PORT1 'thread_work_total{role="groom"}' 3
-# move it around a couple of times to make it likely to hit a nonexistent entry during iteration
-mv R/debuginfod-rpms/rhel7 R/debuginfod-rpms/rhel7renamed
-kill -USR1 $PID1 # scan cycle
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 6
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-mv R/debuginfod-rpms/rhel7renamed R/debuginfod-rpms/rhel7renamed2
-kill -USR1 $PID1 # scan cycle
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 7
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-mv R/debuginfod-rpms/rhel7renamed2 R/debuginfod-rpms/rhel7renamed3
-kill -USR1 $PID1 # scan cycle
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 8
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-
-# retest rhel7
-archive_test bc1febfd03ca05e030f0d205f7659db29f8a4b30 /usr/src/debug/hello-1.0/hello.c $SHA
-archive_test f0aa15b8aba4f3c28cac3c2a73801fefa644a9f2 /usr/src/debug/hello-1.0/hello.c $SHA
-
-egrep '(libc.error.*rhel7)|(bc1febfd03ca)|(f0aa15b8aba)' vlog$PORT1
-
-########################################################################
-
-# Federation mode
-
-# find another unused port
-while true; do
- PORT2=`expr '(' $RANDOM % 1000 ')' + 9000`
- ss -atn | fgrep ":$PORT2" || break
-done
-
-export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache2
-mkdir -p $DEBUGINFOD_CACHE_PATH
-# NB: inherits the DEBUGINFOD_URLS to the first server
-# NB: run in -L symlink-following mode for the L subdir
-env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d ${DB}_2 -p $PORT2 -L L D > vlog$PORT2 2>&1 &
-PID2=$!
-tempfiles vlog$PORT2
-errfiles vlog$PORT2
-tempfiles ${DB}_2
-wait_ready $PORT2 'ready' 1
-wait_ready $PORT2 'thread_work_total{role="traverse"}' 1
-wait_ready $PORT2 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT2 'thread_busy{role="scan"}' 0
-
-wait_ready $PORT2 'thread_busy{role="http-buildid"}' 0
-wait_ready $PORT2 'thread_busy{role="http-metrics"}' 1
-
-# have clients contact the new server
-export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
-
-if type bsdtar 2>/dev/null; then
- # copy in the deb files
- cp -rvp ${abs_srcdir}/debuginfod-debs/*deb D
- kill -USR1 $PID2
- # All debs need to be in the index
- debs=$(find D -name \*.deb | wc -l)
- wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs`
- ddebs=$(find D -name \*.ddeb | wc -l)
- wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs`
-
- # ubuntu
- archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" ""
-fi
-
-rm -rf $DEBUGINFOD_CACHE_PATH
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-
-# send a request to stress XFF and User-Agent federation relay;
-# we'll grep for the two patterns in vlog$PORT1
-curl -s -H 'User-Agent: TESTCURL' -H 'X-Forwarded-For: TESTXFF' $DEBUGINFOD_URLS/buildid/deaddeadbeef00000000/debuginfo -o /dev/null || true
-
-grep UA:TESTCURL vlog$PORT1
-grep XFF:TESTXFF vlog$PORT1
-
-
-# confirm that first server can't resolve symlinked info in L/ but second can
-BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
- -a L/foo | grep 'Build ID' | cut -d ' ' -f 7`
-file L/foo
-file -L L/foo
-export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1
-rm -rf $DEBUGINFOD_CACHE_PATH
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
-export DEBUGINFOD_URLS=http://127.0.0.1:$PORT2
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-
-# test again with scheme free url
-export DEBUGINFOD_URLS=127.0.0.1:$PORT1
-rm -rf $DEBUGINFOD_CACHE_PATH
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo # drop 000-perm negative-hit file
-export DEBUGINFOD_URLS=127.0.0.1:$PORT2
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-
-# test parallel queries in client
-export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache3
-mkdir -p $DEBUGINFOD_CACHE_PATH
-export DEBUGINFOD_URLS="BAD http://127.0.0.1:$PORT1 127.0.0.1:$PORT1 http://127.0.0.1:$PORT2 DNE"
-
-testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
-
-########################################################################
-
-# Fetch some metrics
-curl -s http://127.0.0.1:$PORT1/badapi
-curl -s http://127.0.0.1:$PORT1/metrics
-curl -s http://127.0.0.1:$PORT2/metrics
-curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*error'
-curl -s http://127.0.0.1:$PORT1/metrics | grep -q 'http_responses_total.*result.*fdcache'
-curl -s http://127.0.0.1:$PORT2/metrics | grep -q 'http_responses_total.*result.*upstream'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_count'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_milliseconds_sum'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_sum'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'fdcache_'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'error_count'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'traversed_total'
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'scanned_bytes_total'
-
-# And generate a few errors into the second debuginfod's logs, for analysis just below
-curl -s http://127.0.0.1:$PORT2/badapi > /dev/null || true
-curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/debuginfo > /dev/null || true
-# NB: this error is used to seed the 404 failure for the survive-404 tests
-
-# Confirm bad artifact types are rejected without leaving trace
-curl -s http://127.0.0.1:$PORT2/buildid/deadbeef/badtype > /dev/null || true
-(curl -s http://127.0.0.1:$PORT2/metrics | grep 'badtype') && false
-
-# Confirm that reused curl connections survive 404 errors.
-# The rm's force an uncached fetch
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-rm -f $DEBUGINFOD_CACHE_PATH/$BUILDID/debuginfo .client_cache*/$BUILDID/debuginfo
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
-
-# Confirm that some debuginfod client pools are being used
-curl -s http://127.0.0.1:$PORT2/metrics | grep 'dc_pool_op.*reuse'
-
-########################################################################
-# Corrupt the sqlite database and get debuginfod to trip across its errors
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'sqlite3.*reset'
-ls -al $DB
-dd if=/dev/zero of=$DB bs=1 count=1
-ls -al $DB
-# trigger some random activity that's Sure to get sqlite3 upset
-kill -USR1 $PID1
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 9
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-kill -USR2 $PID1
-wait_ready $PORT1 'thread_work_total{role="groom"}' 4
-curl -s http://127.0.0.1:$PORT1/buildid/beefbeefbeefd00dd00d/debuginfo > /dev/null || true
-curl -s http://127.0.0.1:$PORT1/metrics | grep 'error_count.*sqlite'
-
-########################################################################
-
-# Run the tests again without the servers running. The target file should
-# be found in the cache.
-
-kill -INT $PID1 $PID2
-wait $PID1 $PID2
-PID1=0
-PID2=0
-tempfiles .debuginfod_*
-
-testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog2 1
-
-# check out the debuginfod logs for the new style status lines
-# cat vlog$PORT2
-grep -q 'UA:.*XFF:.*GET /buildid/.* 200 ' vlog$PORT2
-grep -q 'UA:.*XFF:.*GET /metrics 200 ' vlog$PORT2
-grep -q 'UA:.*XFF:.*GET /badapi 503 ' vlog$PORT2
-grep -q 'UA:.*XFF:.*GET /buildid/deadbeef.* 404 ' vlog$PORT2
-
-########################################################################
-
-# Add some files to the cache that do not fit its naming format.
-# They should survive cache cleaning.
-mkdir $DEBUGINFOD_CACHE_PATH/malformed
-touch $DEBUGINFOD_CACHE_PATH/malformed0
-touch $DEBUGINFOD_CACHE_PATH/malformed/malformed1
-
-# A valid format for an empty buildid subdirectory
-mkdir $DEBUGINFOD_CACHE_PATH/00000000
-touch -d '1970-01-01' $DEBUGINFOD_CACHE_PATH/00000000 # old enough to guarantee nukage
-
-# Trigger a cache clean and run the tests again. The clients should be unable to
-# find the target.
-echo 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s
-echo 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s
-
-testrun ${abs_builddir}/debuginfod_build_id_find -e F/prog 1
-
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID2 && false || true
-
-if [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \
- || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then
- echo "unrelated files did not survive cache cleaning"
- exit 1
-fi
-
-if [ -d $DEBUGINFOD_CACHE_PATH/00000000 ]; then
- echo "failed to rmdir old cache dir"
- exit 1
-fi
-
-# Test debuginfod without a path list; reuse $PORT1
-env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F &
-PID3=$!
-wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
-wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
-wait_ready $PORT1 'thread_busy{role="scan"}' 0
-kill -int $PID3
-wait $PID3
-PID3=0
-
-########################################################################
-# Test fetching a file using file:// . No debuginfod server needs to be run for
-# this test.
-local_dir=${PWD}/mocktree/buildid/aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd/source/my/path
-mkdir -p ${local_dir}
-echo "int main() { return 0; }" > ${local_dir}/main.c
-
-# first test that is doesn't work, when no DEBUGINFOD_URLS is set
-DEBUGINFOD_URLS=""
-testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c && false || true
-
-# Now test is with proper DEBUGINFOD_URLS
-DEBUGINFOD_URLS="file://${PWD}/mocktree/"
-filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find source aaaaaaaaaabbbbbbbbbbccccccccccdddddddddd /my/path/main.c`
-cmp $filename ${local_dir}/main.c
-
-exit 0
diff --git a/tests/run-debuginfod-malformed.sh b/tests/run-debuginfod-malformed.sh
new file mode 100755
index 00000000..83e6a3a9
--- /dev/null
+++ b/tests/run-debuginfod-malformed.sh
@@ -0,0 +1,111 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9200
+# find an unused port number
+get_ports
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+mkdir F
+mkdir -p $DEBUGINFOD_CACHE_PATH
+
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
+ -t0 -g0 -v F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# And an initial scan should be done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# We use -t0 and -g0 here to turn off time-based scanning & grooming.
+# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
+########################################################################
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
+tempfiles p+r%o\$g.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
+testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv p+r%o\$g F
+mv p+r%o\$g.debug F
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+# Add some files to the cache that do not fit its naming format.
+# They should survive cache cleaning.
+mkdir $DEBUGINFOD_CACHE_PATH/malformed
+touch $DEBUGINFOD_CACHE_PATH/malformed0
+touch $DEBUGINFOD_CACHE_PATH/malformed/malformed1
+
+# A valid format for an empty buildid subdirectory
+mkdir $DEBUGINFOD_CACHE_PATH/00000000
+touch -d '1970-01-01' $DEBUGINFOD_CACHE_PATH/00000000 # old enough to guarantee nukage
+
+# Trigger a cache clean and run the tests again. The clients should be unable to
+# find the target.
+echo 0 > $DEBUGINFOD_CACHE_PATH/cache_clean_interval_s
+echo 0 > $DEBUGINFOD_CACHE_PATH/max_unused_age_s
+
+testrun ${abs_builddir}/debuginfod_build_id_find -e F/p+r%o\$g 1
+
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && false || true
+
+if [ ! -f $DEBUGINFOD_CACHE_PATH/malformed0 ] \
+ || [ ! -f $DEBUGINFOD_CACHE_PATH/malformed/malformed1 ]; then
+ echo "unrelated files did not survive cache cleaning"
+ err
+fi
+
+if [ -d $DEBUGINFOD_CACHE_PATH/00000000 ]; then
+ echo "failed to rmdir old cache dir"
+ err
+fi
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-negative-cache.sh b/tests/run-debuginfod-negative-cache.sh
new file mode 100755
index 00000000..f40e99c5
--- /dev/null
+++ b/tests/run-debuginfod-negative-cache.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=8000
+get_ports
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
+ -t0 -g0 -v ${PWD} > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+########################################################################
+# PR25628
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+
+# The query is designed to fail, while the empty file should be created.
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
+if [ ! -f $DEBUGINFOD_CACHE_PATH/01234567/debuginfo ]; then
+ echo "could not find cache in $DEBUGINFOD_CACHE_PATH"
+ err
+fi
+
+if [ `stat -c "%s" $DEBUGINFOD_CACHE_PATH/01234567/debuginfo` != 0 ]; then
+ echo "The cache $DEBUGINFOD_CACHE_PATH/01234567/debuginfo is not empty"
+ err
+fi
+
+bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
+bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
+if [ "$bytecount_before" != "$bytecount_after" ]; then
+ echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} has changed."
+ err
+fi
+
+# set cache_miss_s to 0 and sleep 1 to make the mtime expire.
+echo 0 > $DEBUGINFOD_CACHE_PATH/cache_miss_s
+sleep 1
+bytecount_before=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
+bytecount_after=`curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_transfer_bytes_count{code="404",type="debuginfo"}'`
+if [ "$bytecount_before" == "$bytecount_after" ]; then
+ echo "http_responses_transfer_bytes_count{code="404",type="debuginfo"} should be incremented."
+ err
+fi
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-no-urls.sh b/tests/run-debuginfod-no-urls.sh
new file mode 100755
index 00000000..7e3ffef6
--- /dev/null
+++ b/tests/run-debuginfod-no-urls.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+########################################################################
+# Test debuginfod without a path list
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9300
+get_ports
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -U -d :memory: -p $PORT1 -L -F &
+PID1=$!
+
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+kill -int $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-percent-escape.sh b/tests/run-debuginfod-percent-escape.sh
new file mode 100755
index 00000000..f7d8dc66
--- /dev/null
+++ b/tests/run-debuginfod-percent-escape.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh # includes set -e
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=10000
+get_ports
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+mkdir F
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE \
+ -F -R -d $DB -p $PORT1 -t0 -g0 -v R ${PWD}/F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# Be patient when run on a busy machine things might take a bit.
+
+# Build a non-stripped binary
+echo "int main() { return 0; }" > ${PWD}/F/p++r\$\#o^^g.c
+gcc -Wl,--build-id -g -o ${PWD}/F/p++r\$\#o^^g ${PWD}/F/p++r\$\#o^^g.c
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a ${PWD}/F/p++r\\$\#o^^g | grep 'Build ID' | cut -d ' ' -f 7`
+tempfiles ${PWD}/F/p++r\$\#o^^g.c ${PWD}/F/p++r\$\#o^^g
+kill -USR1 $PID1
+# Now there should be 1 files in the index
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+ls F
+env DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache DEBUGINFOD_URLS="http://127.0.0.1:$PORT1" \
+ LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find -vvv source F/p++r\$\#o^^g ${abs_builddir}/F/p++r\$\#o^^g.c > vlog1 2>&1 || true
+tempfiles vlog1
+grep 'F/p%2B%2Br%24%23o%5E%5Eg.c' vlog1
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-query-retry.sh b/tests/run-debuginfod-query-retry.sh
new file mode 100755
index 00000000..0cfdba92
--- /dev/null
+++ b/tests/run-debuginfod-query-retry.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+########################################################################
+# set up tests for retrying failed queries.
+retry_attempts=`(testrun env DEBUGINFOD_URLS=http://255.255.255.255/JUNKJUNK DEBUGINFOD_RETRY_LIMIT=10 DEBUGINFOD_VERBOSE=1 DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache \
+ ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo /bin/sh || true) 2>&1 >/dev/null \
+ | grep -c 'Retry failed query'`
+if [ $retry_attempts -ne 10 ]; then
+ echo "retry mechanism failed."
+ exit 1;
+fi
+
+exit 0;
diff --git a/tests/run-debuginfod-regex.sh b/tests/run-debuginfod-regex.sh
new file mode 100755
index 00000000..6837ea86
--- /dev/null
+++ b/tests/run-debuginfod-regex.sh
@@ -0,0 +1,101 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+mkdir F
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9400
+get_ports
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod \
+ $VERBOSE -F -p $PORT1 -t0 -g0 -d ${DB} F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+
+# Wait till the server is ready and an initial scan has been done
+wait_ready $PORT1 'ready' 1
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/prog.c
+tempfiles prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+
+mv prog F
+mv prog.debug F
+tempfiles F/prog.debug F/prog
+
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+cp ${DB} ${DB}.backup
+tempfiles ${DB}.backup
+
+kill $PID1
+wait $PID1
+PID1=0
+
+#######################################################################
+## PR27711
+# Test to ensure that the --include="^$" --exclude=".*" options remove all files from a database backup
+#
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod \
+ $VERBOSE -p $PORT2 -t0 -g0 --regex-groom --include="^$" --exclude=".*" -d ${DB}.backup > vlog$PORT2 2>&1 &
+
+#reuse PID1
+PID1=$!
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+# Server must become ready
+wait_ready $PORT2 'ready' 1
+
+# Wait till the initial groom cycle has been done
+wait_ready $PORT2 'thread_work_total{role="groom"}' 1
+wait_ready $PORT2 'groom{statistic="archive d/e"}' 0
+wait_ready $PORT2 'groom{statistic="archive sdef"}' 0
+wait_ready $PORT2 'groom{statistic="archive sref"}' 0
+wait_ready $PORT2 'groom{statistic="buildids"}' 0
+wait_ready $PORT2 'groom{statistic="file d/e"}' 0
+wait_ready $PORT2 'groom{statistic="file s"}' 0
+wait_ready $PORT2 'groom{statistic="files scanned (#)"}' 0
+wait_ready $PORT2 'groom{statistic="files scanned (mb)"}' 0
+
+kill $PID1
+wait $PID1
+PID1=0
+
+exit 0;
+
diff --git a/tests/run-debuginfod-response-headers.sh b/tests/run-debuginfod-response-headers.sh
new file mode 100755
index 00000000..62c43887
--- /dev/null
+++ b/tests/run-debuginfod-response-headers.sh
@@ -0,0 +1,100 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh # includes set -e
+
+# for test case debugging, uncomment:
+set -x
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9500
+get_ports
+mkdir F R
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -R -d $DB -p $PORT1 -t0 -g0 -v R F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+########################################################################
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/prog.c
+tempfiles prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+
+mv prog F
+
+cp -rvp ${abs_srcdir}/debuginfod-rpms R
+if [ "$zstd" = "false" ]; then # nuke the zstd fedora 31 ones
+ rm -vrf R/debuginfod-rpms/fedora31
+fi
+
+kill -USR1 $PID1
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+# All rpms need to be in the index, except the dummy permission-000 one
+rpms=$(find R -name \*rpm | grep -v nothing | wc -l)
+wait_ready $PORT1 'scanned_files_total{source=".rpm archive"}' $rpms
+kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->srefs
+# Wait till both files are in the index and scan/index fully finished
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+
+########################################################################
+## PR27277
+# Make a simple request to the debuginfod server and check debuginfod-find's vlog to see if
+# the custom HTTP headers are received.
+rm -rf $DEBUGINFOD_CACHE_PATH
+env DEBUGINFOD_URLS="http://127.0.0.1:"$PORT1 LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find\
+ -vvv executable F/prog > vlog-find$PORT1.1 2>&1
+tempfiles vlog-find$PORT1.1
+grep 'Content-Length: ' vlog-find$PORT1.1
+grep 'X-DEBUGINFOD-FILE: ' vlog-find$PORT1.1
+grep 'X-DEBUGINFOD-SIZE: ' vlog-find$PORT1.1
+
+# Check to see if an executable file located in an archive prints the file's description and archive
+env DEBUGINFOD_URLS="http://127.0.0.1:"$PORT1 LD_LIBRARY_PATH=$ldpath ${abs_top_builddir}/debuginfod/debuginfod-find\
+ -vvv executable c36708a78618d597dee15d0dc989f093ca5f9120 > vlog-find$PORT1.2 2>&1
+tempfiles vlog-find$PORT1.2
+grep 'Content-Length: ' vlog-find$PORT1.2
+grep 'X-DEBUGINFOD-FILE: ' vlog-find$PORT1.2
+grep 'X-DEBUGINFOD-SIZE: ' vlog-find$PORT1.2
+grep 'X-DEBUGINFOD-ARCHIVE: ' vlog-find$PORT1.2
+
+# Check that X-DEBUGINFOD-SIZE matches the size of each file
+for file in vlog-find$PORT1.1 vlog-find$PORT1.2
+do
+ st_size=$(stat -c%s $(tail -n 1 $file))
+ x_debuginfod_size=$(grep 'X-DEBUGINFOD-SIZE' $file | egrep -o '[0-9]+')
+ test $st_size -eq $x_debuginfod_size
+done
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-sizetime.sh b/tests/run-debuginfod-sizetime.sh
new file mode 100755
index 00000000..2cf6f252
--- /dev/null
+++ b/tests/run-debuginfod-sizetime.sh
@@ -0,0 +1,82 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+set -x
+unset VALGRIND_CMD
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9600
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+echo "int main() { return 0; }" > ${PWD}/prog.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o prog ${PWD}/foobar///./../prog.c
+testrun ${abs_top_builddir}/src/strip -g -f prog.debug ${PWD}/prog
+tempfiles prog prog.debug prog.c
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a prog | grep 'Build ID' | cut -d ' ' -f 7`
+
+env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB -t0 -g0 ${PWD} > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+wait_ready $PORT1 'ready' 1
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+## PR27892
+# Ensure DEBUGINFOD_MAXSIZE is functional and sends back the correct http
+# code
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_RETRY_LIMIT=1 DEBUGINFOD_URLS="http://127.0.0.1:$PORT1/" DEBUGINFOD_MAXSIZE=1 \
+ ${abs_top_builddir}/debuginfod/debuginfod-find -v executable ${PWD}/prog 2> find-vlog$PORT1 || true
+tempfiles find-vlog$PORT1
+errfiles find-vlog$PORT1
+echo "Checking maxsize"
+grep "using max size 1B" find-vlog$PORT1
+echo "Checking maxsize"
+grep 'serving file '$(realpath ${PWD})'/prog' vlog$PORT1
+echo "Checking maxsize"
+grep 'File too large' vlog$PORT1
+if [ -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID} ]; then
+ echo "File cached after maxsize check"
+ err
+fi
+# Ensure no file is downloaded for longer than DEBUGINFOD_MAXTIME
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS="http://127.0.0.1:$PORT1/" DEBUGINFOD_MAXTIME=1 \
+ ${abs_top_builddir}/debuginfod/debuginfod-find -v debuginfo ${PWD}/prog.debug 2> find-vlog$PORT1 || true
+tempfiles find-vlog$PORT1
+grep 'using max time' find-vlog$PORT1
+# Ensure p+r%o\$g.debug is NOT cached
+if [ -f ${DEBUGINFOD_CACHE_PATH}/${BUILDID} ]; then
+ echo "File cached after maxtime check"
+ err
+fi
+
+kill $PID1
+wait $PID1
+PID1=0
+
+exit 0;
diff --git a/tests/run-debuginfod-tmp-home.sh b/tests/run-debuginfod-tmp-home.sh
new file mode 100755
index 00000000..5946777a
--- /dev/null
+++ b/tests/run-debuginfod-tmp-home.sh
@@ -0,0 +1,126 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+mkdir F
+mkdir -p $DEBUGINFOD_CACHE_PATH
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9700
+get_ports
+
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
+ -t0 -g0 -v F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# And initial scan should be done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+# We use -t0 and -g0 here to turn off time-based scanning & grooming.
+# For testing purposes, we just sic SIGUSR1 / SIGUSR2 at the process.
+
+########################################################################
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
+tempfiles p+r%o\$g.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
+testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv p+r%o\$g F
+mv p+r%o\$g.debug F
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+########################################################################
+
+# Test whether the cache default locations are correct
+mkdir tmphome
+
+# $HOME/.cache should be created.
+testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/debuginfo ]; then
+ echo "could not find cache in $PWD/tmphome/.cache"
+ err
+fi
+
+# $HOME/.cache should be found.
+testrun env HOME=$PWD/tmphome XDG_CACHE_HOME= DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find executable $BUILDID
+if [ ! -f $PWD/tmphome/.cache/debuginfod_client/$BUILDID/executable ]; then
+ echo "could not find cache in $PWD/tmphome/.cache"
+ err
+fi
+# $XDG_CACHE_HOME should take priority over $HOME.cache.
+testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+if [ ! -f $PWD/tmpxdg/debuginfod_client/$BUILDID/debuginfo ]; then
+ echo "could not find cache in $PWD/tmpxdg/"
+ err
+fi
+
+# A cache at the old default location ($HOME/.debuginfod_client_cache) should take
+# priority over $HOME/.cache, $XDG_CACHE_HOME.
+cp -vr $DEBUGINFOD_CACHE_PATH tmphome/.debuginfod_client_cache || true
+# ||true is for tolerating errors, such a valgrind or something else
+# leaving negative-hit files in there
+
+# Add a file that doesn't exist in $HOME/.cache, $XDG_CACHE_HOME.
+mkdir tmphome/.debuginfod_client_cache/deadbeef
+echo ELF... > tmphome/.debuginfod_client_cache/deadbeef/debuginfo
+filename=`testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH= ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo deadbeef`
+cmp $filename tmphome/.debuginfod_client_cache/deadbeef/debuginfo
+
+# $DEBUGINFO_CACHE_PATH should take priority over all else.
+testrun env HOME=$PWD/tmphome XDG_CACHE_HOME=$PWD/tmpxdg DEBUGINFOD_CACHE_PATH=$PWD/tmpcache ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID
+if [ ! -f $PWD/tmpcache/$BUILDID/debuginfo ]; then
+ echo "could not find cache in $PWD/tmpcache/"
+ err
+fi
+rm -rf ${PWD}/tmphome/ ${PWD}/tmpxdg ${PWD}/tmpcache
+
+kill $PID1
+wait $PID1
+PID1=0
+exit 0
diff --git a/tests/run-debuginfod-webapi-concurrency.sh b/tests/run-debuginfod-webapi-concurrency.sh
new file mode 100755
index 00000000..47dcadcc
--- /dev/null
+++ b/tests/run-debuginfod-webapi-concurrency.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+
+mkdir Z
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=12000
+get_ports
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+cp -rvp ${abs_srcdir}/debuginfod-tars Z
+tempfiles Z
+
+
+for Cnum in "" "-C" "-C10" "-C100"
+do
+ env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../debuginfod/debuginfod $VERBOSE $Cnum -d :memory: -Z .tar.xz -Z .tar.bz2=bzcat -p $PORT1 -t0 -g0 -v --fdcache-fds=0 --fdcache-prefetch-fds=0 Z >> vlog$PORT1 2>&1 &
+ PID1=$!
+ tempfiles vlog$PORT1
+ errfiles vlog$PORT1
+
+ wait_ready $PORT1 'ready' 1
+ # Wait for server to finish indexing
+ wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+ wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+ wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+ # Do a bunch of lookups in parallel
+ lookup_nr=64
+ for jobs in `seq $lookup_nr`; do
+ curl -s http://localhost:$PORT1/buildid/cee13b2ea505a7f37bd20d271c6bc7e5f8d2dfcb/debuginfo > /dev/null &
+ done
+
+ # all curls should succeed
+ wait_ready $PORT1 'http_responses_transfer_bytes_count{code="200",type="debuginfo"}' $lookup_nr
+
+ (sleep 5;
+ curl -s http://localhost:$PORT1/metrics | egrep 'error|responses';
+ kill $PID1) &
+ wait # for all curls, the ()& from just above, and for debuginfod
+ PID1=0
+done
+
+# Note this xfail comes too late, the above wait_ready for
+# http_responses_transfer_bytes_count will have failed.
+xfail "grep Server.reached.connection vlog$PORT1" # PR28661
+
+exit 0
diff --git a/tests/run-debuginfod-writable.sh b/tests/run-debuginfod-writable.sh
new file mode 100755
index 00000000..c521a572
--- /dev/null
+++ b/tests/run-debuginfod-writable.sh
@@ -0,0 +1,88 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2019-2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+mkdir F
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9800
+get_ports
+
+DB=${PWD}/.debuginfod_tmp.sqlite
+tempfiles $DB
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS= ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -F -p $PORT1 -d $DB \
+ -t0 -g0 -v F > vlog$PORT1 2>&1 &
+PID1=$!
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+# Server must become ready
+wait_ready $PORT1 'ready' 1
+# And initial scan should be done
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 1
+
+export DEBUGINFOD_URLS=http://127.0.0.1:$PORT1/ # or without trailing /
+
+# Check thread comm names
+ps -q $PID1 -e -L -o '%p %c %a' | grep groom
+ps -q $PID1 -e -L -o '%p %c %a' | grep scan
+ps -q $PID1 -e -L -o '%p %c %a' | grep traverse
+
+########################################################################
+
+# Compile a simple program, strip its debuginfo and save the build-id.
+# Also move the debuginfo into another directory so that elfutils
+# cannot find it without debuginfod.
+echo "int main() { return 0; }" > ${PWD}/p+r%o\$g.c
+tempfiles p+r%o\$g.c
+# Create a subdirectory to confound source path names
+mkdir foobar
+gcc -Wl,--build-id -g -o p+r%o\$g ${PWD}/foobar///./../p+r%o\$g.c
+testrun ${abs_top_builddir}/src/strip -g -f p+r%o\$g.debug ${PWD}/p+r%o\$g
+BUILDID=`env LD_LIBRARY_PATH=$ldpath ${abs_builddir}/../src/readelf \
+ -a p+r%o\\$g | grep 'Build ID' | cut -d ' ' -f 7`
+
+mv p+r%o\$g F
+mv p+r%o\$g.debug F
+kill -USR1 $PID1
+# Wait till both files are in the index.
+wait_ready $PORT1 'thread_work_total{role="traverse"}' 2
+wait_ready $PORT1 'thread_work_pending{role="scan"}' 0
+wait_ready $PORT1 'thread_busy{role="scan"}' 0
+
+#######################################################################
+# Test whether debuginfod-find is able to fetch those files.
+rm -rf $DEBUGINFOD_CACHE_PATH # clean it from previous tests
+filename=`testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID`
+cmp $filename F/p+r%o\$g.debug
+if [ `stat -c "%A" $filename` != "-r--------" ]; then
+ echo "cache file writable, boo"
+ err
+fi
+
+kill $PID1
+wait $PID1
+PID1=0
+
+exit 0
diff --git a/tests/run-debuginfod-x-forwarded-for.sh b/tests/run-debuginfod-x-forwarded-for.sh
new file mode 100755
index 00000000..5b756b22
--- /dev/null
+++ b/tests/run-debuginfod-x-forwarded-for.sh
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+#
+# Copyright (C) 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/debuginfod-subr.sh
+
+# for test case debugging, uncomment:
+set -x
+unset VALGRIND_CMD
+
+export DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache
+# This variable is essential and ensures no time-race for claiming ports occurs
+# set base to a unique multiple of 100 not used in any other 'run-debuginfod-*' test
+base=9900
+get_ports
+
+# Test when debuginfod hitting X-Forwarded-For hops limit.
+# This test will start two servers (as a loop) with two different hop limits.
+
+tempfiles vlog$PORT1
+errfiles vlog$PORT1
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT2 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d :memory: --forwarded-ttl-limit 0 -p $PORT1 > vlog$PORT1 2>&1 &
+PID1=$!
+
+tempfiles vlog$PORT2
+errfiles vlog$PORT2
+env LD_LIBRARY_PATH=$ldpath DEBUGINFOD_URLS=http://127.0.0.1:$PORT1 ${abs_builddir}/../debuginfod/debuginfod $VERBOSE -d :memory: --forwarded-ttl-limit 1 -p $PORT2 > vlog$PORT2 2>&1 &
+PID2=$!
+
+wait_ready $PORT1 'ready' 1
+wait_ready $PORT2 'ready' 1
+
+export DEBUGINFOD_URLS="http://127.0.0.1:$PORT1/"
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 01234567 || true
+
+# Use a different buildid to avoid using same cache.
+export DEBUGINFOD_URLS="http://127.0.0.1:$PORT2/"
+testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo 11234567 || true
+
+grep "forwared-ttl-limit reached and will not query the upstream servers" vlog$PORT1
+grep -v "forwared-ttl-limit reached and will not query the upstream servers" vlog$PORT2 | grep "not found" vlog$PORT2
+
+kill $PID1 $PID2
+wait $PID1 $PID2
+
+PID1=0
+PID2=0
+
+exit 0
diff --git a/tests/run-large-elf-file.sh b/tests/run-large-elf-file.sh
index 667d24d8..7116de53 100755
--- a/tests/run-large-elf-file.sh
+++ b/tests/run-large-elf-file.sh
@@ -1,5 +1,6 @@
#! /usr/bin/env bash
# Copyright (C) 2019 Red Hat, Inc.
+# Copyright (C) 2022 Mark J. Wielaard <[email protected]>
# This file is part of elfutils.
#
# This file is free software; you can redistribute it and/or modify
@@ -26,6 +27,16 @@ if test $long_bit -ne 64; then
exit 77
fi
+# The test binary also needs to be 64bits itself
+elfclass=64
+testrun ${abs_top_builddir}/src/readelf -h ${abs_builddir}/addsections | grep ELF32 \
+ && elfclass=32
+echo elfclass: $elfclass
+if test $elfclass -ne 64; then
+ echo "Only 64bit binaries can create > 4GB ELF files"
+ exit 77
+fi
+
# These tests need lots of disk space since they test files > 4GB.
# Skip if there just isn't enough (2.5 * 4 = 10GB).
space_available=$[$(stat -f --format="%a*%S" .)/(1024 * 1024 * 1024)]
diff --git a/tests/run-nvidia-extended-linemap-libdw.sh b/tests/run-nvidia-extended-linemap-libdw.sh
new file mode 100755
index 00000000..d1df2cf3
--- /dev/null
+++ b/tests/run-nvidia-extended-linemap-libdw.sh
@@ -0,0 +1,60 @@
+# Copyright (C) 2011 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# NOTE:
+# the file testfile_nvidia_linemap is a CUDA binary for an NVIDIA A100 generated as follows using CUDA 11.2
+# nvcc -o main main.cu -Xcompiler "-g -fopenmp" -O3 -lineinfo -arch sm_80 -lcudart -lcuda -lstdc++ -lm
+# cuobjdump -xelf all main
+# mv main.sm_80.cubin testfile_nvidia_linemap
+
+testfiles testfile_nvidia_linemap
+testrun_compare ${abs_top_builddir}/tests/nvidia_extended_linemap_libdw testfile_nvidia_linemap << EOF
+off = 0
+ 18 lines
+0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:25:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+10: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:26:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+40: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:27:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+90: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:25:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+a0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:28:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:28:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+100: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ foo inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:28
+150: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:9:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ foo inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:28
+1e0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+1e0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:6:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+1e0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ foo inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:6
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+220: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:9:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ foo inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:6
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+2b0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:7:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+2f0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:8:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+2f0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:18:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ _Z1aPiS_S_ inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:8
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+330: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:19:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+ _Z1aPiS_S_ inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/bar.h:8
+ bar inlined at /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:31
+3c0: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:33:0: is_stmt:yes, end_seq:no, bb:no, prologue:no, epilogue:no
+480: /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4/main.cu:33:0: is_stmt:yes, end_seq:yes, bb:no, prologue:no, epilogue:no
+EOF
diff --git a/tests/run-nvidia-extended-linemap-readelf.sh b/tests/run-nvidia-extended-linemap-readelf.sh
new file mode 100755
index 00000000..1fa9b7b4
--- /dev/null
+++ b/tests/run-nvidia-extended-linemap-readelf.sh
@@ -0,0 +1,120 @@
+# Copyright (C) 2011 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# NOTE:
+# the file testfile_nvidia_linemap is a CUDA binary for an NVIDIA A100 generated as follows using CUDA 11.2
+# nvcc -o main main.cu -Xcompiler "-g -fopenmp" -O3 -lineinfo -arch sm_80 -lcudart -lcuda -lstdc++ -lm
+# cuobjdump -xelf all main
+# mv main.sm_80.cubin testfile_nvidia_linemap
+
+testfiles testfile_nvidia_linemap
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile_nvidia_linemap << EOF
+
+DWARF section [ 5] '.debug_line' at offset 0x3e0:
+
+Table at offset 0:
+
+ Length: 253
+ DWARF version: 2
+ Prologue length: 111
+ Address size: 8
+ Segment selector size: 0
+ Min instruction length: 1
+ Max operations per instruction: 1
+ Initial value if 'is_stmt': 1
+ Line base: -5
+ Line range: 14
+ Opcode base: 10
+
+Opcodes:
+ [1] 0 arguments
+ [2] 1 argument
+ [3] 1 argument
+ [4] 1 argument
+ [5] 1 argument
+ [6] 0 arguments
+ [7] 0 arguments
+ [8] 0 arguments
+ [9] 1 argument
+
+Directory table:
+ /home/johnmc/hpctoolkit-gpu-samples/nvidia_extended_linemap4
+
+File name table:
+ Entry Dir Time Size Name
+ 1 1 1626104146 1819 main.cu
+ 2 1 1626104111 211 bar.h
+
+Line number statements:
+ [ 79] extended opcode 2: set address to 0 <kernel>
+ [ 84] set file to 1
+ [ 86] advance line by constant 24 to 25
+ [ 88] copy
+ [ 89] special opcode 240: address+16 = 0x10 <kernel+0x10>, line+1 = 26
+ [ 8a] advance line by constant 1 to 27
+ [ 8c] advance address by 48 to 0x40 <kernel+0x40>
+ [ 8e] copy
+ [ 8f] advance line by constant -2 to 25
+ [ 91] advance address by 80 to 0x90 <kernel+0x90>
+ [ 94] copy
+ [ 95] special opcode 242: address+16 = 0xa0 <kernel+0xa0>, line+3 = 28
+ [ 96] advance address by 96 to 0x100 <kernel+0x100>
+ [ 99] copy
+ [ 9a] extended opcode 144: set inlined context 6, function name foo (0x0)
+ [ 9f] advance line by constant -20 to 8
+ [ a1] copy
+ [ a2] advance line by constant 1 to 9
+ [ a4] advance address by 80 to 0x150 <kernel+0x150>
+ [ a7] copy
+ [ a8] extended opcode 144: set inlined context 0, function name foo (0x0)
+ [ ad] advance line by constant 22 to 31
+ [ af] advance address by 144 to 0x1e0 <kernel+0x1e0>
+ [ b2] copy
+ [ b3] set file to 2
+ [ b5] extended opcode 144: set inlined context 9, function name bar (0x4)
+ [ ba] advance line by constant -25 to 6
+ [ bc] copy
+ [ bd] set file to 1
+ [ bf] extended opcode 144: set inlined context 10, function name foo (0x0)
+ [ c4] advance line by constant 2 to 8
+ [ c6] copy
+ [ c7] advance line by constant 1 to 9
+ [ c9] advance address by 64 to 0x220 <kernel+0x220>
+ [ cc] copy
+ [ cd] set file to 2
+ [ cf] extended opcode 144: set inlined context 9, function name bar (0x4)
+ [ d4] advance line by constant -2 to 7
+ [ d6] advance address by 144 to 0x2b0 <kernel+0x2b0>
+ [ d9] copy
+ [ da] advance line by constant 1 to 8
+ [ dc] advance address by 64 to 0x2f0 <kernel+0x2f0>
+ [ df] copy
+ [ e0] set file to 1
+ [ e2] extended opcode 144: set inlined context 14, function name _Z1aPiS_S_ (0x8)
+ [ e7] advance line by constant 10 to 18
+ [ e9] copy
+ [ ea] advance line by constant 1 to 19
+ [ ec] advance address by 64 to 0x330 <kernel+0x330>
+ [ ef] copy
+ [ f0] extended opcode 144: set inlined context 0, function name foo (0x0)
+ [ f5] advance line by constant 14 to 33
+ [ f7] advance address by 144 to 0x3c0 <kernel+0x3c0>
+ [ fa] copy
+ [ fb] advance address by 192 to 0x480
+ [ fe] extended opcode 1: end of sequence
+EOF
diff --git a/tests/run-readelf-d.sh b/tests/run-readelf-d.sh
index d0b6ed24..69b01c49 100755
--- a/tests/run-readelf-d.sh
+++ b/tests/run-readelf-d.sh
@@ -34,7 +34,7 @@ testfiles testlib_dynseg.so
testrun_compare ${abs_top_builddir}/src/readelf -d testlib_dynseg.so <<\EOF
-Dynamic segment contains 28 entries:
+Dynamic segment contains 23 entries:
Addr: 0x00000000000017e0 Offset: 0x0007e0 Link to section: [ 3] '.dynstr'
Type Value
PLTGOT 0x00000000000019c8
@@ -60,11 +60,6 @@ Dynamic segment contains 28 entries:
VERNEED 0x0000000000000498
VERNEEDNUM 2
NULL
- NULL
- NULL
- NULL
- NULL
- NULL
EOF
exit 0
diff --git a/tests/run-readelf-fat-lto.sh b/tests/run-readelf-fat-lto.sh
new file mode 100755
index 00000000..e03cec3a
--- /dev/null
+++ b/tests/run-readelf-fat-lto.sh
@@ -0,0 +1,53 @@
+. $srcdir/test-subr.sh
+
+# - s.c
+# int main_argc_remaining;
+#
+# int main_argc() {
+# int result = 0;
+# if (main_argc_remaining)
+# result = 0;
+#
+# return 0;
+# }
+#
+# gcc -gdwarf-5 -c -o testfile-dwarf5-fat-lto.o -flto -O s.c -g -ffat-lto-objects
+
+testfiles testfile-dwarf5-fat-lto.o
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=loc --debug-dump=ranges -N -U testfile-dwarf5-fat-lto.o << EOF
+
+DWARF section [26] '.debug_loclists' at offset 0x7db:
+Table at Offset 0x0:
+
+ Length: 24
+ DWARF version: 5
+ Address size: 8
+ Segment size: 0
+ Offset entries: 0
+ CU [ c] base: 000000000000000000
+
+ Offset: c, Index: 0
+ view pair 2, 3
+
+ Offset: e, Index: 2
+ start_length 0x0, 0
+ [ 0] lit0
+ [ 1] stack_value
+ end_of_list
+
+
+DWARF section [30] '.debug_rnglists' at offset 0x827:
+Table at Offset 0x0:
+
+ Length: 19
+ DWARF version: 5
+ Address size: 8
+ Segment size: 0
+ Offset entries: 0
+ CU [ c] base: 000000000000000000
+
+ Offset: c, Index: 0
+ start_length 0x0, 8
+ end_of_list
+
+EOF
diff --git a/tests/run-readelf-multi-noline.sh b/tests/run-readelf-multi-noline.sh
new file mode 100755
index 00000000..d72a9fd4
--- /dev/null
+++ b/tests/run-readelf-multi-noline.sh
@@ -0,0 +1,170 @@
+#! /bin/sh
+# Copyright (C) 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# = a.c =
+# int a;
+
+# = b.c =
+# int b;
+
+# = m.c =
+# int main () { }
+
+# gcc -g -o testfile_multi_noline a.c b.c m.c
+
+testfiles testfile_multi_noline
+
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=line testfile_multi_noline <<\EOF
+
+DWARF section [29] '.debug_line' at offset 0x1221:
+
+Table at offset 0:
+
+ Length: 32
+ DWARF version: 3
+ Prologue length: 26
+ Address size: 8
+ Segment selector size: 0
+ Min instruction length: 4
+ Max operations per instruction: 1
+ Initial value if 'is_stmt': 1
+ Line base: -5
+ Line range: 14
+ Opcode base: 13
+
+Opcodes:
+ [ 1] 0 arguments
+ [ 2] 1 argument
+ [ 3] 1 argument
+ [ 4] 1 argument
+ [ 5] 1 argument
+ [ 6] 0 arguments
+ [ 7] 0 arguments
+ [ 8] 0 arguments
+ [ 9] 1 argument
+ [10] 0 arguments
+ [11] 0 arguments
+ [12] 1 argument
+
+Directory table:
+
+File name table:
+ Entry Dir Time Size Name
+ 1 0 0 0 a.c
+
+No line number statements.
+
+Table at offset 36:
+
+ Length: 32
+ DWARF version: 3
+ Prologue length: 26
+ Address size: 8
+ Segment selector size: 0
+ Min instruction length: 4
+ Max operations per instruction: 1
+ Initial value if 'is_stmt': 1
+ Line base: -5
+ Line range: 14
+ Opcode base: 13
+
+Opcodes:
+ [ 1] 0 arguments
+ [ 2] 1 argument
+ [ 3] 1 argument
+ [ 4] 1 argument
+ [ 5] 1 argument
+ [ 6] 0 arguments
+ [ 7] 0 arguments
+ [ 8] 0 arguments
+ [ 9] 1 argument
+ [10] 0 arguments
+ [11] 0 arguments
+ [12] 1 argument
+
+Directory table:
+
+File name table:
+ Entry Dir Time Size Name
+ 1 0 0 0 b.c
+
+No line number statements.
+
+Table at offset 72:
+
+ Length: 54
+ DWARF version: 3
+ Prologue length: 26
+ Address size: 8
+ Segment selector size: 0
+ Min instruction length: 4
+ Max operations per instruction: 1
+ Initial value if 'is_stmt': 1
+ Line base: -5
+ Line range: 14
+ Opcode base: 13
+
+Opcodes:
+ [ 1] 0 arguments
+ [ 2] 1 argument
+ [ 3] 1 argument
+ [ 4] 1 argument
+ [ 5] 1 argument
+ [ 6] 0 arguments
+ [ 7] 0 arguments
+ [ 8] 0 arguments
+ [ 9] 1 argument
+ [10] 0 arguments
+ [11] 0 arguments
+ [12] 1 argument
+
+Directory table:
+
+File name table:
+ Entry Dir Time Size Name
+ 1 0 0 0 m.c
+
+Line number statements:
+ [ 6c] set column to 13
+ [ 6e] extended opcode 2: set address to +0x724 <main>
+ [ 79] copy
+ [ 7a] set column to 15
+ [ 7c] special opcode 32: address+4 = +0x728 <main+0x4>, line+0 = 1
+ [ 7d] advance address by 4 to +0x72c
+ [ 7f] extended opcode 1: end of sequence
+EOF
+
+testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=decodedline testfile_multi_noline <<\EOF
+
+DWARF section [29] '.debug_line' at offset 0x1221:
+
+ CU [b] a.c
+ line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End)
+ CU [44] b.c
+ line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End)
+ CU [7d] m.c
+ line:col SBPE* disc isa op address (Statement Block Prologue Epilogue *End)
+ /tmp/m.c (mtime: 0, length: 0)
+ 1:13 S 0 0 0 +0x0000000000000724 <main>
+ 1:15 S 0 0 0 +0x0000000000000728 <main+0x4>
+ 1:15 S * 0 0 0 +0x000000000000072b <main+0x7>
+
+EOF
+
+exit 0
diff --git a/tests/run-strip-largealign.sh b/tests/run-strip-largealign.sh
new file mode 100755
index 00000000..4f81d3c1
--- /dev/null
+++ b/tests/run-strip-largealign.sh
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Copyright (C) 2021 Runsafe Security, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+. $srcdir/test-subr.sh
+
+# = testfile-largealign.S =
+# section .data
+# align 4096
+# dd 0x12345678
+#
+# nasm -f elf64 -o testfile-largealign.o testfile-largealign.S
+
+infile=testfile-largealign.o
+outfile=$infile.stripped
+
+testfiles $infile
+tempfiles $outfile
+
+testrun ${abs_top_builddir}/src/strip -o $outfile $infile
+testrun ${abs_top_builddir}/src/elflint --gnu $outfile
diff --git a/tests/run-varlocs-vars.sh b/tests/run-varlocs-vars.sh
new file mode 100755
index 00000000..e7598bf0
--- /dev/null
+++ b/tests/run-varlocs-vars.sh
@@ -0,0 +1,93 @@
+#! /bin/sh
+# Copyright (C) 2013, 2021 Red Hat, Inc.
+# This file is part of elfutils.
+#
+# This file is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# elfutils is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. $srcdir/test-subr.sh
+
+# Testfiles generated with:
+#
+# $ cat foo.c
+# int x = 1;
+# int y = 2;
+#
+# for cc in gcc clang; do
+# for v in 4 5; do
+# for w in 32 64; do
+# out="testfile-vars-$cc-dwarf$v-$w.o"
+# "$cc" -m"$w" -Wall -Wextra -gdwarf-"$v" -c foo.c -o "$out"
+# done
+# done
+# done
+
+testfiles testfile-vars-clang-dwarf4-32.o
+testfiles testfile-vars-clang-dwarf4-64.o
+testfiles testfile-vars-clang-dwarf5-32.o
+testfiles testfile-vars-clang-dwarf5-64.o
+testfiles testfile-vars-gcc-dwarf4-32.o
+testfiles testfile-vars-gcc-dwarf4-64.o
+testfiles testfile-vars-gcc-dwarf5-32.o
+testfiles testfile-vars-gcc-dwarf5-64.o
+
+tempfiles varlocs.out
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-clang-dwarf4-32.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-clang-dwarf4-64.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-clang-dwarf5-32.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr: 0x0}
+ location (exprloc) {addr: 0x4}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-clang-dwarf5-32.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr: 0x0}
+ location (exprloc) {addr: 0x4}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-gcc-dwarf4-32.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-gcc-dwarf4-64.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-gcc-dwarf5-32.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+testrun ${abs_top_builddir}/tests/varlocs --debug --exprlocs -e testfile-vars-gcc-dwarf5-64.o | grep exprloc > varlocs.out
+diff -u varlocs.out - <<EOF
+ location (exprloc) {addr(0x0)}
+ location (exprloc) {addr(0x4)}
+EOF
+
+exit 0
diff --git a/tests/show-die-info.c b/tests/show-die-info.c
index 34e27a3b..1a3191cd 100644
--- a/tests/show-die-info.c
+++ b/tests/show-die-info.c
@@ -97,7 +97,7 @@ handle (Dwarf *dbg, Dwarf_Die *die, int n)
printf ("%*s Attrs :", n * 5, "");
for (cnt = 0; cnt < 0xffff; ++cnt)
if (dwarf_hasattr (die, cnt))
- printf (" %s", dwarf_attr_string (cnt));
+ printf (" %s", dwarf_attr_string (cnt) ?: "<unknown>");
puts ("");
if (dwarf_hasattr (die, DW_AT_low_pc) && dwarf_lowpc (die, &addr) == 0)
diff --git a/tests/testfile-dwarf5-fat-lto.o.bz2 b/tests/testfile-dwarf5-fat-lto.o.bz2
new file mode 100644
index 00000000..ce3659f4
--- /dev/null
+++ b/tests/testfile-dwarf5-fat-lto.o.bz2
Binary files differ
diff --git a/tests/testfile-largealign.o.bz2 b/tests/testfile-largealign.o.bz2
new file mode 100644
index 00000000..324c1eae
--- /dev/null
+++ b/tests/testfile-largealign.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-clang-dwarf4-32.o.bz2 b/tests/testfile-vars-clang-dwarf4-32.o.bz2
new file mode 100644
index 00000000..c1ddf81f
--- /dev/null
+++ b/tests/testfile-vars-clang-dwarf4-32.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-clang-dwarf4-64.o.bz2 b/tests/testfile-vars-clang-dwarf4-64.o.bz2
new file mode 100644
index 00000000..df33299f
--- /dev/null
+++ b/tests/testfile-vars-clang-dwarf4-64.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-clang-dwarf5-32.o.bz2 b/tests/testfile-vars-clang-dwarf5-32.o.bz2
new file mode 100644
index 00000000..b1d6b6c4
--- /dev/null
+++ b/tests/testfile-vars-clang-dwarf5-32.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-clang-dwarf5-64.o.bz2 b/tests/testfile-vars-clang-dwarf5-64.o.bz2
new file mode 100644
index 00000000..adf6c6a5
--- /dev/null
+++ b/tests/testfile-vars-clang-dwarf5-64.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-gcc-dwarf4-32.o.bz2 b/tests/testfile-vars-gcc-dwarf4-32.o.bz2
new file mode 100644
index 00000000..da9aac73
--- /dev/null
+++ b/tests/testfile-vars-gcc-dwarf4-32.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-gcc-dwarf4-64.o.bz2 b/tests/testfile-vars-gcc-dwarf4-64.o.bz2
new file mode 100644
index 00000000..26421644
--- /dev/null
+++ b/tests/testfile-vars-gcc-dwarf4-64.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-gcc-dwarf5-32.o.bz2 b/tests/testfile-vars-gcc-dwarf5-32.o.bz2
new file mode 100644
index 00000000..cb1c7054
--- /dev/null
+++ b/tests/testfile-vars-gcc-dwarf5-32.o.bz2
Binary files differ
diff --git a/tests/testfile-vars-gcc-dwarf5-64.o.bz2 b/tests/testfile-vars-gcc-dwarf5-64.o.bz2
new file mode 100644
index 00000000..e286f8f7
--- /dev/null
+++ b/tests/testfile-vars-gcc-dwarf5-64.o.bz2
Binary files differ
diff --git a/tests/testfile_multi_noline.bz2 b/tests/testfile_multi_noline.bz2
new file mode 100755
index 00000000..39320d1f
--- /dev/null
+++ b/tests/testfile_multi_noline.bz2
Binary files differ
diff --git a/tests/testfile_nvidia_linemap.bz2 b/tests/testfile_nvidia_linemap.bz2
new file mode 100644
index 00000000..8a6d09fb
--- /dev/null
+++ b/tests/testfile_nvidia_linemap.bz2
Binary files differ
diff --git a/tests/varlocs.c b/tests/varlocs.c
index 152c6555..d2c13767 100644
--- a/tests/varlocs.c
+++ b/tests/varlocs.c
@@ -76,7 +76,7 @@ dwarf_encoding_string (unsigned int code)
if (likely (code < sizeof (known) / sizeof (known[0])))
return known[code];
- return NULL;
+ return "<unknown encoding>";
}
static const char *
@@ -88,7 +88,7 @@ dwarf_tag_string (unsigned int tag)
DWARF_ALL_KNOWN_DW_TAG
#undef DWARF_ONE_KNOWN_DW_TAG
default:
- return NULL;
+ return "<unknown tag>";
}
}
@@ -101,7 +101,7 @@ dwarf_attr_string (unsigned int attrnum)
DWARF_ALL_KNOWN_DW_AT
#undef DWARF_ONE_KNOWN_DW_AT
default:
- return NULL;
+ return "<unknown attr>";
}
}
@@ -114,7 +114,7 @@ dwarf_form_string (unsigned int form)
DWARF_ALL_KNOWN_DW_FORM
#undef DWARF_ONE_KNOWN_DW_FORM
default:
- return NULL;
+ return "<unknown form>";
}
}
@@ -160,7 +160,7 @@ dwarf_opcode_string (unsigned int code)
if (likely (code < sizeof (known) / sizeof (known[0])))
return known[code];
- return NULL;
+ return "<unknown opcode>";
}
// Forward reference for print_expr_block.
@@ -198,7 +198,6 @@ print_expr (Dwarf_Attribute *attr, Dwarf_Op *expr, Dwarf_Addr addr, int depth)
uint8_t atom = expr->atom;
const char *opname = dwarf_opcode_string (atom);
- assert (opname != NULL);
switch (atom)
{