diff options
Diffstat (limited to 'tests')
51 files changed, 1310 insertions, 53 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog index 99f9da9d..57fc4c8e 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,151 @@ +2020-10-31 Mark Wielaard <mark@klomp.org> + + * dwfl-proc-attach.c (dlopen): New external function override. + +2020-10-31 Mark Wielaard <mark@klomp.org> + + * test-wrapper.sh: Use =, not == for string compare. + +2020-10-29 Mark Wielaard <mark@klomp.org> + + * test-wrapper.sh: Determine whether the test is a script or not + and run binaries directly under valgrind. + * dwfl-bug-fd-leak.c (main): Call getrlimit before calling setrlimit. + * dwfl-proc-attach.c (main): Call dwfl_end, pthread_cancel and + pthread_join. + * vdsosyms.c (main): Call dwfl_end. + +2020-10-31 Frank Ch. Eigler <fche@redhat.com> + + * run-debuginfod-find.sh: Modify for tweaked/new metrics. + +2020-10-30 Frank Ch. Eigler <fche@redhat.com> + + PR26775 + * run-debuginfod-find.sh: Modify test for restored + thread_work_total semantics for grooming. + +2020-10-29 Frank Ch. Eigler <fche@redhat.com> + + PR26775 + * run-debuginfod-find.sh: Modify test for different + thread_work_total semantics for grooming. + +2020-10-29 Frank Ch. Eigler <fche@redhat.com> + + PR26810 + * run-debuginfod-find.sh: Add tests for successful archive fetches across + renamed RPMs, even without grooming. + +2020-10-25 Mark Wielaard <mark@klomp.org> + + * read_unaligned.c: New test. + * Makefile.am (check_PROGRAMS, TESTS): Add read_unaligned. + (read_unaligned_LDADD): New variable. + +2020-10-28 Tom Tromey <tom@tromey.com> + + PR26773 + * Makefile.am (check_PROGRAMS, TESTS): Add leb128. + (leb128_LDADD): New variable. + * leb128.c: New file. + +2020-10-19 Mark Wielaard <mark@klomp.org> + + * addrcfi.c (print_register): Make ops_mem 3 elements. + +2020-10-19 Mark Wielaard <mark@klomp.org> + + * testfile60.bz2: Removed. + * Makefile.am (EXTRA_DIST): Remove testfile60.bz2. + * run-allregs.sh: Remove tilegx testfile60 testcase. + +2020-10-20 Frank Ch. Eigler <fche@redhat.com> + + PR26756: more prometheus metrics + * run-debuginfod-find.sh: Trigger some errors with dummy "nothing.rpm" + and check for new metrics. + +2020-09-18 Mark Wielaard <mark@klomp.org> + + * run-readelf-compressed-zstd.sh: New test. + * Makefile.am (EXTRA_DISTS): Add run-readelf-compressed-zstd.sh. + (TESTS): Add run-readelf-compressed-zstd.sh if HAVE_ZSTD. + +2020-09-03 Mark Wielaard <mark@klomp.org> + + * run-readelf-frames.sh: New test. + * Makefile.am (TESTS): Add run-readelf-frames.sh. + (EXTRA_DIST): Likewise. + +2020-09-03 Mark Wielaard <mark@klomp.org> + + * testfile-gnu-property-note-aarch64.bz2: New file. + * run-readelf-n.sh: Handle testfile-gnu-property-note-aarch64. + * Makefile.am (EXTRA_DIST): Add + testfile-gnu-property-note-aarch64.bz2. + +2020-07-19 Mark Wielaard <mark@klomp.org> + + * asm-tst1.c: Include libebl.h after libasm.h. + * asm-tst2.c: Likewise. + * asm-tst3.c: Likewise. + * asm-tst4.c: Likewise. + * asm-tst5.c: Likewise. + * asm-tst6.c: Likewise. + * asm-tst7.c: Likewise. + * asm-tst8.c: Likewise. + * asm-tst9.c: Likewise. + +2020-07-05 Mark Wielaard <mark@klomp.org> + + * run-test-includes.sh: New test. + * Makefile.am (TESTS): Add run-test-includes.sh. + (EXTRA_DIST): Likewise. + +2020-07-03 Alice Zhang <alizhang@redhat.com> + + * run-debuginfod-find.sh: Add scheme free url testcase. + +2020-06-19 Mark Wielaard <mark@klomp.org> + + * Makefile.am (TESTS): Don't add run-debuginfod-find.sh when + DUMMY_LIBDEBUGINFOD. + +2020-06-16 Mark Wielaard <mark@klomp.org> + + * coverage.sh: Use /usr/bin/env bash. + * run-ar.sh: Likewise. + * run-backtrace-core-aarch64.sh: Likewise. + * run-backtrace-core-i386.sh: Likewise. + * run-backtrace-core-ppc.sh: Likewise. + * run-backtrace-core-s390.sh: Likewise. + * run-backtrace-core-s390x.sh: Likewise. + * run-backtrace-core-sparc.sh: Likewise. + * run-backtrace-core-x32.sh: Likewise. + * run-backtrace-core-x86_64.sh: Likewise. + * run-backtrace-data.sh: Likewise. + * run-backtrace-demangle.sh: Likewise. + * run-backtrace-dwarf.sh: Likewise. + * run-backtrace-fp-core-aarch64.sh: Likewise. + * run-backtrace-fp-core-i386.sh: Likewise. + * run-backtrace-fp-core-ppc64le.sh: Likewise. + * run-backtrace-fp-core-x86_64.sh: Likewise. + * run-backtrace-native-biarch.sh: Likewise. + * run-backtrace-native-core-biarch.sh: Likewise. + * run-backtrace-native-core.sh: Likewise. + * run-backtrace-native.sh: Likewise. + * run-debuginfod-find.sh: Likewise. + * run-deleted.sh: Likewise. + * run-dwelf_elf_e_machine_string.sh: Likewise. + * run-large-elf-file.sh: Likewise. + * run-lfs-symbols.sh: Likewise. + * run-linkmap-cut.sh: Likewise. + +2020-06-11 Mark Wielaard <mark@klomp.org> + + * Makefile.am (nlist-test): Add GCOV flags when necessary. + 2020-06-06 Mark Wielaard <mark@klomp.org> * testfilesyms32.bz2: New test file. diff --git a/tests/Makefile.am b/tests/Makefile.am index fa4999df..0a776692 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -63,7 +63,7 @@ check_PROGRAMS = arextract arsymtest newfile saridx scnnames sectiondump \ all-dwarf-ranges unit-info next_cfi \ elfcopy addsections xlate_notes elfrdwrnop \ dwelf_elf_e_machine_string \ - getphdrnum + getphdrnum leb128 read_unaligned asm_TESTS = asm-tst1 asm-tst2 asm-tst3 asm-tst4 asm-tst5 \ asm-tst6 asm-tst7 asm-tst8 asm-tst9 @@ -80,13 +80,19 @@ backtrace-child-biarch$(EXEEXT): backtrace-child.c $(AM_LDFLAGS) $(LDFLAGS) $(backtrace_child_LDFLAGS) \ -o $@ $< +if GCOV +GCOV_FLAGS=-fprofile-arcs -ftest-coverage +else +GCOV_FLAGS= +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 test-nlist$(EXEEXT): test-nlist.c $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(test_nlist_CFLAGS) $(test_nlist_LDADD) -o $@ $< + $(test_nlist_CFLAGS) $(GCOV_FLAGS) -o $@ $< $(test_nlist_LDADD) TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ update1 update2 update3 update4 \ @@ -118,6 +124,7 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-readelf-test4.sh run-readelf-twofiles.sh \ run-readelf-macro.sh run-readelf-loc.sh run-readelf-ranges.sh \ run-readelf-aranges.sh run-readelf-line.sh run-readelf-z.sh \ + run-readelf-frames.sh \ run-readelf-n.sh \ run-native-test.sh run-bug1-test.sh \ run-debuglink.sh run-debugaltlink.sh run-buildid.sh \ @@ -176,7 +183,8 @@ TESTS = run-arextract.sh run-arsymtest.sh run-ar.sh newfile test-nlist \ run-dwelf_elf_e_machine_string.sh \ run-elfclassify.sh run-elfclassify-self.sh \ run-pt_gnu_prop-tests.sh \ - run-getphdrnum.sh + run-getphdrnum.sh run-test-includes.sh \ + leb128 read_unaligned if !BIARCH export ELFUTILS_DISABLE_BIARCH = 1 @@ -195,6 +203,10 @@ if LZMA TESTS += run-readelf-s.sh run-dwflsyms.sh endif +if HAVE_ZSTD +TESTS += run-readelf-compressed-zstd.sh +endif + if HAVE_LIBASM check_PROGRAMS += $(asm_TESTS) TESTS += $(asm_TESTS) run-disasm-bpf.sh @@ -202,8 +214,11 @@ endif if DEBUGINFOD check_PROGRAMS += debuginfod_build_id_find +# With the dummy delegation doesn't work +if !DUMMY_LIBDEBUGINFOD TESTS += run-debuginfod-find.sh endif +endif EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-show-die-info.sh run-get-files.sh run-get-lines.sh \ @@ -244,6 +259,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-nm-syms.sh testfilesyms32.bz2 testfilesyms64.bz2 \ run-nm-self.sh run-readelf-self.sh run-readelf-info-plus.sh \ run-readelf-compressed.sh \ + run-readelf-compressed-zstd.sh \ run-readelf-const-values.sh testfile-const-values.debug.bz2 \ run-addrcfi.sh run-dwarfcfi.sh \ testfile11-debugframe.bz2 testfile12-debugframe.bz2 \ @@ -302,12 +318,14 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfile-dwzstr.bz2 testfile-dwzstr.multi.bz2 \ run-readelf-addr.sh run-readelf-str.sh \ run-readelf-types.sh \ + run-readelf-frames.sh \ run-readelf-n.sh \ testfile-gnu-property-note.bz2 testfile-gnu-property-note.o.bz2 \ testfile_gnu_props.32le.o.bz2 \ testfile_gnu_props.64le.o.bz2 \ testfile_gnu_props.32be.o.bz2 \ testfile_gnu_props.64be.o.bz2 \ + testfile-gnu-property-note-aarch64.bz2 \ run-allfcts-multi.sh \ test-offset-loop.bz2 test-offset-loop.alt.bz2 \ run-prelink-addr-test.sh \ @@ -348,7 +366,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ run-macro-test.sh testfile-macinfo.bz2 testfile-macros.bz2 \ run-elf_cntl_gelf_getshdr.sh \ run-test-archive64.sh testarchive64.a.bz2 \ - testfile60.bz2 testfile61.bz2 \ + testfile61.bz2 \ run-readelf-vmcoreinfo.sh testfile62.bz2 \ run-readelf-mixed-corenote.sh testfile63.bz2 testfile64.bz2 \ testfile65.bz2 testfile67.bz2 testfile68.bz2 \ @@ -494,7 +512,8 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ debuginfod-tars/pacman-sources/hello.c \ run-pt_gnu_prop-tests.sh \ testfile_pt_gnu_prop.bz2 testfile_pt_gnu_prop32.bz2 \ - run-getphdrnum.sh testfile-phdrs.elf.bz2 + run-getphdrnum.sh testfile-phdrs.elf.bz2 \ + run-test-includes.sh if USE_VALGRIND @@ -675,6 +694,8 @@ xlate_notes_LDADD = $(libelf) elfrdwrnop_LDADD = $(libelf) dwelf_elf_e_machine_string_LDADD = $(libelf) $(libdw) getphdrnum_LDADD = $(libelf) $(libdw) +leb128_LDADD = $(libelf) $(libdw) +read_unaligned_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/addrcfi.c b/tests/addrcfi.c index 589b8513..2b7d7bd0 100644 --- a/tests/addrcfi.c +++ b/tests/addrcfi.c @@ -92,7 +92,7 @@ print_register (void *arg, printf ("\t%s reg%u (%s%s): ", setname, regno, prefix, regname); - Dwarf_Op ops_mem[2]; + Dwarf_Op ops_mem[3]; Dwarf_Op *ops; size_t nops; int result = dwarf_frame_register (stuff->frame, regno, ops_mem, &ops, &nops); diff --git a/tests/asm-tst1.c b/tests/asm-tst1.c index cdf2a921..d03a4361 100644 --- a/tests/asm-tst1.c +++ b/tests/asm-tst1.c @@ -20,8 +20,8 @@ #endif #include <fcntl.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <string.h> diff --git a/tests/asm-tst2.c b/tests/asm-tst2.c index 9e88b70c..e65a9d2f 100644 --- a/tests/asm-tst2.c +++ b/tests/asm-tst2.c @@ -20,8 +20,8 @@ #endif #include <fcntl.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <string.h> diff --git a/tests/asm-tst3.c b/tests/asm-tst3.c index 39c1d90c..e45fa16a 100644 --- a/tests/asm-tst3.c +++ b/tests/asm-tst3.c @@ -20,8 +20,8 @@ #endif #include <fcntl.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <string.h> diff --git a/tests/asm-tst4.c b/tests/asm-tst4.c index 5114938b..1a05bfcc 100644 --- a/tests/asm-tst4.c +++ b/tests/asm-tst4.c @@ -20,8 +20,8 @@ #endif #include <fcntl.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <stdlib.h> diff --git a/tests/asm-tst5.c b/tests/asm-tst5.c index dcb852f8..256873f0 100644 --- a/tests/asm-tst5.c +++ b/tests/asm-tst5.c @@ -20,8 +20,8 @@ #endif #include <fcntl.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <stdlib.h> diff --git a/tests/asm-tst6.c b/tests/asm-tst6.c index 829cd90c..4a665ed0 100644 --- a/tests/asm-tst6.c +++ b/tests/asm-tst6.c @@ -19,8 +19,8 @@ # include <config.h> #endif -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <stdlib.h> diff --git a/tests/asm-tst7.c b/tests/asm-tst7.c index 90179769..87c21485 100644 --- a/tests/asm-tst7.c +++ b/tests/asm-tst7.c @@ -21,8 +21,8 @@ #include <fcntl.h> #include <inttypes.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <unistd.h> diff --git a/tests/asm-tst8.c b/tests/asm-tst8.c index a65509fe..7dbac10f 100644 --- a/tests/asm-tst8.c +++ b/tests/asm-tst8.c @@ -21,8 +21,8 @@ #include <fcntl.h> #include <inttypes.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <unistd.h> diff --git a/tests/asm-tst9.c b/tests/asm-tst9.c index 681e872d..6bec3f6e 100644 --- a/tests/asm-tst9.c +++ b/tests/asm-tst9.c @@ -21,8 +21,8 @@ #include <fcntl.h> #include <inttypes.h> -#include ELFUTILS_HEADER(ebl) #include ELFUTILS_HEADER(asm) +#include ELFUTILS_HEADER(ebl) #include <libelf.h> #include <stdio.h> #include <string.h> diff --git a/tests/coverage.sh b/tests/coverage.sh index 01d292cc..448d43ba 100755 --- a/tests/coverage.sh +++ b/tests/coverage.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash if [ "x$1" = "x-v" ]; then verbose=yes diff --git a/tests/dwfl-bug-fd-leak.c b/tests/dwfl-bug-fd-leak.c index ee3a916b..b0913361 100644 --- a/tests/dwfl-bug-fd-leak.c +++ b/tests/dwfl-bug-fd-leak.c @@ -101,7 +101,14 @@ main (void) /* Set locale. */ (void) setlocale (LC_ALL, ""); - struct rlimit fd_limit = { .rlim_cur = 32, .rlim_max = 32 }; + /* Get both the soft and hard limits first. The soft limit is what + will be enforced against the process. The hard limit is the max + that can be set for the soft limit. We don't want to lower it + because we might not be able to (under valgrind). */ + struct rlimit fd_limit; + if (getrlimit (RLIMIT_NOFILE, &fd_limit) < 0) + error (2, errno, "getrlimit"); + fd_limit.rlim_cur = 32; if (setrlimit (RLIMIT_NOFILE, &fd_limit) < 0) error (2, errno, "setrlimit"); diff --git a/tests/dwfl-proc-attach.c b/tests/dwfl-proc-attach.c index 102ba181..d02e9fc0 100644 --- a/tests/dwfl-proc-attach.c +++ b/tests/dwfl-proc-attach.c @@ -97,7 +97,26 @@ main (int argc __attribute__ ((unused)), if (dwfl_getthreads (dwfl, thread_callback, &threads) != DWARF_CB_OK) error (-1, 0, "dwfl_getthreads failed: %s", dwfl_errmsg (-1)); + dwfl_end (dwfl); + + pthread_cancel (thread1); + pthread_cancel (thread2); + pthread_join (thread1, NULL); + pthread_join (thread2, NULL); + return (threads == 3) ? 0 : -1; } +/* HACK. This is a simple workaround for a combination of old glibc + and valgrind. libdw will try to dlopen libdebuginfod this causes + some unsuppressable memory leak warnings when the process is + multi-threaded under valgrind because of some bad backtraces. + So simply override dlopen and always return NULL so libdebuginfod + (and libcurl) are never loaded. This test doesn't rely on + libdebuginfod anyway. */ +void *dlopen (void) +{ + return NULL; +} + #endif /* __linux__ */ diff --git a/tests/leb128.c b/tests/leb128.c new file mode 100644 index 00000000..47b57c0d --- /dev/null +++ b/tests/leb128.c @@ -0,0 +1,173 @@ +/* Test program for leb128 + Copyright (C) 2020 Tom Tromey + 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/>. */ + +#include <config.h> +#include <stddef.h> +#include <stdbool.h> +#include <stdint.h> +#include <libdw.h> +#include "../libdw/libdwP.h" +#include "../libdw/memory-access.h" + +#define OK 0 +#define FAIL 1 + +static const unsigned char v0[] = { 0x0 }; +static const unsigned char v1[] = { 0x1 }; +static const unsigned char v23[] = { 23 }; +static const unsigned char vm_1[] = { 0x7f }; +static const unsigned char vm_2[] = { 0x7e }; +static const unsigned char s127[] = { 0xff, 0x00 }; +static const unsigned char v128[] = { 0x80, 0x01 }; +static const unsigned char v129[] = { 0x81, 0x01 }; +static const unsigned char vm_127[] = { 0x81, 0x7f }; +static const unsigned char vm_128[] = { 0x80, 0x7f }; +static const unsigned char vm_129[] = { 0xff, 0x7e }; +static const unsigned char vhuge[] = + { + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x0 + }; +static const unsigned char most_positive[] = + { + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x3f + }; +static const unsigned char most_negative[] = + { + 0x80, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x40 + }; +static const unsigned char minus_one[] = + { + 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0x7f + }; +static const unsigned char int64_max_m1[] = + { + 0xfe, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0x00 + }; +static const unsigned char int64_min_p1[] = + { + 0x81, 0x80, 0x80, 0x80, 0x80, + 0x80, 0x80, 0x80, 0x80, 0x7f + }; + +static int +test_one_sleb (const unsigned char *data, size_t len, int64_t expect) +{ + int64_t value; + const unsigned char *p; + + p = data; + get_sleb128 (value, p, p + len); + if (value != expect || p != data + len) + return FAIL; + + p = data; + get_sleb128_unchecked (value, p); + if (value != expect || p != data + len) + return FAIL; + + return OK; +} + +static int +test_sleb (void) +{ +#define TEST(ARRAY, V) \ + if (test_one_sleb (ARRAY, sizeof (ARRAY), V) != OK) \ + return FAIL; + + TEST (v0, 0); + TEST (v1, 1); + TEST (v23, 23); + TEST (vm_1, -1); + TEST (vm_2, -2); + TEST (s127, 127); + TEST (v128, 128); + TEST (v129, 129); + TEST (vm_127, -127); + TEST (vm_128, -128); + TEST (vm_129, -129); + TEST (vhuge, 9223372036854775807ll); + TEST (most_positive, 4611686018427387903ll); + TEST (most_negative, -4611686018427387904ll); + TEST (minus_one, -1); + TEST (int64_max_m1, INT64_MAX - 1); + TEST (int64_min_p1, INT64_MIN + 1); + +#undef TEST + + return OK; +} + +static int +test_one_uleb (const unsigned char *data, size_t len, uint64_t expect) +{ + uint64_t value; + const unsigned char *p; + + p = data; + get_uleb128 (value, p, p + len); + if (value != expect || p != data + len) + return FAIL; + + p = data; + get_uleb128_unchecked (value, p); + if (value != expect || p != data + len) + return FAIL; + + return OK; +} + +static int +test_uleb (void) +{ +#define TEST(ARRAY, V) \ + if (test_one_uleb (ARRAY, sizeof (ARRAY), V) != OK) \ + return FAIL; + + TEST (v0, 0); + TEST (v1, 1); + TEST (v23, 23); + TEST (vm_1, 127); + TEST (vm_2, 126); + TEST (s127, 127); + TEST (v128, 128); + TEST (v129, 129); + TEST (vm_127, 16257); + TEST (vm_128, 16256); + TEST (vm_129, 16255); + TEST (vhuge, 9223372036854775807ull); + TEST (most_positive, 4611686018427387903ull); + TEST (most_negative, 4611686018427387904ull); + TEST (minus_one, 9223372036854775807ull); + TEST (int64_max_m1, INT64_MAX - 1); + TEST (int64_min_p1, INT64_MIN + 1); + +#undef TEST + + return OK; +} + +int +main (void) +{ + return test_sleb () || test_uleb (); +} diff --git a/tests/read_unaligned.c b/tests/read_unaligned.c new file mode 100644 index 00000000..15e0c002 --- /dev/null +++ b/tests/read_unaligned.c @@ -0,0 +1,564 @@ +/* Test program for read_[type]_unaligned. + Copyright (C) 2020, 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/>. */ + +#include <assert.h> +#include <endian.h> +#include <inttypes.h> +#include <stdbool.h> +#include <stdint.h> +#include <stdio.h> + +#include "../libdw/libdwP.h" +#include "../libdw/memory-access.h" + +union u8 +{ + uint8_t v; + unsigned char c[1]; +}; + +union s8 +{ + int8_t v; + unsigned char c[1]; +}; + +union u16 +{ + uint16_t v; + unsigned char c[2]; +}; + +union s16 +{ + int16_t v; + unsigned char c[2]; +}; + +union u24 +{ + uint32_t v:24; + unsigned char c[3]; +} __attribute__((packed)); + +union u32 +{ + uint32_t v; + unsigned char c[4]; +}; + +union s32 +{ + int32_t v; + unsigned char c[4]; +}; + +union u64 +{ + uint64_t v; + unsigned char c[8]; +}; + +union s64 +{ + uint64_t v; + unsigned char c[8]; +}; + +uint8_t u8_nums[] = + { + 0, + 1, + UINT8_MAX / 2 - 1, + UINT8_MAX / 2, + UINT8_MAX / 2 + 1, + UINT8_MAX, + UINT8_MAX -1 + }; + +int8_t s8_nums[] = + { + INT8_MIN, + INT8_MIN + 1, + -1, + 0, + 1, + INT8_MAX, + INT8_MAX - 1 + }; + +uint16_t u16_nums[] = + { + 0, + 1, + UINT16_MAX / 2 - 1, + UINT16_MAX / 2, + UINT16_MAX / 2 + 1, + UINT16_MAX, + UINT16_MAX -1 + }; + +int16_t s16_nums[] = + { + INT16_MIN, + INT16_MIN + 1, + -1, + 0, + 1, + INT16_MAX, + INT16_MAX - 1 + }; + +#define UINT24_MAX 0xffffff + +uint32_t u24_nums[] = + { + 0, + 1, + UINT24_MAX / 2 - 1, + UINT24_MAX / 2, + UINT24_MAX / 2 + 1, + UINT24_MAX, + UINT24_MAX -1 + }; + +uint32_t u32_nums[] = + { + 0, + 1, + UINT32_MAX / 2 - 1, + UINT32_MAX / 2, + UINT32_MAX / 2 + 1, + UINT32_MAX, + UINT32_MAX -1 + }; + +int32_t s32_nums[] = + { + INT32_MIN, + INT32_MIN + 1, + -1, + 0, + 1, + INT32_MAX, + INT32_MAX - 1 + }; + +uint64_t u64_nums[] = + { + 0, + 1, + UINT64_MAX / 2 - 1, + UINT64_MAX / 2, + UINT64_MAX / 2 + 1, + UINT64_MAX, + UINT64_MAX -1 + }; + +int64_t s64_nums[] = + { + INT64_MIN, + INT64_MIN + 1, + -1, + 0, + 1, + INT64_MAX, + INT64_MAX - 1 + }; + +static unsigned char le_mem[] = + { + /* u8 */ + 0x00, + 0x01, + 0x7e, + 0x7f, + 0x80, + 0xff, + 0xfe, + /* s8 */ + 0x80, + 0x81, + 0xff, + 0x00, + 0x01, + 0x7f, + 0x7e, + /* u16 */ + 0x00, 0x00, + 0x01, 0x00, + 0xfe, 0x7f, + 0xff, 0x7f, + 0x00, 0x80, + 0xff, 0xff, + 0xfe, 0xff, + /* s16 */ + 0x00, 0x80, + 0x01, 0x80, + 0xff, 0xff, + 0x00, 0x00, + 0x01, 0x00, + 0xff, 0x7f, + 0xfe, 0x7f, + /* u24 */ + 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, + 0xfe, 0xff, 0x7f, + 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, + 0xfe, 0xff, 0xff, + /* u32 */ + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, + 0xfe, 0xff, 0xff, 0x7f, + 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, + 0xfe, 0xff, 0xff, 0xff, + /* s32 */ + 0x00, 0x00, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0x7f, + 0xfe, 0xff, 0xff, 0x7f, + /* u64 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + /* s64 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, + }; + +static unsigned char be_mem[] = + { + /* u8 */ + 0x00, + 0x01, + 0x7e, + 0x7f, + 0x80, + 0xff, + 0xfe, + /* s8 */ + 0x80, + 0x81, + 0xff, + 0x00, + 0x01, + 0x7f, + 0x7e, + /* u16 */ + 0x00, 0x00, + 0x00, 0x01, + 0x7f, 0xfe, + 0x7f, 0xff, + 0x80, 0x00, + 0xff, 0xff, + 0xff, 0xfe, + /* s16 */ + 0x80, 0x00, + 0x80, 0x01, + 0xff, 0xff, + 0x00, 0x00, + 0x00, 0x01, + 0x7f, 0xff, + 0x7f, 0xfe, + /* u24 */ + 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, + 0x7f, 0xff, 0xfe, + 0x7f, 0xff, 0xff, + 0x80, 0x00, 0x00, + 0xff, 0xff, 0xff, + 0xff, 0xff, 0xfe, + /* u32 */ + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x7f, 0xff, 0xff, 0xfe, + 0x7f, 0xff, 0xff, 0xff, + 0x80, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xfe, + /* s32 */ + 0x80, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x01, + 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, + 0x7f, 0xff, 0xff, 0xff, + 0x7f, 0xff, 0xff, 0xfe, + /* u64 */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, + 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, + /* s64 */ + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, + }; + +int +main (int argc, char **argv __attribute__((unused))) +{ + /* No arguments means check, otherwise Write out the memory array. */ + bool write = false; + if (argc > 1) + write = true; + + bool is_le = (BYTE_ORDER == LITTLE_ENDIAN); + + if (write) + { + if (is_le) + printf ("static unsigned char le_mem[] =\n"); + else + printf ("static unsigned char be_mem[] =\n"); + printf (" {\n"); + } + + Dwarf dbg_le = { .other_byte_order = !is_le }; + Dwarf dbg_be = { .other_byte_order = is_le }; + + unsigned char *p_le = le_mem; + unsigned char *p_be = be_mem; + + union u8 u8; + if (write) + printf (" /* u8 */\n"); + for (size_t i = 0; i < sizeof (u8_nums) / sizeof (u8); i++) + { + if (write) + { + u8.v = u8_nums[i]; + printf (" 0x%02" PRIx8 ",\n", u8.c[0]); + } + else + { + uint8_t v = *p_le++; + assert (v == u8_nums[i]); + v = *p_be++; + assert (v == u8_nums[i]); + } + } + + union s8 s8; + if (write) + printf (" /* s8 */\n"); + for (size_t i = 0; i < sizeof (s8_nums) / sizeof (s8); i++) + { + if (write) + { + s8.v = s8_nums[i]; + printf (" 0x%02" PRIx8 ",\n", s8.c[0]); + } + else + { + int8_t v = *p_le++; + assert (v == s8_nums[i]); + v = *p_be++; + assert (v == s8_nums[i]); + } + } + + union u16 u16; + if (write) + printf (" /* u16 */\n"); + for (size_t i = 0; i < sizeof (u16_nums) / sizeof (u16); i++) + { + if (write) + { + u16.v = u16_nums[i]; + printf (" 0x%02" PRIx8 ", ", u16.c[0]); + printf ("0x%02" PRIx8 ",\n", u16.c[1]); + } + else + { + uint16_t v = read_2ubyte_unaligned_inc (&dbg_le, p_le); + assert (v == u16_nums[i]); + v = read_2ubyte_unaligned_inc (&dbg_be, p_be); + assert (v == u16_nums[i]); + } + } + + union s16 s16; + if (write) + printf (" /* s16 */\n"); + for (size_t i = 0; i < sizeof (s16_nums) / sizeof (s16); i++) + { + if (write) + { + s16.v = s16_nums[i]; + printf (" 0x%02" PRIx8 ", ", s16.c[0]); + printf ("0x%02" PRIx8 ",\n", s16.c[1]); + } + else + { + int16_t v = read_2sbyte_unaligned_inc (&dbg_le, p_le); + assert (v == s16_nums[i]); + v = read_2sbyte_unaligned_inc (&dbg_be, p_be); + assert (v == s16_nums[i]); + } + } + + union u24 u24; + if (write) + printf (" /* u24 */\n"); + for (size_t i = 0; i < sizeof (u24_nums) / sizeof (uint32_t); i++) + { + if (write) + { + u24.v = u24_nums[i]; + printf (" 0x%02" PRIx8 ", ", u24.c[0]); + printf ("0x%02" PRIx8 ", ", u24.c[1]); + printf ("0x%02" PRIx8 ",\n", u24.c[2]); + } + else + { + uint32_t v = read_3ubyte_unaligned_inc (&dbg_le, p_le); + assert (v == u24_nums[i]); + v = read_3ubyte_unaligned_inc (&dbg_be, p_be); + assert (v == u24_nums[i]); + } + } + + union u32 u32; + if (write) + printf (" /* u32 */\n"); + for (size_t i = 0; i < sizeof (u32_nums) / sizeof (u32); i++) + { + if (write) + { + u32.v = u32_nums[i]; + printf (" 0x%02" PRIx8 ", ", u32.c[0]); + printf ("0x%02" PRIx8 ", ", u32.c[1]); + printf ("0x%02" PRIx8 ", ", u32.c[2]); + printf ("0x%02" PRIx8 ",\n", u32.c[3]); + } + else + { + uint32_t v = read_4ubyte_unaligned_inc (&dbg_le, p_le); + assert (v == u32_nums[i]); + v = read_4ubyte_unaligned_inc (&dbg_be, p_be); + assert (v == u32_nums[i]); + } + } + + union s32 s32; + if (write) + printf (" /* s32 */\n"); + for (size_t i = 0; i < sizeof (s32_nums) / sizeof (s32); i++) + { + if (write) + { + s32.v = s32_nums[i]; + printf (" 0x%02" PRIx8 ", ", s32.c[0]); + printf ("0x%02" PRIx8 ", ", s32.c[1]); + printf ("0x%02" PRIx8 ", ", s32.c[2]); + printf ("0x%02" PRIx8 ",\n", s32.c[3]); + } + else + { + int32_t v = read_4sbyte_unaligned_inc (&dbg_le, p_le); + assert (v == s32_nums[i]); + v = read_4sbyte_unaligned_inc (&dbg_be, p_be); + assert (v == s32_nums[i]); + } + } + + union u64 u64; + if (write) + printf (" /* u64 */\n"); + for (size_t i = 0; i < sizeof (u64_nums) / sizeof (u64); i++) + { + if (write) + { + u64.v = u64_nums[i]; + printf (" 0x%02" PRIx8 ", ", u64.c[0]); + printf ("0x%02" PRIx8 ", ", u64.c[1]); + printf ("0x%02" PRIx8 ", ", u64.c[2]); + printf ("0x%02" PRIx8 ", ", u64.c[3]); + printf ("0x%02" PRIx8 ", ", u64.c[4]); + printf ("0x%02" PRIx8 ", ", u64.c[5]); + printf ("0x%02" PRIx8 ", ", u64.c[6]); + printf ("0x%02" PRIx8 ",\n", u64.c[7]); + } + else + { + uint64_t v = read_8ubyte_unaligned_inc (&dbg_le, p_le); + assert (v == u64_nums[i]); + v = read_8ubyte_unaligned_inc (&dbg_be, p_be); + assert (v == u64_nums[i]); + } + } + + union s64 s64; + if (write) + printf (" /* s64 */\n"); + for (size_t i = 0; i < sizeof (s64_nums) / sizeof (s64); i++) + { + if (write) + { + s64.v = s64_nums[i]; + printf (" 0x%02" PRIx8 ", ", s64.c[0]); + printf ("0x%02" PRIx8 ", ", s64.c[1]); + printf ("0x%02" PRIx8 ", ", s64.c[2]); + printf ("0x%02" PRIx8 ", ", s64.c[3]); + printf ("0x%02" PRIx8 ", ", s64.c[4]); + printf ("0x%02" PRIx8 ", ", s64.c[5]); + printf ("0x%02" PRIx8 ", ", s64.c[6]); + printf ("0x%02" PRIx8 ",\n", s64.c[7]); + } + else + { + int64_t v = read_8sbyte_unaligned_inc (&dbg_le, p_le); + assert (v == s64_nums[i]); + v = read_8sbyte_unaligned_inc (&dbg_be, p_be); + assert (v == s64_nums[i]); + } + } + + if (write) + printf (" };\n"); + else + { + assert (p_le == le_mem + sizeof (le_mem)); + assert (p_be == be_mem + sizeof (be_mem)); + } + + return 0; +} diff --git a/tests/run-ar.sh b/tests/run-ar.sh index fb9394d5..656f1d1a 100755 --- a/tests/run-ar.sh +++ b/tests/run-ar.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2017 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-aarch64.sh b/tests/run-backtrace-core-aarch64.sh index a29a6613..41221d36 100755 --- a/tests/run-backtrace-core-aarch64.sh +++ b/tests/run-backtrace-core-aarch64.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-i386.sh b/tests/run-backtrace-core-i386.sh index 7294ec3d..c497f4aa 100755 --- a/tests/run-backtrace-core-i386.sh +++ b/tests/run-backtrace-core-i386.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-ppc.sh b/tests/run-backtrace-core-ppc.sh index 555ac352..1a51046c 100755 --- a/tests/run-backtrace-core-ppc.sh +++ b/tests/run-backtrace-core-ppc.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-s390.sh b/tests/run-backtrace-core-s390.sh index d3b6dc9c..ce3afb93 100755 --- a/tests/run-backtrace-core-s390.sh +++ b/tests/run-backtrace-core-s390.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-s390x.sh b/tests/run-backtrace-core-s390x.sh index c3e236d4..39450c14 100755 --- a/tests/run-backtrace-core-s390x.sh +++ b/tests/run-backtrace-core-s390x.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-sparc.sh b/tests/run-backtrace-core-sparc.sh index 60399baa..2f39e745 100755 --- a/tests/run-backtrace-core-sparc.sh +++ b/tests/run-backtrace-core-sparc.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2015 Oracle, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-x32.sh b/tests/run-backtrace-core-x32.sh index 2ad76bcf..e6144b35 100755 --- a/tests/run-backtrace-core-x32.sh +++ b/tests/run-backtrace-core-x32.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) H.J. Lu <hjl.tools@gmail.com>, 2015. # This file is part of elfutils. # diff --git a/tests/run-backtrace-core-x86_64.sh b/tests/run-backtrace-core-x86_64.sh index d00cd6d6..49248015 100755 --- a/tests/run-backtrace-core-x86_64.sh +++ b/tests/run-backtrace-core-x86_64.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-data.sh b/tests/run-backtrace-data.sh index 3062c304..f67a43ef 100755 --- a/tests/run-backtrace-data.sh +++ b/tests/run-backtrace-data.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-demangle.sh b/tests/run-backtrace-demangle.sh index 2d253240..403a4852 100755 --- a/tests/run-backtrace-demangle.sh +++ b/tests/run-backtrace-demangle.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2014, 2015 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-dwarf.sh b/tests/run-backtrace-dwarf.sh index 8834048a..7ed795d8 100755 --- a/tests/run-backtrace-dwarf.sh +++ b/tests/run-backtrace-dwarf.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-fp-core-aarch64.sh b/tests/run-backtrace-fp-core-aarch64.sh index fda88d37..397e3c3a 100755 --- a/tests/run-backtrace-fp-core-aarch64.sh +++ b/tests/run-backtrace-fp-core-aarch64.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2017 The Qt Company # This file is part of elfutils. # diff --git a/tests/run-backtrace-fp-core-i386.sh b/tests/run-backtrace-fp-core-i386.sh index c58ff532..43f859fe 100755 --- a/tests/run-backtrace-fp-core-i386.sh +++ b/tests/run-backtrace-fp-core-i386.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2017 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-fp-core-ppc64le.sh b/tests/run-backtrace-fp-core-ppc64le.sh index 326ca342..345b8dbe 100755 --- a/tests/run-backtrace-fp-core-ppc64le.sh +++ b/tests/run-backtrace-fp-core-ppc64le.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2017 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-fp-core-x86_64.sh b/tests/run-backtrace-fp-core-x86_64.sh index 348eb183..12f44c4b 100755 --- a/tests/run-backtrace-fp-core-x86_64.sh +++ b/tests/run-backtrace-fp-core-x86_64.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2017 The Qt Company # This file is part of elfutils. # diff --git a/tests/run-backtrace-native-biarch.sh b/tests/run-backtrace-native-biarch.sh index 2afe38a5..92869830 100755 --- a/tests/run-backtrace-native-biarch.sh +++ b/tests/run-backtrace-native-biarch.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013, 2015 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-native-core-biarch.sh b/tests/run-backtrace-native-core-biarch.sh index 02552ce9..23274257 100755 --- a/tests/run-backtrace-native-core-biarch.sh +++ b/tests/run-backtrace-native-core-biarch.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013, 2015 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-native-core.sh b/tests/run-backtrace-native-core.sh index cb025a56..db95895f 100755 --- a/tests/run-backtrace-native-core.sh +++ b/tests/run-backtrace-native-core.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-backtrace-native.sh b/tests/run-backtrace-native.sh index ddae345d..823c4117 100755 --- a/tests/run-backtrace-native.sh +++ b/tests/run-backtrace-native.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2013 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-debuginfod-find.sh b/tests/run-debuginfod-find.sh index 7faad331..48dbc7d4 100755 --- a/tests/run-debuginfod-find.sh +++ b/tests/run-debuginfod-find.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright (C) 2019-2020 Red Hat, Inc. # This file is part of elfutils. @@ -95,6 +95,10 @@ wait_ready() fi } +# create a 000 empty .rpm file to evoke a metric-visible error +touch R/nothing.rpm +chmod 000 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 -Z .tar.xz -Z .tar.bz2=bzcat -v R F Z L > vlog4 2>&1 & PID1=$! tempfiles vlog4 @@ -240,13 +244,13 @@ fi cp -rvp ${abs_srcdir}/debuginfod-tars Z kill -USR1 $PID1 -# All rpms need to be in the index -rpms=$(find R -name \*rpm | wc -l) -wait_ready $PORT1 'scanned_total{source=".rpm archive"}' $rpms +# 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_total{source=".tar.xz archive"}' $txz +wait_ready $PORT1 'scanned_files_total{source=".tar.xz archive"}' $txz tb2=$(find Z -name \*tar.bz2 | wc -l) -wait_ready $PORT1 'scanned_total{source=".tar.bz2 archive"}' $tb2 +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 :) @@ -255,7 +259,7 @@ kill -USR1 $PID1 # two hits of SIGUSR1 may be needed to resolve .debug->dwz->sr mkdir extracted cd extracted subdir=0; -newrpms=$(find ../R -name \*\.rpm) +newrpms=$(find ../R -name \*\.rpm | grep -v nothing) for i in $newrpms; do subdir=$[$subdir+1]; mkdir $subdir; @@ -341,7 +345,7 @@ RPM_BUILDID=d44d42cbd7d915bc938c81333a21e355a6022fb7 # in rhel6/ subdir, for a l rm -r R/debuginfod-rpms/rhel6/* kill -USR2 $PID1 # groom cycle # Expect 3 rpms to be deleted by the groom -# 1 groom already took place at/soon-after startup, so -USR2 makes 2 +# 1 groom cycle already took place at/soon-after startup, so -USR2 makes 2 wait_ready $PORT1 'thread_work_total{role="groom"}' 2 wait_ready $PORT1 'groom{statistic="file d/e"}' 3 @@ -353,6 +357,38 @@ 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)' vlog4 + +######################################################################## + # Federation mode # find another unused port @@ -383,9 +419,9 @@ if type bsdtar 2>/dev/null; then kill -USR1 $PID2 # All debs need to be in the index debs=$(find D -name \*.deb | wc -l) - wait_ready $PORT2 'scanned_total{source=".deb archive"}' `expr $debs` + wait_ready $PORT2 'scanned_files_total{source=".deb archive"}' `expr $debs` ddebs=$(find D -name \*.ddeb | wc -l) - wait_ready $PORT2 'scanned_total{source=".ddeb archive"}' `expr $ddebs` + wait_ready $PORT2 'scanned_files_total{source=".ddeb archive"}' `expr $ddebs` # ubuntu archive_test f17a29b5a25bd4960531d82aa6b07c8abe84fa66 "" "" @@ -413,6 +449,12 @@ testrun ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo $BUILDID && fal 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 +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 @@ -434,6 +476,10 @@ curl -s http://127.0.0.1:$PORT1/metrics | grep 'http_responses_duration_millisec 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 diff --git a/tests/run-deleted.sh b/tests/run-deleted.sh index 0f647621..a1ec1ecf 100755 --- a/tests/run-deleted.sh +++ b/tests/run-deleted.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2014 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-dwelf_elf_e_machine_string.sh b/tests/run-dwelf_elf_e_machine_string.sh index ba6d0e63..658f229f 100755 --- a/tests/run-dwelf_elf_e_machine_string.sh +++ b/tests/run-dwelf_elf_e_machine_string.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Test to make sure all EM values in elf.h are recognized # Copyright (C) 2019 Red Hat, Inc. # This file is part of elfutils. diff --git a/tests/run-large-elf-file.sh b/tests/run-large-elf-file.sh index cbe30615..667d24d8 100755 --- a/tests/run-large-elf-file.sh +++ b/tests/run-large-elf-file.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2019 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-lfs-symbols.sh b/tests/run-lfs-symbols.sh index b65391b6..7398e7f4 100755 --- a/tests/run-lfs-symbols.sh +++ b/tests/run-lfs-symbols.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2015 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-linkmap-cut.sh b/tests/run-linkmap-cut.sh index de2bc7cc..053b96dc 100755 --- a/tests/run-linkmap-cut.sh +++ b/tests/run-linkmap-cut.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#! /usr/bin/env bash # Copyright (C) 2014 Red Hat, Inc. # This file is part of elfutils. # diff --git a/tests/run-readelf-compressed-zstd.sh b/tests/run-readelf-compressed-zstd.sh new file mode 100755 index 00000000..96208092 --- /dev/null +++ b/tests/run-readelf-compressed-zstd.sh @@ -0,0 +1,39 @@ +#! /bin/sh +# Copyright (C) 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/>. + +. $srcdir/test-subr.sh + +if ! grep -q -F '#define USE_ZSTD' ${abs_top_builddir}/config.h; then + echo "elfutils built without zstd support" + exit 77 +fi + +# See run-strip-reloc.sh +testfiles hello_i386.ko + +tempfiles hello_i386.ko.zst readelf.out.1 readelf.out.2 + +testrun ${abs_top_builddir}/src/readelf -a hello_i386.ko > readelf.out.1 +zstd hello_i386.ko +testrun ${abs_top_builddir}/src/readelf -a hello_i386.ko.zst > readelf.out.2 + +diff -u readelf.out.1 readelf.out.2 +if [ $? != 0 ]; then + exit 1; +fi + +exit 0 diff --git a/tests/run-readelf-frames.sh b/tests/run-readelf-frames.sh new file mode 100755 index 00000000..f0429d19 --- /dev/null +++ b/tests/run-readelf-frames.sh @@ -0,0 +1,173 @@ +#! /bin/sh +# Copyright (C) 2020 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 + +# See run-readelf-n.sh +testfiles testfile-gnu-property-note-aarch64 + +testrun_compare ${abs_top_builddir}/src/readelf --debug-dump=frames testfile-gnu-property-note-aarch64 <<\EOF + +Call frame search table section [17] '.eh_frame_hdr': + version: 1 + eh_frame_ptr_enc: 0x1b (sdata4 pcrel) + fde_count_enc: 0x3 (udata4) + table_enc: 0x3b (sdata4 datarel) + eh_frame_ptr: 0x44 (offset: 0x758) + fde_count: 7 + Table: + 0xfffffe70 (offset: 0x580) -> 0x5c fde=[ 14] + 0xfffffea0 (offset: 0x5b0) -> 0x70 fde=[ 28] + 0xfffffee0 (offset: 0x5f0) -> 0x84 fde=[ 3c] + 0xffffff20 (offset: 0x630) -> 0xac fde=[ 64] + 0xffffff28 (offset: 0x638) -> 0xc0 fde=[ 78] + 0xffffff40 (offset: 0x650) -> 0xd8 fde=[ 90] + 0xffffffc0 (offset: 0x6d0) -> 0x110 fde=[ c8] + +Call frame information section [18] '.eh_frame' at offset 0x758: + + [ 0] CIE length=16 + CIE_id: 0 + version: 1 + augmentation: "zR" + code_alignment_factor: 4 + data_alignment_factor: -8 + return_address_register: 30 + Augmentation data: 0x1b (FDE address encoding: sdata4 pcrel) + + Program: + def_cfa r31 (sp) at offset 0 + + [ 14] FDE length=16 cie=[ 0] + CIE_pointer: 24 + initial_location: 0x0000000000400580 (offset: 0x580) + address_range: 0x30 (end offset: 0x5b0) + + Program: + nop + nop + nop + + [ 28] FDE length=16 cie=[ 0] + CIE_pointer: 44 + initial_location: 0x00000000004005b0 (offset: 0x5b0) + address_range: 0x3c (end offset: 0x5ec) + + Program: + nop + nop + nop + + [ 3c] FDE length=36 cie=[ 0] + CIE_pointer: 64 + initial_location: 0x00000000004005f0 (offset: 0x5f0) + address_range: 0x38 (end offset: 0x628) + + Program: + advance_loc 1 to 0x5f4 + AARCH64_negate_ra_state + advance_loc 1 to 0x5f8 + def_cfa_offset 32 + offset r29 (x29) at cfa-32 + offset r30 (x30) at cfa-24 + advance_loc 2 to 0x600 + offset r19 (x19) at cfa-16 + advance_loc 8 to 0x620 + restore r30 (x30) + restore r29 (x29) + restore r19 (x19) + def_cfa_offset 0 + advance_loc 1 to 0x624 + AARCH64_negate_ra_state + nop + nop + nop + + [ 64] FDE length=16 cie=[ 0] + CIE_pointer: 104 + initial_location: 0x0000000000400630 (offset: 0x630) + address_range: 0x8 (end offset: 0x638) + + Program: + nop + nop + nop + + [ 78] FDE length=20 cie=[ 0] + CIE_pointer: 124 + initial_location: 0x0000000000400638 (offset: 0x638) + address_range: 0xc (end offset: 0x644) + + Program: + nop + nop + nop + nop + nop + nop + nop + + [ 90] FDE length=52 cie=[ 0] + CIE_pointer: 148 + initial_location: 0x0000000000400650 (offset: 0x650) + address_range: 0x80 (end offset: 0x6d0) + + Program: + advance_loc 1 to 0x654 + AARCH64_negate_ra_state + advance_loc 1 to 0x658 + def_cfa_offset 64 + offset r29 (x29) at cfa-64 + offset r30 (x30) at cfa-56 + advance_loc 2 to 0x660 + offset r19 (x19) at cfa-48 + offset r20 (x20) at cfa-40 + advance_loc 3 to 0x66c + offset r21 (x21) at cfa-32 + offset r22 (x22) at cfa-24 + advance_loc 5 to 0x680 + offset r23 (x23) at cfa-16 + offset r24 (x24) at cfa-8 + advance_loc 18 to 0x6c8 + restore r30 (x30) + restore r29 (x29) + restore r23 (x23) + restore r24 (x24) + restore r21 (x21) + restore r22 (x22) + restore r19 (x19) + restore r20 (x20) + def_cfa_offset 0 + advance_loc 1 to 0x6cc + AARCH64_negate_ra_state + nop + nop + + [ c8] FDE length=16 cie=[ 0] + CIE_pointer: 204 + initial_location: 0x00000000004006d0 (offset: 0x6d0) + address_range: 0x8 (end offset: 0x6d8) + + Program: + nop + nop + nop + + [ dc] Zero terminator +EOF + +exit 0 diff --git a/tests/run-readelf-n.sh b/tests/run-readelf-n.sh index cc7d7f66..4c98fd82 100755 --- a/tests/run-readelf-n.sh +++ b/tests/run-readelf-n.sh @@ -226,3 +226,34 @@ Note section [ 4] '.note.gnu.property' of 56 bytes at offset 0x40: GNU 8 GNU_PROPERTY_TYPE_0 NO_COPY_ON_PROTECTION EOF + +# - testfile-gnu-property-note.c +# int +# main () +# { +# return 0; +# } +# +# gcc -mbranch-protection=standard -c testfile-gnu-property-note.c +# gcc -o testfile-gnu-property-note-aarch64 testfile-gnu-property-note.o +# eu-strip --remove-section=.gnu.build.attributes \ +# testfile-gnu-property-note-aarch64 + +testfiles testfile-gnu-property-note-aarch64 +testrun_compare ${abs_top_builddir}/src/readelf -n testfile-gnu-property-note-aarch64 << EOF + +Note section [ 2] '.note.gnu.property' of 32 bytes at offset 0x2c8: + Owner Data size Type + GNU 16 GNU_PROPERTY_TYPE_0 + AARCH64 FEATURE_1_AND: 00000003 BTI PAC + +Note section [ 3] '.note.gnu.build-id' of 36 bytes at offset 0x2e8: + Owner Data size Type + GNU 20 GNU_BUILD_ID + Build ID: af82d6df6f3b396487e3e27a826ca9cbbbecbe5f + +Note section [ 4] '.note.ABI-tag' of 32 bytes at offset 0x30c: + Owner Data size Type + GNU 16 GNU_ABI_TAG + OS: Linux, ABI: 3.7.0 +EOF diff --git a/tests/run-test-includes.sh b/tests/run-test-includes.sh new file mode 100755 index 00000000..b0ccdd9b --- /dev/null +++ b/tests/run-test-includes.sh @@ -0,0 +1,26 @@ +# All public include headers should be usable "standalone". + +. $srcdir/test-subr.sh + +echo '#include "libelf.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf -xc - +echo '#include "gelf.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf -xc - + +echo '#include "dwarf.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \ + -I ${abs_srcdir}/../libdw -xc - +echo '#include "libdw.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \ + -I ${abs_srcdir}/../libdw -xc - + +echo '#include "libdwfl.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \ + -I ${abs_srcdir}/../libdw -I ${abs_srcdir}/../libdwfl -xc - +echo '#include "libdwelf.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \ + -I ${abs_srcdir}/../libdw -I ${abs_srcdir}/../libdwelf -xc - + +echo '#include "libasm.h"' \ + | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \ + -I ${abs_srcdir}/../libasm -xc - diff --git a/tests/test-wrapper.sh b/tests/test-wrapper.sh index 09b4d49f..c5d3f159 100755 --- a/tests/test-wrapper.sh +++ b/tests/test-wrapper.sh @@ -44,6 +44,7 @@ case "$1" in *.sh) export built_library_path program_transform_name elfutils_testrun export elfutils_tests_rpath + is_shell_script="yes" ;; *) if [ $elfutils_testrun = built ]; then @@ -55,6 +56,7 @@ case "$1" in LD_LIBRARY_PATH="${libdir}:${libdir}/elfutils$old_path" fi export LD_LIBRARY_PATH + is_shell_script="no" ;; esac @@ -62,4 +64,10 @@ if [ "x$VALGRIND_CMD" != "x" ]; then export VALGRIND_CMD fi -exec "$@" +# When it is a run-*.sh script the VALGRIND_CMD will be passed on +# otherwise we'll need to run the binary explicitly under valgrind. +if [ "x$is_shell_script" = xyes ]; then + exec "$@" +else + exec $VALGRIND_CMD "$@" +fi diff --git a/tests/testfile-gnu-property-note-aarch64.bz2 b/tests/testfile-gnu-property-note-aarch64.bz2 Binary files differnew file mode 100755 index 00000000..2fe37b19 --- /dev/null +++ b/tests/testfile-gnu-property-note-aarch64.bz2 diff --git a/tests/testfile60.bz2 b/tests/testfile60.bz2 Binary files differdeleted file mode 100755 index 6a0cd7bc..00000000 --- a/tests/testfile60.bz2 +++ /dev/null diff --git a/tests/vdsosyms.c b/tests/vdsosyms.c index 7bfa7381..83ab034f 100644 --- a/tests/vdsosyms.c +++ b/tests/vdsosyms.c @@ -103,6 +103,8 @@ main (int argc __attribute__ ((unused)), char **argv __attribute__ ((unused))) if (dwfl_getmodules (dwfl, module_callback, NULL, 0) != 0) error (1, 0, "dwfl_getmodules: %s", dwfl_errmsg (-1)); + dwfl_end (dwfl); + /* No symbols is ok, then we haven't seen the vdso at all on this arch. */ return vdso_syms >= 0 ? 0 : -1; } |