Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc (ABI comparison) and various other fixes #287

Closed
wants to merge 8 commits into from
5 changes: 4 additions & 1 deletion build-aux/abi-check-templ.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<headers>
@PREFIX@/usr/include/qb
</headers>
@SKIPLIB_CMT@<skip_libs>
@SKIPLIB_CMT@ @PREFIX@/usr/lib64/libqb.so
@SKIPLIB_CMT@</skip_libs>
<libs>
@PREFIX@/usr/lib64/libqb.so
@PREFIX@/usr/lib64/libqb.so@LIB_SUFFIX@
</libs>
</descriptor>
49 changes: 35 additions & 14 deletions check
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -334,4 +356,3 @@ case $command in
esac
cd -
exit 0

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions include/qb/qbarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/

Expand Down
16 changes: 8 additions & 8 deletions include/qb/qblist.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
> $@

Expand Down
71 changes: 40 additions & 31 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -98,20 +104,19 @@ $(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
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
Expand All @@ -121,28 +126,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
Expand All @@ -157,15 +162,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:
Expand Down
107 changes: 107 additions & 0 deletions tests/check_list.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* Copyright 2018 Red Hat, Inc.
*
* All rights reserved.
*
* Author: Jan Pokorny <[email protected]>
*
* 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 <http://www.gnu.org/licenses/>.
*/

#include "os_base.h"

#include "check_common.h"

#include <qb/qblist.h>
#include <qb/qblog.h>

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;
}
Loading