Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp127062lqg; Fri, 26 Apr 2024 10:30:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX1rOyRxMhmppys4VgTWNP6V7lKoDsbyQeC2M/UnDDzz61qEJKgXSCjzFnjATNG/Kah9cszoESjD5zsLUai1uXIUCpkXvCmqhDKc7gFRw== X-Google-Smtp-Source: AGHT+IEkTyF6NAcGdb3gjbnY9TsG8R8vBYL7qtY9LqTWM9NqVG5ZQ/t4fAvxhMIcgTthUVY93l4F X-Received: by 2002:a05:6a20:7351:b0:1a3:dc61:926a with SMTP id v17-20020a056a20735100b001a3dc61926amr279288pzc.54.1714152608067; Fri, 26 Apr 2024 10:30:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714152608; cv=pass; d=google.com; s=arc-20160816; b=mCXH/wHJtlreeSm8dFV8Uhdq5UOSgZziIpfLFiK6wxTzLmrjMS6rEfSssFdZO7ov0W ILSQJ5Urrbx8+dWjOHWC5Fb7AGq+aPJcvM84bU9Q4SbA7JDOJ0x25bPfeneXaFLOp4v2 fJ/Mf94ATFzORscFZHRCR+A+NPN7/KfF65Etk2SKPAyYoflix2LdDi9eXaybxvkYhLhp 7qDB4bzoVTeRaLs8Ure1ptdJNqm6tYZ7w1+Rq0holJ/8OghI1tVbXUp4i54J2uOprer4 ucv1kUcLSEeDnaNqbdZTyNGBhimNLcmDBIqfSf5Gt2AXFfXt/OyrFrrJr/e0yO3Rpmen opQA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GdmQ38iPWCvq0OGnCPLAADhaaAPU5D4AyZc0+nhNlnM=; fh=T/ngxZ/rchirObc+ozpAMGxUCKvTk1uHXxRS2gfk1OI=; b=W6ICda+Axhl1L1rKm95xDU1GWXcVNCXoit1l3N0mhItsJzE2utbcLEN8HKpXhL17c9 Jiq5hPZygOkf0JLFmmzKTIrHvk3enJ/YGt/Qjx1Umuo7MC+vCuwjTl9S+ubhBWhpXGi3 GTQAGDmpTJmp4a1a3eGxQyog9ToFfajCgeIaydIQNXafSglrpZDWEQXE72gRSRLoqfKx gvX01HUP9rrmZXw4lSkbQmYJZi34O0c/KsVE96B4+OLYNDhr7T0lz/FfYbAkP4TW5J5S Jto/Cw2holNlZtvm/1cTpPxRba+nQB+rhs7hCpbqU2wjnvH7tWPj1I9qNGEhYilYGH5F DFaA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=pbmiykND; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-160483-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160483-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m67-20020a633f46000000b005f7fd775d79si13997072pga.229.2024.04.26.10.30.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 10:30:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160483-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=pbmiykND; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-160483-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160483-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 4DA12281DC2 for ; Fri, 26 Apr 2024 17:29:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47F2A180A79; Fri, 26 Apr 2024 17:23:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="pbmiykND" Received: from smtp-42a9.mail.infomaniak.ch (smtp-42a9.mail.infomaniak.ch [84.16.66.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA22D17107F for ; Fri, 26 Apr 2024 17:23:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714152199; cv=none; b=IROvhZmn+Knx5ed6H0Gt43iFgJASpmOc+OpMGRmv1j09DlcI97VOQRPjPURIAnWHLLrZSrzqQhCb6SGfFiLHypc2GVnbJLAcsLHdcaBmVUQeS5XbvGADFz4+nXp9DlKhdxA4C6H0enzMh7qqkTdlinphBSAFb01xHtNLRoLF1xk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714152199; c=relaxed/simple; bh=gwbWMnpY1+lUZlBeZaHSY89u6ODnUz6pnZkGqVpTNCo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=e/PayhQ1jOaWIVPU9Zxl0vrQKMFMspK25RsccITXhmojlz9JKqYeCVTsWwo7n42v3sSI68L2gyy2QmqcQKuRlRcDAy2DQVQi/sXrr158xgWPKR2AuFuYcv2cP7J6J4thfPekJSF49LF9qgp9W7sLfweVPBzYeXQrgrPG8V9Zh3A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=pbmiykND; arc=none smtp.client-ip=84.16.66.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Received: from smtp-3-0000.mail.infomaniak.ch (smtp-3-0000.mail.infomaniak.ch [10.4.36.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VR0172sVxz18Db; Fri, 26 Apr 2024 19:23:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714152187; bh=gwbWMnpY1+lUZlBeZaHSY89u6ODnUz6pnZkGqVpTNCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pbmiykND1AXRM5ZnVIIoaeUJ3Y14bvSN/SpP9EDXo5SCljXDDre058h2CAigBkjzV nWHU9jZuZDz/DvGthgLXzE16Wr267NN2Nzc0uN8zynUeFZa7rcTzQHTO0AtRlfMycf niblLrY9T1avT16y4yT0PlcIy4K/aUyrlLxMnx3I= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VR0166Ygpzgq1; Fri, 26 Apr 2024 19:23:06 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Christian Brauner , Jakub Kicinski , Kees Cook , Mark Brown , Shengyu Li , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , "David S . Miller" , =?UTF-8?q?G=C3=BCnther=20Noack?= , Will Drewry , kernel test robot , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Shuah Khan Subject: [PATCH v1 3/5] selftests/harness: Fix fixture teardown Date: Fri, 26 Apr 2024 19:22:50 +0200 Message-ID: <20240426172252.1862930-4-mic@digikod.net> In-Reply-To: <20240426172252.1862930-1-mic@digikod.net> References: <20240426172252.1862930-1-mic@digikod.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Infomaniak-Routing: alpha Make sure fixture teardowns are run when test cases failed, including when _metadata->teardown_parent is set to true. Make sure only one fixture teardown is run per test case, handling the case where the test child forks. Cc: Shuah Khan Cc: Shengyu Li Fixes: 72d7cb5c190b ("selftests/harness: Prevent infinite loop due to Assert in FIXTURE_TEARDOWN") Fixes: 0710a1a73fb4 ("selftests/harness: Merge TEST_F_FORK() into TEST_F()") Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240426172252.1862930-4-mic@digikod.net --- tools/testing/selftests/kselftest_harness.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index ba3ddeda24bf..73491efbae9e 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -383,7 +383,10 @@ FIXTURE_DATA(fixture_name) self; \ pid_t child = 1; \ int status = 0; \ - bool jmp = false; \ + /* Makes sure there is only one teardown, even when child forks again. */ \ + bool *teardown = mmap(NULL, sizeof(*teardown), \ + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); \ + *teardown = false; \ memset(&self, 0, sizeof(FIXTURE_DATA(fixture_name))); \ if (setjmp(_metadata->env) == 0) { \ /* Use the same _metadata. */ \ @@ -400,15 +403,16 @@ _metadata->exit_code = KSFT_FAIL; \ } \ } \ - else \ - jmp = true; \ if (child == 0) { \ - if (_metadata->setup_completed && !_metadata->teardown_parent && !jmp) \ + if (_metadata->setup_completed && !_metadata->teardown_parent && \ + __sync_bool_compare_and_swap(teardown, false, true)) \ fixture_name##_teardown(_metadata, &self, variant->data); \ _exit(0); \ } \ - if (_metadata->setup_completed && _metadata->teardown_parent) \ + if (_metadata->setup_completed && _metadata->teardown_parent && \ + __sync_bool_compare_and_swap(teardown, false, true)) \ fixture_name##_teardown(_metadata, &self, variant->data); \ + munmap(teardown, sizeof(*teardown)); \ if (!WIFEXITED(status) && WIFSIGNALED(status)) \ /* Forward signal to __wait_for_test(). */ \ kill(getpid(), WTERMSIG(status)); \ -- 2.44.0