[PATCH] Fix errors found by api-sanity-autotest
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
build-aux/api-auto-test.xml | 9 +++++++
check | 11 ++++++++
include/qb/qbmap.h | 2 +-
lib/ipcc.c | 20 +++++++++++++-
lib/ipcs.c | 49 ++++++++++++++++++++++++++++++++++++-
lib/log.c | 4 +++
lib/log_blackbox.c | 2 +-
lib/log_format.c | 4 +++
lib/ringbuffer.c | 56 ++++++++++++++++++++++++++++++++++++++----
tests/.gitignore | 1 +
10 files changed, 146 insertions(+), 12 deletions(-)
create mode 100644 build-aux/api-auto-test.xml
diff --git a/build-aux/api-auto-test.xml b/build-aux/api-auto-test.xml
new file mode 100644
index 0000000..e89b780
--- /dev/null
+++ b/build-aux/api-auto-test.xml
@@ -0,0 +1,9 @@
+<version>
+ master
+</version>
+<headers>
+ include/qb
+</headers>
+<libs>
+ lib/
+</libs>
diff --git a/check b/check
index eff22cb..287f707 100755
--- a/check
+++ b/check
@@ -198,6 +198,14 @@ check_abi() {
git checkout master
}
+check_api_sanity() {
+ make
+ export CFLAGS="-Wall -ggdb2"
+ api-sanity-autotest -l libqb -d build-aux/api-auto-test.xml -gen -build -run
+ google-chrome test_results/libqb/master/test_results.html
+ google-chrome test_results/libqb/master/test_results.html
+}
+
check_all() {
check_ansi
check_nosection
@@ -251,6 +259,9 @@ case $command in
abi)
check_abi $args
;;
+ api_sanity)
+ check_api_sanity
+ ;;
all)
check_all
;;
diff --git a/include/qb/qbmap.h b/include/qb/qbmap.h
index 36f51f3..dc32a56 100644
--- a/include/qb/qbmap.h
+++ b/include/qb/qbmap.h
@@ -133,7 +133,7 @@ int32_t qb_map_notify_del(qb_map_t* m, const char* key,
*/
int32_t qb_map_notify_del_2(qb_map_t* m, const char* key,
qb_map_notify_fn fn, int32_t events,
- void *userdata);
+ void *user_data);
/**
* Inserts a new key and value into a qb_map_t.
diff --git a/lib/ipcc.c b/lib/ipcc.c
index 9b51266..be09631 100644
--- a/lib/ipcc.c
+++ b/lib/ipcc.c
@@ -90,7 +90,7 @@ qb_ipcc_send(struct qb_ipcc_connection * c, const void *msg_ptr, size_t msg_len)
ssize_t res;
ssize_t res2;
- if (msg_len > c->request.max_msg_size) {
+ if (c == NULL || msg_len > c->request.max_msg_size) {
return -EINVAL;
}
if (c->funcs.fc_get) {
@@ -133,7 +133,7 @@ qb_ipcc_sendv(struct qb_ipcc_connection * c, const struct iovec * iov,
for (i = 0; i < iov_len; i++) {
total_size += iov[i].iov_len;
}
- if (total_size > c->request.max_msg_size) {
+ if (c == NULL || total_size > c->request.max_msg_size) {
return -EINVAL;
}
@@ -171,6 +171,9 @@ qb_ipcc_recv(struct qb_ipcc_connection * c, void *msg_ptr,
{
int32_t res = 0;
int32_t res2 = 0;
+ if (c == NULL) {
+ return -EINVAL;
+ }
res = c->funcs.recv(&c->response, msg_ptr, msg_len, ms_timeout);
if ((res == -EAGAIN || res == -ETIMEDOUT) && c->needs_sock_for_poll) {
@@ -191,6 +194,10 @@ qb_ipcc_sendv_recv(qb_ipcc_connection_t * c,
{
ssize_t res = 0;
+ if (c == NULL) {
+ return -EINVAL;
+ }
+
if (c->funcs.fc_get) {
res = c->funcs.fc_get(&c->request);
if (res < 0) {
@@ -215,6 +222,9 @@ qb_ipcc_sendv_recv(qb_ipcc_connection_t * c,
int32_t
qb_ipcc_fd_get(struct qb_ipcc_connection * c, int32_t * fd)
{
+ if (c == NULL) {
+ return -EINVAL;
+ }
if (c->type == QB_IPC_SOCKET) {
*fd = c->event.u.us.sock;
} else {
@@ -232,6 +242,9 @@ qb_ipcc_event_recv(struct qb_ipcc_connection * c, void *msg_pt,
ssize_t size;
struct qb_ipc_one_way *ow = NULL;
+ if (c == NULL) {
+ return -EINVAL;
+ }
if (c->needs_sock_for_poll) {
ow = &c->setup;
}
@@ -262,6 +275,9 @@ qb_ipcc_disconnect(struct qb_ipcc_connection *c)
{
qb_util_log(LOG_DEBUG, "%s()", __func__);
+ if (c == NULL) {
+ return;
+ }
qb_ipcc_us_sock_close(c->setup.u.us.sock);
if (c->funcs.disconnect) {
c->funcs.disconnect(c);
diff --git a/lib/ipcs.c b/lib/ipcs.c
index 70d4382..cf014d4 100644
--- a/lib/ipcs.c
+++ b/lib/ipcs.c
@@ -80,6 +80,13 @@ qb_ipcs_run(struct qb_ipcs_service *s)
{
int32_t res;
+
+ if (s->poll_fns.dispatch_add == NULL ||
+ s->poll_fns.dispatch_mod == NULL ||
+ s->poll_fns.dispatch_del == NULL) {
+ return -EINVAL;
+ }
+
switch (s->type) {
case QB_IPC_SOCKET:
qb_ipcs_us_init((struct qb_ipcs_service *)s);
@@ -216,6 +223,9 @@ qb_ipcs_response_send(struct qb_ipcs_connection *c, const void *data,
{
ssize_t res;
+ if (c == NULL) {
+ return -EINVAL;
+ }
qb_ipcs_connection_ref(c);
res = c->service->funcs.send(&c->response, data, size);
if (res == size) {
@@ -234,6 +244,9 @@ qb_ipcs_response_sendv(struct qb_ipcs_connection * c, const struct iovec * iov,
{
ssize_t res;
+ if (c == NULL) {
+ return -EINVAL;
+ }
qb_ipcs_connection_ref(c);
res = c->service->funcs.sendv(&c->response, iov, iov_len);
if (res > 0) {
@@ -274,6 +287,9 @@ qb_ipcs_event_send(struct qb_ipcs_connection * c, const void *data, size_t size)
ssize_t res;
ssize_t res2 = 0;
+ if (c == NULL) {
+ return -EINVAL;
+ }
qb_ipcs_connection_ref(c);
res = c->service->funcs.send(&c->event, data, size);
@@ -312,6 +328,9 @@ qb_ipcs_event_sendv(struct qb_ipcs_connection * c,
ssize_t res;
ssize_t res2;
+ if (c == NULL) {
+ return -EINVAL;
+ }
qb_ipcs_connection_ref(c);
res = c->service->funcs.sendv(&c->event, iov, iov_len);
@@ -367,7 +386,7 @@ qb_ipcs_connection_next_get(struct qb_ipcs_service * s,
struct qb_ipcs_connection *c;
struct qb_list_head *iter;
- if (current->list.next == &s->connections) {
+ if (current == NULL || current->list.next == &s->connections) {
return NULL;
}
iter = current->list.next;
@@ -381,6 +400,9 @@ qb_ipcs_connection_next_get(struct qb_ipcs_service * s,
int32_t
qb_ipcs_service_id_get(struct qb_ipcs_connection * c)
{
+ if (c == NULL) {
+ return -EINVAL;
+ }
return c->service->service_id;
}
@@ -411,7 +433,9 @@ qb_ipcs_connection_alloc(struct qb_ipcs_service *s)
void
qb_ipcs_connection_ref(struct qb_ipcs_connection *c)
{
- qb_atomic_int_inc(&c->refcount);
+ if (c) {
+ qb_atomic_int_inc(&c->refcount);
+ }
}
void
@@ -419,6 +443,9 @@ qb_ipcs_connection_unref(struct qb_ipcs_connection *c)
{
int32_t free_it;
+ if (c == NULL) {
+ return;
+ }
if (c->refcount < 1) {
qb_util_log(LOG_ERR, "%s() ref:%d state:%d fd:%d",
__func__, c->refcount, c->state,
@@ -443,6 +470,9 @@ qb_ipcs_disconnect(struct qb_ipcs_connection *c)
int32_t res = 0;
qb_loop_job_dispatch_fn rerun_job;
+ if (c == NULL) {
+ return;
+ }
qb_util_log(LOG_DEBUG, "%s() state:%d", __func__, c->state);
if (c->state == QB_IPCS_CONNECTION_ACTIVE) {
@@ -482,6 +512,9 @@ qb_ipcs_disconnect(struct qb_ipcs_connection *c)
static void
qb_ipcs_flowcontrol_set(struct qb_ipcs_connection *c, int32_t fc_enable)
{
+ if (c == NULL) {
+ return;
+ }
if (c->fc_enabled != fc_enable) {
c->service->funcs.fc_set(&c->request, fc_enable);
c->fc_enabled = fc_enable;
@@ -640,12 +673,18 @@ qb_ipcs_dispatch_connection_request(int32_t fd, int32_t revents, void *data)
void
qb_ipcs_context_set(struct qb_ipcs_connection *c, void *context)
{
+ if (c == NULL) {
+ return;
+ }
c->context = context;
}
void *
qb_ipcs_context_get(struct qb_ipcs_connection *c)
{
+ if (c == NULL) {
+ return NULL;
+ }
return c->context;
}
@@ -654,6 +693,9 @@ qb_ipcs_connection_stats_get(qb_ipcs_connection_t * c,
struct qb_ipcs_connection_stats * stats,
int32_t clear_after_read)
{
+ if (c == NULL) {
+ return -EINVAL;
+ }
memcpy(stats, &c->stats, sizeof(struct qb_ipcs_connection_stats));
if (clear_after_read) {
memset(&c->stats, 0, sizeof(struct qb_ipcs_connection_stats));
@@ -666,6 +708,9 @@ int32_t
qb_ipcs_stats_get(struct qb_ipcs_service * s,
struct qb_ipcs_stats * stats, int32_t clear_after_read)
{
+ if (s == NULL) {
+ return -EINVAL;
+ }
memcpy(stats, &s->stats, sizeof(struct qb_ipcs_stats));
if (clear_after_read) {
memset(&s->stats, 0, sizeof(struct qb_ipcs_stats));
diff --git a/lib/log.c b/lib/log.c
index fd974b6..201670d 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -244,6 +244,10 @@ qb_log_from_external_source_va(const char *function,
struct qb_list_head *f_item;
int32_t pos;
+ if (!logger_inited) {
+ return;
+ }
+
cs = qb_log_dcs_get(&new_dcs, function, filename,
format, priority, lineno, tags);
if (cs == NULL) {
diff --git a/lib/log_blackbox.c b/lib/log_blackbox.c
index 28c10c6..c9d091b 100644
--- a/lib/log_blackbox.c
+++ b/lib/log_blackbox.c
@@ -144,7 +144,7 @@ qb_log_blackbox_print_from_file(const char *bb_filename)
int fd;
char time_buf[64];
- fd = open(bb_filename, O_CREAT | O_RDWR, 0700);
+ fd = open(bb_filename, 0);
if (fd < 0) {
qb_perror(LOG_ERR, "qb_log_blackbox_print_from_file");
return;
diff --git a/lib/log_format.c b/lib/log_format.c
index 7f452e2..55d8a6f 100644
--- a/lib/log_format.c
+++ b/lib/log_format.c
@@ -174,6 +174,10 @@ qb_log_target_format(int32_t target,
int c;
struct qb_log_target *t = qb_log_target_get(target);
+ if (t->format == NULL) {
+ return;
+ }
+
while ((c = t->format[format_buffer_idx])) {
cutoff = 0;
ralign = 0;
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index ff490df..e767077 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -250,18 +250,27 @@ qb_rb_close(qb_ringbuffer_t * rb)
char *
qb_rb_name_get(qb_ringbuffer_t * rb)
{
+ if (rb == NULL) {
+ return NULL;
+ }
return rb->shared_hdr->hdr_path;
}
void *
qb_rb_shared_user_data_get(qb_ringbuffer_t * rb)
{
+ if (rb == NULL) {
+ return NULL;
+ }
return rb->shared_hdr->user_data;
}
int32_t
qb_rb_refcount_get(qb_ringbuffer_t * rb)
{
+ if (rb == NULL) {
+ return -EINVAL;
+ }
return qb_atomic_int_get(&rb->shared_hdr->ref_count);
}
@@ -272,6 +281,9 @@ qb_rb_space_free(qb_ringbuffer_t * rb)
uint32_t read_size;
size_t space_free = 0;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
write_size = rb->shared_hdr->write_pt;
/*
* TODO idx_cache_line_step (write_size);
@@ -298,6 +310,9 @@ qb_rb_space_used(qb_ringbuffer_t * rb)
uint32_t read_size;
size_t space_used;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
write_size = rb->shared_hdr->write_pt;
read_size = rb->shared_hdr->read_pt;
@@ -316,6 +331,9 @@ qb_rb_space_used(qb_ringbuffer_t * rb)
ssize_t
qb_rb_chunks_used(struct qb_ringbuffer_s *rb)
{
+ if (rb == NULL) {
+ return -EINVAL;
+ }
return rb->sem_getvalue_fn(rb);
}
@@ -324,6 +342,9 @@ qb_rb_chunk_alloc(qb_ringbuffer_t * rb, size_t len)
{
uint32_t write_pt;
+ if (rb == NULL) {
+ return NULL;
+ }
/*
* Reclaim data if we are over writing and we need space
*/
@@ -381,11 +402,15 @@ qb_rb_chunk_step(qb_ringbuffer_t * rb, uint32_t pointer)
int32_t
qb_rb_chunk_commit(qb_ringbuffer_t * rb, size_t len)
{
- uint32_t old_write_pt = rb->shared_hdr->write_pt;
+ uint32_t old_write_pt;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
/*
* commit the magic & chunk_size
*/
+ old_write_pt = rb->shared_hdr->write_pt;
rb->shared_data[old_write_pt] = len;
rb->shared_data[old_write_pt + 1] = QB_RB_CHUNK_MAGIC;
@@ -410,6 +435,10 @@ qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
char *dest = qb_rb_chunk_alloc(rb, len);
int32_t res = 0;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
+
if (dest == NULL) {
return -errno;
}
@@ -427,12 +456,12 @@ qb_rb_chunk_write(qb_ringbuffer_t * rb, const void *data, size_t len)
void
qb_rb_chunk_reclaim(qb_ringbuffer_t * rb)
{
- uint32_t old_read_pt = rb->shared_hdr->read_pt;
+ uint32_t old_read_pt;
- if (qb_rb_space_used(rb) == 0) {
+ if (rb == NULL || qb_rb_space_used(rb) == 0) {
return;
}
-
+ old_read_pt = rb->shared_hdr->read_pt;
qb_rb_chunk_check(rb, old_read_pt);
rb->shared_hdr->read_pt = qb_rb_chunk_step(rb, old_read_pt);
@@ -456,6 +485,9 @@ qb_rb_chunk_peek(qb_ringbuffer_t * rb, void **data_out, int32_t timeout)
uint32_t chunk_magic;
int32_t res;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
res = rb->sem_timedwait_fn(rb, timeout);
if (res < 0 && res != -EIDRM) {
if (res != -ETIMEDOUT) {
@@ -484,6 +516,9 @@ qb_rb_chunk_read(qb_ringbuffer_t * rb, void *data_out, size_t len,
uint32_t chunk_size;
int32_t res = 0;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
if (rb->sem_timedwait_fn) {
res = rb->sem_timedwait_fn(rb, timeout);
}
@@ -554,6 +589,9 @@ qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
ssize_t result;
ssize_t written_size = 0;
+ if (rb == NULL) {
+ return -EINVAL;
+ }
print_header(rb);
result = write(fd, &rb->shared_hdr->size, sizeof(uint32_t));
@@ -598,7 +636,7 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags)
uint32_t write_pt;
qb_ringbuffer_t *rb = calloc(1, sizeof(qb_ringbuffer_t));
- if (rb == NULL) {
+ if (rb == NULL || fd < 0) {
return NULL;
}
rb->shared_hdr = calloc(1, sizeof(struct qb_ringbuffer_shared_s));
@@ -632,6 +670,7 @@ qb_rb_create_from_file(int32_t fd, uint32_t flags)
if (n_read != n_required) {
qb_util_log(LOG_WARNING, "read %zd bytes, but expected %zu",
n_read, n_required);
+ goto cleanup_fail;
}
n_read = read(fd, &write_pt, sizeof(uint32_t));
@@ -659,7 +698,12 @@ cleanup_fail2:
int32_t
qb_rb_chown(qb_ringbuffer_t * rb, uid_t owner, gid_t group)
{
- int32_t res = chown(rb->shared_hdr->data_path, owner, group);
+ int32_t res;
+
+ if (rb == NULL) {
+ return -EINVAL;
+ }
+ res = chown(rb->shared_hdr->data_path, owner, group);
if (res < 0) {
return -errno;
}
diff --git a/tests/.gitignore b/tests/.gitignore
index 4b117ca..a3be604 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -7,3 +7,4 @@ loop
rbreader
rbwriter
write_logs.c
+libqb
--
1.7.7.3
12 years, 5 months
[PATCH] map: enforce uniqueness of the notifiers based on (func, key, event, userdata)
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/hashtable.c | 4 +++-
lib/skiplist.c | 12 ++++++++++++
lib/trie.c | 12 ++++++++++++
tests/check_map.c | 9 +++++++++
4 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/lib/hashtable.c b/lib/hashtable.c
index 27e41ac..f6f2edf 100644
--- a/lib/hashtable.c
+++ b/lib/hashtable.c
@@ -269,7 +269,9 @@ hashtable_notify_add(qb_map_t * m, const char *key,
for (list = head->next; list != head; list = list->next) {
f = qb_list_entry(list, struct qb_map_notifier, list);
- if (f->events == events && f->callback == fn) {
+ if (f->events == events &&
+ f->user_data == user_data &&
+ f->callback == fn) {
return -EEXIST;
}
}
diff --git a/lib/skiplist.c b/lib/skiplist.c
index b5b22db..045fa11 100644
--- a/lib/skiplist.c
+++ b/lib/skiplist.c
@@ -241,6 +241,7 @@ skiplist_notify_add(qb_map_t * m, const char *key,
struct skiplist *t = (struct skiplist *)m;
struct qb_map_notifier *f;
struct skiplist_node *n;
+ struct qb_list_head *list;
if (key) {
n = skiplist_lookup(t, key);
@@ -248,6 +249,17 @@ skiplist_notify_add(qb_map_t * m, const char *key,
n = t->header;
}
if (n) {
+ for (list = n->notifier_head.next;
+ list != &n->notifier_head; list = list->next) {
+ f = qb_list_entry(list, struct qb_map_notifier, list);
+
+ if (f->events == events &&
+ f->callback == fn &&
+ f->user_data == user_data) {
+ return -EEXIST;
+ }
+ }
+
f = malloc(sizeof(struct qb_map_notifier));
if (f == NULL) {
return -errno;
diff --git a/lib/trie.c b/lib/trie.c
index 90f66dd..3283d12 100644
--- a/lib/trie.c
+++ b/lib/trie.c
@@ -309,6 +309,7 @@ trie_notify_add(qb_map_t * m, const char *key,
struct trie *t = (struct trie *)m;
struct qb_map_notifier *f;
struct trie_node *n;
+ struct qb_list_head *list;
if (key) {
n = trie_lookup(t, key, QB_TRUE);
@@ -316,6 +317,17 @@ trie_notify_add(qb_map_t * m, const char *key,
n = t->header;
}
if (n) {
+ for (list = n->notifier_head.next;
+ list != &n->notifier_head; list = list->next) {
+ f = qb_list_entry(list, struct qb_map_notifier, list);
+
+ if (f->events == events &&
+ f->callback == fn &&
+ f->user_data == user_data) {
+ return -EEXIST;
+ }
+ }
+
f = malloc(sizeof(struct qb_map_notifier));
if (f == NULL) {
return -errno;
diff --git a/tests/check_map.c b/tests/check_map.c
index 7d4f316..815b321 100644
--- a/tests/check_map.c
+++ b/tests/check_map.c
@@ -313,6 +313,15 @@ test_map_notifications_basic(qb_map_t *m)
QB_MAP_NOTIFY_REPLACED|
QB_MAP_NOTIFY_RECURSIVE));
ck_assert_int_eq(i, -ENOENT);
+
+/* test uniquess */
+ qb_map_put(m, "fred", "null");
+ i = qb_map_notify_add(m, "fred", my_map_notification,
+ QB_MAP_NOTIFY_REPLACED, m);
+ ck_assert_int_eq(i, 0);
+ i = qb_map_notify_add(m, "fred", my_map_notification,
+ QB_MAP_NOTIFY_REPLACED, m);
+ ck_assert_int_eq(i, -EEXIST);
}
static void
--
1.7.7.3
12 years, 5 months
[PATCH 1/6] By default don't build in the slow benchlog
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
configure.ac | 12 ++++++++++++
tests/Makefile.am | 2 ++
tests/bench-log.c | 2 +-
3 files changed, 15 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index c8dcd2c..855dfef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -311,6 +311,10 @@ AC_ARG_ENABLE([coverage],
[ --enable-coverage : coverage analysis of the codebase. ],
[ default="no" ])
+AC_ARG_ENABLE([slow-tests],
+ [ --enable-slow-tests : build and run slow tests. ],
+ [ default="no" ])
+
AC_ARG_WITH([socket-dir],
[ --with-socket-dir=DIR : socket dir. ],
[ SOCKETDIR="$withval" ],
@@ -379,6 +383,14 @@ else
COVERAGE_LDFLAGS=""
fi
+
+if test "x${enable_slow_tests}" = xyes ; then
+ AC_DEFINE([HAVE_SLOW_TESTS], 1,[have slow tests])
+ AC_MSG_NOTICE([Enabling Slow tests])
+fi
+AM_CONDITIONAL(HAVE_SLOW_TESTS, [test "x$enable_slow_tests" = xyes])
+
+
AM_CONDITIONAL(USE_TIMERFD, [test "x$ac_cv_func_timerfd_create" = xyes])
# --- callsite sections ---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fbe1ba0..634e0ed 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -48,6 +48,7 @@ loop_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
loop_LDADD = -lrt $(top_builddir)/lib/libqb.la
if HAVE_DICT_WORDS
+if HAVE_SLOW_TESTS
EXTRA_DIST += make-log-test
CLEANFILES += write_logs.c
MAINTAINERCLEANFILES += write_logs.c
@@ -63,6 +64,7 @@ distclean-compile:
rm -rf write_logs.c
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
diff --git a/tests/bench-log.c b/tests/bench-log.c
index 236ec18..7d54439 100644
--- a/tests/bench-log.c
+++ b/tests/bench-log.c
@@ -82,7 +82,7 @@ main(void)
qb_log(LOG_DEBUG, "%i %u %p", -534, 4508, &i);
}
bm_finish ("qb_log 3 args(int):");
-#ifdef HAVE_DICT_WORDS
+#if defined(HAVE_DICT_WORDS) && defined(HAVE_SLOW_TESTS)
qb_util_stopwatch_start(sw);
log_dict_words();
bm_finish ("qb_log /usr/share/dict/words:");
--
1.7.7.3
12 years, 5 months
[PATCH] check: add abi checking script
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
.gitignore | 3 ++
build-aux/abi-check-templ.xml | 12 +++++++++++
check | 44 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+), 0 deletions(-)
create mode 100644 build-aux/abi-check-templ.xml
diff --git a/.gitignore b/.gitignore
index 6d212db..8bed236 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,3 +34,6 @@ lib/run_splint.sh
.tarball-version
libqb.spec
include/qb/stamp-h2
+cov
+compat_reports
+abi_dumps
\ No newline at end of file
diff --git a/build-aux/abi-check-templ.xml b/build-aux/abi-check-templ.xml
new file mode 100644
index 0000000..4cac826
--- /dev/null
+++ b/build-aux/abi-check-templ.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<descriptor>
+<version>
+ @VERSION@
+</version>
+<headers>
+ @PREFIX@/usr/include/qb
+</headers>
+<libs>
+ @PREFIX(a)/usr/lib64/libqb.so
+</libs>
+</descriptor>
diff --git a/check b/check
index ddeba67..eff22cb 100755
--- a/check
+++ b/check
@@ -157,6 +157,47 @@ check_coverity() {
cov-format-errors --dir cov
}
+check_abi() {
+ ver1=$1
+ ver2=$2
+
+ TMPL=build-aux/abi-check-templ.xml
+ checker=abi-compliance-checker
+
+ mkdir -p abi_dumps/libqb
+ 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
+ b=api-check-$v
+ echo "== Version $v =="
+ if [ ! -f abi_dumps/libqb/libqb_$v.abi.tar.gz ]
+ then
+ git checkout -B $b $t
+ ./autogen.sh
+ ./configure
+ make
+ make install DESTDIR=$p
+ $checker -l libqb -dump_abi abi_dumps/libqb/$v.xml
+ fi
+ done
+
+ $checker -l libqb \
+ -d1 abi_dumps/libqb/libqb_$ver1.abi.tar.gz \
+ -d2 abi_dumps/libqb/libqb_$ver2.abi.tar.gz
+
+ google-chrome compat_reports/libqb/$ver1\_to_$ver2/abi_compat_report.html
+
+ echo mv compat_reports/libqb/$ver1\_to_$ver2/abi_compat_report.html abi_compat_report_$ver1\_to_$ver2.html
+ echo scp abi_compat_report_$ver1\_to_$ver2.html fedorahosted.org:quarterback
+ git checkout master
+}
+
check_all() {
check_ansi
check_nosection
@@ -207,6 +248,9 @@ case $command in
coverity)
check_coverity
;;
+ abi)
+ check_abi $args
+ ;;
all)
check_all
;;
--
1.7.7.3
12 years, 5 months
[PATCH 1/3] LOG: clean up mem better when qb_log_fini is called
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log.c | 8 +-------
lib/log_dcs.c | 3 +++
lib/log_thread.c | 1 +
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index 5911f06..aa740b0 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -707,10 +707,8 @@ qb_log_fini(void)
for (pos = 0; pos <= conf_active_max; pos++) {
t = &conf[pos];
- if (t->state != QB_LOG_STATE_ENABLED) {
- continue;
- }
_log_target_disable(t);
+ free(conf[pos].format);
qb_list_for_each_safe(iter2, next2, &t->filter_head) {
flt = qb_list_entry(iter2, struct qb_log_filter, list);
qb_list_del(iter2);
@@ -765,10 +763,6 @@ qb_log_target_get(int32_t pos)
void *
qb_log_target_user_data_get(int32_t t)
{
- if (!logger_inited) {
- errno = -EINVAL;
- return NULL;
- }
if (t < 0 || t >= QB_LOG_TARGET_MAX ||
conf[t].state == QB_LOG_STATE_UNUSED) {
errno = -EBADF;
diff --git a/lib/log_dcs.c b/lib/log_dcs.c
index d19f7b0..bbd2362 100644
--- a/lib/log_dcs.c
+++ b/lib/log_dcs.c
@@ -181,4 +181,7 @@ qb_log_dcs_init(void)
void
qb_log_dcs_fini(void)
{
+ qb_array_free(lookup_arr);
+ qb_array_free(callsite_arr);
+ (void)qb_thread_lock_destroy(arr_next_lock);
}
diff --git a/lib/log_thread.c b/lib/log_thread.c
index b728f06..4756816 100644
--- a/lib/log_thread.c
+++ b/lib/log_thread.c
@@ -273,4 +273,5 @@ qb_log_thread_stop(void)
sem_post(&logt_print_finished);
pthread_join(logt_thread_id, NULL);
}
+ (void)qb_thread_lock_destroy(logt_wthread_lock);
}
--
1.7.7
12 years, 5 months
[PATCH 1/2] TEST: add a test that reproduces issue/20
by Angus Salkeld
https://github.com/asalkeld/libqb/issues/20
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/check_array.c | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/tests/check_array.c b/tests/check_array.c
index 8d3bce2..47f1c23 100644
--- a/tests/check_array.c
+++ b/tests/check_array.c
@@ -67,6 +67,14 @@ START_TEST(test_array_limits)
}
END_TEST
+START_TEST(test_array_alloc_free)
+{
+ qb_array_t *a;
+ a = qb_array_create(65536, sizeof(struct test_my_st));
+ qb_array_free(a);
+}
+END_TEST
+
START_TEST(test_array_correct_retrieval)
{
qb_array_t *a;
@@ -134,6 +142,10 @@ static Suite *array_suite(void)
tcase_add_test(tc, test_array_limits);
suite_add_tcase(s, tc);
+ tc = tcase_create("alloc_free");
+ tcase_add_test(tc, test_array_alloc_free);
+ suite_add_tcase(s, tc);
+
tc = tcase_create("correct_retrieval");
tcase_add_test(tc, test_array_correct_retrieval);
suite_add_tcase(s, tc);
--
1.7.7
12 years, 5 months
[PATCH 1/5] MAP: Fix trie_new_node() and make skiplist_node_new() more consistent.
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/skiplist.c | 10 +++++-----
lib/trie.c | 3 +--
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/skiplist.c b/lib/skiplist.c
index b929505..da36f8d 100644
--- a/lib/skiplist.c
+++ b/lib/skiplist.c
@@ -117,12 +117,12 @@ skiplist_node_new(const int8_t level, const char *key, const void *value)
new_node->forward = (struct skiplist_node **)
(calloc(level + 1, sizeof(struct skiplist_node *)));
- if (new_node->forward)
- return new_node;
-
- free(new_node);
+ if (new_node->forward == NULL) {
+ free(new_node);
+ return NULL;
+ }
- return NULL;
+ return new_node;
}
static struct skiplist_node *
diff --git a/lib/trie.c b/lib/trie.c
index 1fdf4ca..67c3946 100644
--- a/lib/trie.c
+++ b/lib/trie.c
@@ -164,11 +164,10 @@ trie_new_node(struct trie *t, struct trie_node *parent)
}
new_node->parent = parent;
-
new_node->num_children = 30;
new_node->children = calloc(new_node->num_children,
sizeof(struct trie_node *));
- if (new_node->children) {
+ if (new_node->children == NULL) {
free(new_node);
return NULL;
}
--
1.7.7
12 years, 5 months