diff --git a/build-aux/abi-check-templ.xml b/build-aux/abi-check-templ.xml index 4cac8266b..87c8a5b8a 100644 --- a/build-aux/abi-check-templ.xml +++ b/build-aux/abi-check-templ.xml @@ -6,7 +6,10 @@ @PREFIX@/usr/include/qb +@SKIPLIB_CMT@ +@SKIPLIB_CMT@ @PREFIX@/usr/lib64/libqb.so +@SKIPLIB_CMT@ - @PREFIX@/usr/lib64/libqb.so + @PREFIX@/usr/lib64/libqb.so@LIB_SUFFIX@ diff --git a/check b/check index 79062c570..1f6b9d562 100755 --- a/check +++ b/check @@ -211,6 +211,8 @@ check_clang() { } check_abi() { + # XXX abi-compliance-checker >= 2 will likely require equivalent of + # https://github.com/lvc/abi-compliance-checker/pull/70 ver1=$1 ver2=$2 if [ -z "$ver1" ] ; then @@ -224,26 +226,46 @@ check_abi() { TMPL=build-aux/abi-check-templ.xml checker=abi-compliance-checker + if abi-compliance-checker -info | grep -Fqe '-cxx-incompatible'; then + checker="${checker} -cxx-incompatible" + fi mkdir -p abi_dumps/libqb + # ABICC only: current script always accompanied with current template + #for v in $ver1 $ver2; do cp "${TMPL}" "abi_dumps/libqb/${v}.tmpl"; done + for v in $ver1 $ver2 do - p=$(pwd)_inst_$v - sed -e "s|@PREFIX@|$p|" -e "s|@VERSION@|$v|" $TMPL > abi_dumps/libqb/$v.xml - done - for v in $ver1 $ver2 - do - p=$(pwd)_inst_$v - t=v$v - echo "== Version $v ==" - if [ ! -f abi_dumps/libqb/libqb_$v.abi.tar.gz ] + p=$(pwd)_inst_${v} + t=v${v} + echo "== Version ${v} ==" + if [ ! -f "abi_dumps/libqb/libqb_${v}.abi.tar.gz" ] then - git checkout $t + git checkout "${t}" ./autogen.sh - ./configure + # XXX still complains about missing -Og (-O0 is used) + ./configure --enable-debug make - make install DESTDIR=$p - $checker -l libqb -dump_abi abi_dumps/libqb/$v.xml + make install DESTDIR="${p}" + lib_suffix=$(cut -c 1-32 "${p}/usr/lib64/libqb.so" \ + | sed -n 's/^INPUT(libqb\.so\([^)]*\).*$/\1/p;q') + # this is currently recommended way of using abi-dumper + # instead of relying on internal processing with ABICC + # itself (still kept around for reference below) + abi-dumper -loud -debug "${p}/usr/lib64/libqb.so${lib_suffix}" \ + -vnum "${v}" -o "abi_dumps/libqb/libqb_${v}.abi.tar.gz" + + # former approach of relying solely on ABICC (XXX -lang C) + #skiplib_cmt= + #[ -n "${lib_suffix}" ] || skiplib_cmt='#' + #sed -e "s|@PREFIX@|${p}|" \ + # -e "s|@VERSION@|${v}|" \ + # -e "s|@SKIPLIB_CMT@|${skiplib_cmt}|" \ + # -e "s|@LIB_SUFFIX@|${lib_suffix}|" \ + # "abi_dumps/libqb/${v}.tmpl" > "abi_dumps/libqb/${v}.xml" + #rm -f "abi_dumps/libqb/${v}.tmpl" + #${checker} -l libqb -dump_abi "abi_dumps/libqb/${v}.xml" \ + # -dump-path "abi_dumps/libqb/libqb_${v}.abi.tar.gz" fi done @@ -334,4 +356,3 @@ case $command in esac cd - exit 0 - diff --git a/configure.ac b/configure.ac index aa99bf0d5..ccfd74e63 100644 --- a/configure.ac +++ b/configure.ac @@ -77,6 +77,7 @@ if ! ${MAKE-make} --version /cannot/make/this >/dev/null 2>&1; then fi AC_PROG_CXX +AM_CONDITIONAL(HAVE_GXX, [test "x$GXX" = xyes]) AC_PROG_AWK AC_PROG_CC AC_PROG_CPP @@ -682,7 +683,7 @@ if test "x${GCC}" = xyes; then && my_var == 3 /* for 2.29.1+ */); return *((int *) __start___verbose); }]] )], - [gcc_has_attribute_section=yes; cp "conftest${ac_exeext}" "conftest.so"], + [gcc_has_attribute_section=yes; cp "conftest${ac_exeext}" "conftest${shrext_cmds}"], [gcc_has_attribute_section=no] ) AX_RESTORE_FLAGS diff --git a/include/qb/qbarray.h b/include/qb/qbarray.h index 776db04e6..270b1c29d 100644 --- a/include/qb/qbarray.h +++ b/include/qb/qbarray.h @@ -52,8 +52,8 @@ extern "C" { * indexing, this gives a valid index range [0, @c QB_ARRAY_MAX_ELEMENTS), * where the notation denotes the beginning of the interval is included and * the end is excluded. In other words, client space shall avoid a pitfall - * of relying solely on the type of @max_elements parameter to - * @ref qb_array_create and/or of @idx parameter to @ref qb_array_index + * of relying solely on the type of @c max_elements parameter to + * @ref qb_array_create and/or of @c idx parameter to @ref qb_array_index * (these types conflict, anyway). */ diff --git a/include/qb/qblist.h b/include/qb/qblist.h index f8ab0d2df..e3ae3f180 100644 --- a/include/qb/qblist.h +++ b/include/qb/qblist.h @@ -109,16 +109,16 @@ static inline void qb_list_del(struct qb_list_head *_remove) /** * Replace old entry by new one - * @param old: the element to be replaced - * @param new: the new element to insert + * @param old_one: the element to be replaced + * @param new_one: the new element to insert */ -static inline void qb_list_replace(struct qb_list_head *old, - struct qb_list_head *new) +static inline void qb_list_replace(struct qb_list_head *old_one, + struct qb_list_head *new_one) { - new->next = old->next; - new->next->prev = new; - new->prev = old->prev; - new->prev->next = new; + new_one->next = old_one->next; + new_one->next->prev = new_one; + new_one->prev = old_one->prev; + new_one->prev->next = new_one; } /** diff --git a/include/qb/qblog.h b/include/qb/qblog.h index 1943b948e..cb582a888 100644 --- a/include/qb/qblog.h +++ b/include/qb/qblog.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. + * Copyright (c) 2017 Red Hat, Inc. * * All rights reserved. * diff --git a/lib/Makefile.am b/lib/Makefile.am index dd50a609b..2eac6d15d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -100,10 +100,9 @@ else endif endif +# nested sed expression is also escaping meta character for the outer one qblog_script.ld: %.ld: %.ld.in - $(AM_V_GEN)$(CPP) -C -D_GNU_SOURCE -P \ - -I$(top_srcdir)/include -I$(top_builddir)/include \ - -xc $< \ + $(AM_V_GEN)$(CPP) -C -D_GNU_SOURCE -P $(AM_CPPFLAGS) -xc $< \ | sed -n "/$$(sed -n '/^[^#]/{s/[*\/]/\\&/g;p;q;}' $<)/,$$ p" \ > $@ diff --git a/tests/Makefile.am b/tests/Makefile.am index 5bc4bbb1b..25efa72ab 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,23 +33,23 @@ noinst_HEADERS = check_common.h format_compare_speed_SOURCES = format_compare_speed.c $(top_builddir)/include/qb/qbutil.h format_compare_speed_LDADD = $(top_builddir)/lib/libqb.la -bmc_SOURCES = bmc.c $(top_builddir)/include/qb/qbipcc.h +bmc_SOURCES = bmc.c bmc_LDADD = $(top_builddir)/lib/libqb.la -bmcpt_SOURCES = bmcpt.c $(top_builddir)/include/qb/qbipcc.h +bmcpt_SOURCES = bmcpt.c bmcpt_LDADD = $(top_builddir)/lib/libqb.la -bms_SOURCES = bms.c $(top_builddir)/include/qb/qbipcs.h -bms_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include $(GLIB_CFLAGS) +bms_SOURCES = bms.c +bms_CFLAGS = $(GLIB_CFLAGS) bms_LDADD = $(top_builddir)/lib/libqb.la $(GLIB_LIBS) -rbwriter_SOURCES = rbwriter.c $(top_builddir)/include/qb/qbrb.h +rbwriter_SOURCES = rbwriter.c rbwriter_LDADD = $(top_builddir)/lib/libqb.la -rbreader_SOURCES = rbreader.c $(top_builddir)/include/qb/qbrb.h +rbreader_SOURCES = rbreader.c rbreader_LDADD = $(top_builddir)/lib/libqb.la -loop_SOURCES = loop.c $(top_builddir)/include/qb/qbloop.h +loop_SOURCES = loop.c loop_LDADD = $(top_builddir)/lib/libqb.la inc_dir = $(top_srcdir)/include/qb @@ -78,7 +78,17 @@ check: check-headers # rely on implicit automake rule to include right (local) includes .PHONY: check-headers -check-headers: $(auto_c_files:.c=.o) +check-headers: $(auto_c_files:.c=.o) $(auto_c_files:.c=.opp) + +# this is to check basic sanity of using libqb from C++ code, if possible +%.opp: %.c +if HAVE_GXX + $(AM_V_GEN)$(CXX) $(AM_CPPFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $< +else + @echo "C++ compatibility tests not run" +endif + +CLEANFILES += ${auto_c_files:.c=.opp} distclean-local: rm -rf auto_*.c @@ -99,20 +109,21 @@ $(builddir)/auto_write_logs.c: make-log-test.sh endif endif -bench_log_SOURCES = bench-log.c $(top_builddir)/include/qb/qblog.h -bench_log_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include +bench_log_SOURCES = bench-log.c bench_log_LDADD = $(top_builddir)/lib/libqb.la if HAVE_CHECK EXTRA_DIST += start.test resources.test EXTRA_DIST += blackbox-segfault.sh -TESTS = start.test array.test map.test rb.test log.test blackbox-segfault.sh loop.test ipc.test resources.test +TESTS = start.test array.test map.test rb.test list.test log.test blackbox-segfault.sh loop.test ipc.test resources.test resources.log: rb.log log.log ipc.log check_LTLIBRARIES = -check_PROGRAMS = array.test map.test rb.test log.test loop.test ipc.test util.test crash_test_dummy file_change_bytes +check_PROGRAMS = array.test ipc.test list.test log.test loop.test \ + map.test rb.test util.test \ + crash_test_dummy file_change_bytes dist_check_SCRIPTS = start.test resources.test blackbox-segfault.sh if HAVE_SLOW_TESTS @@ -122,28 +133,28 @@ endif file_change_bytes_SOURCES = file_change_bytes.c -crash_test_dummy_SOURCES = crash_test_dummy.c $(top_builddir)/include/qb/qblog.h -crash_test_dummy_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +crash_test_dummy_SOURCES = crash_test_dummy.c +crash_test_dummy_CFLAGS = @CHECK_CFLAGS@ crash_test_dummy_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -array_test_SOURCES = check_array.c $(top_builddir)/include/qb/qbarray.h -array_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +array_test_SOURCES = check_array.c +array_test_CFLAGS = @CHECK_CFLAGS@ array_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -map_test_SOURCES = check_map.c $(top_builddir)/include/qb/qbmap.h -map_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +map_test_SOURCES = check_map.c +map_test_CFLAGS = @CHECK_CFLAGS@ map_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -rb_test_SOURCES = check_rb.c $(top_builddir)/include/qb/qbrb.h -rb_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +rb_test_SOURCES = check_rb.c +rb_test_CFLAGS = @CHECK_CFLAGS@ rb_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -loop_test_SOURCES = check_loop.c $(top_builddir)/include/qb/qbloop.h -loop_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +loop_test_SOURCES = check_loop.c +loop_test_CFLAGS = @CHECK_CFLAGS@ loop_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ -ipc_test_SOURCES = check_ipc.c $(top_builddir)/include/qb/qbipcc.h $(top_builddir)/include/qb/qbipcs.h -ipc_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +ipc_test_SOURCES = check_ipc.c +ipc_test_CFLAGS = @CHECK_CFLAGS@ ipc_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ if HAVE_FAILURE_INJECTION ipc_test_LDADD += _failure_injection.la @@ -158,15 +169,19 @@ check_LTLIBRARIES += _syslog_override.la _syslog_override_la_SOURCES = _syslog_override.c _syslog_override.h _syslog_override_la_LDFLAGS = -module -log_test_SOURCES = check_log.c $(top_builddir)/include/qb/qblog.h -log_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +log_test_SOURCES = check_log.c +log_test_CFLAGS = @CHECK_CFLAGS@ log_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ log_test_LDADD += _syslog_override.la -util_test_SOURCES = check_util.c $(top_builddir)/include/qb/qbutil.h -util_test_CFLAGS = @CHECK_CFLAGS@ -I$(top_srcdir)/include +util_test_SOURCES = check_util.c +util_test_CFLAGS = @CHECK_CFLAGS@ util_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ +list_test_SOURCES = check_list.c +list_test_CFLAGS = @CHECK_CFLAGS@ +list_test_LDADD = $(top_builddir)/lib/libqb.la @CHECK_LIBS@ + endif clean-local: diff --git a/tests/check_list.c b/tests/check_list.c new file mode 100644 index 000000000..b82766820 --- /dev/null +++ b/tests/check_list.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2018 Red Hat, Inc. + * + * All rights reserved. + * + * Author: Jan Pokorny + * + * This file is part of libqb. + * + * libqb is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or + * (at your option) any later version. + * + * libqb 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libqb. If not, see . + */ + +#include "os_base.h" + +#include "check_common.h" + +#include +#include + +typedef struct { + struct qb_list_head list; + size_t i; +} enlistable_num_t; + +#define DIMOF(_a) sizeof(_a)/sizeof(*(_a)) + +START_TEST(test_list_iter) +{ + QB_LIST_DECLARE(mylist); + enlistable_num_t reference_head[] = { {.i=0}, {.i=1}, {.i=2}, {.i=3} }; + enlistable_num_t reference_tail[] = { {.i=4}, {.i=5}, {.i=6}, {.i=7} }; + enlistable_num_t *iter, replacement = {.i=8}; + size_t iter_i; + + for (iter_i = DIMOF(reference_head); iter_i > 0; iter_i--) { + /* prepends in reverse order */ + qb_list_add(&reference_head[iter_i-1].list, &mylist); + } + for (iter_i = 0; iter_i < DIMOF(reference_tail); iter_i++) { + /* appends in natural order */ + qb_list_add_tail(&reference_tail[iter_i].list, &mylist); + } + + /* assert the constructed list corresponds to ordered sequence... */ + + /* ... increasing when iterating forward */ + iter_i = 0; + qb_list_for_each_entry(iter, &mylist, list) { + ck_assert_int_eq(iter->i, iter_i); + iter_i++; + } + + /* ... and decreasing when iterating backward */ + qb_list_for_each_entry_reverse(iter, &mylist, list) { + ck_assert_int_gt(iter_i, 0); + ck_assert_int_eq(iter->i, iter_i-1); + iter_i--; + } + ck_assert_int_eq(iter_i, 0); + + /* also check qb_list_replace and qb_list_first_entry */ + qb_list_replace(mylist.next, &replacement.list); + ck_assert_int_eq(qb_list_first_entry(&mylist, enlistable_num_t, list)->i, + replacement.i); +} +END_TEST + +static Suite *array_suite(void) +{ + TCase *tc; + Suite *s = suite_create("qb_list"); + + add_tcase(s, tc, test_list_iter); + + return s; +} + +int32_t main(void) +{ + int32_t number_failed; + + Suite *s = array_suite(); + SRunner *sr = srunner_create(s); + + qb_log_init("check", LOG_USER, LOG_EMERG); + atexit(qb_log_fini); + qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE); + qb_log_filter_ctl(QB_LOG_STDERR, QB_LOG_FILTER_ADD, + QB_LOG_FILTER_FILE, "*", LOG_INFO); + qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); + + srunner_run_all(sr, CK_VERBOSE); + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} diff --git a/tests/functional/log_client.c b/tests/functional/log_client.c index d5d80890f..9d202dc98 100644 --- a/tests/functional/log_client.c +++ b/tests/functional/log_client.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. + * Copyright (c) 2017 Red Hat, Inc. * * All rights reserved. * diff --git a/tests/functional/log_interlib.c b/tests/functional/log_interlib.c index 228a339d8..80c19276a 100644 --- a/tests/functional/log_interlib.c +++ b/tests/functional/log_interlib.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. + * Copyright (c) 2017 Red Hat, Inc. * * All rights reserved. * diff --git a/tests/functional/log_interlib_client.c b/tests/functional/log_interlib_client.c index 820df67ce..b064a7553 100644 --- a/tests/functional/log_interlib_client.c +++ b/tests/functional/log_interlib_client.c @@ -1,5 +1,5 @@ /* - * Copyright 2017 Red Hat, Inc. + * Copyright (c) 2017 Red Hat, Inc. * * All rights reserved. * diff --git a/tests/print_ver.c b/tests/print_ver.c index 752aeb02d..6b96ae45e 100644 --- a/tests/print_ver.c +++ b/tests/print_ver.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. + * Copyright (c) 2016-2018 Red Hat, Inc. * * All rights reserved. * @@ -38,5 +38,5 @@ main(void) semicolon intentionally omitted so as to avoid unnecessary message source diagnostics (bug or feature?) with some GCC versions (5.3.1) */ #define MSG QB_PP_STRINGIFY( \ - GCC warning QB_PP_STRINGIFY(VERSION parsed as: QB_VER_STR)) -_Pragma(MSG) + message (QB_PP_STRINGIFY(VERSION parsed as: QB_VER_STR))) +_Pragma(MSG);