Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp19358lqh; Mon, 6 May 2024 09:56:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOg76XduX3sj4/E8pLj4DeLjPajCfFevMa+PUP9PthqkFEsfO+zfx+TfJ6ni/GbU0ffyK7HuKLQSBmJEbc+KXD6JCvnOxY5M5Kh1ysuQ== X-Google-Smtp-Source: AGHT+IGFa8a/veXmeZiTId4LAHwcl0t/osXGFwABIMzL6avLQvjv6k9Ebz7IIpP1Bj7/zAsVPSXo X-Received: by 2002:a17:903:2985:b0:1e3:999a:9726 with SMTP id lm5-20020a170903298500b001e3999a9726mr13823185plb.29.1715014608890; Mon, 06 May 2024 09:56:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715014608; cv=pass; d=google.com; s=arc-20160816; b=MZUgNAsX/YxwWBikIdLlqYB/4hZBY33+lX2QBpYlovw/vrBJ8umrw1eDPhsoCJRGdI Y2iK7en9t4e3+6AibObzPIoTsaaYpfSM1GzFd8XFsYa9xH8dKaPZOIjc01JMttxgNpc0 RLGbRvOUHRqHAshm0892kbwA6xa2aBkUm5Fo8mkRTg3d4l1czDQXPlX085ogi6RzcjGC SFaOkjw8d8COLEb7/FcbC+57smV8rxZ2lZAuR33wMho/Z1L+q21thghNk1EQdIphEk2j i8zhpSlKBbUFzD/ZngvADmtfhoVjzKG47hEQLZqQFNddoHXD1q0sN8A4Sc8BgiEknMLL IzzQ== 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=UxRe/C98vho2w0FgyMujx+wUXucr1FSYiVy43znZMK4=; fh=h2xHIZSGiUwuZyladnT9pE6uX086qy42ByZk41PjzSs=; b=KpPMhig3dGfMkgGNNYFK2Y/4htwGRLYsbE2UmXd2EkDfdCP/ZFJeIp4aRIiDI0Lm/7 PrUNxMx2Kn7uK0dy+5LO4CgVR0zkP0khgQdUkgukSCNLPJviV7GgHaoYoTBGa2PguAmR Yl6P74Rc+YbSjQy4SWi0ZbUMp0C1cCmVltK7wyirhkSxtOm/UBSJrPay4kEhsvEwqcuT nN4ACO1sptwzkL8YNafrEQwXNqZilOsXD1vRpI2gbfYyPmZ1vRHJ2UzWeeXSKLdAd/Is xfkeWZoFdJqW6X9NlgmdndisfwPI+5SPj3g2oVKnWxoVToZECrV3PZ/WtAvFaFW2sJcJ FZAg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="1DU1kfR/"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-170197-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170197-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q8-20020a170902bd8800b001eb0daf403csi8327533pls.237.2024.05.06.09.56.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 09:56:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170197-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="1DU1kfR/"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-170197-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170197-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5EA28B213CF for ; Mon, 6 May 2024 16:55:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F5A015746E; Mon, 6 May 2024 16:55:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="1DU1kfR/" Received: from smtp-bc0a.mail.infomaniak.ch (smtp-bc0a.mail.infomaniak.ch [45.157.188.10]) (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 E5E71156F36 for ; Mon, 6 May 2024 16:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.157.188.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715014530; cv=none; b=DCsyXM5Whs+wYC6yJTH7h1oYjc5DT85chhb2+rYddf3LNCdc+GR2JyK1VayseEfpGNm0P/zrAgd+cZsHtlnL/uckMdJhr/oUxyAb4Wu35H3yJD6sxjotd6WjTDm3tLjlCBP7j03CRAitOd3B2jppc8kTu1a1UubQiTFrZbpJHQY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715014530; c=relaxed/simple; bh=gdjWab4WlvmPrqP7rpboralxnLabzwMWE9avaczrXTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=s51vwktVdclB/lqB1ivT1UeGVb6W+vmLoHV4IPPpOq+Ob9Pr8EWnSHLub2w7jTWElRvj3m7zbumA5CWleLq/RZXnTPA9W5dJzqlWOoQZYdX+Gu8JN0phRXL9UNJEEmtV4i3kgY9SWaIn+5di8p5fCp89HpPYXIndjgSytWfBH6E= 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=1DU1kfR/; arc=none smtp.client-ip=45.157.188.10 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-0001.mail.infomaniak.ch (smtp-3-0001.mail.infomaniak.ch [10.4.36.108]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VY6wb0X4wzvhq; Mon, 6 May 2024 18:55:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1715014526; bh=gdjWab4WlvmPrqP7rpboralxnLabzwMWE9avaczrXTs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1DU1kfR/sXMZBLxgai2/BDVVqEj7PiizKYVxllSOUMXty7lPe28fR1havdD00J/mF Tw3fJ33J2L27vmFtr8p+G+TP2A2C4w54AyunZtTumG1czFOHP4W1vuYiWa4xDPC2Gs FnMZL20Cu11fLKacx/pUC06XfR6A2LdDjR1F6FGs= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4VY6wZ1vl8zvSl; Mon, 6 May 2024 18:55:26 +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 v6 03/10] selftests/harness: Fix fixture teardown Date: Mon, 6 May 2024 18:55:11 +0200 Message-ID: <20240506165518.474504-4-mic@digikod.net> In-Reply-To: <20240506165518.474504-1-mic@digikod.net> References: <20240506165518.474504-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/20240506165518.474504-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