diff --git a/packaging/docker/Dockerfile.dev-centos b/packaging/docker/Dockerfile.dev-centos index 1a54830da..898d002d2 100644 --- a/packaging/docker/Dockerfile.dev-centos +++ b/packaging/docker/Dockerfile.dev-centos @@ -28,7 +28,7 @@ # along with this program. If not, see . ################################################################################### -# This is a Centos 7 image including the devtoolset-7 for a more recenter toolchain +# This is a Centos 7 image including the devtoolset-7 for a more up-to-date toolchain # See: https://www.softwarecollections.org/en/scls/rhscl/devtoolset-7/ FROM registry.centos.org/centos/devtoolset-7-toolchain-centos7 @@ -108,12 +108,12 @@ RUN cd /tmp && \ rm -rf /tmp/spdlog # Build & Install Criterion -RUN cd /tmp && \ - git clone --recursive https://github.com/Snaipe/Criterion && \ - mkdir -p Criterion/build && cd Criterion/build && \ - git checkout v2.3.3 && \ - cmake3 -DCMAKE_INSTALL_LIBDIR=/usr/local/lib64 .. && make install && \ - rm -rf /tmp/* +#RUN cd /tmp && \ +# git clone --recursive https://github.com/Snaipe/Criterion && \ +# mkdir -p Criterion/build && cd Criterion/build && \ +# git checkout v2.3.3 && \ +# cmake3 -DCMAKE_INSTALL_LIBDIR=/usr/local/lib64 .. && make install && \ +# rm -rf /tmp/* # Build & Install libwebsockets RUN cd /tmp && \ diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 6ec8a8ae1..570963c8c 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -31,6 +31,7 @@ set(TEST_SRC queue.cpp queue_signalled.cpp signal.cpp + helpers.cpp ) add_executable(unit-tests ${TEST_SRC}) diff --git a/tests/unit/helpers.cpp b/tests/unit/helpers.cpp new file mode 100644 index 000000000..23866e41c --- /dev/null +++ b/tests/unit/helpers.cpp @@ -0,0 +1,13 @@ +#include + +#include + +#include "helpers.hpp" + +char * cr_strdup(const char *str) +{ + char *ptr = (char *) cr_malloc(strlen(str) + 1); + if (ptr) + strcpy(ptr, str); + return ptr; +} diff --git a/tests/unit/helpers.hpp b/tests/unit/helpers.hpp new file mode 100644 index 000000000..61f8cc925 --- /dev/null +++ b/tests/unit/helpers.hpp @@ -0,0 +1,3 @@ +#pragma once + +char * cr_strdup(const char *str); diff --git a/tests/unit/io.cpp b/tests/unit/io.cpp index 81fefa31b..3df15b7ca 100644 --- a/tests/unit/io.cpp +++ b/tests/unit/io.cpp @@ -36,34 +36,40 @@ #include #include +#include "helpers.hpp" + using namespace villas; extern void init_memory(); #define NUM_VALUES 10 -struct param { - std::basic_string, criterion::allocator> fmt; +class Param { + +public: + char * fmt; int cnt; int bits; }; -static struct param params[] = { - { "gtnet", 1, 32 }, - { "gtnet.fake", 1, 32 }, - { "raw.8", 1, 8 }, - { "raw.16.be", 1, 16 }, - { "raw.16.le", 1, 16 }, - { "raw.32.be", 1, 32 }, - { "raw.32.le", 1, 32 }, - { "raw.64.be", 1, 64 }, - { "raw.64.le", 1, 64 }, - { "villas.human", 10, 0 }, - { "villas.binary", 10, 0 }, - { "csv", 10, 0 }, - { "json", 10, 0 }, +const auto d = cr_strdup; + +static criterion::parameters params = { + { d("gtnet"), 1, 32 }, + { d("gtnet.fake"), 1, 32 }, + { d("raw.8"), 1, 8 }, + { d("raw.16.be"), 1, 16 }, + { d("raw.16.le"), 1, 16 }, + { d("raw.32.be"), 1, 32 }, + { d("raw.32.le"), 1, 32 }, + { d("raw.64.be"), 1, 64 }, + { d("raw.64.le"), 1, 64 }, + { d("villas.human"), 10, 0 }, + { d("villas.binary"), 10, 0 }, + { d("csv"), 10, 0 }, + { d("json"), 10, 0 }, #ifdef PROTOBUF_FOUND - { "protobuf", 10, 0 } + { d("protobuf"), 10, 0 } #endif }; @@ -205,10 +211,10 @@ void cr_assert_eq_sample_raw(struct sample *a, struct sample *b, int flags, int ParameterizedTestParameters(io, lowlevel) { - return criterion_test_params(params); + return params; } -ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory) +ParameterizedTest(Param *p, io, lowlevel, .init = init_memory) { int ret; unsigned cnt; @@ -241,8 +247,8 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory) fill_sample_data(&signals, smps, p->cnt); - f = format_type_lookup(p->fmt.c_str()); - cr_assert_not_null(f, "Format '%s' does not exist", p->fmt.c_str()); + f = format_type_lookup(p->fmt); + cr_assert_not_null(f, "Format '%s' does not exist", p->fmt); ret = io_init(&io, f, &signals, (int) SampleFlags::HAS_ALL); cr_assert_eq(ret, 0); @@ -274,10 +280,10 @@ ParameterizedTest(struct param *p, io, lowlevel, .init = init_memory) ParameterizedTestParameters(io, highlevel) { - return criterion_test_params(params); + return params; } -ParameterizedTest(struct param *p, io, highlevel, .init = init_memory) +ParameterizedTest(Param *p, io, highlevel, .init = init_memory) { int ret, cnt; char *retp; @@ -322,8 +328,8 @@ ParameterizedTest(struct param *p, io, highlevel, .init = init_memory) ret = asprintf(&fn, "%s/file", dir); cr_assert_gt(ret, 0); - f = format_type_lookup(p->fmt.c_str()); - cr_assert_not_null(f, "Format '%s' does not exist", p->fmt.c_str()); + f = format_type_lookup(p->fmt); + cr_assert_not_null(f, "Format '%s' does not exist", p->fmt); ret = io_init(&io, f, &signals, (int) SampleFlags::HAS_ALL); cr_assert_eq(ret, 0); diff --git a/tests/unit/json.cpp b/tests/unit/json.cpp index 9db7999ba..a47393cb1 100644 --- a/tests/unit/json.cpp +++ b/tests/unit/json.cpp @@ -27,54 +27,56 @@ #include #include -using str = std::basic_string, criterion::allocator>; +#include "helpers.hpp" struct param { - std::vector> argv; - str json; + char *argv[32]; + char *json; }; ParameterizedTestParameters(json, json_load_cli) { - static struct param params[] = { + const auto d = cr_strdup; + + static criterion::parameters params = { // Combined long option { - .argv = { "dummy", "--option=value" }, - .json = "{ \"option\" : \"value\" }" + .argv = { d("dummy"), d("--option=value") }, + .json = d("{ \"option\" : \"value\" }") }, // Separated long option { - .argv = { "dummy", "--option", "value" }, - .json = "{ \"option\" : \"value\" }" + .argv = { d("dummy"), d("--option"), d("value") }, + .json = d("{ \"option\" : \"value\" }") }, // All kinds of data types { - .argv = { "dummy", "--integer", "1", "--real", "1.1", "--bool", "true", "--null", "null", "--string", "hello world" }, - .json = "{ \"integer\" : 1, \"real\" : 1.1, \"bool\" : true, \"null\" : null, \"string\" : \"hello world\" }" + .argv = { d("dummy"), d("--integer"), d("1"), d("--real"), d("1.1"), d("--bool"), d("true"), d("--null"), d("null"), d("--string"), d("hello world") }, + .json = d("{ \"integer\" : 1, \"real\" : 1.1, \"bool\" : true, \"null\" : null, \"string\" : \"hello world\" }") }, // Array generation { - .argv = { "dummy", "--bool", "true", "--bool", "false" }, - .json = "{ \"bool\" : [ true, false ] }" + .argv = { d("dummy"), d("--bool"), d("true"), d("--bool"), d("false") }, + .json = d("{ \"bool\" : [ true, false ] }") }, // Dots in the option name generate sub objects { - .argv = { "dummy", "--sub.option", "value" }, - .json = "{ \"sub\" : { \"option\" : \"value\" } }" + .argv = { d("dummy"), d("--sub.option"), d("value") }, + .json = d("{ \"sub\" : { \"option\" : \"value\" } }") }, // Nesting is possible { - .argv = { "dummy", "--sub.sub.option", "value" }, - .json = "{ \"sub\" : { \"sub\" : { \"option\" : \"value\" } } }" + .argv = { d("dummy"), d("--sub.sub.option"), d("value") }, + .json = d("{ \"sub\" : { \"sub\" : { \"option\" : \"value\" } } }") }, // Multiple subgroups are merged { - .argv = { "dummy", "--sub.sub.option", "value1", "--sub.option", "value2" }, - .json = "{ \"sub\" : { \"option\" : \"value2\", \"sub\" : { \"option\" : \"value1\" } } }" + .argv = { d("dummy"), d("--sub.sub.option"), d("value1"), d("--sub.option"), d("value2") }, + .json = d("{ \"sub\" : { \"option\" : \"value2\", \"sub\" : { \"option\" : \"value1\" } } }") } }; - return criterion_test_params(params); + return params; } ParameterizedTest(struct param *p, json, json_load_cli) @@ -82,15 +84,13 @@ ParameterizedTest(struct param *p, json, json_load_cli) json_error_t err; json_t *json, *cli; - json = json_loads(p->json.c_str(), 0, &err); + json = json_loads(p->json, 0, &err); cr_assert_not_null(json); - auto argv = new const char*[p->argv.size() + 1]; - for (unsigned i = 0; i < p->argv.size(); i++) - argv[i] = p->argv[i].c_str(); - argv[p->argv.size()] = nullptr; + int argc = 0; + while (p->argv[argc]) argc++; - cli = json_load_cli(p->argv.size(), argv); + cli = json_load_cli(argc, (const char **) p->argv); cr_assert_not_null(cli); //json_dumpf(json, stdout, JSON_INDENT(2)); putc('\n', stdout);