From: Adeel Kazmi Date: Thu, 9 Jan 2020 17:23:57 +0000 (+0000) Subject: Merge "Fix random crash in TCT when stderr is closed but we try to write to it" into... X-Git-Tag: dali_1.4.53~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=6f410ceca1ec96e6cb1fdc482ae222ab58a824de;hp=15f1c1df72116aff4fa95a04f5aed0793748dee0 Merge "Fix random crash in TCT when stderr is closed but we try to write to it" into devel/master --- diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp index c4a27d1..b42b9f9 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-harness.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include #include #include +#include namespace TestHarness { @@ -41,6 +42,20 @@ const char* basename(const char* path) return slash; } +void SuppressLogOutput() +{ + // Close stdout and stderr to suppress the log output + close(STDOUT_FILENO); // File descriptor number for stdout is 1 + close(STDERR_FILENO); // File descriptor number for stderr is 2 + + // The POSIX specification requires that /dev/null must be provided, + // The open function always chooses the lowest unused file descriptor + // It is sufficient for stdout to be writable. + open("/dev/null", O_WRONLY); // Redirect file descriptor number 1 (i.e. stdout) to /dev/null + // When stderr is opened it must be both readable and writable. + open("/dev/null", O_RDWR); // Redirect file descriptor number 2 (i.e. stderr) to /dev/null +} + int32_t RunTestCase( struct ::testcase_s& testCase ) { int32_t result = EXIT_STATUS_TESTCASE_FAILED; @@ -78,8 +93,7 @@ int32_t RunTestCaseInChildProcess( struct ::testcase_s& testCase, bool suppressO { if( suppressOutput ) { - close(STDOUT_FILENO); - close(STDERR_FILENO); + SuppressLogOutput(); } else { @@ -222,8 +236,7 @@ int32_t RunAllInParallel( const char* processName, ::testcase tc_array[], bool int32_t pid = fork(); if( pid == 0 ) // Child process { - close(STDOUT_FILENO); - close(STDERR_FILENO); + SuppressLogOutput(); exit( RunTestCase( tc_array[nextTestCase] ) ); } else if(pid == -1)