mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fix Criterion tests
This commit is contained in:
parent
755a1abab2
commit
170c284b24
6 changed files with 80 additions and 57 deletions
|
@ -28,7 +28,7 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
###################################################################################
|
||||
|
||||
# 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 && \
|
||||
|
|
|
@ -31,6 +31,7 @@ set(TEST_SRC
|
|||
queue.cpp
|
||||
queue_signalled.cpp
|
||||
signal.cpp
|
||||
helpers.cpp
|
||||
)
|
||||
|
||||
add_executable(unit-tests ${TEST_SRC})
|
||||
|
|
13
tests/unit/helpers.cpp
Normal file
13
tests/unit/helpers.cpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include <cstring>
|
||||
|
||||
#include <criterion/criterion.h>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
char * cr_strdup(const char *str)
|
||||
{
|
||||
char *ptr = (char *) cr_malloc(strlen(str) + 1);
|
||||
if (ptr)
|
||||
strcpy(ptr, str);
|
||||
return ptr;
|
||||
}
|
3
tests/unit/helpers.hpp
Normal file
3
tests/unit/helpers.hpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
char * cr_strdup(const char *str);
|
|
@ -36,34 +36,40 @@
|
|||
#include <villas/io.h>
|
||||
#include <villas/log.hpp>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
using namespace villas;
|
||||
|
||||
extern void init_memory();
|
||||
|
||||
#define NUM_VALUES 10
|
||||
|
||||
struct param {
|
||||
std::basic_string<char, std::char_traits<char>, criterion::allocator<char>> 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<Param> 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);
|
||||
|
|
|
@ -27,54 +27,56 @@
|
|||
#include <villas/utils.hpp>
|
||||
#include <villas/config_helper.hpp>
|
||||
|
||||
using str = std::basic_string<char, std::char_traits<char>, criterion::allocator<char>>;
|
||||
#include "helpers.hpp"
|
||||
|
||||
struct param {
|
||||
std::vector<str, criterion::allocator<str>> 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<struct param> 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);
|
||||
|
|
Loading…
Add table
Reference in a new issue