Skip to content
Snippets Groups Projects
Commit 96aa70a1 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

clang-tidy: fix issues in TimeoutAqlTest

parent 1525f468
No related branches found
No related tags found
1 merge request!200clang tidy fixes
...@@ -25,10 +25,10 @@ ...@@ -25,10 +25,10 @@
#define FD_STDERR 2 #define FD_STDERR 2
   
/* Communication between signal handler and the rest of the program */ /* Communication between signal handler and the rest of the program */
int g_Wakeup [ 2 ]; // pipe for wakeup std::array < int, 2 > g_Wakeup; // pipe for wakeup
int g_RecvSignal; // signalled flag bool g_RecvSignal; // signalled flag
   
int waitSignalTimeout ( const std::chrono::microseconds& duration ) { bool waitSignalTimeout ( const std::chrono::microseconds& duration ) {
struct timeval tv; struct timeval tv;
fd_set rd; fd_set rd;
   
...@@ -48,10 +48,10 @@ std::string readFromFD ( int fd ) { ...@@ -48,10 +48,10 @@ std::string readFromFD ( int fd ) {
   
std::string res; std::string res;
int rd; int rd;
char buf [ BUFSIZE ]; std::array < char, BUFSIZE > buf;
   
while ( ( rd = read ( fd, &buf, BUFSIZE - 1 ) ) > 0 ) { while ( ( rd = read ( fd, buf.data ( ), buf.size ( ) - 1 ) ) > 0 ) {
res.append ( buf, rd ); res.append ( buf.data ( ), rd );
} }
   
return res; return res;
...@@ -63,7 +63,7 @@ void writeToFD ( int fd, const std::string & message, const std::string & errorD ...@@ -63,7 +63,7 @@ void writeToFD ( int fd, const std::string & message, const std::string & errorD
} }
   
void newSigChild ( int ) { 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 // write into the pipe so select can read something, this effectively means that SIGCHILD was raised
writeToFD ( g_Wakeup [ PIPE_WR ], " ", "wakeup signalling" ); writeToFD ( g_Wakeup [ PIPE_WR ], " ", "wakeup signalling" );
...@@ -75,29 +75,29 @@ struct ChildStatus { ...@@ -75,29 +75,29 @@ struct ChildStatus {
std::string outAql, outStdout, outStderr; 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 */ /* Register SIGCHLD handler */
struct sigaction act; struct sigaction act;
memset ( &act, 0, sizeof ( act ) ); memset ( &act, 0, sizeof ( act ) );
act . sa_handler = newSigChild; act . sa_handler = newSigChild;
sigaction ( SIGCHLD, &act, nullptr ); sigaction ( SIGCHLD, &act, nullptr );
   
int pipeAqlOutput [ 2 ]; /* parent-child communication ( aql output ) */ std::array < int, 2 > pipeAqlOutput; /* parent-child communication ( aql output ) */
int pipeStdout [ 2 ]; /* parent-child communication ( child stdout ) */ std::array < int, 2 > pipeStdout; /* parent-child communication ( child stdout ) */
int pipeStderr [ 2 ]; /* parent-child communication ( child stderr ) */ 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)" ); 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)" ); 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)" ); throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (child stderr)" );
   
/* SIGCHLD was not yet raised, initialize communication pipe */ /* SIGCHLD was not yet raised, initialize communication pipe */
g_RecvSignal = 0; g_RecvSignal = false;
if ( pipe ( g_Wakeup ) ) if ( pipe ( g_Wakeup.data ( ) ) )
throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (wakeup signalling)" ); throw std::runtime_error ( "TimeoutAqlTest: Failed to initialize pipe (wakeup signalling)" );
   
/* random seed for aql */ /* random seed for aql */
...@@ -238,18 +238,18 @@ std::string printTest ( const std::vector < std::string > & queries ) { ...@@ -238,18 +238,18 @@ std::string printTest ( const std::vector < std::string > & queries ) {
return oss.str ( ); 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 ); std::ifstream ifs ( file );
REQUIRE ( ifs.is_open ( ) ); REQUIRE ( ifs.is_open ( ) );
auto testChildStatus = _TimeoutAqlTestImpl ( timeout, ifs ); auto testChildStatus = TimeoutAqlTestImpl ( timeout, ifs );
processTestChildStatus ( testChildStatus, timeout, timeoutError, printTest ( file ) ); 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; std::stringstream ifs;
for ( const auto & q : queries ) for ( const auto & q : queries )
ifs << q << "\n"; ifs << q << "\n";
   
auto testChildStatus = _TimeoutAqlTestImpl ( timeout, ifs ); auto testChildStatus = TimeoutAqlTestImpl ( timeout, ifs );
processTestChildStatus ( testChildStatus, timeout, timeoutError, printTest ( queries ) ); processTestChildStatus ( testChildStatus, timeout, timeoutError, printTest ( queries ) );
} }
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
   
using namespace std::literals::chrono_literals; using namespace std::literals::chrono_literals;
   
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 );
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 );
   
/** /**
* @param timeout timeout (use std chrono literals) ofthe test * @param timeout timeout (use std chrono literals) ofthe test
...@@ -17,7 +17,7 @@ void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::vec ...@@ -17,7 +17,7 @@ void _TimeoutAqlTest ( const std::chrono::microseconds & timeout, const std::vec
*/ */
template < class D > template < class D >
void TimeoutAqlTest ( const D & timeout, const std::vector < std::string > & queries, bool timeoutError = false ) { 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 ...@@ -27,5 +27,5 @@ void TimeoutAqlTest ( const D & timeout, const std::vector < std::string > & que
*/ */
template < class D > template < class D >
void TimeoutAqlTest ( const D & timeout, const std::filesystem::path & file, bool timeoutError ) { 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 );
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment