[libbacktrace] Add tests for unused formats

When building libbacktrace, we typically use elf.c, and don't build pecoff.c,
xcoff.c or unknown.c.

Add testcases that use unused format to ensure that we also build and
test those on a typical development setup.

Bootstrapped and reg-tested on x86_64.

2018-11-30  Tom de Vries  <tdevries@suse.de>

	* Makefile.am (check_PROGRAMS): Add test_elf, test_xcoff_32,
	test_xcoff_64, test_pecoff and test_unknown.
	* Makefile.in: Regenerate.
	* test_format.c: New file.

From-SVN: r266668
This commit is contained in:
Tom de Vries 2018-11-30 15:33:23 +00:00 committed by Tom de Vries
parent 9b7d1a9741
commit 187b9e1dc5
4 changed files with 228 additions and 12 deletions

View File

@ -1,3 +1,10 @@
2018-11-30 Tom de Vries <tdevries@suse.de>
* Makefile.am (check_PROGRAMS): Add test_elf, test_xcoff_32,
test_xcoff_64, test_pecoff and test_unknown.
* Makefile.in: Regenerate.
* test_format.c: New file.
2018-11-30 Tom de Vries <tdevries@suse.de>
* Makefile.am : Add _with_alloc version for each test in

View File

@ -96,6 +96,45 @@ libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
check_LTLIBRARIES += libbacktrace_noformat.la
libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
xcoff_%.c: xcoff.c
SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
REPLACE='#undef BACKTRACE_XCOFF_SIZE\n#define BACKTRACE_XCOFF_SIZE'; \
$(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
$(srcdir)/xcoff.c \
> $@
test_elf_SOURCES = test_format.c testlib.c
test_elf_LDADD = libbacktrace_noformat.la elf.lo
check_PROGRAMS += test_elf
test_xcoff_32_SOURCES = test_format.c testlib.c
test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
check_PROGRAMS += test_xcoff_32
test_xcoff_64_SOURCES = test_format.c testlib.c
test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
check_PROGRAMS += test_xcoff_64
test_pecoff_SOURCES = test_format.c testlib.c
test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
check_PROGRAMS += test_pecoff
test_unknown_SOURCES = test_format.c testlib.c
test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
check_PROGRAMS += test_unknown
unittest_SOURCES = unittest.c testlib.c
unittest_LDADD = libbacktrace.la

View File

@ -121,9 +121,10 @@ build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3)
@NATIVE_TRUE@am__append_1 = unittest unittest_alloc btest btest_alloc \
@NATIVE_TRUE@ stest stest_alloc ztest ztest_alloc edtest \
@NATIVE_TRUE@ edtest_alloc
@NATIVE_TRUE@am__append_1 = test_elf test_xcoff_32 test_xcoff_64 \
@NATIVE_TRUE@ test_pecoff test_unknown unittest unittest_alloc \
@NATIVE_TRUE@ btest btest_alloc stest stest_alloc ztest \
@NATIVE_TRUE@ ztest_alloc edtest edtest_alloc
@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_2 = -lz
@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_3 = -lz
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_4 = ttest ttest_alloc
@ -168,11 +169,18 @@ am__objects_1 = atomic.lo dwarf.lo fileline.lo posix.lo print.lo \
@NATIVE_TRUE@am_libbacktrace_alloc_la_OBJECTS = $(am__objects_1)
libbacktrace_alloc_la_OBJECTS = $(am_libbacktrace_alloc_la_OBJECTS)
@NATIVE_TRUE@am_libbacktrace_alloc_la_rpath =
@NATIVE_TRUE@am__EXEEXT_1 = unittest$(EXEEXT) unittest_alloc$(EXEEXT) \
@NATIVE_TRUE@ btest$(EXEEXT) btest_alloc$(EXEEXT) \
@NATIVE_TRUE@ stest$(EXEEXT) stest_alloc$(EXEEXT) \
@NATIVE_TRUE@ ztest$(EXEEXT) ztest_alloc$(EXEEXT) \
@NATIVE_TRUE@ edtest$(EXEEXT) edtest_alloc$(EXEEXT)
@NATIVE_TRUE@am_libbacktrace_noformat_la_OBJECTS = $(am__objects_1)
libbacktrace_noformat_la_OBJECTS = \
$(am_libbacktrace_noformat_la_OBJECTS)
@NATIVE_TRUE@am_libbacktrace_noformat_la_rpath =
@NATIVE_TRUE@am__EXEEXT_1 = test_elf$(EXEEXT) test_xcoff_32$(EXEEXT) \
@NATIVE_TRUE@ test_xcoff_64$(EXEEXT) test_pecoff$(EXEEXT) \
@NATIVE_TRUE@ test_unknown$(EXEEXT) unittest$(EXEEXT) \
@NATIVE_TRUE@ unittest_alloc$(EXEEXT) btest$(EXEEXT) \
@NATIVE_TRUE@ btest_alloc$(EXEEXT) stest$(EXEEXT) \
@NATIVE_TRUE@ stest_alloc$(EXEEXT) ztest$(EXEEXT) \
@NATIVE_TRUE@ ztest_alloc$(EXEEXT) edtest$(EXEEXT) \
@NATIVE_TRUE@ edtest_alloc$(EXEEXT)
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__EXEEXT_2 = ttest$(EXEEXT) \
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ ttest_alloc$(EXEEXT)
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__EXEEXT_3 = \
@ -245,6 +253,30 @@ stest_OBJECTS = $(am_stest_OBJECTS)
@NATIVE_TRUE@am_stest_alloc_OBJECTS = $(am__objects_6)
stest_alloc_OBJECTS = $(am_stest_alloc_OBJECTS)
@NATIVE_TRUE@stest_alloc_DEPENDENCIES = libbacktrace_alloc.la
@NATIVE_TRUE@am_test_elf_OBJECTS = test_format.$(OBJEXT) \
@NATIVE_TRUE@ testlib.$(OBJEXT)
test_elf_OBJECTS = $(am_test_elf_OBJECTS)
@NATIVE_TRUE@test_elf_DEPENDENCIES = libbacktrace_noformat.la elf.lo
@NATIVE_TRUE@am_test_pecoff_OBJECTS = test_format.$(OBJEXT) \
@NATIVE_TRUE@ testlib.$(OBJEXT)
test_pecoff_OBJECTS = $(am_test_pecoff_OBJECTS)
@NATIVE_TRUE@test_pecoff_DEPENDENCIES = libbacktrace_noformat.la \
@NATIVE_TRUE@ pecoff.lo
@NATIVE_TRUE@am_test_unknown_OBJECTS = test_format.$(OBJEXT) \
@NATIVE_TRUE@ testlib.$(OBJEXT)
test_unknown_OBJECTS = $(am_test_unknown_OBJECTS)
@NATIVE_TRUE@test_unknown_DEPENDENCIES = libbacktrace_noformat.la \
@NATIVE_TRUE@ unknown.lo
@NATIVE_TRUE@am_test_xcoff_32_OBJECTS = test_format.$(OBJEXT) \
@NATIVE_TRUE@ testlib.$(OBJEXT)
test_xcoff_32_OBJECTS = $(am_test_xcoff_32_OBJECTS)
@NATIVE_TRUE@test_xcoff_32_DEPENDENCIES = libbacktrace_noformat.la \
@NATIVE_TRUE@ xcoff_32.lo
@NATIVE_TRUE@am_test_xcoff_64_OBJECTS = test_format.$(OBJEXT) \
@NATIVE_TRUE@ testlib.$(OBJEXT)
test_xcoff_64_OBJECTS = $(am_test_xcoff_64_OBJECTS)
@NATIVE_TRUE@test_xcoff_64_DEPENDENCIES = libbacktrace_noformat.la \
@NATIVE_TRUE@ xcoff_64.lo
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am_ttest_OBJECTS = \
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ ttest-ttest.$(OBJEXT) \
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ ttest-testlib.$(OBJEXT)
@ -323,13 +355,17 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(libbacktrace_la_SOURCES) $(EXTRA_libbacktrace_la_SOURCES) \
$(libbacktrace_alloc_la_SOURCES) $(btest_SOURCES) \
$(libbacktrace_alloc_la_SOURCES) \
$(libbacktrace_noformat_la_SOURCES) $(btest_SOURCES) \
$(btest_alloc_SOURCES) $(ctesta_SOURCES) \
$(ctesta_alloc_SOURCES) $(ctestg_SOURCES) \
$(ctestg_alloc_SOURCES) $(edtest_SOURCES) \
$(edtest_alloc_SOURCES) $(stest_SOURCES) \
$(stest_alloc_SOURCES) $(ttest_SOURCES) $(ttest_alloc_SOURCES) \
$(unittest_SOURCES) $(unittest_alloc_SOURCES) $(ztest_SOURCES) \
$(stest_alloc_SOURCES) $(test_elf_SOURCES) \
$(test_pecoff_SOURCES) $(test_unknown_SOURCES) \
$(test_xcoff_32_SOURCES) $(test_xcoff_64_SOURCES) \
$(ttest_SOURCES) $(ttest_alloc_SOURCES) $(unittest_SOURCES) \
$(unittest_alloc_SOURCES) $(ztest_SOURCES) \
$(ztest_alloc_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
@ -739,10 +775,24 @@ libbacktrace_la_LIBADD = \
libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
TESTS = $(check_PROGRAMS) $(am__append_5)
@NATIVE_TRUE@check_LTLIBRARIES = libbacktrace_alloc.la
@NATIVE_TRUE@check_LTLIBRARIES = libbacktrace_alloc.la \
@NATIVE_TRUE@ libbacktrace_noformat.la
@NATIVE_TRUE@libbacktrace_alloc_la_SOURCES = $(libbacktrace_la_SOURCES)
@NATIVE_TRUE@libbacktrace_alloc_la_LIBADD = $(BACKTRACE_FILE) $(FORMAT_FILE) read.lo alloc.lo
@NATIVE_TRUE@libbacktrace_alloc_la_DEPENDENCIES = $(libbacktrace_alloc_la_LIBADD)
@NATIVE_TRUE@libbacktrace_noformat_la_SOURCES = $(libbacktrace_la_SOURCES)
@NATIVE_TRUE@libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
@NATIVE_TRUE@libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
@NATIVE_TRUE@test_elf_SOURCES = test_format.c testlib.c
@NATIVE_TRUE@test_elf_LDADD = libbacktrace_noformat.la elf.lo
@NATIVE_TRUE@test_xcoff_32_SOURCES = test_format.c testlib.c
@NATIVE_TRUE@test_xcoff_32_LDADD = libbacktrace_noformat.la xcoff_32.lo
@NATIVE_TRUE@test_xcoff_64_SOURCES = test_format.c testlib.c
@NATIVE_TRUE@test_xcoff_64_LDADD = libbacktrace_noformat.la xcoff_64.lo
@NATIVE_TRUE@test_pecoff_SOURCES = test_format.c testlib.c
@NATIVE_TRUE@test_pecoff_LDADD = libbacktrace_noformat.la pecoff.lo
@NATIVE_TRUE@test_unknown_SOURCES = test_format.c testlib.c
@NATIVE_TRUE@test_unknown_LDADD = libbacktrace_noformat.la unknown.lo
@NATIVE_TRUE@unittest_SOURCES = unittest.c testlib.c
@NATIVE_TRUE@unittest_LDADD = libbacktrace.la
@NATIVE_TRUE@unittest_alloc_SOURCES = $(unittest_SOURCES)
@ -895,6 +945,9 @@ libbacktrace.la: $(libbacktrace_la_OBJECTS) $(libbacktrace_la_DEPENDENCIES) $(EX
libbacktrace_alloc.la: $(libbacktrace_alloc_la_OBJECTS) $(libbacktrace_alloc_la_DEPENDENCIES) $(EXTRA_libbacktrace_alloc_la_DEPENDENCIES)
$(AM_V_CCLD)$(LINK) $(am_libbacktrace_alloc_la_rpath) $(libbacktrace_alloc_la_OBJECTS) $(libbacktrace_alloc_la_LIBADD) $(LIBS)
libbacktrace_noformat.la: $(libbacktrace_noformat_la_OBJECTS) $(libbacktrace_noformat_la_DEPENDENCIES) $(EXTRA_libbacktrace_noformat_la_DEPENDENCIES)
$(AM_V_CCLD)$(LINK) $(am_libbacktrace_noformat_la_rpath) $(libbacktrace_noformat_la_OBJECTS) $(libbacktrace_noformat_la_LIBADD) $(LIBS)
clean-checkPROGRAMS:
@list='$(check_PROGRAMS)'; test -n "$$list" || exit 0; \
echo " rm -f" $$list; \
@ -944,6 +997,26 @@ stest_alloc$(EXEEXT): $(stest_alloc_OBJECTS) $(stest_alloc_DEPENDENCIES) $(EXTRA
@rm -f stest_alloc$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(stest_alloc_OBJECTS) $(stest_alloc_LDADD) $(LIBS)
test_elf$(EXEEXT): $(test_elf_OBJECTS) $(test_elf_DEPENDENCIES) $(EXTRA_test_elf_DEPENDENCIES)
@rm -f test_elf$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_elf_OBJECTS) $(test_elf_LDADD) $(LIBS)
test_pecoff$(EXEEXT): $(test_pecoff_OBJECTS) $(test_pecoff_DEPENDENCIES) $(EXTRA_test_pecoff_DEPENDENCIES)
@rm -f test_pecoff$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_pecoff_OBJECTS) $(test_pecoff_LDADD) $(LIBS)
test_unknown$(EXEEXT): $(test_unknown_OBJECTS) $(test_unknown_DEPENDENCIES) $(EXTRA_test_unknown_DEPENDENCIES)
@rm -f test_unknown$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_unknown_OBJECTS) $(test_unknown_LDADD) $(LIBS)
test_xcoff_32$(EXEEXT): $(test_xcoff_32_OBJECTS) $(test_xcoff_32_DEPENDENCIES) $(EXTRA_test_xcoff_32_DEPENDENCIES)
@rm -f test_xcoff_32$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_xcoff_32_OBJECTS) $(test_xcoff_32_LDADD) $(LIBS)
test_xcoff_64$(EXEEXT): $(test_xcoff_64_OBJECTS) $(test_xcoff_64_DEPENDENCIES) $(EXTRA_test_xcoff_64_DEPENDENCIES)
@rm -f test_xcoff_64$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_xcoff_64_OBJECTS) $(test_xcoff_64_LDADD) $(LIBS)
ttest$(EXEEXT): $(ttest_OBJECTS) $(ttest_DEPENDENCIES) $(EXTRA_ttest_DEPENDENCIES)
@rm -f ttest$(EXEEXT)
$(AM_V_CCLD)$(ttest_LINK) $(ttest_OBJECTS) $(ttest_LDADD) $(LIBS)
@ -1312,6 +1385,41 @@ recheck: all $(check_LTLIBRARIES) $(check_PROGRAMS)
am__force_recheck=am--force-recheck \
TEST_LOGS="$$log_list"; \
exit $$?
test_elf.log: test_elf$(EXEEXT)
@p='test_elf$(EXEEXT)'; \
b='test_elf'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_xcoff_32.log: test_xcoff_32$(EXEEXT)
@p='test_xcoff_32$(EXEEXT)'; \
b='test_xcoff_32'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_xcoff_64.log: test_xcoff_64$(EXEEXT)
@p='test_xcoff_64$(EXEEXT)'; \
b='test_xcoff_64'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_pecoff.log: test_pecoff$(EXEEXT)
@p='test_pecoff$(EXEEXT)'; \
b='test_pecoff'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
test_unknown.log: test_unknown$(EXEEXT)
@p='test_unknown$(EXEEXT)'; \
b='test_unknown'; \
$(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \
--log-file $$b.log --trs-file $$b.trs \
$(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
unittest.log: unittest$(EXEEXT)
@p='unittest$(EXEEXT)'; \
b='unittest'; \
@ -1580,6 +1688,13 @@ uninstall-am:
.PRECIOUS: Makefile
@NATIVE_TRUE@xcoff_%.c: xcoff.c
@NATIVE_TRUE@ SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
@NATIVE_TRUE@ REPLACE='#undef BACKTRACE_XCOFF_SIZE\n#define BACKTRACE_XCOFF_SIZE'; \
@NATIVE_TRUE@ $(SED) "s/^$$SEARCH\$$/$$REPLACE $*/" \
@NATIVE_TRUE@ $(srcdir)/xcoff.c \
@NATIVE_TRUE@ > $@
@NATIVE_TRUE@edtest2_build.c: gen_edtest2_build; @true
@NATIVE_TRUE@gen_edtest2_build: $(srcdir)/edtest2.c
@NATIVE_TRUE@ cat $(srcdir)/edtest2.c > tmp-edtest2_build.c

View File

@ -0,0 +1,55 @@
/* test_format.c -- Test for libbacktrace library
Copyright (C) 2018 Free Software Foundation, Inc.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
(1) Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
(2) Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
(3) The name of the author may not be used to
endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* This program tests the externally visible interfaces of the
libbacktrace library. */
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "filenames.h"
#include "backtrace.h"
#include "backtrace-supported.h"
#include "testlib.h"
int
main (int argc ATTRIBUTE_UNUSED, char **argv)
{
state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
error_callback_create, NULL);
exit (failures ? EXIT_FAILURE : EXIT_SUCCESS);
}