Commit 3b388897 authored by tobias schroedter's avatar tobias schroedter

Merging 302 and 307

parents d6611b95 ac39c9af
Pipeline #18651 passed with stages
in 19 minutes and 2 seconds
...@@ -584,20 +584,20 @@ routing/ai_router/perception/sign.cpp ...@@ -584,20 +584,20 @@ routing/ai_router/perception/sign.cpp
routing/ai_router/Cortex.cpp routing/ai_router/Cortex.cpp
#AI router trips #AI router trips
routing/ai_router_trips/AIRouterTrips.cpp #routing/ai_router_trips/AIRouterTrips.cpp
routing/ai_router_trips/BrainStorage.cpp #routing/ai_router_trips/BrainStorage.cpp
routing/ai_router_trips/cognitiveMap/associations.cpp #routing/ai_router_trips/cognitiveMap/associations.cpp
routing/ai_router_trips/cognitiveMap/connection.cpp #routing/ai_router_trips/cognitiveMap/connection.cpp
routing/ai_router_trips/cognitiveMap/cognitivemap.cpp #routing/ai_router_trips/cognitiveMap/cognitivemap.cpp
routing/ai_router_trips/cognitiveMap/landmark.cpp #routing/ai_router_trips/cognitiveMap/landmark.cpp
routing/ai_router_trips/cognitiveMap/region.cpp #routing/ai_router_trips/cognitiveMap/region.cpp
routing/ai_router_trips/cognitiveMap/landmarknetwork.cpp #routing/ai_router_trips/cognitiveMap/landmarknetwork.cpp
routing/ai_router_trips/cognitiveMap/internnavigationnetwork.cpp #routing/ai_router_trips/cognitiveMap/internnavigationnetwork.cpp
routing/ai_router_trips/perception/visualsystem.cpp #routing/ai_router_trips/perception/visualsystem.cpp
routing/ai_router_trips/perception/visibleenvironment.cpp #routing/ai_router_trips/perception/visibleenvironment.cpp
routing/ai_router_trips/perception/cgalgeometry.cpp #routing/ai_router_trips/perception/cgalgeometry.cpp
routing/ai_router_trips/perception/sign.cpp #routing/ai_router_trips/perception/sign.cpp
routing/ai_router_trips/Cortex.cpp #routing/ai_router_trips/Cortex.cpp
) )
SET(AIROUTER_HDR SET(AIROUTER_HDR
......
This diff is collapsed.
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "../geometry/Building.h" #include "../geometry/Building.h"
#include "../geometry/GeometryReader.h" #include "../geometry/GeometryReader.h"
#include "../geometry/Trips.h" #include "../geometry/Trips.h"
#include "../tinyxml/tinyxml.h"
//TODO: the class name GeoFileParser is misleading as the ``geometry'' file contains among others also relations (transitions) //TODO: the class name GeoFileParser is misleading as the ``geometry'' file contains among others also relations (transitions)
//TODO: between geometries/rooms. Probably, EnvironmentFileParser would be better, still parts of the environment are //TODO: between geometries/rooms. Probably, EnvironmentFileParser would be better, still parts of the environment are
...@@ -39,6 +40,10 @@ public: ...@@ -39,6 +40,10 @@ public:
virtual void LoadBuilding(Building* building) override; virtual void LoadBuilding(Building* building) override;
virtual bool LoadTrafficInfo(Building* building) override; virtual bool LoadTrafficInfo(Building* building) override;
bool parseDoorNode(TiXmlElement * xDoor, int id, Building* building);
Goal* parseGoalNode(TiXmlElement * e);
Transition* parseTransitionNode(TiXmlElement * xTrans, Building * building);
Goal* parseWaitingAreaNode(TiXmlElement * e);
private: private:
Configuration* _configuration; Configuration* _configuration;
......
...@@ -61,11 +61,11 @@ const vector<Trajectories*>& IODispatcher::GetIOHandlers() ...@@ -61,11 +61,11 @@ const vector<Trajectories*>& IODispatcher::GetIOHandlers()
return _outputHandlers; return _outputHandlers;
} }
void IODispatcher::WriteHeader(long nPeds, double fps, Building* building, int seed) void IODispatcher::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
for (auto const & it : _outputHandlers) for (auto const & it : _outputHandlers)
{ {
it->WriteHeader(nPeds, fps, building, seed); it->WriteHeader(nPeds, fps, building, seed, count);
} }
} }
void IODispatcher::WriteGeometry(Building* building) void IODispatcher::WriteGeometry(Building* building)
...@@ -118,7 +118,7 @@ string TrajectoriesJPSV04::WritePed(Pedestrian* ped) ...@@ -118,7 +118,7 @@ string TrajectoriesJPSV04::WritePed(Pedestrian* ped)
return string(tmp); return string(tmp);
} }
void TrajectoriesJPSV04::WriteHeader(long nPeds, double fps, Building* building, int seed) void TrajectoriesJPSV04::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
building->GetCaption(); building->GetCaption();
string tmp; string tmp;
...@@ -329,11 +329,14 @@ TrajectoriesFLAT::TrajectoriesFLAT() : Trajectories() ...@@ -329,11 +329,14 @@ TrajectoriesFLAT::TrajectoriesFLAT() : Trajectories()
{ {
} }
void TrajectoriesFLAT::WriteHeader(long nPeds, double fps, Building* building, int seed) void TrajectoriesFLAT::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
(void) seed; (void) nPeds; (void) seed; (void) nPeds;
char tmp[CLENGTH] = ""; char tmp[100] = "";
Write("#description: my super simulation"); sprintf(tmp, "#description: jpscore (%s)", JPSCORE_VERSION);
Write(tmp);
sprintf(tmp, "#count: %d", count);
Write(tmp);
sprintf(tmp, "#framerate: %0.2f",fps); sprintf(tmp, "#framerate: %0.2f",fps);
Write(tmp); Write(tmp);
sprintf(tmp,"#geometry: %s",building->GetGeometryFilename().c_str()); sprintf(tmp,"#geometry: %s",building->GetGeometryFilename().c_str());
...@@ -353,7 +356,6 @@ void TrajectoriesFLAT::WriteGeometry(Building* building) ...@@ -353,7 +356,6 @@ void TrajectoriesFLAT::WriteGeometry(Building* building)
void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building) void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building)
{ {
char tmp[CLENGTH] = ""; char tmp[CLENGTH] = "";
const vector< Pedestrian* >& allPeds = building->GetAllPedestrians(); const vector< Pedestrian* >& allPeds = building->GetAllPedestrians();
for(unsigned int p=0;p<allPeds.size();p++){ for(unsigned int p=0;p<allPeds.size();p++){
Pedestrian* ped = allPeds[p]; Pedestrian* ped = allPeds[p];
...@@ -363,7 +365,6 @@ void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building) ...@@ -363,7 +365,6 @@ void TrajectoriesFLAT::WriteFrame(int frameNr, Building* building)
sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x, y,z); sprintf(tmp, "%d\t%d\t%0.2f\t%0.2f\t%0.2f", ped->GetID(), frameNr, x, y,z);
Write(tmp); Write(tmp);
} }
} }
void TrajectoriesFLAT::WriteFooter() void TrajectoriesFLAT::WriteFooter()
...@@ -396,10 +397,11 @@ TrajectoriesVTK::TrajectoriesVTK() ...@@ -396,10 +397,11 @@ TrajectoriesVTK::TrajectoriesVTK()
{ {
} }
void TrajectoriesVTK::WriteHeader(long nPeds, double fps, Building* building, int seed) void TrajectoriesVTK::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
//suppress unused warnings //suppress unused warnings
(void) nPeds; (void) fps ; (void) seed; (void) nPeds; (void) fps ; (void) seed; (void) count;
Write("# vtk DataFile Version 4.0"); Write("# vtk DataFile Version 4.0");
Write(building->GetCaption()); Write(building->GetCaption());
Write("ASCII"); Write("ASCII");
...@@ -465,7 +467,7 @@ void TrajectoriesVTK::WriteFooter() ...@@ -465,7 +467,7 @@ void TrajectoriesVTK::WriteFooter()
} }
void TrajectoriesJPSV06::WriteHeader(long nPeds, double fps, Building* building, int seed) void TrajectoriesJPSV06::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
building->GetCaption(); building->GetCaption();
string tmp; string tmp;
...@@ -621,7 +623,7 @@ void TrajectoriesXML_MESH::WriteGeometry(Building* building) ...@@ -621,7 +623,7 @@ void TrajectoriesXML_MESH::WriteGeometry(Building* building)
} }
void TrajectoriesJPSV05::WriteHeader(long nPeds, double fps, Building* building, int seed) void TrajectoriesJPSV05::WriteHeader(long nPeds, double fps, Building* building, int seed, int count)
{ {
building->GetCaption(); building->GetCaption();
string tmp; string tmp;
......
...@@ -51,7 +51,7 @@ public: ...@@ -51,7 +51,7 @@ public:
void AddIO(Trajectories* ioh); void AddIO(Trajectories* ioh);
const std::vector<Trajectories*>& GetIOHandlers(); const std::vector<Trajectories*>& GetIOHandlers();
void WriteHeader(long nPeds, double fps, Building* building, int seed); void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
void WriteGeometry(Building* building); void WriteGeometry(Building* building);
void WriteFrame(int frameNr, Building* building); void WriteFrame(int frameNr, Building* building);
void WriteFooter(); void WriteFooter();
...@@ -67,7 +67,7 @@ public: ...@@ -67,7 +67,7 @@ public:
_outputHandler = nullptr; _outputHandler = nullptr;
}; };
virtual ~Trajectories(){delete _outputHandler;}; virtual ~Trajectories(){delete _outputHandler;};
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed)=0; virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count)=0;
virtual void WriteGeometry(Building* building)=0; virtual void WriteGeometry(Building* building)=0;
virtual void WriteFrame(int frameNr, Building* building)=0; virtual void WriteFrame(int frameNr, Building* building)=0;
virtual void WriteFooter()=0; virtual void WriteFooter()=0;
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
TrajectoriesJPSV04(){}; TrajectoriesJPSV04(){};
virtual ~TrajectoriesJPSV04(){}; virtual ~TrajectoriesJPSV04(){};
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed); virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
virtual void WriteGeometry(Building* building); virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building); virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter(); virtual void WriteFooter();
...@@ -121,7 +121,7 @@ public: ...@@ -121,7 +121,7 @@ public:
TrajectoriesJPSV05(){}; TrajectoriesJPSV05(){};
virtual ~TrajectoriesJPSV05(){}; virtual ~TrajectoriesJPSV05(){};
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed); virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
virtual void WriteGeometry(Building* building); virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building); virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter(); virtual void WriteFooter();
...@@ -139,7 +139,7 @@ public: ...@@ -139,7 +139,7 @@ public:
} }
; ;
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed); virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
virtual void WriteGeometry(Building* building); virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building); virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter(); virtual void WriteFooter();
...@@ -157,7 +157,7 @@ public: ...@@ -157,7 +157,7 @@ public:
} }
; ;
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed); virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
virtual void WriteGeometry(Building* building); virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building); virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter(); virtual void WriteFooter();
...@@ -192,7 +192,7 @@ public: ...@@ -192,7 +192,7 @@ public:
TrajectoriesJPSV06(){}; TrajectoriesJPSV06(){};
virtual ~TrajectoriesJPSV06(){ }; virtual ~TrajectoriesJPSV06(){ };
virtual void WriteHeader(long nPeds, double fps, Building* building, int seed); virtual void WriteHeader(long nPeds, double fps, Building* building, int seed, int count);
virtual void WriteGeometry(Building* building); virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building); virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter(); virtual void WriteFooter();
......
This diff is collapsed.
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#define JPSCORE_PEDDISTRIBUTIONPARSER_H #define JPSCORE_PEDDISTRIBUTIONPARSER_H
#include "../pedestrian/PedDistributionLoader.h" #include "../pedestrian/PedDistributionLoader.h"
#include "../tinyxml/tinyxml.h"
class PedDistributionParser : public PedDistributionLoader { class PedDistributionParser : public PedDistributionLoader {
...@@ -32,6 +33,8 @@ public: ...@@ -32,6 +33,8 @@ public:
virtual bool LoadPedDistribution(std::vector<std::shared_ptr<StartDistribution> >& startDis, virtual bool LoadPedDistribution(std::vector<std::shared_ptr<StartDistribution> >& startDis,
std::vector<std::shared_ptr<StartDistribution> >& startDisSub, std::vector<std::shared_ptr<StartDistribution> >& startDisSub,
std::vector<std::shared_ptr<AgentsSource> >& startDisSources) override; std::vector<std::shared_ptr<AgentsSource> >& startDisSources) override;
std::shared_ptr<AgentsSource> parseSourceNode(TiXmlElement* e);
private: private:
const Configuration* _configuration; const Configuration* _configuration;
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "pedestrian/AgentsQueue.h" #include "pedestrian/AgentsQueue.h"
#include "pedestrian/AgentsSourcesManager.h" #include "pedestrian/AgentsSourcesManager.h"
#include "geometry/WaitingArea.h" #include "geometry/WaitingArea.h"
#include <filesystem>
namespace fs = std::filesystem;
#ifdef _OPENMP #ifdef _OPENMP
...@@ -48,10 +50,13 @@ ...@@ -48,10 +50,13 @@
using namespace std; using namespace std;
OutputHandler* Log; OutputHandler* Log;
Trajectories* outputTXT;
Simulation::Simulation(Configuration* args) Simulation::Simulation(Configuration* args)
:_config(args) :_config(args)
{ {
_countTraj = 0;
_maxFileSize = 10; // MB
_nPeds = 0; _nPeds = 0;
_seed = 8091983; _seed = 8091983;
_deltaT = 0; _deltaT = 0;
...@@ -156,9 +161,9 @@ bool Simulation::InitArgs() ...@@ -156,9 +161,9 @@ bool Simulation::InitArgs()
case FORMAT_PLAIN: { case FORMAT_PLAIN: {
OutputHandler* file = new FileHandler( OutputHandler* file = new FileHandler(
_config->GetTrajectoriesFile().c_str()); _config->GetTrajectoriesFile().c_str());
Trajectories* output = new TrajectoriesFLAT(); outputTXT = new TrajectoriesFLAT();
output->SetOutputHandler(file); outputTXT->SetOutputHandler(file);
_iod->AddIO(output); _iod->AddIO(outputTXT);
break; break;
} }
case FORMAT_VTK: { case FORMAT_VTK: {
...@@ -391,9 +396,9 @@ void Simulation::UpdateRoutesAndLocations() ...@@ -391,9 +396,9 @@ void Simulation::UpdateRoutesAndLocations()
// } // }
} }
void Simulation::PrintStatistics() void Simulation::PrintStatistics(double simTime)
{ {
Log->Write("\nRooms Egress Time:"); Log->Write("\nRooms Egress. Simulation Time: %.2f", simTime);
Log->Write("=================="); Log->Write("==================");
Log->Write("id\tcaption\tegress time (s)"); Log->Write("id\tcaption\tegress time (s)");
...@@ -422,6 +427,7 @@ void Simulation::PrintStatistics() ...@@ -422,6 +427,7 @@ void Simulation::PrintStatistics()
} }
Log->Write("More Information in the file: %s", statsfile.c_str()); Log->Write("More Information in the file: %s", statsfile.c_str());
auto output = new FileHandler(statsfile.c_str()); auto output = new FileHandler(statsfile.c_str());
output->Write("#Simulation time: %.2f", simTime);
output->Write("#Flow at exit "+goal->GetCaption()+"( ID "+to_string(goal->GetID())+" )"); output->Write("#Flow at exit "+goal->GetCaption()+"( ID "+to_string(goal->GetID())+" )");
output->Write("#Time (s) cummulative number of agents \n"); output->Write("#Time (s) cummulative number of agents \n");
output->Write(goal->GetFlowCurve()); output->Write(goal->GetFlowCurve());
...@@ -442,6 +448,7 @@ void Simulation::PrintStatistics() ...@@ -442,6 +448,7 @@ void Simulation::PrintStatistics()
+ to_string(itr.first/1000) + "_" + to_string(itr.first % 1000) +".dat"; + to_string(itr.first/1000) + "_" + to_string(itr.first % 1000) +".dat";
Log->Write("More Information in the file: %s", statsfile.c_str()); Log->Write("More Information in the file: %s", statsfile.c_str());
auto output = new FileHandler(statsfile.c_str()); auto output = new FileHandler(statsfile.c_str());
output->Write("#Simulation time: %.2f", simTime);
output->Write("#Flow at crossing " + goal->GetCaption() + "( ID " + to_string(goal->GetID()) output->Write("#Flow at crossing " + goal->GetCaption() + "( ID " + to_string(goal->GetID())
+ " ) in Room ( ID "+ to_string(itr.first / 1000) + " )"); + " ) in Room ( ID "+ to_string(itr.first / 1000) + " )");
output->Write("#Time (s) cummulative number of agents \n"); output->Write("#Time (s) cummulative number of agents \n");
...@@ -456,7 +463,8 @@ void Simulation::RunHeader(long nPed) ...@@ -456,7 +463,8 @@ void Simulation::RunHeader(long nPed)
{ {
// writing the header // writing the header
if (nPed==-1) nPed = _nPeds; if (nPed==-1) nPed = _nPeds;
_iod->WriteHeader(nPed, _fps, _building.get(), _seed); _iod->WriteHeader(nPed, _fps, _building.get(), _seed, 0);// first trajectory
// count = 0
_iod->WriteGeometry(_building.get()); _iod->WriteGeometry(_building.get());
if( _gotSources) if( _gotSources)
_iod->WriteSources( GetAgentSrcManager().GetSources()); _iod->WriteSources( GetAgentSrcManager().GetSources());
...@@ -466,7 +474,6 @@ void Simulation::RunHeader(long nPed) ...@@ -466,7 +474,6 @@ void Simulation::RunHeader(long nPed)
int firstframe = (Pedestrian::GetGlobalTime()/_deltaT)/writeInterval; int firstframe = (Pedestrian::GetGlobalTime()/_deltaT)/writeInterval;
_iod->WriteFrame(firstframe, _building.get()); _iod->WriteFrame(firstframe, _building.get());
//first initialisation needed by the linked-cells //first initialisation needed by the linked-cells
UpdateRoutesAndLocations(); UpdateRoutesAndLocations();
ProcessAgentsQueue(); ProcessAgentsQueue();
...@@ -481,7 +488,10 @@ double Simulation::RunBody(double maxSimTime) ...@@ -481,7 +488,10 @@ double Simulation::RunBody(double maxSimTime)
//take the current time from the pedestrian //take the current time from the pedestrian
double t = Pedestrian::GetGlobalTime(); double t = Pedestrian::GetGlobalTime();
fs::path TrajectoryName(_config->GetTrajectoriesFile());// in case we
// may need to
// generate
// several small files
//frame number. This function can be called many times, //frame number. This function can be called many times,
static int frameNr = (int) (1+t/_deltaT); // Frame Number static int frameNr = (int) (1+t/_deltaT); // Frame Number
...@@ -508,6 +518,7 @@ double Simulation::RunBody(double maxSimTime) ...@@ -508,6 +518,7 @@ double Simulation::RunBody(double maxSimTime)
bar->SetStyle("\u2588", "-"); //for linux bar->SetStyle("\u2588", "-"); //for linux
#endif #endif
int initialnPeds = _nPeds; int initialnPeds = _nPeds;
// main program loop // main program loop
while ((_nPeds || (!_agentSrcManager.IsCompleted()&& _gotSources) ) && t<maxSimTime) { while ((_nPeds || (!_agentSrcManager.IsCompleted()&& _gotSources) ) && t<maxSimTime) {
t = 0+(frameNr-1)*_deltaT; t = 0+(frameNr-1)*_deltaT;
...@@ -549,6 +560,24 @@ double Simulation::RunBody(double maxSimTime) ...@@ -549,6 +560,24 @@ double Simulation::RunBody(double maxSimTime)
// write the trajectories // write the trajectories
if (0==frameNr%writeInterval) { if (0==frameNr%writeInterval) {
_iod->WriteFrame(frameNr/writeInterval, _building.get()); _iod->WriteFrame(frameNr/writeInterval, _building.get());
fs::path p = _config->GetTrajectoriesFile();
int sf = fs::file_size(p);
if(sf>_maxFileSize*1024*1024)
{
std::string extention = p.extension().string();
_countTraj++;
char tmp_traj_name[100];
sprintf(tmp_traj_name,"%s_%.4d_%s", TrajectoryName.stem().string().c_str(), _countTraj, extention.c_str());
_config->SetTrajectoriesFile(tmp_traj_name);
Log->Write("INFO:\tNew trajectory file <%s>", tmp_traj_name);
OutputHandler* file = new FileHandler(_config->GetTrajectoriesFile().c_str());
outputTXT->SetOutputHandler(file);
//_config->GetProjectRootDir()+"_1_"+_config->GetTrajectoriesFile());
// _config->SetTrajectoriesFile(name);
_iod->WriteHeader(_nPeds, _fps, _building.get(), _seed, _countTraj);
// _iod->WriteGeometry(_building.get());
}
} }
if(!_gotSources && !_periodic && _config->print_prog_bar()) if(!_gotSources && !_periodic && _config->print_prog_bar())
...@@ -596,6 +625,13 @@ double Simulation::RunBody(double maxSimTime) ...@@ -596,6 +625,13 @@ double Simulation::RunBody(double maxSimTime)
} }
} }
} }
if(frameNr % 1000 == 0)
{
Log->Write("INFO:\tUpdate door statistics at t=%.2f", t);
PrintStatistics(t);
}
}// while time }// while time
return t; return t;
} }
......
...@@ -156,7 +156,7 @@ public: ...@@ -156,7 +156,7 @@ public:
/** /**
* print some statistics about the simulation * print some statistics about the simulation
*/ */
void PrintStatistics(); void PrintStatistics(double time);
/** /**
* @return the agents source manager * @return the agents source manager
...@@ -186,7 +186,8 @@ public: ...@@ -186,7 +186,8 @@ public:
void UpdateDoorticks() const; void UpdateDoorticks() const;
int GetMaxSimTime() const; int GetMaxSimTime() const;
int _countTraj=0; // count number of TXT trajectories to produce
double _maxFileSize; // in MB
}; };
#endif /*SIMULATION_H_*/ #endif /*SIMULATION_H_*/
...@@ -74,42 +74,42 @@ FIND_PROGRAM( GENHTML_PATH genhtml ) ...@@ -74,42 +74,42 @@ FIND_PROGRAM( GENHTML_PATH genhtml )
FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests)
IF(NOT GCOV_PATH) IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...") MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF() # NOT GCOV_PATH ENDIF() # NOT GCOV_PATH
IF(NOT CMAKE_COMPILER_IS_GNUCXX) IF(NOT CMAKE_COMPILER_IS_GNUCXX)
# Clang version 3.0.0 and greater now supports gcov as well. # Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.") MESSAGE(WARNING "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") IF(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF() ENDIF()
ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX ENDIF() # NOT CMAKE_COMPILER_IS_GNUCXX
SET(CMAKE_CXX_FLAGS_COVERAGE SET(CMAKE_CXX_FLAGS_COVERAGE
"-g -O0 --coverage -fprofile-arcs -ftest-coverage" "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C++ compiler during coverage builds." CACHE STRING "Flags used by the C++ compiler during coverage builds."
FORCE ) FORCE )
SET(CMAKE_C_FLAGS_COVERAGE SET(CMAKE_C_FLAGS_COVERAGE
"-g -O0 --coverage -fprofile-arcs -ftest-coverage" "-g -O0 --coverage -fprofile-arcs -ftest-coverage"
CACHE STRING "Flags used by the C compiler during coverage builds." CACHE STRING "Flags used by the C compiler during coverage builds."
FORCE ) FORCE )
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
"" ""
CACHE STRING "Flags used for linking binaries during coverage builds." CACHE STRING "Flags used for linking binaries during coverage builds."
FORCE ) FORCE )
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
"" ""
CACHE STRING "Flags used by the shared libraries linker during coverage builds." CACHE STRING "Flags used by the shared libraries linker during coverage builds."
FORCE ) FORCE )
MARK_AS_ADVANCED( MARK_AS_ADVANCED(
CMAKE_CXX_FLAGS_COVERAGE CMAKE_CXX_FLAGS_COVERAGE
CMAKE_C_FLAGS_COVERAGE CMAKE_C_FLAGS_COVERAGE
CMAKE_EXE_LINKER_FLAGS_COVERAGE CMAKE_EXE_LINKER_FLAGS_COVERAGE
CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage"))
MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" ) MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" )
ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
...@@ -123,38 +123,38 @@ ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" ...@@ -123,38 +123,38 @@ ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug"
# Pass them in list form, e.g.: "-j;2" for -j 2 # Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH) IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...") MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF() # NOT LCOV_PATH ENDIF() # NOT LCOV_PATH
IF(NOT GENHTML_PATH) IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF() # NOT GENHTML_PATH ENDIF() # NOT GENHTML_PATH
# Setup target # Setup target
ADD_CUSTOM_TARGET(${_targetname} ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov # Cleanup lcov
${LCOV_PATH} --directory . --zerocounters ${LCOV_PATH} --directory . --zerocounters
# Run tests # Run tests
COMMAND ${_testrunner} -R Boost ${ARGV3} COMMAND ${_testrunner} -R Boost ${ARGV3}
# Capturing lcov counters and generating report # Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info
COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' --output-file ${_outputname}.info.cleaned COMMAND ${LCOV_PATH} --remove ${_outputname}.info 'tests/*' '/usr/*' --output-file ${_outputname}.info.cleaned
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned
COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
) )
# Show info where to find the report # Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ; COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
) )
ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
...@@ -165,30 +165,30 @@ ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE ...@@ -165,30 +165,30 @@ ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE
# Pass them in list form, e.g.: "-j;2" for -j 2 # Pass them in list form, e.g.: "-j;2" for -j 2
FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname)
IF(NOT PYTHON_EXECUTABLE) IF(NOT PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "Python 3 not found! Aborting...") MESSAGE(FATAL_ERROR "Python 3 not found! Aborting...")
ENDIF() # NOT PYTHON_EXECUTABLE ENDIF() # NOT PYTHON_EXECUTABLE
IF(NOT GCOVR_PATH) IF(NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") MESSAGE(FATAL_ERROR "gcovr not found! Aborting...")
ENDIF() # NOT GCOVR_PATH ENDIF() # NOT GCOVR_PATH
ADD_CUSTOM_TARGET(${_targetname} ADD_CUSTOM_TARGET(${_targetname}
# Run tests # Run tests
MESSAGE(WARNING "running: " ${_testrunner} -R Boost ${ARGV3}) MESSAGE(WARNING "running: " ${_testrunner} -R Boost ${ARGV3})
${_testrunner} -R Boost ${ARGV3} ${_testrunner} -R Boost ${ARGV3}