mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
Merge branch 'feature/criterion-spdlog' into develop
This commit is contained in:
commit
3257ee00c0
5 changed files with 107 additions and 14 deletions
|
@ -81,7 +81,7 @@ public:
|
|||
protected:
|
||||
static SpdLogger
|
||||
getStaticLogger()
|
||||
{ return loggerGetOrCreate("Plugin"); }
|
||||
{ return loggerGetOrCreate("plugin"); }
|
||||
|
||||
private:
|
||||
/* Just using a standard std::list<> to hold plugins is problematic, because
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
fpga.cpp
|
||||
logging.cpp
|
||||
# dma.c
|
||||
fifo.cpp
|
||||
# hls.c
|
||||
|
|
|
@ -4,23 +4,16 @@
|
|||
#include <villas/directed_graph.hpp>
|
||||
#include <villas/log.hpp>
|
||||
|
||||
static void init_graph()
|
||||
{
|
||||
spdlog::set_pattern("[%T] [%l] [%n] %v");
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
}
|
||||
|
||||
TestSuite(graph,
|
||||
.init = init_graph,
|
||||
.description = "Graph library"
|
||||
);
|
||||
|
||||
Test(graph, basic, .description = "DirectedGraph")
|
||||
{
|
||||
auto logger = loggerGetOrCreate("unittest:basic");
|
||||
auto logger = loggerGetOrCreate("test:graph:basic");
|
||||
logger->info("Testing basic graph construction and modification");
|
||||
|
||||
villas::graph::DirectedGraph<> g("unittest:basic");
|
||||
villas::graph::DirectedGraph<> g("test:graph:basic");
|
||||
|
||||
std::shared_ptr<villas::graph::Vertex> v1(new villas::graph::Vertex);
|
||||
std::shared_ptr<villas::graph::Vertex> v2(new villas::graph::Vertex);
|
||||
|
@ -48,11 +41,11 @@ Test(graph, basic, .description = "DirectedGraph")
|
|||
|
||||
Test(graph, path, .description = "Find path")
|
||||
{
|
||||
auto logger = loggerGetOrCreate("unittest:path");
|
||||
auto logger = loggerGetOrCreate("test:graph:path");
|
||||
logger->info("Testing path finding algorithm");
|
||||
|
||||
using Graph = villas::graph::DirectedGraph<>;
|
||||
Graph g("unittest:path");
|
||||
Graph g("test:graph:path");
|
||||
|
||||
std::shared_ptr<villas::graph::Vertex> v1(new villas::graph::Vertex);
|
||||
std::shared_ptr<villas::graph::Vertex> v2(new villas::graph::Vertex);
|
||||
|
|
101
fpga/tests/logging.cpp
Normal file
101
fpga/tests/logging.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
#include <cstdarg>
|
||||
#include <memory>
|
||||
|
||||
#include <criterion/logging.h>
|
||||
#include <criterion/options.h>
|
||||
|
||||
#include <villas/log.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
extern "C" {
|
||||
/* We override criterions function here */
|
||||
void criterion_log_noformat(enum criterion_severity severity, const char *msg);
|
||||
void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...);
|
||||
void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args);
|
||||
}
|
||||
|
||||
struct criterion_prefix_data {
|
||||
const char *prefix;
|
||||
const char *color;
|
||||
};
|
||||
|
||||
static void format_msg(char *buf, size_t buflen, const char *msg, va_list args)
|
||||
{
|
||||
int len = vsnprintf(buf, buflen, msg, args);
|
||||
|
||||
/* Strip new line */
|
||||
char *nl = strchr(buf, '\n');
|
||||
if (nl)
|
||||
*nl = 0;
|
||||
}
|
||||
|
||||
void criterion_log_noformat(enum criterion_severity severity, const char *msg)
|
||||
{
|
||||
auto logger = loggerGetOrCreate("criterion");
|
||||
|
||||
switch (severity) {
|
||||
case CR_LOG_INFO:
|
||||
logger->info(msg);
|
||||
break;
|
||||
|
||||
case CR_LOG_WARNING:
|
||||
logger->warn(msg);
|
||||
break;
|
||||
|
||||
case CR_LOG_ERROR:
|
||||
logger->error(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args)
|
||||
{
|
||||
char formatted_msg[1024];
|
||||
|
||||
if (level < criterion_options.logging_threshold)
|
||||
return;
|
||||
|
||||
format_msg(formatted_msg, sizeof(formatted_msg), msg, args);
|
||||
|
||||
auto logger = loggerGetOrCreate("criterion");
|
||||
logger->info(formatted_msg);
|
||||
}
|
||||
|
||||
void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...)
|
||||
{
|
||||
char formatted_msg[1024];
|
||||
|
||||
va_list args;
|
||||
|
||||
if (level < criterion_options.logging_threshold)
|
||||
return;
|
||||
|
||||
va_start(args, msg);
|
||||
format_msg(formatted_msg, sizeof(formatted_msg), msg, args);
|
||||
va_end(args);
|
||||
|
||||
auto logger = loggerGetOrCreate("criterion");
|
||||
|
||||
if (strstr(formatted_msg, "Warning"))
|
||||
logger->warn(formatted_msg);
|
||||
else if (strstr(formatted_msg, "Failed"))
|
||||
logger->error(formatted_msg);
|
||||
else if(!strcmp(prefix->prefix, "----") && !strcmp(prefix->color, "\33[0;34m"))
|
||||
logger->info(formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "----") && !strcmp(prefix->color, "\33[1;30m"))
|
||||
logger->debug(formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "===="))
|
||||
logger->info(formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "RUN "))
|
||||
logger->info("Run: {}", formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "SKIP"))
|
||||
logger->info("Skip: {}", formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "PASS"))
|
||||
logger->info("Pass: {}", formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "FAIL"))
|
||||
logger->error("Fail: {}", formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "WARN"))
|
||||
logger->warn(formatted_msg);
|
||||
else if (!strcmp(prefix->prefix, "ERR "))
|
||||
logger->error(formatted_msg);
|
||||
}
|
|
@ -64,8 +64,6 @@ int main(int argc, char *argv[])
|
|||
{
|
||||
int ret;
|
||||
|
||||
auto logger = loggerGetOrCreate("unittest");
|
||||
spdlog::set_pattern("[%T] [%l] [%n] %v");
|
||||
spdlog::set_level(spdlog::level::debug);
|
||||
|
||||
/* Run criterion tests */
|
||||
|
|
Loading…
Add table
Reference in a new issue