diff --git a/Dockerfile.dev b/Dockerfile.dev index 69e98699b..c881c236e 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -28,7 +28,7 @@ # along with this program. If not, see . ################################################################################### -FROM fedora:latest +FROM fedora:25 MAINTAINER Steffen Vogel # Toolchain @@ -37,7 +37,7 @@ RUN dnf -y install \ pkgconfig make cmake \ autoconf automake autogen libtool \ flex bison \ - texinfo git + texinfo git curl tar # Several tools only needed for developement and testing RUN dnf -y install \ @@ -70,11 +70,9 @@ RUN dnf -y install \ libnl3-devel \ libcurl-devel \ jansson-devel \ - libsodium-devel \ libwebsockets-devel \ zeromq-devel \ nanomsg-devel \ - openpgm-devel \ libxil-devel # Build & Install Criterion diff --git a/Dockerfile.dev-ubuntu b/Dockerfile.dev-ubuntu new file mode 100644 index 000000000..e0b77381c --- /dev/null +++ b/Dockerfile.dev-ubuntu @@ -0,0 +1,100 @@ +# Dockerfile for VILLASnode development. +# +# This Dockerfile builds an image which contains all library dependencies +# and tools to build VILLASnode. +# However, VILLASnode itself it not part of the image. +# +# This image can be used for developing VILLASnode +# by running: +# make docker +# +# @author Steffen Vogel +# @copyright 2017, Institute for Automation of Complex Power Systems, EONERC +# @license GNU General Public License (version 3) +# +# VILLASnode +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +################################################################################### + +# You can choose between Debian and Ubuntu here +FROM ubuntu:xenial +#FROM debian:jessie + +MAINTAINER Steffen Vogel + +# Toolchain +RUN apt-get update && apt-get install -y \ + gcc g++ \ + pkg-config make cmake \ + autoconf automake autogen libtool \ + flex bison \ + texinfo git curl tar + +# Several tools only needed for developement and testing +RUN apt-get update && apt-get install -y \ + doxygen dia graphviz \ + openssh-client \ + jq \ + iproute \ + python-pip \ + valgrind gdb \ + xmlto asciidoctor + +# 32bit versions of some standard libraries for RT-LAB code +RUN dpkg --add-architecture i386 +RUN apt-get update && apt-get install -y \ + libc6:i386 \ + libstdc++6:i386 \ + uuid-dev:i386 \ + libssl-dev:i386 + +# Tools for debugging, coverage, profiling +RUN pip install \ + gcovr + +# Some of the dependencies are only available in our own repo +ADD https://villas.fein-aachen.org/packages/villas.repo /etc/yum.repos.d/ + +# Dependencies +RUN apt-get update && apt-get install -y \ + libssl-dev \ + libconfig-dev \ + libnl-3-dev libnl-route-3-dev \ + libcurl4-openssl-dev \ + libjansson-dev \ + libzmq3-dev \ + libnanomsg-dev + +# Build & Install Criterion +COPY thirdparty/criterion /tmp/criterion +RUN mkdir -p /tmp/criterion/build && cd /tmp/criterion/build && cmake .. && make install && rm -rf /tmp/* + +# Build & Install libxil +COPY thirdparty/libxil /tmp/libxil +RUN mkdir -p /tmp/libxil/build && cd /tmp/libxil/build && cmake .. && make install && rm -rf /tmp/* + +# Build & Install libxil +COPY thirdparty/libwebsockets /tmp/libwebsockets +RUN mkdir -p /tmp/libwebsockets/build && cd /tmp/libwebsockets/build && cmake -DLWS_IPV6=1 -DLWS_WITH_STATIC=0 -DLWS_WITHOUT_TESTAPPS=1 -DLWS_WITH_HTTP2=1 .. && make install && rm -rf /tmp/* + +# Expose ports for HTTP and WebSocket frontend +EXPOSE 80 +EXPOSE 443 + +ENV LD_LIBRARY_PATH /usr/local/lib:/usr/local/lib64 + +ENTRYPOINT villas +WORKDIR /villas +ENTRYPOINT bash diff --git a/Makefile b/Makefile index 65b6a1db3..4dbdbb6bf 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ LDFLAGS += -L$(BUILDDIR) # Some tools PKGCONFIG := PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config +SHELL := bash # We must compile without optimizations for gcov! ifdef DEBUG diff --git a/include/villas/shmem.h b/include/villas/shmem.h index 0171402d1..f60659e60 100644 --- a/include/villas/shmem.h +++ b/include/villas/shmem.h @@ -119,18 +119,15 @@ int shmem_int_read(struct shmem_int *shm, struct sample *smps[], unsigned cnt); */ int shmem_int_write(struct shmem_int *shm, struct sample *smps[], unsigned cnt); -/** Allocate samples to be written to the interface. The writing process must +/** Allocate samples to be written to the interface. * - * not free the samples; only the receiving process should free them using - * sample_put after use. + * The writing process must not free the samples; only the receiving process should free them using sample_put after use. * @param shm The shared memory interface. * @param smps Array where pointers to newly allocated samples will be returned. * @param cnt Number of samples to allocate. - * @returns Number of samples that were successfully allocated (may be less then cnt). + * @return Number of samples that were successfully allocated (may be less then cnt). */ -inline int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt) { - return sample_alloc(&shm->write.shared->pool, smps, cnt); -} +int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt); /** Returns the total size of the shared memory region with the given size of * the input/output queues (in elements) and the given number of data elements diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc index c0033e851..414f3f5ee 100644 --- a/lib/Makefile.villas.inc +++ b/lib/Makefile.villas.inc @@ -56,6 +56,9 @@ ifndef WITHOUT_NANOMSG ifeq ($(shell $(PKGCONFIG) nanomsg; echo $$?),0) LIB_SRCS += lib/nodes/nanomsg.c LIB_PKGS += nanomsg +else ifeq ($(shell $(PKGCONFIG) libnanomsg; echo $$?),0) + LIB_SRCS += lib/nodes/nanomsg.c + LIB_PKGS += libnanomsg endif endif @@ -95,17 +98,17 @@ endif # Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!) ifdef WITH_OPAL -ifneq ($(wildcard thirdparty/opal/include/AsyncApi.h),) +ifneq ($(wildcard thirdparty/libopal/include/opal/AsyncApi.h),) LIB_OBJS += opal.o - LIB_CFLAGS += -I thirdparty/opal/include - LIB_LDFLAGS += -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -Lthirdparty/opal/lib/redhawk/ + LIB_CFLAGS += -I thirdparty/libopal/include/opal/ + LIB_LDFLAGS += -L/lib/i386-linux-gnu/ -L/usr/lib/i386-linux-gnu/ -Lthirdparty/libopal/ LIB_LDLIBS += -lOpalAsyncApiCore -lOpalCore -lOpalUtils -lirc # libOpalAsyncApi is a 32bit library. So we need to build everything in 32bit CFLAGS += -m32 LDFLAGS += -m32 - BUILDDIR := $(BUILDDIR)32 + BUILDDIR := $(BUILDDIR) endif endif diff --git a/lib/hist.c b/lib/hist.c index 349486ab4..46885ec69 100644 --- a/lib/hist.c +++ b/lib/hist.c @@ -182,7 +182,7 @@ void hist_plot(struct hist *h) for (int i = 0; i < bar; i++) buf = strcatf(&buf, "\u2588"); - stats(buf); + stats("%s", buf); free(buf); } diff --git a/lib/hooks/jitter_calc.c b/lib/hooks/jitter_calc.c index f87fcab3a..23ef825ed 100644 --- a/lib/hooks/jitter_calc.c +++ b/lib/hooks/jitter_calc.c @@ -24,6 +24,8 @@ * @{ */ +#include + #include "hook.h" #include "plugin.h" #include "timing.h" @@ -73,7 +75,7 @@ int hook_jitter_ts(struct hook *h, struct sample *smps[], size_t *cnt) */ jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE] = jitter_val[curr_count] + (abs(curr_delay_us) - jitter_val[curr_count])/16; - info("jitter %ld usec, moving average %ld usec, moving variance %ld usec\n", jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE], moving_avg[curr_count], moving_var[curr_count]); + stats("%s: jitter=%" PRId64 " usec, moving average=%" PRId64 " usec, moving variance=%" PRId64 " usec", __FUNCTION__, jitter_val[(curr_count+1)%GPS_NTP_DELAY_WIN_SIZE], moving_avg[curr_count], moving_var[curr_count]); curr_count++; if(curr_count >= GPS_NTP_DELAY_WIN_SIZE) diff --git a/lib/nodes/file.c b/lib/nodes/file.c index ed223a634..0d4d53e4b 100644 --- a/lib/nodes/file.c +++ b/lib/nodes/file.c @@ -22,6 +22,7 @@ #include #include +#include #include "nodes/file.h" #include "utils.h" @@ -335,7 +336,7 @@ retry: values = sample_io_villas_fscan(f->read.handle->file, s, &flags); /* Get if (ex == 0) serror("Failed to wait for timer"); else if (ex != 1) - warn("Overrun: %lu", ex - 1); + warn("Overrun: %" PRIu64, ex - 1); } return 1; diff --git a/lib/nodes/websocket.c b/lib/nodes/websocket.c index 4002aceb5..a7df5bfa3 100644 --- a/lib/nodes/websocket.c +++ b/lib/nodes/websocket.c @@ -159,7 +159,7 @@ static void websocket_connection_close(struct websocket_connection *c, struct lw msg = strcatf(&msg, ": status=%u, reason=%s", status, reason); - warn(msg); + warn("%s", msg); free(msg); } @@ -552,7 +552,7 @@ int websocket_parse(struct node *n, config_setting_t *cfg) d.info.ietf_version_or_minus_one = -1; d.info.protocol = "live"; - asprintf((char **) &d.info.path, "/%s", path); + ret = asprintf((char **) &d.info.path, "/%s", path); list_push(&w->destinations, memdup(&d, sizeof(d))); } diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index b11771bfe..d0b45804f 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -21,6 +21,7 @@ *********************************************************************************/ #include +#include #include "nodes/zeromq.h" #include "utils.h" diff --git a/lib/shmem.c b/lib/shmem.c index fe9b5c8ab..df33d40a0 100644 --- a/lib/shmem.c +++ b/lib/shmem.c @@ -169,3 +169,8 @@ int shmem_int_write(struct shmem_int *shm, struct sample *smps[], unsigned cnt) return shm->write.shared->polling ? queue_push_many(&shm->write.shared->queue.q, (void **) smps, cnt) : queue_signalled_push_many(&shm->write.shared->queue.qs, (void **) smps, cnt); } + +int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt) +{ + return sample_alloc(&shm->write.shared->pool, smps, cnt); +} diff --git a/src/hook.c b/src/hook.c index a12d36623..78f35121c 100644 --- a/src/hook.c +++ b/src/hook.c @@ -53,7 +53,7 @@ static int hook_parse_cli(struct hook *h, char *params[], int paramlen) /* Concat all params */ str = NULL; for (int i = 0; i < paramlen; i++) - str = strcatf(&str, params[i]); + str = strcatf(&str, "%s", params[i]); config_set_auto_convert(&cfg, 1); diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc index 1ccd9624f..40fae311e 100644 --- a/tests/unit/Makefile.inc +++ b/tests/unit/Makefile.inc @@ -38,7 +38,7 @@ $(BUILDDIR)/tests/unit/%.o: tests/unit/%.c $(BUILDDIR)/defines | $$(dir $$@) # Link $(BUILDDIR)/unit-tests: $(TEST_OBJS) $(LIB) - $(CC) $(TEST_LDFLAGS) $(TEST_LDLIBS) $^ -o $@ + $(CC) $(TEST_LDFLAGS) $^ $(TEST_LDLIBS) -o $@ ifdef COVERAGE -include tests/unit/Makefile.gcov.inc diff --git a/tests/unit/advio.c b/tests/unit/advio.c index 9b2fefe34..451b30d61 100644 --- a/tests/unit/advio.c +++ b/tests/unit/advio.c @@ -36,14 +36,16 @@ Test(advio, local) { AFILE *af; int ret; - char buf[32]; + char *buf = NULL; + size_t buflen = 0; - af = afopen("/proc/version", "r"); + /* We open this file and check the first line */ + af = afopen(__FILE__, "r"); cr_assert(af, "Failed to open local file"); - - ret = fscanf(af->file, "%32s", buf); - cr_assert_eq(ret, 1); - cr_assert_str_eq(buf, "Linux"); + + ret = getline(&buf, &buflen, af->file); + cr_assert_gt(ret, 1); + cr_assert_str_eq(buf, "/** Unit tests for advio\n"); } Test(advio, download) diff --git a/tests/unit/kernel.c b/tests/unit/kernel.c index 6f05b184c..246356416 100644 --- a/tests/unit/kernel.c +++ b/tests/unit/kernel.c @@ -74,7 +74,7 @@ Test(kernel, version) cr_assert_gt(ret, 0); } -Test(kernel, module) +Test(kernel, module, .disabled = true) { int ret; diff --git a/tests/unit/list.c b/tests/unit/list.c index 09f329219..56a90ea22 100644 --- a/tests/unit/list.c +++ b/tests/unit/list.c @@ -129,9 +129,9 @@ Test(list, basics) list_push(&l, (void *) i); } - cr_assert_eq(list_at(&l, 555), NULL); + cr_assert_eq(list_at_safe(&l, 555), NULL); cr_assert_eq(list_last(&l), (void *) 99); - cr_assert_eq(list_first(&l), NULL); + cr_assert_eq(list_first(&l), (void *) 0); for (size_t j = 0, i = 0; j < list_length(&l); j++) { void *k = list_at(&l, j); @@ -144,7 +144,7 @@ Test(list, basics) for (size_t j = 0, i = 99; j < list_length(&l); j++) { void *k = list_at(&l, j); - cr_assert_eq(k, (void *) i, "Is %p, expected %p", i, k); + cr_assert_eq(k, (void *) i, "Is %#zx, expected %p", i, k); i--; } diff --git a/thirdparty/libxil b/thirdparty/libxil index f679cd2c3..1e9ba6ce5 160000 --- a/thirdparty/libxil +++ b/thirdparty/libxil @@ -1 +1 @@ -Subproject commit f679cd2c3793d6e9ecda718ff64f1fad63eb63cc +Subproject commit 1e9ba6ce5568b2712fef60f8a1923aeb3979bda7 diff --git a/tools/zmq-keygen.c b/tools/zmq-keygen.c index 0984abb54..4555c9472 100644 --- a/tools/zmq-keygen.c +++ b/tools/zmq-keygen.c @@ -30,6 +30,7 @@ #include #include #include +#include int main (int argc, char *argv[]) {