diff --git a/tests/testing/TimeoutAqlTest.cpp b/tests/testing/TimeoutAqlTest.cpp index f439727e1e91118b1de14af97fc3ec5752a3c51e..c2d8a650c95776666150f2da9d4ba0d8094dfaf7 100644 --- a/tests/testing/TimeoutAqlTest.cpp +++ b/tests/testing/TimeoutAqlTest.cpp @@ -25,10 +25,10 @@ #define FD_STDERR 2 /* Communication between signal handler and the rest of the program */ -int g_Wakeup [ 2 ]; // pipe for wakeup -int g_RecvSignal; // signalled flag +std::array < int, 2 > g_Wakeup; // pipe for wakeup +bool g_RecvSignal; // signalled flag -int waitSignalTimeout ( const std::chrono::microseconds& duration ) { +bool waitSignalTimeout ( const std::chrono::microseconds& duration ) { struct timeval tv; fd_set rd; @@ -48,10 +48,10 @@ std::string readFromFD ( int fd ) { std::string res; int rd; - char buf [ BUFSIZE ]; + std::array < char, BUFSIZE > buf; - while ( ( rd = read ( fd, &buf, BUFSIZE - 1 ) ) > 0 ) { - res.append ( buf, rd ); + while ( ( rd = read ( fd, buf.data ( ), buf.size ( ) - 1 ) ) > 0 ) { + res.append ( buf.data ( ), rd ); } return res; @@ -63,7 +63,7 @@ void writeToFD ( int fd, const std::string & message, const std::string & errorD } void newSigChild ( int ) { - g_RecvSignal = 1; + g_RecvSignal = true; // write into the pipe so select can read something, this effectively means that SIGCHILD was raised writeToFD ( g_Wakeup [ PIPE_WR ], " ", "wakeup signalling" ); @@ -75,29 +75,29 @@ struct ChildStatus { std::string outAql, outStdout, outStderr; }; -ChildStatus _TimeoutAqlTestImpl ( const std::chrono::microseconds & timeout, std::istream& is ) { +ChildStatus TimeoutAqlTestImpl ( const std::chrono::microseconds & timeout, std::istream& is ) { /* Register SIGCHLD handler */ struct sigaction act; memset ( &act, 0, sizeof ( act ) ); act . sa_handler = newSigChild; sigaction ( SIGCHLD, &act, nullptr ); - int pipeAqlOutput [ 2 ]; /* parent-child communication ( aql output ) */ - int pipeStdout [ 2 ]; /* parent-child communication ( child stdout ) */ - int pipeStderr [ 2 ]; /* parent-child communication ( child stderr ) */ + std::array < int, 2 > pipeAqlOutput; /* parent-child communication ( aql output ) */ + std::array < int, 2 > pipeStdout; /* parent-child communication ( child stdout ) */ + std::array < int, 2 > pipeStderr; /* parent-child communication ( child stderr ) */ - if ( pipe ( pipeAqlOutput ) != 0 ) + if ( pipe ( pipeAqlOutput.data ( ) ) != 0 ) throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (aql output)" ); - if ( pipe ( pipeStdout ) != 0 ) + if ( pipe ( pipeStdout. data ( ) ) != 0 ) throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (child stdout)" ); - if ( pipe ( pipeStderr ) != 0 ) + if ( pipe ( pipeStderr. data ( ) ) != 0 ) throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (child stderr)" ); /* SIGCHLD was not yet raised, initialize communication pipe */ - g_RecvSignal = 0; - if ( pipe ( g_Wakeup ) ) + g_RecvSignal = false; + if ( pipe ( g_Wakeup.data ( ) ) ) throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (wakeup signalling)" ); /* random seed for aql */ @@ -238,18 +238,18 @@ std::string printTest ( const std::vector < std::string > & queries ) { return oss.str ( ); } -void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::filesystem::path & file, bool timeoutError ) { +void TimeoutAqlTestInt ( const std::chrono::microseconds & timeout, const std::filesystem::path & file, bool timeoutError ) { std::ifstream ifs ( file ); REQUIRE ( ifs.is_open ( ) ); - auto testChildStatus = _TimeoutAqlTestImpl ( timeout, ifs ); + auto testChildStatus = TimeoutAqlTestImpl ( timeout, ifs ); processTestChildStatus ( testChildStatus, timeout, timeoutError, printTest ( file ) ); } -void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::vector < std::string > & queries, bool timeoutError ) { +void TimeoutAqlTestInt ( const std::chrono::microseconds & timeout, const std::vector < std::string > & queries, bool timeoutError ) { std::stringstream ifs; for ( const auto & q : queries ) ifs << q << "\n"; - auto testChildStatus = _TimeoutAqlTestImpl ( timeout, ifs ); + auto testChildStatus = TimeoutAqlTestImpl ( timeout, ifs ); processTestChildStatus ( testChildStatus, timeout, timeoutError, printTest ( queries ) ); } diff --git a/tests/testing/TimeoutAqlTest.hpp b/tests/testing/TimeoutAqlTest.hpp index 8fd77c27912fb0319ea8fb69052befea5314a97f..52575ae93ace5c36643a1d80db86b437de4cb368 100644 --- a/tests/testing/TimeoutAqlTest.hpp +++ b/tests/testing/TimeoutAqlTest.hpp @@ -7,8 +7,8 @@ using namespace std::literals::chrono_literals; -void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::filesystem::path & file, bool timeoutError ); -void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::vector < std::string > & queries, bool timeoutError ); +void TimeoutAqlTestInt ( const std::chrono::microseconds & timeout, const std::filesystem::path & file, bool timeoutError ); +void TimeoutAqlTestInt ( const std::chrono::microseconds & timeout, const std::vector < std::string > & queries, bool timeoutError ); /** * @param timeout timeout (use std chrono literals) ofthe test @@ -17,7 +17,7 @@ void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::vec */ template < class D > void TimeoutAqlTest ( const D & timeout, const std::vector < std::string > & queries, bool timeoutError = false ) { - _TimeoutAqlTest ( std::chrono::duration_cast < std::chrono::microseconds > ( timeout ), queries, timeoutError ); + TimeoutAqlTestInt ( std::chrono::duration_cast < std::chrono::microseconds > ( timeout ), queries, timeoutError ); } /** @@ -27,5 +27,5 @@ void TimeoutAqlTest ( const D & timeout, const std::vector < std::string > & que */ template < class D > void TimeoutAqlTest ( const D & timeout, const std::filesystem::path & file, bool timeoutError ) { - _TimeoutAqlTest ( std::chrono::duration_cast < std::chrono::microseconds > ( timeout ), file, timeoutError ); + TimeoutAqlTestInt ( std::chrono::duration_cast < std::chrono::microseconds > ( timeout ), file, timeoutError ); }