Commit 951955ae authored by Steffen Schotthöfer's avatar Steffen Schotthöfer
Browse files

logger validation test added fixed


Former-commit-id: d4b1f55a
parent 886130f5
......@@ -62,7 +62,7 @@ QUAD_ORDER = 8
% ----- Output ----
%
VOLUME_OUTPUT = (ANALYTIC, MINIMAL, MOMENTS, DUAL_MOMENTS)
VOLUME_OUTPUT_FREQUENCY = 3
VOLUME_OUTPUT_FREQUENCY = 0
SCREEN_OUTPUT = (ITER, MASS, RMS_FLUX, VTK_OUTPUT, CSV_OUTPUT)
SCREEN_OUTPUT_FREQUENCY = 1
HISTORY_OUTPUT = (ITER, MASS, RMS_FLUX, VTK_OUTPUT, CSV_OUTPUT)
......
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Validate Screen Output Test %
% Author <Steffen Schotthöfer> %
% Date 20.11.2020 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% ---- File specifications ----
OUTPUT_DIR = ../../result
OUTPUT_FILE = validate_screen_output
LOG_DIR = ../../result/logs
LOG_FILE = validate_logger_output
MESH_FILE = linesource.su2
%
% ---- Problem specifications ----
%
PROBLEM = LINESOURCE
SCATTER_COEFF = 1
%
% ---- Solver specifications ----
%
SOLVER = SN_SOLVER
CFL_NUMBER = 0.7
TIME_FINAL = 0.2
%
% ---- Boundary Conditions ----
%
BC_NEUMANN = ( void )
QUAD_TYPE = LEBEDEV
QUAD_ORDER = 15
%
% ----- Output ----
%
VOLUME_OUTPUT = ( MINIMAL)
VOLUME_OUTPUT_FREQUENCY = 0
SCREEN_OUTPUT = (ITER, MASS, RMS_FLUX, VTK_OUTPUT, CSV_OUTPUT)
SCREEN_OUTPUT_FREQUENCY = 1
HISTORY_OUTPUT = (ITER, MASS, RMS_FLUX, VTK_OUTPUT, CSV_OUTPUT)
HISTORY_OUTPUT_FREQUENCY = 1
2020-11-20 11:48:45.266053 , Iter,Mass,RMS_flux,VTK_out,CSV_out
2020-11-20 11:48:45.266297 , 0.000000,1.815994,51.851194,0.000000,1.000000
2020-11-20 11:48:45.266515 , 1.000000,1.815994,23.856349,1.000000,1.000000
......@@ -164,19 +164,35 @@ TEST_CASE( "linesource_MN", "[validation_tests]" ) {
}
// --- Validation Tests Output ---
void tokenize( std::string const& str, const char delim, std::vector<std::string>& out ) {
size_t start;
size_t end = 0;
while( ( start = str.find_first_not_of( delim, end ) ) != std::string::npos ) {
end = str.find( delim, start );
out.push_back( str.substr( start, end - start ) );
}
}
TEST_CASE( "screen_output", "[output]" ) {
spdlog::drop_all(); // Make sure to write in own logging file
std::string config_file_name = std::string( TESTS_PATH ) + "input/validate_logger.cfg";
std::string screenLoggerReference = std::string( TESTS_PATH ) + "input/validate_screen_output_reference";
std::string screenLogger = std::string( TESTS_PATH ) + "../result/logs/validate_screen_output";
std::string historyLoggerReference = std::string( TESTS_PATH ) + "input/validate_screen_output_csv_reference";
std::string historyLogger = std::string( TESTS_PATH ) + "../result/logs/validate_screen_output_csv";
std::string screenLoggerReference = std::string( TESTS_PATH ) + "input/validate_logger_reference";
std::string screenLogger = std::string( TESTS_PATH ) + "../result/logs/validate_logger_output";
std::string historyLoggerReference = std::string( TESTS_PATH ) + "input/validate_logger_csv_reference";
std::string historyLogger = std::string( TESTS_PATH ) + "../result/logs/validate_logger_output_csv";
Config* config = new Config( config_file_name );
Solver* solver = Solver::Create( config );
solver->Solve();
// Force Logger to flush
auto log = spdlog::get( "event" );
auto logCSV = spdlog::get( "tabular" );
log->flush();
logCSV->flush();
// --- Read and validate logger ---
std::ifstream screenLoggerReferenceStream( screenLoggerReference );
std::ifstream screenLoggerStream( screenLogger );
......@@ -185,15 +201,29 @@ TEST_CASE( "screen_output", "[output]" ) {
std::string line, lineRef;
bool lineValid;
const char delimScreen = '|';
const char delimHist = ',';
// --- Screen Logger
while( !screenLoggerReferenceStream.eof() && !screenLoggerStream.eof() ) {
std::getline( screenLoggerReferenceStream, lineRef );
std::getline( screenLoggerStream, line );
lineValid = lineRef.compare( line ) == 0;
if( !lineValid ) {
std::cout << lineRef << "\n" << line << "\n";
// ignore date (before first "|")
std::vector<std::string> out;
std::vector<std::string> outRef;
tokenize( line, delimScreen, out );
tokenize( lineRef, delimScreen, outRef );
REQUIRE( out.size() == outRef.size() ); // Sanity check
for( unsigned idx_token = 1; idx_token < out.size(); idx_token++ ) { // Skip date ==> start from 1
lineValid = outRef[idx_token].compare( out[idx_token] ) == 0;
if( !lineValid ) {
std::cout << lineRef << "\n" << line << "\n";
}
REQUIRE( lineValid );
}
REQUIRE( lineValid );
}
bool eqLen = screenLoggerReferenceStream.eof() && screenLoggerStream.eof();
if( !eqLen ) {
......@@ -201,11 +231,25 @@ TEST_CASE( "screen_output", "[output]" ) {
}
REQUIRE( eqLen ); // Files must be of same length
// --- History Logger
while( !historyLoggerReferenceStream.eof() && !historyLoggerStream.eof() ) {
std::getline( historyLoggerReferenceStream, lineRef );
std::getline( historyLoggerStream, line );
lineValid = lineRef.compare( line ) == 0;
REQUIRE( lineValid );
// ignore date (before first "|")
std::vector<std::string> out;
std::vector<std::string> outRef;
tokenize( line, delimHist, out );
tokenize( lineRef, delimHist, outRef );
REQUIRE( out.size() == outRef.size() ); // sanity check
for( unsigned idx_token = 1; idx_token < out.size(); idx_token++ ) { // Skip date ==> start from 1
lineValid = outRef[idx_token].compare( out[idx_token] ) == 0;
if( !lineValid ) {
std::cout << lineRef << "\n" << line << "\n";
}
REQUIRE( lineValid );
}
}
eqLen = historyLoggerReferenceStream.eof() && historyLoggerStream.eof();
if( !eqLen ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment