From 1754b394d4aee1f02ba37d9b87d96f1ad240ba4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 4 Jan 2018 14:50:40 +0100 Subject: [PATCH 1/8] doc: qbarray.h: fix garbled Doxygen markup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- include/qb/qbarray.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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). */ From d300b7fdaec5183c375a894727f8551bf17c8b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 4 Jan 2018 21:12:56 +0100 Subject: [PATCH 2/8] build: follow-up for and fine-tuning of a rushed 6d62b64 commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (It made a service as-was, but being afforded more time, this would have accompanied that commit right away, for better understanding, brevity and uniformity.) Signed-off-by: Jan Pokorný --- configure.ac | 2 +- lib/Makefile.am | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index f9761ccf3..295522538 100644 --- a/configure.ac +++ b/configure.ac @@ -662,7 +662,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/lib/Makefile.am b/lib/Makefile.am index b035f0b0d..b3905c33a 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" \ > $@ From 1e7c85a17a61e2a9b3b0e51da6cd41aa5e2ece51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 4 Jan 2018 18:26:13 +0100 Subject: [PATCH 3/8] build: prune superfluous Makefile declarations within tests directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There was a significant redundancy wrt. build flags and EXTRA_DIST assignment (the latter become redundant as of f6e4042 at latest) spread all over the place (vivat copy&paste). Also, in one instance, CPPFLAGS (used) was confused with CFLAGS (meant). Signed-off-by: Jan Pokorný --- tests/Makefile.am | 52 ++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index df1af81a7..71066f581 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 @@ -98,14 +98,10 @@ $(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 += resources.test -EXTRA_DIST += blackbox-segfault.sh - TESTS = array.test map.test rb.test log.test blackbox-segfault.sh loop.test ipc.test resources.test resources.log: rb.log log.log ipc.log @@ -121,28 +117,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 @@ -157,13 +153,13 @@ 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@ endif From e0bc8b191289c1f701e36194a3bee7d1b1ba361d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Tue, 9 Jan 2018 22:12:31 +0100 Subject: [PATCH 4/8] maint: check abi: fix two issues with abi-compliance-checker/libstdc++ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ABICC >= 2 needs to be passed -cxx-incompatible switch because C is no longer a default for this tool (used to be vice versa), plus current version will stop choking on C vs. C++ (our C code with C++ compatibility wrapping being viewed from C++ perspective for the purpose of dumping the declared symbols, which somewhat conflicts with internal masking of the C++ keywords being used as valid C identifiers [yet some instances must not be masked here, see https://github.com/lvc/abi-compliance-checker/issues/64) only if _also_ something like this is applied: https://github.com/lvc/abi-compliance-checker/pull/70 2. since 20246f5, libqb.so no longer poses a symlink to the actual version-qualified shared library, but rather a standalone linker script, which confuses ABICC, so blacklist that file for the scanning purposes explicitly, together with referring to the library through it's basic version qualification (which alone, sadly, is not sufficient as ABICC proceeds to scan whole containing directory despite particular file is specified) Signed-off-by: Jan Pokorný --- build-aux/abi-check-templ.xml | 5 ++++- check | 40 +++++++++++++++++++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) 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..2a6328e27 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,39 @@ 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 + # current script should always be 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 make - make install DESTDIR=$p - $checker -l libqb -dump_abi abi_dumps/libqb/$v.xml + make install DESTDIR="${p}" + skiplib_cmt= + lib_suffix=$(cut -c 1-32 "${p}/usr/lib64/libqb.so" \ + | sed -n 's/^INPUT(libqb\.so\([^)]*\).*$/\1/p;q') + [ -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" + # XXX -lang C + ${checker} -l libqb -dump_abi "abi_dumps/libqb/${v}.xml" \ + -dump-path "abi_dumps/libqb/libqb_${v}.abi.tar.gz" fi done @@ -334,4 +349,3 @@ case $command in esac cd - exit 0 - From 1646253e138878c68462e26533136560cdef70f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Wed, 10 Jan 2018 14:54:14 +0100 Subject: [PATCH 5/8] maint: check abi: switch to abi-dumper for creating "ABI dumps" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Beside avoiding issues with abi-compliance-checker in the role of ABI dumps producer (see the preceding commit), it also seems to generate more accurate picture (maybe because it expressly requires compiling with debugging information requested). Signed-off-by: Jan Pokorný --- check | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/check b/check index 2a6328e27..1f6b9d562 100755 --- a/check +++ b/check @@ -231,8 +231,8 @@ check_abi() { fi mkdir -p abi_dumps/libqb - # current script should always be accompanied with current template - for v in $ver1 $ver2; do cp "${TMPL}" "abi_dumps/libqb/${v}.tmpl"; done + # 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 @@ -243,22 +243,29 @@ check_abi() { then git checkout "${t}" ./autogen.sh - ./configure + # XXX still complains about missing -Og (-O0 is used) + ./configure --enable-debug make make install DESTDIR="${p}" - skiplib_cmt= lib_suffix=$(cut -c 1-32 "${p}/usr/lib64/libqb.so" \ | sed -n 's/^INPUT(libqb\.so\([^)]*\).*$/\1/p;q') - [ -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" - # XXX -lang C - ${checker} -l libqb -dump_abi "abi_dumps/libqb/${v}.xml" \ - -dump-path "abi_dumps/libqb/libqb_${v}.abi.tar.gz" + # 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 From 3107df1d18b8e25a823c6d58f8afb2f3065a31a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 4 Jan 2018 18:35:04 +0100 Subject: [PATCH 6/8] Low: qblist.h: fix incompatibility with C++ & check it regularly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Primary trigger was the fact that "./check abi" (via build-aux/generate-docs) choked on that because abi-compliance-checker (ABICC) uses g++ to list symbols in header files playing hide-and-see regarding C identifiers otherwise conflicting with C++ keywords, which is moreover triggered only with -cxx-incompatible switch since ABICC 2.0 (and even then the respective code needs some further tweaking: https://github.com/lvc/abi-compliance-checker/pull/70), and this switch wasn't historically applied. Anyway, this C++ perspective there was likely unprecedented even though libqb no doubt targets such compatiblity. To avoid its breakage within the public headers' scope in the future, arrange for checking it regularly alongside the "auto_check_header" tests (cf. make -C tests check-headers). Signed-off-by: Jan Pokorný --- include/qb/qblist.h | 16 ++++++++-------- tests/Makefile.am | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) 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/tests/Makefile.am b/tests/Makefile.am index 71066f581..def4b41d0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -78,7 +78,13 @@ 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 attest basic sanity for using libqb from C++ code when possible +%.opp: %.c + @which $(CXX) >/dev/null || { echo '$<: cannot test C++ compat'; exit 0; } + $(AM_V_GEN)$(CXX) $(AM_CPPFLAGS) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $< +CLEANFILES += ${auto_c_files:.c=.opp} distclean-compile: rm -rf auto_*.c From 76345296dab87554e91cc5f22a93522ba6da1780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Thu, 4 Jan 2018 18:59:50 +0100 Subject: [PATCH 7/8] tests: check_list.c: start zeroing in on the gaps in tests' coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- tests/Makefile.am | 11 ++++- tests/check_list.c | 107 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 tests/check_list.c diff --git a/tests/Makefile.am b/tests/Makefile.am index def4b41d0..a13892778 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -108,12 +108,15 @@ bench_log_SOURCES = bench-log.c bench_log_LDADD = $(top_builddir)/lib/libqb.la if HAVE_CHECK -TESTS = array.test map.test rb.test log.test blackbox-segfault.sh loop.test ipc.test resources.test +TESTS = array.test ipc.test list.test log.test loop.test \ + map.test rb.test resources.test blackbox-segfault.sh 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 = resources.test blackbox-segfault.sh if HAVE_SLOW_TESTS @@ -168,6 +171,10 @@ 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..1eb53f6a6 --- /dev/null +++ b/tests/check_list.c @@ -0,0 +1,107 @@ +/* + * Copyright 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_uint_eq(iter->i, iter_i); + iter_i++; + } + + /* ... and decreasing when iterating backward */ + qb_list_for_each_entry_reverse(iter, &mylist, list) { + ck_assert_uint_gt(iter_i, 0); + ck_assert_uint_eq(iter->i, iter_i-1); + iter_i--; + } + ck_assert_uint_eq(iter_i, 0); + + /* also check qb_list_replace and qb_list_first_entry */ + qb_list_replace(mylist.next, &replacement.list); + ck_assert_uint_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; +} From fb45f6671c1d04017c88567006229e6d3365c663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pokorn=C3=BD?= Date: Sun, 21 Jan 2018 13:02:00 +0100 Subject: [PATCH 8/8] tests: print_ver: make preprocessor emit "note" rather than warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IIRC, Chrissie asked about this around inclusion of the test at hand, and it seemed there was no way but to emit a warning to get something output at all. Now it turns wrong, and moreover, we make the code not fixed on GCC specific pragmas, with a bit of luck, "#pragma message" approach is adopted more widely by compilers. Signed-off-by: Jan Pokorný --- tests/print_ver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/print_ver.c b/tests/print_ver.c index 752aeb02d..6b16a7827 100644 --- a/tests/print_ver.c +++ b/tests/print_ver.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Red Hat, Inc. + * Copyright 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);