Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1172014lqo; Sat, 11 May 2024 10:18:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKBQTf+kqwJ24zBO6qakM6KueDF7nw0ZldRcRRWhKbevmq1sa9RsbdjnOuX3E74C5tGaTgNgSabw+XMzyV+n1P9yXG2dBu/9TbzhQzOw== X-Google-Smtp-Source: AGHT+IEeXfGksL1ctkfSZMaVyVEQv5OZiQX43IIiwexGyENSsRHgOBELfW01P/nO0RlKDsQVU/rL X-Received: by 2002:a17:902:e84e:b0:1ec:b6e2:da89 with SMTP id d9443c01a7336-1ef440505b8mr78738735ad.61.1715447913135; Sat, 11 May 2024 10:18:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715447913; cv=pass; d=google.com; s=arc-20160816; b=uSYro/6GZ3XaPyxUeJ3gL4DGgYG1HAMwGyjfxg2XhS3jNe/YVRFPHR4wsRGIsdbQ9d bH+d+MRHlRapZJCV6T8kXT6nX/p8Fb3uaKG0DKi49XV0N3QjJB8ja3i3S/fiABaxXQFw 2vi5FhYaF2QblTlkms8KxzsGpUWE14buwd3f0UvKZQHenHcg3nm9Exx7NbfEAu+3rfOO yY3Gc5zZU4fwF82+SuZhfJBKq0XBmMJObrgWn/ftkZoykTauT5lWTXKlCQF6W30k9no9 xJi2IuDEAXA84WIqrQOOoh5AFyH4+w3yROvZz+BqvlbXSSXfSsLJcXPMI8G12uMjRZpa 6vbQ== 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=ItMTZYFsQr6hEmRCd+hw3M8K9T4Nec7f+7qfQcftklE=; fh=h2xHIZSGiUwuZyladnT9pE6uX086qy42ByZk41PjzSs=; b=KuCLz1RtJ41ah4YSeKYfYrgPfaNsGAfg+Prsw21wXf5V+ugdCCVV2aL4FkOGcg+l48 MlvaCAeI9GFQ3KnKOOvaIeebp9puHT6kpHIKtfFe3/9jJMekLfZizcBgFq2hm07jpEdy aWuUN9lrF3+XUyZGlleiJ9ugsJPH/iBpoiU13FDcc3S/91ygZVOS1z6FwN9ozHhHk/4E 87k6u+CA8F2RVXkvgMh8fSh/sQDcJqyedOhut9mpKvzjYEsEvsCDyZ0zKci4yv1UQ3v0 UDAYotJPVJVFarBoNdqL8MvvQSsWYgCbXMgWauhcq9h/nCN4CSxrxan/nLOS0w4p9rV/ OsRQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=yrDpfYn5; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-176661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176661-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c03901fsi56413325ad.361.2024.05.11.10.18.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 May 2024 10:18:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b=yrDpfYn5; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-176661-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176661-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 9EBFCB2107C for ; Sat, 11 May 2024 17:18:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id ACBCE6A347; Sat, 11 May 2024 17:15:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="yrDpfYn5" Received: from smtp-8fae.mail.infomaniak.ch (smtp-8fae.mail.infomaniak.ch [83.166.143.174]) (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 56FF057CAC for ; Sat, 11 May 2024 17:15:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.166.143.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715447710; cv=none; b=B1Ad3kOC4KjBU0pZTiS7581BCOhxjrkUOf82QkaIAqoQWlLPYGUE9vCp71rxPZiexgWfdaUKkieqrpNFCc9xGi1SomXuzu69nzmqpIJTYIZZrfFtA90P5aFDCjSGuI++kfEY1je8U5rvKMW2+RNdlXbdSVRGQUh6LBv5tc7zXBM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715447710; c=relaxed/simple; bh=6guh9BQ5rVONa/bVyJCE/mpvREYMTA6JDcfQf6vaLP4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o2szeoKSAqkt+w7HjhcQCxF+0vvzEBiEfDMsGguyh1NczCCfoXVWj5tm2sAhrl7l6lAtM5RwHMjIVt7GEKIAOw6sjP1SfP4dm/NEWZYnZx9Z24NGnizJmKEqQ2rBTyljfL1fuEZ7xzdZlYCgMg8+ARZfJEeaLeAOFma/RPZacFA= 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=yrDpfYn5; arc=none smtp.client-ip=83.166.143.174 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-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4VcC6s2hVRzlMR; Sat, 11 May 2024 19:15:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1715447701; bh=ItMTZYFsQr6hEmRCd+hw3M8K9T4Nec7f+7qfQcftklE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yrDpfYn5sBSTPp2UkPB4Uhtvy93ocHWXxkXIgH5aOxQpuhJhFd4X3Yk0NksyC6VeV bQBRZN2nlNnP6Yie9El0d0KYRTBkqtH47MhExd9rLSiBGE4ON9C7JgmB1zNeRR+zFV hEtC9AWfiMligrgX+qFyIi2DtUvYY20tndoaIPVw= Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4VcC6r58Z8z9Rg; Sat, 11 May 2024 19:15:00 +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 08/10] selftests/harness: Share _metadata between forked processes Date: Sat, 11 May 2024 19:14:43 +0200 Message-ID: <20240511171445.904356-9-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 Unconditionally share _metadata between all forked processes, which enables to actually catch errors which were previously ignored. This is required for a following commit replacing vfork() with clone3() and CLONE_VFORK (i.e. not sharing the full memory) . It should also be useful to share _metadata to extend expectations to test process's forks. For instance, this change identified a wrong expectation in pidfd_setns_test. Because this _metadata is used by the new XFAIL_ADD(), use a global pointer initialized in TEST_F(). This is OK because only XFAIL_ADD() use it, and XFAIL_ADD() already depends on TEST_F(). Cc: Jakub Kicinski Cc: Shuah Khan Cc: Will Drewry Reviewed-by: Kees Cook Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240511171445.904356-9-mic@digikod.net --- Changes since v6: * Use a global pointer per TEST_F() and complete build of the __test_xfail object in the xfail constructor to fix XFAIL_ADD(): https://lore.kernel.org/r/202405100339.vfBe0t9C-lkp@intel.com/ Changes since v4: * Reset _metadata's aborted and setup_completed fields. Changes since v1: * Extract change from a bigger patch (suggested by Kees). --- tools/testing/selftests/kselftest_harness.h | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index 201040207c85..28415798fa60 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -430,19 +430,19 @@ static inline pid_t clone3_vfork(void) kill(getpid(), WTERMSIG(status)); \ __test_check_assert(_metadata); \ } \ - static struct __test_metadata \ - _##fixture_name##_##test_name##_object = { \ - .name = #test_name, \ - .fn = &wrapper_##fixture_name##_##test_name, \ - .fixture = &_##fixture_name##_fixture_object, \ - .termsig = signal, \ - .timeout = tmout, \ - .teardown_parent = false, \ - }; \ + static struct __test_metadata *_##fixture_name##_##test_name##_object; \ static void __attribute__((constructor)) \ _register_##fixture_name##_##test_name(void) \ { \ - __register_test(&_##fixture_name##_##test_name##_object); \ + struct __test_metadata *object = mmap(NULL, sizeof(*object), \ + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); \ + object->name = #test_name; \ + object->fn = &wrapper_##fixture_name##_##test_name; \ + object->fixture = &_##fixture_name##_fixture_object; \ + object->termsig = signal; \ + object->timeout = tmout; \ + _##fixture_name##_##test_name##_object = object; \ + __register_test(object); \ } \ static void fixture_name##_##test_name( \ struct __test_metadata __attribute__((unused)) *_metadata, \ @@ -850,11 +850,12 @@ struct __test_xfail { { \ .fixture = &_##fixture_name##_fixture_object, \ .variant = &_##fixture_name##_##variant_name##_object, \ - .test = &_##fixture_name##_##test_name##_object, \ }; \ static void __attribute__((constructor)) \ _register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \ { \ + _##fixture_name##_##variant_name##_##test_name##_xfail.test = \ + _##fixture_name##_##test_name##_object; \ __register_xfail(&_##fixture_name##_##variant_name##_##test_name##_xfail); \ } @@ -1181,6 +1182,9 @@ void __run_test(struct __fixture_metadata *f, /* reset test struct */ t->exit_code = KSFT_PASS; t->trigger = 0; + t->aborted = false; + t->setup_completed = false; + memset(t->env, 0, sizeof(t->env)); memset(t->results->reason, 0, sizeof(t->results->reason)); if (asprintf(&test_name, "%s%s%s.%s", f->name, -- 2.45.0