Fix to test framework.
authorBartlomiej Grzelewski <b.grzelewski@samsung.com>
Wed, 6 Feb 2013 14:50:49 +0000 (15:50 +0100)
committerLukasz Marek <l.marek@samsung.com>
Mon, 11 Feb 2013 10:59:13 +0000 (11:59 +0100)
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
modules/test/src/test_runner.cpp
modules/test/src/test_runner_child.cpp

index c82a04d..99a2cb5 100644 (file)
@@ -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<TestRunner> TestRunnerSingleton;
index 4826369..126f1b0 100644 (file)
@@ -268,6 +268,9 @@ void TestRunner::Usage()
     fprintf(
         stderr,
         "  --listingroup=<group name>\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
index bd23771..bf773c6 100644 (file)
@@ -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);
     }
 }