From 3cf50db98d2343472c5e2a68e6b152df414a8006 Mon Sep 17 00:00:00 2001 From: daniel-k Date: Wed, 10 Jan 2018 15:26:52 +0100 Subject: [PATCH] logging: use new spdlog library in favor of Logger --- fpga/CMakeLists.txt | 2 + fpga/include/villas/dependency_graph_impl.hpp | 13 +- fpga/include/villas/fpga/card.hpp | 9 ++ fpga/include/villas/fpga/ip.hpp | 14 ++- fpga/include/villas/log.hpp | 19 +++ fpga/include/villas/plugin.hpp | 6 + fpga/lib/card.cpp | 21 ++-- fpga/lib/ip.cpp | 112 ++++++++---------- fpga/lib/ip_node.cpp | 21 ++-- fpga/lib/ips/fifo.cpp | 6 +- fpga/lib/ips/switch.cpp | 24 ++-- fpga/lib/plugin.cpp | 11 +- fpga/tests/fifo.cpp | 24 ++-- fpga/tests/main.cpp | 8 +- 14 files changed, 182 insertions(+), 108 deletions(-) diff --git a/fpga/CMakeLists.txt b/fpga/CMakeLists.txt index af9f08dc1..540ccee44 100644 --- a/fpga/CMakeLists.txt +++ b/fpga/CMakeLists.txt @@ -6,6 +6,8 @@ set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) set (CMAKE_CXX_STANDARD 17) +include_directories(thirdparty/spdlog/include) + add_subdirectory(lib) add_subdirectory(tests) add_subdirectory(src) diff --git a/fpga/include/villas/dependency_graph_impl.hpp b/fpga/include/villas/dependency_graph_impl.hpp index f5d5b32d7..0b4be0869 100644 --- a/fpga/include/villas/dependency_graph_impl.hpp +++ b/fpga/include/villas/dependency_graph_impl.hpp @@ -2,8 +2,12 @@ #error "Do not include this file directly, please include depedency_graph.hpp" #endif -#include "dependency_graph.hpp" #include +#include "dependency_graph.hpp" + +#include "log.hpp" + +static auto logger = loggerGetOrCreate("DependencyGraph"); namespace villas { namespace utils { @@ -53,7 +57,7 @@ DependencyGraph::dump() { for(auto& dep : node.second) { ss << dep << " "; } - cpp_debug << node.first << ": " << ss.str(); + logger->info("{}: {}", node.first, ss.str()); } } @@ -91,10 +95,9 @@ DependencyGraph::getEvaluationOrder() const // if a round doesn't add any elements and is not the last, then // there is a circular dependency if(added == 0 and graph.size() > 0) { - cpp_error << "Circular dependency detected! IPs not available:"; - Logger::Indenter indent = cpp_debug.indent(); + logger->error("Circular dependency detected! IPs not available:"); for(auto& [key, value] : graph) { - cpp_error << key; + logger->error(" {}", key); } break; } diff --git a/fpga/include/villas/fpga/card.hpp b/fpga/include/villas/fpga/card.hpp index d3a79a4fc..a65590432 100644 --- a/fpga/include/villas/fpga/card.hpp +++ b/fpga/include/villas/fpga/card.hpp @@ -93,6 +93,11 @@ public: size_t maplen; size_t dmalen; + +protected: + SpdLogger + getLogger() const + { return loggerGetOrCreate(name); } }; using CardList = std::list>; @@ -109,6 +114,10 @@ public: static PCIeCard* create(); + + static SpdLogger + getStaticLogger() + { return loggerGetOrCreate("PCIeCardFactory"); } }; } // namespace fpga diff --git a/fpga/include/villas/fpga/ip.hpp b/fpga/include/villas/fpga/ip.hpp index d78edb850..2071a6bb4 100644 --- a/fpga/include/villas/fpga/ip.hpp +++ b/fpga/include/villas/fpga/ip.hpp @@ -60,7 +60,7 @@ public: friend std::ostream& operator<< (std::ostream& stream, const IpIdentifier& id) - { return stream << "Name: " << TXT_BOLD(id.name) << " (VLNV: " << id.vlnv << ")"; } + { return stream << TXT_BOLD(id.name) << " vlnv=" << id.vlnv; } Vlnv vlnv; std::string name; @@ -120,6 +120,9 @@ protected: uintptr_t getAddrMapped(uintptr_t address) const; + SpdLogger + getLogger() { return loggerGetOrCreate(id.name); } + struct IrqPort { int num; std::string controllerName; @@ -149,6 +152,10 @@ public: static IpCoreList make(PCIeCard* card, json_t *json_ips); +protected: + SpdLogger + getLogger() { return loggerGetOrCreate(getName()); } + private: /// Create a concrete IP instance virtual IpCore* create() = 0; @@ -157,11 +164,16 @@ private: virtual bool configureJson(IpCore& ip, json_t *json) { return true; } + virtual Vlnv getCompatibleVlnv() const = 0; virtual std::string getName() const = 0; virtual std::string getDescription() const = 0; virtual std::list getDependencies() const { return {}; } +protected: + static SpdLogger + getStaticLogger() { return loggerGetOrCreate("IpCoreFactory"); } + private: static IpCoreFactory* lookup(const Vlnv& vlnv); diff --git a/fpga/include/villas/log.hpp b/fpga/include/villas/log.hpp index 13ee951f3..83244395f 100644 --- a/fpga/include/villas/log.hpp +++ b/fpga/include/villas/log.hpp @@ -3,9 +3,28 @@ #include #include +#define SPDLOG_LEVEL_NAMES { "trace", "debug", "info ", "warn ", "error", "crit ", "off " } +#define SPDLOG_NAME_WIDTH 17 + +#include +#include + #define _ESCAPE "\x1b" #define TXT_BOLD(s) _ESCAPE "[1m" + std::string(s) + _ESCAPE "[0m" +using SpdLogger = std::shared_ptr; + +inline SpdLogger loggerGetOrCreate(const std::string& logger_name) +{ + auto logger = spdlog::get(logger_name); + if(not logger) { + logger = spdlog::stdout_color_mt(logger_name); + } + return logger; +} + + + class LoggerIndent; class Logger { diff --git a/fpga/include/villas/plugin.hpp b/fpga/include/villas/plugin.hpp index 26a220fd2..97de10d4d 100644 --- a/fpga/include/villas/plugin.hpp +++ b/fpga/include/villas/plugin.hpp @@ -28,6 +28,7 @@ #include #include +#include "log.hpp" #include "utils.h" namespace villas { @@ -77,6 +78,11 @@ public: void *handle; enum state state; +protected: + static SpdLogger + getStaticLogger() + { return loggerGetOrCreate("Plugin"); } + private: /* Just using a standard std::list<> to hold plugins is problematic, because we want to push Plugins to the list from within each Plugin's constructor diff --git a/fpga/lib/card.cpp b/fpga/lib/card.cpp index 96da37c74..99dca69f5 100644 --- a/fpga/lib/card.cpp +++ b/fpga/lib/card.cpp @@ -56,12 +56,12 @@ CardList fpga::PCIeCardFactory::make(json_t *json, struct pci* pci, ::vfio_container* vc) { CardList cards; + auto logger = getStaticLogger(); const char *card_name; json_t *json_card; json_object_foreach(json, card_name, json_card) { - cpp_info << "Found config for FPGA card " << card_name; - Logger::Indenter indent = cpp_debug.indent(); + logger->info("Found config for FPGA card {}", card_name); json_t* json_ips = nullptr; const char* pci_slot = nullptr; @@ -77,7 +77,7 @@ fpga::PCIeCardFactory::make(json_t *json, struct pci* pci, ::vfio_container* vc) "id", &pci_id); if(ret != 0) { - cpp_warn << "Cannot parse JSON config"; + logger->warn("Cannot parse JSON config"); continue; } @@ -93,29 +93,28 @@ fpga::PCIeCardFactory::make(json_t *json, struct pci* pci, ::vfio_container* vc) const char* error; if (pci_slot != nullptr and pci_device_parse_slot(&card->filter, pci_slot, &error) != 0) { - cpp_warn << "Failed to parse PCI slot: " << error; + logger->warn("Failed to parse PCI slot: {}", error); } if (pci_id != nullptr and pci_device_parse_id(&card->filter, pci_id, &error) != 0) { - cpp_warn << "Failed to parse PCI ID: " << error; + logger->warn("Failed to parse PCI ID: {}", error); } // TODO: currently fails, fix and remove comment // if(not card->start()) { -// cpp_warn << "Cannot start FPGA card " << card_name; -// delete card; +// logger->warn("Cannot start FPGA card {}", card_name); // continue; // } card->ips = ip::IpCoreFactory::make(card.get(), json_ips); if(card->ips.empty()) { - cpp_error << "Cannot initialize IPs"; + logger->error("Cannot initialize IPs of FPGA card {}", card_name); continue; } if(not card->check()) { - cpp_warn << "Checking failed, destroying ..."; + logger->warn("Checking of FPGA card {} failed", card_name); continue; } @@ -148,6 +147,8 @@ bool fpga::PCIeCard::start() int ret; struct pci_device *pdev; + auto logger = getLogger(); + /* Search for FPGA card */ pdev = pci_lookup_device(pci, &filter); if (!pdev) @@ -176,7 +177,7 @@ bool fpga::PCIeCard::start() serror("Failed to reset PCI device"); if(not reset()) { - cpp_debug << "Failed to reset FGPA card"; + logger->error("Failed to reset FGPA card"); return false; } } diff --git a/fpga/lib/ip.cpp b/fpga/lib/ip.cpp index 0fdb365fe..460e0ddb1 100644 --- a/fpga/lib/ip.cpp +++ b/fpga/lib/ip.cpp @@ -48,10 +48,11 @@ static bool buildDependencyGraph(DependencyGraph& dependencyGraph, json_t* json_ips, std::string name) { -// cpp_debug << "preparse " << name; - const bool nodeExists = dependencyGraph.addNode(name); + // HACK: just get the right logger + auto logger = loggerGetOrCreate("IpCoreFactory"); + // do not add IP multiple times // this happens if more than 1 IP depends on a certain other IP if(nodeExists) { @@ -60,22 +61,22 @@ buildDependencyGraph(DependencyGraph& dependencyGraph, json_t* json_ips, std::st json_t* json_ip = json_object_get(json_ips, name.c_str()); if(json_ip == nullptr) { - cpp_error << "IP " << name << " not found in config"; + logger->error("IP {} not found in config", name); return false; } for(auto& dependencyToken : dependencyTokens) { json_t* json_dependency = json_object_get(json_ip, dependencyToken.c_str()); if(json_dependency == nullptr) { - cpp_debug << "Property " << dependencyToken << " of " << TXT_BOLD(name) - << " not present"; + logger->debug("Property {} of {} is not present", + dependencyToken, TXT_BOLD(name)); continue; } const char* value = json_string_value(json_dependency); if(value == nullptr) { - cpp_warn << "Property " << dependencyToken << " of " << TXT_BOLD(name) - << " is invalid"; + logger->warn("Property {} of {} is invalid", + dependencyToken, TXT_BOLD(name)); continue; } @@ -83,15 +84,15 @@ buildDependencyGraph(DependencyGraph& dependencyGraph, json_t* json_ips, std::st if(mapping.size() != 2) { - cpp_error << "Invalid " << dependencyToken << " mapping" - << " of " << TXT_BOLD(name); + logger->error("Invalid {} mapping of {}", + dependencyToken, TXT_BOLD(name)); dependencyGraph.removeNode(name); return false; } if(name == mapping[0]) { - cpp_error << "IP " << TXT_BOLD(name)<< " cannot depend on itself"; + logger->error("IP {} cannot depend on itself", TXT_BOLD(name)); dependencyGraph.removeNode(name); return false; @@ -102,8 +103,8 @@ buildDependencyGraph(DependencyGraph& dependencyGraph, json_t* json_ips, std::st dependencyGraph.addDependency(name, mapping[0]); if(not buildDependencyGraph(dependencyGraph, json_ips, mapping[0])) { - cpp_error << "Dependency " << mapping[0] << " of " << TXT_BOLD(name) - << " not satified"; + logger->error("Dependency {} of {} not satisfied", + mapping[0], TXT_BOLD(name)); dependencyGraph.removeNode(mapping[0]); return false; @@ -118,14 +119,12 @@ namespace villas { namespace fpga { namespace ip { - void IpCore::dump() { - cpp_info << id; - { - Logger::Indenter indent = cpp_info.indent(); - cpp_info << " Baseaddr: 0x" << std::hex << baseaddr << std::dec; -// cpp_info << " IRQ: " << irq; -// cpp_info << " Port: " << port; + auto logger = getLogger(); + + logger->info("Base address = {:08x}", baseaddr); + for(auto& [num, irq] : irqs) { + logger->info("IRQ {}: {}:{}", num, irq.controllerName, irq.num); } } @@ -155,40 +154,32 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) { DependencyGraph dependencyGraph; IpCoreList initializedIps; + auto loggerStatic = getStaticLogger(); - { - Logger::Indenter indent = cpp_debug.indent(); - cpp_debug << "Parsing IP dependency graph:"; - void* iter = json_object_iter(json_ips); - while(iter != nullptr) { - buildDependencyGraph(dependencyGraph, json_ips, json_object_iter_key(iter)); - iter = json_object_iter_next(json_ips, iter); - } - } - - { - Logger::Indenter indent = cpp_debug.indent(); - cpp_debug << "IP initialization order:"; - - for(auto& ipName : dependencyGraph.getEvaluationOrder()) { - cpp_debug << TXT_BOLD(ipName); - } + loggerStatic->debug("Parsing IP dependency graph:"); + void* iter = json_object_iter(json_ips); + while(iter != nullptr) { + buildDependencyGraph(dependencyGraph, json_ips, json_object_iter_key(iter)); + iter = json_object_iter_next(json_ips, iter); } - - cpp_info << "Initializing IP cores"; - - Logger::Indenter indent = cpp_info.indent(); + loggerStatic->debug("IP initialization order:"); for(auto& ipName : dependencyGraph.getEvaluationOrder()) { - cpp_debug << TXT_BOLD(ipName); + loggerStatic->debug(" {}", TXT_BOLD(ipName)); + } + + + for(auto& ipName : dependencyGraph.getEvaluationOrder()) { + loggerStatic->info("Initializing {}", TXT_BOLD(ipName)); + json_t* json_ip = json_object_get(json_ips, ipName.c_str()); // extract VLNV from JSON const char* vlnv; if(json_unpack(json_ip, "{ s: s }", "vlnv", &vlnv) != 0) { - cpp_warn << "IP " << ipName << " has no entry 'vlnv'"; + loggerStatic->warn("IP {} has no entry 'vlnv'", ipName); continue; } @@ -202,13 +193,15 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) IpCoreFactory* ipCoreFactory = lookup(id.vlnv); if(ipCoreFactory == nullptr) { - cpp_warn << "No plugin found to handle " << vlnv; + loggerStatic->warn("No plugin found to handle {}", vlnv); continue; } else { - cpp_debug << "Using " << ipCoreFactory->getName() - << " for IP " << vlnv; + loggerStatic->debug("Using {} for IP {}", + ipCoreFactory->getName(), vlnv); } + auto logger = ipCoreFactory->getLogger(); + // Create new IP instance. Since this function is virtual, it will // construct the right, specialized type without knowing it here // because we have already picked the right factory. @@ -218,8 +211,8 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) auto ip = std::unique_ptr(ipCoreFactory->create()); if(ip == nullptr) { - cpp_warn << "Cannot create an instance of " - << ipCoreFactory->getName(); + logger->warn("Cannot create an instance of {}", + ipCoreFactory->getName()); continue; } @@ -229,8 +222,8 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) // extract base address if it has one if(json_unpack(json_ip, "{ s?: i }", "baseaddr", &ip->baseaddr) != 0) { - cpp_warn << "Problem while parsing base address of IP " - << TXT_BOLD(ipName); + logger->warn("Problem while parsing base address of IP {}", + TXT_BOLD(ipName)); continue; } @@ -242,8 +235,8 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) const char* irq = json_string_value(json_irq); auto tokens = utils::tokenize(irq, ":"); if(tokens.size() != 2) { - cpp_warn << "Cannot parse IRQ '" << irq << "' of" - << TXT_BOLD(ipName); + logger->warn("Cannot parse IRQ '{}' of {}", + irq, TXT_BOLD(ipName)); continue; } @@ -251,11 +244,11 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) try { num = std::stoi(tokens[1]); } catch(const std::invalid_argument&) { - cpp_warn << "IRQ number is not an integer: '" << irq << "'"; + logger->warn("IRQ number is not an integer: '{}'", irq); continue; } - ip->irqs[index] = {num, tokens[0]}; + ip->irqs[index] = {num, tokens[0], ""}; } } @@ -270,14 +263,13 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) }); if(iter == initializedIps.end()) { - cpp_error << "Cannot find '" << depName << "' dependency " - << depVlnv.toString() - << "of " << TXT_BOLD(ipName); + logger->error("Cannot find '{}' dependency {} of {}", + depName, depVlnv, TXT_BOLD(ipName)); dependenciesOk = false; break; } - cpp_debug << "Found dependency IP " << (*iter)->id; + logger->debug("Found dependency IP {}", (*iter)->id); ip->dependencies[depName] = (*iter).get(); } @@ -287,18 +279,18 @@ IpCoreFactory::make(PCIeCard* card, json_t *json_ips) // IP-specific setup via JSON config if(not ipCoreFactory->configureJson(*ip, json_ip)) { - cpp_warn << "Cannot configure IP from JSON"; + logger->warn("Cannot configure IP from JSON"); continue; } // TODO: currently fails, fix and remove comment // if(not ip->start()) { -// cpp_error << "Cannot start IP" << ip->id.name; +// logger->error("Cannot start IP {}", ip->id.name); // continue; // } if(not ip->check()) { - cpp_error << "Checking IP " << ip->id.name << " failed"; + logger->error("Checking of IP {} failed", ip->id.name); continue; } diff --git a/fpga/lib/ip_node.cpp b/fpga/lib/ip_node.cpp index 47539c674..6c2b5df04 100644 --- a/fpga/lib/ip_node.cpp +++ b/fpga/lib/ip_node.cpp @@ -16,10 +16,11 @@ bool IpNodeFactory::configureJson(IpCore& ip, json_t* json_ip) { auto& ipNode = reinterpret_cast(ip); + auto logger = getLogger(); json_t* json_ports = json_object_get(json_ip, "ports"); if(json_ports == nullptr) { - cpp_error << "IpNode " << ip << " has no ports property"; + logger->error("IpNode {} has no ports property", ip); return false; } @@ -30,7 +31,7 @@ IpNodeFactory::configureJson(IpCore& ip, json_t* json_ip) const bool hasSlavePorts = json_is_array(json_slave); if( (not hasMasterPorts) and (not hasSlavePorts)) { - cpp_error << "IpNode " << ip << " has no ports"; + logger->error("IpNode {} has no ports", ip); return false; } @@ -50,6 +51,8 @@ IpNodeFactory::configureJson(IpCore& ip, json_t* json_ip) bool IpNodeFactory::populatePorts(std::map& portMap, json_t* json) { + auto logger = getLogger(); + size_t index; json_t* json_port; json_array_foreach(json, index, json_port) { @@ -60,19 +63,19 @@ IpNodeFactory::populatePorts(std::map& portMap, json_t* "num", &myPortNum, "to", &to); if(ret != 0) { - cpp_error << "Port definition required field 'num'"; + logger->error("Port definition required field 'num'"); return false; } if(to == nullptr) { - cpp_warn << "Nothing connected to port " << myPortNum; + logger->debug("Nothing connected to port {}", myPortNum); portMap[myPortNum] = {}; continue; } const auto tokens = utils::tokenize(to, ":"); if(tokens.size() != 2) { - cpp_error << "Too many tokens in property 'other'"; + logger->error("Too many tokens in property 'other'"); return false; } @@ -80,11 +83,11 @@ IpNodeFactory::populatePorts(std::map& portMap, json_t* try { otherPortNum = std::stoi(tokens[1]); } catch(const std::invalid_argument&) { - cpp_error << "Other port number is not an integral number"; + logger->error("Other port number is not an integral number"); return false; } - cpp_debug << "Adding port mapping: " << myPortNum << ":" << to; + logger->debug("Adding port mapping: {}:{}", myPortNum, to); portMap[myPortNum] = { otherPortNum, tokens[0] }; } @@ -116,6 +119,8 @@ IpNode::loopbackPossible() const bool IpNode::connectLoopback() { + auto logger = getLogger(); + auto ports = getLoopbackPorts(); const auto& portMaster = portsMaster[ports.first]; const auto& portSlave = portsSlave[ports.second]; @@ -125,7 +130,7 @@ IpNode::connectLoopback() card->lookupIp(portMaster.nodeName)); if(axiStreamSwitch == nullptr) { - cpp_error << "Cannot find IP " << *axiStreamSwitch; + logger->error("Cannot find IP {}", *axiStreamSwitch); return false; } diff --git a/fpga/lib/ips/fifo.cpp b/fpga/lib/ips/fifo.cpp index 410e745ac..2dd1276b9 100644 --- a/fpga/lib/ips/fifo.cpp +++ b/fpga/lib/ips/fifo.cpp @@ -43,14 +43,16 @@ static FifoFactory factory; bool FifoFactory::configureJson(IpCore &ip, json_t *json_ip) { + auto logger = getLogger(); + if(not IpNodeFactory::configureJson(ip, json_ip)) { - cpp_error << "Configuring IpNode failed"; + logger->error("Configuring IpNode failed"); return false; } auto& fifo = reinterpret_cast(ip); if(json_unpack(json_ip, "{ s: i }", "baseaddr_axi4", &fifo.baseaddr_axi4) != 0) { - cpp_warn << "Cannot parse property 'baseaddr_axi4' of " << ip; + logger->warn("Cannot parse property 'baseaddr_axi4'"); return false; } diff --git a/fpga/lib/ips/switch.cpp b/fpga/lib/ips/switch.cpp index 51148a895..f60c552fb 100644 --- a/fpga/lib/ips/switch.cpp +++ b/fpga/lib/ips/switch.cpp @@ -43,7 +43,6 @@ AxiStreamSwitch::start() sw_cfg.MaxNumSI = portsSlave.size(); if(XAxisScr_CfgInitialize(&xSwitch, &sw_cfg, getBaseaddr()) != XST_SUCCESS) { - cpp_error << "Cannot start " << *this; return false; } @@ -64,15 +63,18 @@ AxiStreamSwitch::start() bool AxiStreamSwitch::connect(int portSlave, int portMaster) { + auto logger = getLogger(); + if(portMapping[portMaster] == portSlave) { - cpp_debug << "Ports already connected"; + logger->debug("Ports already connected"); return true; } for(auto [master, slave] : portMapping) { if(slave == portSlave) { - cpp_warn << "Slave " << slave << " has already been connected to " - << "master " << master << ". Disabling master " << master; + logger->warn("Slave {} has already been connected to master {}. " + "Disabling master {}.", + slave, master, master); XAxisScr_RegUpdateDisable(&xSwitch); XAxisScr_MiPortDisable(&xSwitch, master); @@ -85,7 +87,7 @@ AxiStreamSwitch::connect(int portSlave, int portMaster) XAxisScr_MiPortEnable(&xSwitch, portMaster, portSlave); XAxisScr_RegUpdateEnable(&xSwitch); - cpp_debug << "Connect slave " << portSlave << " to master " << portMaster; + logger->debug("Connect slave {} to master {}", portSlave, portMaster); return true; } @@ -93,8 +95,10 @@ AxiStreamSwitch::connect(int portSlave, int portMaster) bool AxiStreamSwitch::disconnectMaster(int port) { - cpp_debug << "Disconnect slave " << portMapping[port] - << " from master " << port; + auto logger = getLogger(); + + logger->debug("Disconnect slave {} from master {}", + portMapping[port], port); XAxisScr_MiPortDisable(&xSwitch, port); portMapping[port] = PORT_DISABLED; @@ -104,15 +108,17 @@ AxiStreamSwitch::disconnectMaster(int port) bool AxiStreamSwitch::disconnectSlave(int port) { + auto logger = getLogger(); + for(auto [master, slave] : portMapping) { if(slave == port) { - cpp_debug << "Disconnect slave " << slave << " from master " << master; + logger->debug("Disconnect slave {} from master {}", slave, master); XAxisScr_MiPortDisable(&xSwitch, master); return true; } } - cpp_debug << "Slave " << port << " hasn't been connected to any master"; + logger->debug("Slave {} hasn't been connected to any master", port); return true; } diff --git a/fpga/lib/plugin.cpp b/fpga/lib/plugin.cpp index b0e2cbd6a..82d358a24 100644 --- a/fpga/lib/plugin.cpp +++ b/fpga/lib/plugin.cpp @@ -30,7 +30,7 @@ #include #include "plugin.hpp" - +#include "log.hpp" namespace villas { @@ -117,15 +117,18 @@ Plugin::unload() void Plugin::dump() { - std::cout << " - " << this->name << ": " << this->description << std::endl; + auto logger = getStaticLogger(); + logger->info("Name: '{}' Description: '{}'", name, description); } void Plugin::dumpList() { - std::cout << "Registered plugins:" << std::endl; + auto logger = getStaticLogger(); + + logger->info("Registered plugins:"); for(auto& p : pluginList) { - std::cout << " - " << p->name << std::endl; + logger->info(" - {}", p->name); } } diff --git a/fpga/tests/fifo.cpp b/fpga/tests/fifo.cpp index 409ee06e7..1d5fc146b 100644 --- a/fpga/tests/fifo.cpp +++ b/fpga/tests/fifo.cpp @@ -34,6 +34,8 @@ #include #include +#include "log.hpp" + extern villas::fpga::PCIeCard* fpga; Test(fpga, fifo, .description = "FIFO") @@ -43,6 +45,8 @@ Test(fpga, fifo, .description = "FIFO") char src[255], dst[255]; struct fpga_ip *fifo; + auto logger = loggerGetOrCreate("unittest:fifo"); + for(auto& ip : fpga->ips) { // skip non-fifo IPs if(*ip != villas::fpga::Vlnv("xilinx.com:ip:axi_fifo_mm_s:")) @@ -51,7 +55,7 @@ Test(fpga, fifo, .description = "FIFO") auto fifo = reinterpret_cast(*ip); if(not fifo.loopbackPossible()) { - cpp_info << "Loopback test not possible for " << *ip; + logger->info("Loopback test not possible for {}", *ip); continue; } @@ -60,16 +64,22 @@ Test(fpga, fifo, .description = "FIFO") /* Get some random data to compare */ memset(dst, 0, sizeof(dst)); len = read_random((char *) src, sizeof(src)); - if (len != sizeof(src)) - error("Failed to get random data"); + if (len != sizeof(src)) { + logger->error("Failed to get random data"); + continue; + } len = fifo.write(src, sizeof(src)); - if (len != sizeof(src)) - cpp_error << "Failed to send to FIFO"; + if (len != sizeof(src)) { + logger->error("Failed to send to FIFO"); + continue; + } len = fifo.read(dst, sizeof(dst)); - if (len != sizeof(dst)) - cpp_error << "Failed to read from FIFO"; + if (len != sizeof(dst)) { + logger->error("Failed to read from FIFO"); + continue; + } /* Compare data */ cr_assert_eq(memcmp(src, dst, sizeof(src)), 0); diff --git a/fpga/tests/main.cpp b/fpga/tests/main.cpp index 3c9c52bd1..46c539926 100644 --- a/fpga/tests/main.cpp +++ b/fpga/tests/main.cpp @@ -33,6 +33,8 @@ #include #include +#include + #define FPGA_CARD "vc707" #define TEST_CONFIG "../etc/fpga.json" #define TEST_LEN 0x1000 @@ -57,7 +59,9 @@ static void init() villas::Plugin::dumpList(); - Logger::setLogLevel(Logger::LogLevel::Debug); + auto logger = loggerGetOrCreate("unittest"); + spdlog::set_pattern("[%T] [%l] [%n] %v"); + spdlog::set_level(spdlog::level::debug); ret = pci_init(&pci); cr_assert_eq(ret, 0, "Failed to initialize PCI sub-system"); @@ -87,7 +91,7 @@ static void init() fpgaCards = fpgaCardPlugin->make(fpgas, &pci, &vc); if(fpgaCards.size() == 0) { - cpp_error << "No FPGA cards found!"; + logger->error("No FPGA cards found!"); } else { fpga = fpgaCards.front().get(); }