From patchwork Wed Jun 27 15:22:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 935569 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.cz 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 41G69d1XfLz9s2g for ; Thu, 28 Jun 2018 01:23:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 6DE851A95EF for ; Wed, 27 Jun 2018 17:22:58 +0200 (CEST) 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 1C40D3E60F2 for ; Wed, 27 Jun 2018 17:22:52 +0200 (CEST) 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 673341A0BC20 for ; Wed, 27 Jun 2018 17:22:51 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6B7AEAEEA; Wed, 27 Jun 2018 15:22:50 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Wed, 27 Jun 2018 17:22:16 +0200 Message-Id: <20180627152217.7067-1-chrubis@suse.cz> 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.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS 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 1/2 v2] tst_test: Fail the test subprocess cannot be killed 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" If there are any leftover children the main test process will likely be killed while sleeping in wait(). That is because all child processes are either waited explicitely by the test code or implicitly by the test library. We also send SIGKILL to the whole process group, so if one of the children continues to live for long enough that very likely means that it ended up stuck in the kernel. So if there are any processes left with in the process group we created once the process group leader i.e. main test process has been waited for we loop for a short while to give the init daemon chance to reap the process after it has been reparented and if that does not happen for a few seconds we declare the process to be stuck in the kernel. Signed-off-by: Cyril Hrubis CC: Eric Biggers --- lib/tst_test.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/tst_test.c b/lib/tst_test.c index 80808854e..329168a24 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015-2016 Cyril Hrubis + * Copyright (c) 2015-2018 Cyril Hrubis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1047,6 +1047,21 @@ static int fork_testrun(void) alarm(0); SAFE_SIGNAL(SIGINT, SIG_DFL); + unsigned int sleep = 100; + unsigned int retries = 0; + + while (kill(-test_pid, 0) == 0) { + + usleep(sleep); + sleep*=2; + + if (retries++ <= 14) + continue; + + tst_res(TFAIL, "Test process child stuck in the kernel!"); + tst_brk(TFAIL, "Congratulation, likely test hit a kernel bug."); + } + if (WIFEXITED(status) && WEXITSTATUS(status)) return WEXITSTATUS(status);