From patchwork Thu May 2 21:09:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= X-Patchwork-Id: 13652089 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 00E1418133D for ; Thu, 2 May 2024 21:09:53 +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=1714684196; cv=none; b=PxTNC1vj6nin1hzeGV/f4hVMu4gxgvT7dgh1s8wltnHOvr+okKwGdxlk/UQW8X4QQKvaEs0mI+f56buufpf7gRAiI2FplytSGXarSfNLor7WUzY7uhmp9wSpWwgYTr9BvVLdM2Izbb8PfVSRFMeDLjpWhhkRjLUfpNNwNgxk1r4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714684196; c=relaxed/simple; bh=KqEsjBjuhpsjwrbJBGS/A9dvVAlJ3/nK7tVCR3svPG8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LT2kUeW0YJLffbSqzis8SpLnzoCK38IQfFnrUsgP3670IAYPjJ7B6hxXiB+6CfYKJqY2orStfJQPujPg66WaR85J8lfSqu73DBzS1rNAg4rZBpQuO72JYpDPEMBJ+Ly7zW8eaB1S+DqIwICy84gUg6NhTz6eEhMOHpqi3meTrXY= 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=Y6QJwMwP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="Y6QJwMwP" 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 4VVmm03jwczL5X; Thu, 2 May 2024 23:09:52 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1714684192; bh=KqEsjBjuhpsjwrbJBGS/A9dvVAlJ3/nK7tVCR3svPG8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y6QJwMwPh4Vk1yiDX75N9NqUtxGjQbcqVDnJJwMC+pksry1GXyClOGQ3GYzXMUgZO HgLgI1GKJocjJZMQo+kHGoQzfFTMTkDLfiAqNYUgFcIeKUQaZgU7TW8RfojFaD2C32 8h9VOq5brlKrfatEcHyD+/ITP9JwPb9ac502cs2c= Received: from unknown by smtp-3-0001.mail.infomaniak.ch (Postfix) with ESMTPA id 4VVmlz3TX3zqTH; Thu, 2 May 2024 23:09:51 +0200 (CEST) From: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= To: Christian Brauner , Jakub Kicinski , Kees Cook , Mark Brown , Sean Christopherson , Shengyu Li , Shuah Khan Cc: =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , "David S . Miller" , =?utf-8?q?G=C3=BCnther_Noack?= , Will Drewry , kernel test robot , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v4 10/10] selftests/harness: Fix TEST_F()'s exit codes Date: Thu, 2 May 2024 23:09:26 +0200 Message-ID: <20240502210926.145539-11-mic@digikod.net> In-Reply-To: <20240502210926.145539-1-mic@digikod.net> References: <20240502210926.145539-1-mic@digikod.net> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Infomaniak-Routing: alpha Always forward grandchild's exit codes to its parent. This fixes KVM_ONE_VCPU_TEST(). Initial patch written by Sean Christopherson [1]. Cc: Jakub Kicinski Cc: Kees Cook Cc: Mark Brown Cc: Sean Christopherson Cc: Shuah Khan Cc: Will Drewry Link: https://lore.kernel.org/r/ZjPelW6-AbtYvslu@google.com [1] Fixes: 0710a1a73fb4 ("selftests/harness: Merge TEST_F_FORK() into TEST_F()") Signed-off-by: Mickaël Salaün Link: https://lore.kernel.org/r/20240502210926.145539-11-mic@digikod.net --- Changes since v3: * New patch mainly from Sean Christopherson. --- tools/testing/selftests/kselftest_harness.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h index d3837a3a584e..77d4fac8d0c0 100644 --- a/tools/testing/selftests/kselftest_harness.h +++ b/tools/testing/selftests/kselftest_harness.h @@ -442,7 +442,7 @@ static inline pid_t clone3_vfork(void) fixture_name##_setup(_metadata, self, variant->data); \ /* Let setup failure terminate early. */ \ if (_metadata->exit_code) \ - _exit(0); \ + _exit(_metadata->exit_code); \ _metadata->setup_completed = true; \ fixture_name##_##test_name(_metadata, self, variant->data); \ } else if (child < 0 || child != waitpid(child, &status, 0)) { \ @@ -454,7 +454,7 @@ static inline pid_t clone3_vfork(void) if (_metadata->setup_completed && !fixture_name##_teardown_parent && \ __sync_bool_compare_and_swap(teardown, false, true)) \ fixture_name##_teardown(_metadata, self, variant->data); \ - _exit(0); \ + _exit(_metadata->exit_code); \ } \ if (_metadata->setup_completed && fixture_name##_teardown_parent && \ __sync_bool_compare_and_swap(teardown, false, true)) \ @@ -462,8 +462,10 @@ static inline pid_t clone3_vfork(void) munmap(teardown, sizeof(*teardown)); \ if (self && fixture_name##_teardown_parent) \ munmap(self, sizeof(*self)); \ - if (!WIFEXITED(status) && WIFSIGNALED(status)) \ - /* Forward signal to __wait_for_test(). */ \ + /* Forward exit codes and signals to __wait_for_test(). */ \ + if (WIFEXITED(status)) \ + _exit(_metadata->exit_code); \ + if (WIFSIGNALED(status)) \ kill(getpid(), WTERMSIG(status)); \ __test_check_assert(_metadata); \ } \