From 2b913d4d69dafb438382471cfdd629e1e01fea30 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Sun, 2 Jul 2017 23:53:48 +0200 Subject: [PATCH] tests: fix valgrind warnings --- include/villas/list.h | 10 +++++++++- include/villas/plugin.h | 4 ++-- lib/nodes/cbuilder.c | 4 ++-- lib/nodes/file.c | 6 +++--- lib/nodes/fpga.c | 7 ++++--- lib/nodes/nanomsg.c | 6 +++--- lib/nodes/ngsi.c | 5 +++-- lib/nodes/opal.c | 6 +++--- lib/nodes/shmem.c | 4 ++-- lib/nodes/socket.c | 4 ++-- lib/nodes/websocket.c | 4 ++-- lib/nodes/zeromq.c | 6 +++--- lib/plugin.c | 7 ++----- src/pipe.c | 9 ++------- tests/Makefile.inc | 6 ++++-- tests/valgrind.supp | 20 ++++++++++++++++++++ 16 files changed, 66 insertions(+), 42 deletions(-) diff --git a/include/villas/list.h b/include/villas/list.h index 18c2d99bd..456fbbdd6 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -29,9 +29,17 @@ .state = STATE_INITIALIZED \ } +#define LIST_INIT_STATIC(l) \ +__attribute__((constructor(105))) static void UNIQUE(__ctor)() {\ + list_init(l); \ +} \ +__attribute__((destructor(105))) static void UNIQUE(__dtor)() { \ + list_destroy(l, NULL, false); \ +} + #define list_length(list) ((list)->length) #define list_at_safe(list, index) ((list)->length > index ? (list)->array[index] : NULL) -#define list_at(list, index) ((list)->array[index]) +#define list_at(list, index) ((list)->array[index]) #define list_first(list) list_at(list, 0) #define list_last(list) list_at(list, (list)->length-1) diff --git a/include/villas/plugin.h b/include/villas/plugin.h index 7d00ca791..2a3ad3d81 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -33,10 +33,10 @@ #include "nodes/cbuilder.h" #define REGISTER_PLUGIN(p) \ -__attribute__((constructor)) static void UNIQUE(__ctor)() { \ +__attribute__((constructor(110))) static void UNIQUE(__ctor)() {\ list_push(&plugins, p); \ } \ -__attribute__((destructor)) static void UNIQUE(__dtor)() { \ +__attribute__((destructor(110))) static void UNIQUE(__dtor)() { \ list_remove(&plugins, p); \ } diff --git a/lib/nodes/cbuilder.c b/lib/nodes/cbuilder.c index 93ca31d38..48e4032e9 100644 --- a/lib/nodes/cbuilder.c +++ b/lib/nodes/cbuilder.c @@ -124,9 +124,9 @@ static struct plugin p = { .start = cbuilder_start, .stop = cbuilder_stop, .read = cbuilder_read, - .write = cbuilder_write, - .instances = LIST_INIT() + .write = cbuilder_write } }; REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) diff --git a/lib/nodes/file.c b/lib/nodes/file.c index b0136629f..eaa73e791 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -397,9 +397,9 @@ static struct plugin p = { .start = file_start, .stop = file_stop, .read = file_read, - .write = file_write, - .instances = LIST_INIT() + .write = file_write } }; -REGISTER_PLUGIN(&p) \ No newline at end of file +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/nodes/fpga.c b/lib/nodes/fpga.c index a406e4cb4..9dacb3a04 100644 --- a/lib/nodes/fpga.c +++ b/lib/nodes/fpga.c @@ -285,9 +285,10 @@ static struct plugin p = { .read = fpga_read, .write = fpga_write, .init = fpga_init, - .deinit = fpga_deinit, - .instances = LIST_INIT() + .deinit = fpga_deinit } }; -REGISTER_PLUGIN(&p) \ No newline at end of file +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) + \ No newline at end of file diff --git a/lib/nodes/nanomsg.c b/lib/nodes/nanomsg.c index 03678231f..a34d0c24c 100644 --- a/lib/nodes/nanomsg.c +++ b/lib/nodes/nanomsg.c @@ -243,9 +243,9 @@ static struct plugin p = { .stop = nanomsg_stop, .deinit = nanomsg_deinit, .read = nanomsg_read, - .write = nanomsg_write, - .instances = LIST_INIT() + .write = nanomsg_write } }; -REGISTER_PLUGIN(&p) \ No newline at end of file +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) diff --git a/lib/nodes/ngsi.c b/lib/nodes/ngsi.c index e80f5bbf8..3799724bf 100644 --- a/lib/nodes/ngsi.c +++ b/lib/nodes/ngsi.c @@ -595,9 +595,10 @@ static struct plugin p = { .read = ngsi_read, .write = ngsi_write, .init = ngsi_init, - .deinit = ngsi_deinit, - .instances = LIST_INIT() + .deinit = ngsi_deinit } }; REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) + diff --git a/lib/nodes/opal.c b/lib/nodes/opal.c index d278dd3a9..c60fac15e 100644 --- a/lib/nodes/opal.c +++ b/lib/nodes/opal.c @@ -306,9 +306,9 @@ static struct plugin p = { .read = opal_read, .write = opal_write, .init = opal_init, - .deinit = opal_deinit, - .instances = LIST_INIT() + .deinit = opal_deinit } }; -REGISTER_PLUGIN(&p) \ No newline at end of file +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/nodes/shmem.c b/lib/nodes/shmem.c index c7fffc112..de95fb984 100644 --- a/lib/nodes/shmem.c +++ b/lib/nodes/shmem.c @@ -194,9 +194,9 @@ static struct plugin p = { .start = shmem_open, .stop = shmem_close, .read = shmem_read, - .write = shmem_write, - .instances = LIST_INIT(), + .write = shmem_write } }; REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 92637d91a..8dfef86c9 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -850,9 +850,9 @@ static struct plugin p = { .read = socket_read, .write = socket_write, .init = socket_init, - .deinit = socket_deinit, - .instances = LIST_INIT() + .deinit = socket_deinit } }; REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index a7df5bfa3..44bb11227 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -600,9 +600,9 @@ static struct plugin p = { .read = websocket_read, .write = websocket_write, .print = websocket_print, - .parse = websocket_parse, - .instances = LIST_INIT() + .parse = websocket_parse } }; REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index cb9540734..ce7bbf6b1 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -484,9 +484,9 @@ static struct plugin p = { .init = zeromq_init, .deinit = zeromq_deinit, .read = zeromq_read, - .write = zeromq_write, - .instances = LIST_INIT() + .write = zeromq_write } }; -REGISTER_PLUGIN(&p) \ No newline at end of file +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file diff --git a/lib/plugin.c b/lib/plugin.c index 85183a4fb..2674e21f2 100644 --- a/lib/plugin.c +++ b/lib/plugin.c @@ -25,12 +25,9 @@ #include "plugin.h" /** Global list of all known plugins */ -struct list plugins = LIST_INIT(); +struct list plugins; -__attribute__((destructor(999))) static void __dtor_plugins() -{ - list_destroy(&plugins, NULL, false); -} +LIST_INIT_STATIC(&plugins) int plugin_init(struct plugin *p) { diff --git a/src/pipe.c b/src/pipe.c index fdedec8c2..b199e09d6 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -73,13 +73,8 @@ static void quit(int signal, siginfo_t *sinfo, void *ctx) pool_destroy(&sendd.pool); } - node_stop(node); - node_destroy(node); - - if (node->_vt->start == websocket_start) { - web_stop(&sn.web); - api_stop(&sn.api); - } + super_node_stop(&sn); + super_node_destroy(&sn); info(GRN("Goodbye!")); exit(EXIT_SUCCESS); diff --git a/tests/Makefile.inc b/tests/Makefile.inc index 7a5cb54cf..8ad1f1344 100644 --- a/tests/Makefile.inc +++ b/tests/Makefile.inc @@ -27,8 +27,10 @@ tests: unit-tests integration-tests run-tests: run-unit-tests run-integration-tests run-valgrind +VALGRIND = valgrind --leak-check=full --show-leak-kinds=all --suppressions=$(SRCDIR)/tests/valgrind.supp + run-valgrind: src - valgrind --leak-check=full --show-leak-kinds=all --suppressions=$(SRCDIR)/tests/valgrind.supp $(BUILDDIR)/villas-node & sleep 2; kill $$!; sleep 1; kill $$! - valgrind --leak-check=full --show-leak-kinds=all --suppressions=$(SRCDIR)/tests/valgrind.supp $(BUILDDIR)/villas-pipe $(SRCDIR)/etc/websocket-loopback.conf ws1 & sleep 2; kill $$!; sleep 1; kill $$! + $(VALGRIND) $(BUILDDIR)/villas-node & sleep 1; kill %1 + $(VALGRIND) $(BUILDDIR)/villas-pipe -t 1 $(SRCDIR)/etc/websocket-loopback.conf ws1 .PHONY: tests run-tests run-valgrind diff --git a/tests/valgrind.supp b/tests/valgrind.supp index ecd01c167..e8e9a9e71 100644 --- a/tests/valgrind.supp +++ b/tests/valgrind.supp @@ -5,4 +5,24 @@ ... fun:SSL_library_init ... +} +{ + libcurl-libnspr4 + Memcheck:Leak + match-leak-kinds: reachable + ... + obj:*/libnspr4.so* + ... + obj:*/libcurl.so* + ... +} +{ + libcurl-crypto + Memcheck:Leak + match-leak-kinds: reachable + ... + obj:*/libcrypto.so* + ... + obj:*/libcurl.so* + ... } \ No newline at end of file