Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1695349lqm; Fri, 3 May 2024 03:59:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUgPpM9kn78Om3MSTJhctWbUFJ/CUvFk2n+H7pQX96kFxYP+ONOHooMSjAIuds024CKuhiolsNj0rQzhElVZFXInQGrlyM0IlEOb9Mm2w== X-Google-Smtp-Source: AGHT+IFj/vwZX3bGcjmQcmvp6ECMdVZ9a/G7f+L+pycrabpWOTgZjrE9gr3P9WscBdrPfVJJ15qy X-Received: by 2002:a50:a414:0:b0:572:2ce6:f71f with SMTP id u20-20020a50a414000000b005722ce6f71fmr2056186edb.5.1714733949925; Fri, 03 May 2024 03:59:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714733949; cv=pass; d=google.com; s=arc-20160816; b=lYhP5supAtlOmwAdPejBEsEL+LO6t6zCE9JoVHNxJD0a0rgKSOg815Qp2p/MVZa1jT U5BrS3DD9Woj292TANTQ9/gR6KlJw9U9VjE+708TctBP7Xw3QDjJWow/AJPTu1N0y/ia HDvaHVAFNag9QoK1QAoOpfzS8R2DYAdxSz9F/8Yd0SGl5Ekh9RtI4FOKAmX1N5WNjnxb A8oIilQ7BcWKHRQh7xOYwvZGdqWBlX53H/ytmbabczq/QjwOUW+0bkEbfplVKr8OgTIx Wd3XVR233nBM7f1HpwGQ5v93TnaFz6HecXFbt1hXwG1mOTj0sR73+QD65PE9/zt3INJt IN7Q== 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=xw+P2iuvsXkDrsEMtw3W5QsbaO6v3kX3+2OjbZ0CamU=; fh=pFOGWyS68KwrsEZD3Ll2e7y6RwSNe0VchkTs/n9iysY=; b=x2vrnlf+gEgUw3ZVkOXlAQpNb9rvJ9F+OCxrCYMOLOWXAPQJt/EVdb0u0HKJphJTL6 ABF7JahDUczbT9VmTtRJGSAiCKwEbtcmtlFBn2iDfVnZCvsBwScWAUBNNZ/9ARqhBP8T Gmqb5WcxarQWUbPWguVp86t3yPPaJ7hg4nlyMkOn5R+F3f+zgP+vV7B/br9OoDjVKqI4 yyGeqGpERYBeotVFYHXvUGVPiItbxs6hej7+Sla0+ofR+qpZAwTs74F7VTRmaMq8y6Kh fdEuZ/TWJyB3z9rk+SjCW/zCzs4QRqTZJ/e+nQbE8WzQcgiApjPx2bX05oWaPiwS9q4d DB6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=ge+KOMD9; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-167549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167549-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id s16-20020a056402165000b00572b0dc6fa7si1396271edx.15.2024.05.03.03.59.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 03:59:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=ge+KOMD9; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-167549-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167549-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 9BF6D1F21635 for ; Fri, 3 May 2024 10:59:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8A58152E1D; Fri, 3 May 2024 10:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="ge+KOMD9" Received: from smtp-190b.mail.infomaniak.ch (smtp-190b.mail.infomaniak.ch [185.125.25.11]) (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 E239B152161 for ; Fri, 3 May 2024 10:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.125.25.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714733918; cv=none; b=jINjM+9QW6MUK8pJf9TjlzJOWW6XeAknVGdttvA8DNBYnKp0p/tX29bBcykh2e6hPqb7xoIFpku41IoVE9suKEoQlE5Ct23QaK/x82pqWUUwDqBM3AJaA/r5e8EJA8rTcsdHtYzo+r8N0kCaRdOluhIdxn593feVNaiBTrC2U20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714733918; c=relaxed/simple; bh=6hZTX3iAyBV3GZyB7BttVc84qiexACw2w7pwZtyy8E0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uH2gsg+6yXSsuwRIob5iKkb68a5zJiGmnQlkW9uW79/rOxbo7cuQ75u//pb/PZPEVOw44yDo8jXkXFyWIsd+VlZkbIDdw8wjzLAOYf/RFFjVCE+Zo/Xj6RdBrkHiD4M4owkOauaCwQq3wR/rHkFP/lxbCd58cNV36+p53Y6rpNw= 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=ge+KOMD9; arc=none smtp.client-ip=185.125.25.11 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-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VW78B357zzCRx; Fri, 3 May 2024 12:58:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714733914; bh=6hZTX3iAyBV3GZyB7BttVc84qiexACw2w7pwZtyy8E0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ge+KOMD94hY6q2t3ZWm7Nkcn0gpq/ANNBk05Fa/4qSb5oMjcFMpa/jon4ytbH6V3k k5CrPeTx5PWDjBCihI4jsPoeUdpKu/0xqmFgSCZDskQaFn+sTTBknKWez/WYbSDIIX AKHKC5dA1MFlsCytbqu6XGeja24wMnkp/NeReDN4= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4VW7895WQcz116c; Fri, 3 May 2024 12:58:33 +0200 (CEST) From: =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= To: Christian Brauner , Jakub Kicinski , Kees Cook , Mark Brown , Sean Christopherson , 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 , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, netdev@vger.kernel.org, Shuah Khan Subject: [PATCH v5 03/10] selftests/harness: Fix fixture teardown Date: Fri, 3 May 2024 12:58:13 +0200 Message-ID: <20240503105820.300927-4-mic@digikod.net> In-Reply-To: <20240503105820.300927-1-mic@digikod.net> References: <20240503105820.300927-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/20240503105820.300927-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