From patchwork Fri Mar 9 09:26:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Moese X-Patchwork-Id: 883528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zyMTw72KZz9sbB for ; Fri, 9 Mar 2018 20:27:16 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 898AC3E751D for ; Fri, 9 Mar 2018 10:27:14 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id 753803E74F0 for ; Fri, 9 Mar 2018 10:27:12 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 8F1151A00F50 for ; Fri, 9 Mar 2018 10:27:05 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1AC75ABE4 for ; Fri, 9 Mar 2018 09:27:04 +0000 (UTC) From: Michael Moese To: ltp@lists.linux.it Date: Fri, 9 Mar 2018 10:26:59 +0100 Message-Id: <20180309092701.8161-1-mmoese@suse.de> X-Mailer: git-send-email 2.13.6 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS, T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/3] Add tst_flush() library function X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Add a library function to flush stderr and stdout streams: void tst_flush(void) This function flushes stderr and stdout streams. In case of an error, the test is aborted with TBROK and an error message is printed. Signed-off-by: Michael Moese --- doc/test-writing-guidelines.txt | 8 ++++++++ include/tst_test.h | 3 +++ lib/tst_test.c | 15 +++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt index 739b295b8..4c60cd66b 100644 --- a/doc/test-writing-guidelines.txt +++ b/doc/test-writing-guidelines.txt @@ -465,6 +465,14 @@ Allows for setting timeout per test iteration dymanically in the test setup(), the timeout is specified in seconds. There are a few testcases whose runtime can vary arbitrarily, these can disable timeouts by setting it to -1. +[source,c] +------------------------------------------------------------------------------ +void tst_flush(void); +------------------------------------------------------------------------------- + +Flush stderr and stdout streams, handling errors appropriately. +You should not use fflush() for stderr or stdout. + 2.2.3 Test temporary directory ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/include/tst_test.h b/include/tst_test.h index af97b8983..54ff306d9 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -70,6 +70,9 @@ void tst_brk_(const char *file, const int lineno, int ttype, #define tst_brk(ttype, arg_fmt, ...) \ tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__) +/* flush stderr and stdout */ +void tst_flush(void); + pid_t safe_fork(const char *filename, unsigned int lineno); #define SAFE_FORK() \ safe_fork(__FILE__, __LINE__) diff --git a/lib/tst_test.c b/lib/tst_test.c index 2cf35ed66..9b4f43828 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -1085,3 +1085,18 @@ void tst_run_tcases(int argc, char *argv[], struct tst_test *self) do_exit(ret); } + + +void tst_flush(void) +{ + int rval; + + rval = fflush(stderr); + if (rval != 0) + tst_brk(TBROK | TERRNO, "fflush(stderr) failed"); + + rval = fflush(stderr); + if (rval != 0) + tst_brk(TBROK | TERRNO, "fflush(stdout) failed"); + +} From patchwork Fri Mar 9 09:27:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Moese X-Patchwork-Id: 883526 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zyMTq489pz9sZD for ; Fri, 9 Mar 2018 20:27:11 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 107423E7499 for ; Fri, 9 Mar 2018 10:27:08 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id A647A3E6DE7 for ; Fri, 9 Mar 2018 10:27:06 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 92C3814060B5 for ; Fri, 9 Mar 2018 10:27:05 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 41F68AC6A for ; Fri, 9 Mar 2018 09:27:05 +0000 (UTC) From: Michael Moese To: ltp@lists.linux.it Date: Fri, 9 Mar 2018 10:27:00 +0100 Message-Id: <20180309092701.8161-2-mmoese@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180309092701.8161-1-mmoese@suse.de> References: <20180309092701.8161-1-mmoese@suse.de> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS, T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/3] remove old tst_flush() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The old tst_flush() was renamed to tst_old_flush(), and tst_flush() was removed from tstapicmd.c. The new tst_flush() has the same prototype as the old one, so any test using it should still be fine. Signed-off-by: Michael Moese --- lib/tst_res.c | 2 +- tools/apicmds/ltpapicmd.c | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/tst_res.c b/lib/tst_res.c index b56f37db0..9c88b2923 100644 --- a/lib/tst_res.c +++ b/lib/tst_res.c @@ -245,7 +245,7 @@ static void tst_condense(int tnum, int ttype, const char *tmesg) Buffered = TRUE; } -void tst_flush(void) +void tst_old_flush(void) { NO_NEWLIB_ASSERT("Unknown", 0); diff --git a/tools/apicmds/ltpapicmd.c b/tools/apicmds/ltpapicmd.c index 9ad68b589..4b66c4226 100644 --- a/tools/apicmds/ltpapicmd.c +++ b/tools/apicmds/ltpapicmd.c @@ -34,8 +34,6 @@ * break remaining test cases * tst_res - Print result message, including file contents * tst_resm - Print result message - * tst_flush - Print any messages pending because of CONDENSE mode, - * and flush output stream * tst_exit - Exit test with a meaningful exit value * * These are the minimum set of functions or commands required to @@ -332,8 +330,6 @@ int main(int argc, char *argv[]) apicmd_resm(argc, argv); } else if (strcmp(cmd_name, "tst_exit") == 0) { tst_exit(); - } else if (strcmp(cmd_name, "tst_flush") == 0) { - tst_flush(); } else if (strcmp(cmd_name, "tst_ncpus") == 0) { printf("%li\n", tst_ncpus()); } else if (strcmp(cmd_name, "tst_ncpus_conf") == 0) { From patchwork Fri Mar 9 09:27:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Moese X-Patchwork-Id: 883527 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zyMTt0my1z9sZq for ; Fri, 9 Mar 2018 20:27:13 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D75113E7561 for ; Fri, 9 Mar 2018 10:27:10 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 97B363E6DE7 for ; Fri, 9 Mar 2018 10:27:07 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 4F0841A0122A for ; Fri, 9 Mar 2018 10:27:06 +0100 (CET) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E6C0EAE70 for ; Fri, 9 Mar 2018 09:27:05 +0000 (UTC) From: Michael Moese To: ltp@lists.linux.it Date: Fri, 9 Mar 2018 10:27:01 +0100 Message-Id: <20180309092701.8161-3-mmoese@suse.de> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180309092701.8161-1-mmoese@suse.de> References: <20180309092701.8161-1-mmoese@suse.de> X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_PASS, T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/3] safe_fork() should use tst_flush() instead of fflush() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" safe_fork() should not use fflush(stdout). This commit makes use of the the newly added tst_flush(), which flushes, in fact, both stdout and stderr. In addition, tests output their results to stderr, so flushing stdout here is simply wrong. Signed-off-by: Michael Moese --- lib/tst_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tst_test.c b/lib/tst_test.c index 9b4f43828..7069bbc5e 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -380,7 +380,7 @@ pid_t safe_fork(const char *filename, unsigned int lineno) if (!tst_test->forks_child) tst_brk(TBROK, "test.forks_child must be set!"); - fflush(stdout); + tst_flush(); pid = fork(); if (pid < 0)