Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1171725lqo; Sat, 11 May 2024 10:17:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXyhMIisIUVj4PrA+skrxMUv2Ba3hjtcBv0zvyavJu6/ILoEwMzMBaBYb2L7HrT8k2fu3PiU9YFN+pTNsPtnlpgu6lkD9uGCgWDYG1pCg== X-Google-Smtp-Source: AGHT+IGkR+yfo3WyX5fO8GwdB+FdVJ0vSu6pfk4jD7Q6QDHrc2CIeFGSeLHp6zsVaTaz5r3G9+bH X-Received: by 2002:a05:620a:c4e:b0:792:d2aa:5e6 with SMTP id af79cd13be357-792d2aa0723mr156660285a.35.1715447855280; Sat, 11 May 2024 10:17:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715447855; cv=pass; d=google.com; s=arc-20160816; b=HZbFvWvDbxrAvilzi0T1s/UXtyEtC12NBMiPixYu5YHHipWhDM2BdFEaMMJsSbhKwc K9B+EkJvZ3HcxHOCQtcbuSWMtDDLQJTNQ/ctu5y/o8tRHszHYbBPdP6cRe1ErduJI5lc aO0Ea10oMrvCunBko9Pieu/z6wKIbOPooFJuqYBbJ5wORUnmVuzAgfUd14YBTHFJpPOW IhxYlCHUpD8ntl3aa41mju7csAcW6BK7EfUwV9IBUUiKxf4sZh8TfnjKJRad8siPrKvo R++aKYeeLcv14wARLS/oc9nMumxizNKEDEXtIUS/3T+OaSaxjWsbYPYuDcj3ltFtnNp3 dy/A== 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=ovB5ZrUNiKpOgIZ9ljhUcoeHZ3JuOZ6b7Y35bC/s7JE=; fh=h2xHIZSGiUwuZyladnT9pE6uX086qy42ByZk41PjzSs=; b=RlYMh1Fm8pa0F53w2otzP8VsoZzxtRd/OVh9m062Saymr09WXJiBFiGZxROlwAy3Rc 8tylZhkT7gX2a1xh39d0qRph1nWOgEW/RVLcCtTj5fB36+YFVZgANgT1nQieWLjeID/Q JVatDYfc+fTRhEdPV+znCP6+UdNNA4b4mwIUzEu7CMqPkcv6ue1w8aVeAyzCnreHw/Wv SIolZMCd1/2iqrzy7gW6cSlBIlan2bVS2cAr9k3QvSj4NtiifWBPtJ3KyLD753HIeC8M D60DwGpbYPt7ojAgplYB0TxGXbLPinhl2iq+TQgnr2qGEWGb2GdyB7U9ims8f9WGK3ks C5ag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=zzg1J08H; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-176658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176658-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-792bf361fd5si653448985a.544.2024.05.11.10.17.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 10:17:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=zzg1J08H; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-176658-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176658-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 072811C2061D for ; Sat, 11 May 2024 17:17:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 124B65DF3B; Sat, 11 May 2024 17:15:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="zzg1J08H" Received: from smtp-8faf.mail.infomaniak.ch (smtp-8faf.mail.infomaniak.ch [83.166.143.175]) (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 C54BE1BDCF for ; Sat, 11 May 2024 17:15:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715447706; cv=none; b=aJj+f//fc1KfmnlJ7U3mG110AlwvThYErhFZtajeR5JLMjaYBO3K8hMnrkipDab8oiVGP7N8eSA196NvVcGpTTBnzEfSG+JNSyDWUekSPE8Pwx+EySfNhdnRyWQmZylzIlRh39LxQustVOwPukxVrXYHEbUBM8CHv0rzGzOryus= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715447706; c=relaxed/simple; bh=L4IsWOpcTXy4CQxpW7VBofOeFKJ+1/rKXTe7cKJk2T8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h02x+vmsh1sPBlwmYLa80W4BlMhY1THFZTP9jfCStdhRaE7p18zCQeRNsRGv/d7mqSCa4cFFXguY+iiUr1/l1r+PEk0J2+OZnK7TW6cgW0lB2B/3U/FF7hzYfFi9DQKGIp4rGTgZJdw8+pxWPXUBfblfOQ5TuUI7s8QDgKDfnsY= 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=zzg1J08H; arc=none smtp.client-ip=83.166.143.175 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-4-0000.mail.infomaniak.ch (smtp-4-0000.mail.infomaniak.ch [10.7.10.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VcC6k748TzlcQ; Sat, 11 May 2024 19:14:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1715447694; bh=ovB5ZrUNiKpOgIZ9ljhUcoeHZ3JuOZ6b7Y35bC/s7JE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zzg1J08HVY4Clr7+T2zqOEXkqP83FppvqtcgRIphdHv4ZeuhKFEi4DoYzf5K9T0ZL BHlkwEGvnjOT7UPbTRgNeig8fKvEF+TNE6Q1DzsxPgltGagqzzcwmA1hJGeNrspKgO nkL3vLu3vj6471+vjxEEN95YC+zr/2HII1nUlk6Y= Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VcC6k1FQNzSJy; Sat, 11 May 2024 19:14:54 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Christian Brauner , Greg Kroah-Hartman , Jakub Kicinski , Kees Cook , Linus Torvalds , Mark Brown , Sasha Levin , Sean Christopherson , Shengyu Li , Shuah Khan , Shuah Khan Cc: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Bagas Sanjaya , Brendan Higgins , David Gow , "David S . Miller" , Florian Fainelli , =?UTF-8?q?G=C3=BCnther=20Noack?= , Jon Hunter , Ron Economos , Ronald Warsow , Stephen Rothwell , Will Drewry , kernel test robot , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH v7 03/10] selftests/harness: Fix fixture teardown Date: Sat, 11 May 2024 19:14:38 +0200 Message-ID: <20240511171445.904356-4-mic@digikod.net> In-Reply-To: <20240511171445.904356-1-mic@digikod.net> References: <20240511171445.904356-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: Jakub Kicinski Cc: Shengyu Li Cc: Shuah Khan Fixes: 72d7cb5c190b ("selftests/harness: Prevent infinite loop due to Assert in FIXTURE_TEARDOWN") Fixes: 0710a1a73fb4 ("selftests/harness: Merge TEST_F_FORK() into TEST_F()") Reviewed-by: Kees Cook Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240511171445.904356-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 d98702b6955d..55699a762c45 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -382,7 +382,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. */ \ @@ -399,15 +402,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.45.0