From 94b8a18e822020f50cd9bfd0e7b97a5a9f03e782 Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Wed, 6 Feb 2013 15:50:49 +0100 Subject: [PATCH] Fix to test framework. Add option allowChildLogs in test framework. Adopt method name to DPL convention. Change SIGINT to SIGKILL in RUNNER_CHILD framework. [Issue#] N/A [Cause] Child process closes 1 and 2 descriptor after fork. [Soution] Add allowChildLogs option. [Problem] Logs from child process was not printed on screen. [Verification] Successful compilation. Change-Id: I97d18f94c751d14119efe02f7b84c3c142ab31d1 --- modules/test/include/dpl/test/test_runner.h | 6 +++++- modules/test/src/test_runner.cpp | 15 ++++++++++++++- modules/test/src/test_runner_child.cpp | 21 ++++++++++++++++----- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/modules/test/include/dpl/test/test_runner.h b/modules/test/include/dpl/test/test_runner.h index c82a04d..99a2cb5 100644 --- a/modules/test/include/dpl/test/test_runner.h +++ b/modules/test/include/dpl/test/test_runner.h @@ -48,6 +48,7 @@ class TestRunner public: TestRunner() : m_terminate(false) + , m_allowChildLogs(false) {} typedef void (*TestCase)(); @@ -90,6 +91,8 @@ class TestRunner // Some test requires to call fork function. // Child process must not produce any logs and should die quietly. bool m_terminate; + bool m_allowChildLogs; + void Banner(); void InvalidArgs(const std::string& message = "Invalid arguments!"); void Usage(); @@ -164,7 +167,8 @@ class TestRunner int ExecTestRunner(const ArgsList& args); bool getRunIgnored() const; // The runner will terminate as soon as possible (after current test). - void terminate(); + void Terminate(); + bool GetAllowChildLogs(); }; typedef DPL::Singleton TestRunnerSingleton; diff --git a/modules/test/src/test_runner.cpp b/modules/test/src/test_runner.cpp index 4826369..126f1b0 100644 --- a/modules/test/src/test_runner.cpp +++ b/modules/test/src/test_runner.cpp @@ -268,6 +268,9 @@ void TestRunner::Usage() fprintf( stderr, " --listingroup=\t Show a list of Test IDS in one group\n"); + fprintf(stderr, " --allowchildlogs\t Allow to print logs from child process on screen.\n"); + fprintf(stderr, " When active child process will be able to print logs on stdout and stderr.\n"); + fprintf(stderr, " Both descriptors will be closed after test.\n"); fprintf(stderr, " --help\t This help\n\n"); std::for_each(m_collectors.begin(), m_collectors.end(), @@ -328,6 +331,7 @@ int TestRunner::ExecTestRunner(const ArgsList& value) const std::string startCmd = "--start="; const std::string listGroupsCmd = "--listgroups"; const std::string listInGroup = "--listingroup="; + const std::string allowChildLogs = "--allowchildlogs"; if (currentCollector) { if (currentCollector->ParseCollectorSpecificArg(arg)) { @@ -389,6 +393,9 @@ int TestRunner::ExecTestRunner(const ArgsList& value) printf("ID:%s\n", test->name.c_str()); } return 0; + } else if (arg.find(allowChildLogs) == 0) { + arg.erase(0, allowChildLogs.length()); + m_allowChildLogs = true; } else if (arg == "--help") { showHelp = true; } else if (arg.find(output) == 0) { @@ -475,9 +482,15 @@ bool TestRunner::getRunIgnored() const return m_runIgnored; } -void TestRunner::terminate() +void TestRunner::Terminate() { m_terminate = true; } + +bool TestRunner::GetAllowChildLogs() +{ + return m_allowChildLogs; +} + } } // namespace DPL diff --git a/modules/test/src/test_runner_child.cpp b/modules/test/src/test_runner_child.cpp index bd23771..bf773c6 100644 --- a/modules/test/src/test_runner_child.cpp +++ b/modules/test/src/test_runner_child.cpp @@ -255,7 +255,7 @@ void RunChildProc(TestRunner::TestCase procChild) if (pipeReturn != PipeWrapper::SUCCESS) { // Timeout or reading error pipe.closeAll(); - kill(pid, SIGINT); + kill(pid, SIGKILL); } int status; @@ -276,13 +276,18 @@ void RunChildProc(TestRunner::TestCase procChild) // child code // End Runner after current test - TestRunnerSingleton::Instance().terminate(); + TestRunnerSingleton::Instance().Terminate(); + int code = 1; std::string msg; - // close(0); // stdin - close(1); // stdout - close(2); // stderr + bool allowLogs = TestRunnerSingleton::Instance().GetAllowChildLogs(); + + close(0); // stdin + if (!allowLogs) { + close(1); // stdout + close(2); // stderr + } pipe.setUsage(PipeWrapper::WRITEONLY); @@ -295,6 +300,12 @@ void RunChildProc(TestRunner::TestCase procChild) msg = "unhandled exeception"; code = 0; } + + if (allowLogs) { + close(1); // stdout + close(2); // stderr + } + pipe.send(code, msg); } } -- 2.7.4