From nobody Fri Dec 19 13:10:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6B58317C21B; Thu, 22 May 2025 17:39:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935556; cv=none; b=jrLgfnnMzRK/mffelMxr6B8FcQdgdBtMrIZ6ICS0gRg6GSDsM5GGp6DqBuwKf0kTbdzeyhUIvjI8npLS5SuGVjxPbPk+4mK1k/BSWhG5ktJRsqvdwU8aSghtB1Hv6npgeanz0shoXxMw+rKp+c8iv96gQXTOpeS6uecylBa6NT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935556; c=relaxed/simple; bh=RyDX1NjAj8sNT7Gl32eMqjY+qWQ421SIQLf7ufug8xU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sw0fJsWUnnp8jrPX9pZtC1ulW3uZQFAuc9oFu7QfgzMyxHFPNCrbWz7idCaFWyD6goDNBt+WAVhLQgFxvld1tOUWJbU2Vl1WXpa3EvxY0OhL8VSUh+6rEvttp0rVhjG909nOXTFTQwFSf2Sc+GdviUcjAco3J3yqXEQxYwkGnZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S5+zTnLo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="S5+zTnLo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C1CDC4CEEA; Thu, 22 May 2025 17:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747935554; bh=RyDX1NjAj8sNT7Gl32eMqjY+qWQ421SIQLf7ufug8xU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=S5+zTnLo89kGHvK7ZA60afinbUNhowNjLA+02ClMEHQnWB6GGnkC4zGDOBvZ3c0gP sFW0O9uG6JMVu4Xa4iGoVl2jPbsTfRUtNIaDupg+1vxi/25qG8/mAUpuiGaQLTnshv NbQlav8XcRe342kA/pwxU/uxGjg7Gn+doJX7Ppuqlkk47lkOWqxOSKhdN6OShZgTC9 Ajlp20G9oG7Muv0LOENCpjONIUB2S6mmUIGJv8f81WR4ypiZyhj2AjrO9CLC+wKqZF 7zOE5WiBQwGIdZT/f6roLkTyoMwx+b4T/Y0ISlE+w/TYp0f3dGAUDjvOg0yn4f/q7o nvdz365smhrwA== From: Mark Brown Date: Thu, 22 May 2025 18:38:50 +0100 Subject: [PATCH 1/4] selftests/mm: Use standard ksft_finished() in cow and gup_longterm 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: quoted-printable Message-Id: <20250522-selftests-mm-cow-dedupe-v1-1-713cee2fdd6d@kernel.org> References: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> In-Reply-To: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> To: Andrew Morton , Shuah Khan , David Hildenbrand Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=1870; i=broonie@kernel.org; h=from:subject:message-id; bh=RyDX1NjAj8sNT7Gl32eMqjY+qWQ421SIQLf7ufug8xU=; b=owGbwMvMwMWocq27KDak/QLjabUkhgz9RKtiP+5fOl9Uy7d8YO/gnahdG3MpvC+w91X69nzNVcXl ju6djMYsDIxcDLJiiixrn2WsSg+X2Dr/0fxXMINYmUCmMHBxCsBEPk5i/83KEWOc+4PNqTs9kT3rwp ky380zfZ7x9s/P8tixQNOEMbmc10i3NyV99x4NqfTPX81eaTr8Vcu/msNYGP5vsc6cvIxTnKYf/gSl 75MzUPjktqC7LPr5ytfsvAkGLUWbnl9VCbkflbrt7YRGrhPXZ2z9JsG3zE1Oqar0Rma2oI+Z+7lPmT 5NV566rL7DOis5dmNDyf9V00PXdarwMzFyFZuXz7Nml7beZHVddeOF+H13Y0w6jmzfc+KtufDygo1V 69qY/vtNPregctdDW7m0TcL7rJiMT3f+DF/PqbU61cvw4C/FlWsr8nqXcPwxsU4Xlj4bt/Rh1WyJs9 8l7688uqrbQ1Ol6/FUZpvozgZWAA== X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB The cow and gup_longterm test programs open code something that looks a lot like the standard ksft_finished() helper to summarise the test results and provide an exit code, convert to use ksft_finished(). Signed-off-by: Mark Brown Acked-by: David Hildenbrand --- tools/testing/selftests/mm/cow.c | 7 +------ tools/testing/selftests/mm/gup_longterm.c | 8 ++------ 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index b6cfe0a4b7df..e70cd3d900cc 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -1771,7 +1771,6 @@ static int tests_per_non_anon_test_case(void) =20 int main(int argc, char **argv) { - int err; struct thp_settings default_settings; =20 ksft_print_header(); @@ -1811,9 +1810,5 @@ int main(int argc, char **argv) thp_restore_settings(); } =20 - err =3D ksft_get_fail_cnt(); - if (err) - ksft_exit_fail_msg("%d out of %d tests failed\n", - err, ksft_test_num()); - ksft_exit_pass(); + ksft_finished(); } diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/self= tests/mm/gup_longterm.c index 21595b20bbc3..e60e62809186 100644 --- a/tools/testing/selftests/mm/gup_longterm.c +++ b/tools/testing/selftests/mm/gup_longterm.c @@ -455,7 +455,7 @@ static int tests_per_test_case(void) =20 int main(int argc, char **argv) { - int i, err; + int i; =20 pagesize =3D getpagesize(); nr_hugetlbsizes =3D detect_hugetlb_page_sizes(hugetlbsizes, @@ -469,9 +469,5 @@ int main(int argc, char **argv) for (i =3D 0; i < ARRAY_SIZE(test_cases); i++) run_test_case(&test_cases[i]); =20 - err =3D ksft_get_fail_cnt(); - if (err) - ksft_exit_fail_msg("%d out of %d tests failed\n", - err, ksft_test_num()); - ksft_exit_pass(); + ksft_finished(); } --=20 2.39.5 From nobody Fri Dec 19 13:10:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 4040E19D88B; Thu, 22 May 2025 17:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935558; cv=none; b=daiorWxZXfRu7y181baWzJ+JWdBILp9qhhW+nmsMf1gpmBTpM92Yqxnkbm4zMiGtCTdDpyVifxcG1GIczGjRxkwCz/gpXgZRMpLRiB7tkwxFOrPqnShN5YuRMSbsRjt1bulcFhay8HXZDCPucxqx87uxLmyekD+rboe5FyzDUtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935558; c=relaxed/simple; bh=BfV3xzhjunrMLDK9cWHpUfmqXZar03TrfugoHRogF2k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=k98rzS79ueodBKEH2Xc1pVtwausI3X0HpWTRwOLi7rVR2p58smHVn1nrmYHe9lKs+zw6UopB7z2MzLm8C/RUfm3OvaX9+o6jFo6XBCtnGYpRhWpxEhu3X0pYsGKyGUFzbbHiKc84aKjgNElKrF1xE2mzr427tvcivvs04iTkBKg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bZKEEf2k; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bZKEEf2k" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E770C4CEE4; Thu, 22 May 2025 17:39:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747935556; bh=BfV3xzhjunrMLDK9cWHpUfmqXZar03TrfugoHRogF2k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=bZKEEf2kmgWS8SMxr95A7OurYGQNSLzhSxXIghZQnB74rli2wfofyjQC3jbgcQCeu 4pjQmW3HdB/eOktv9Hcnk1gfqlPUU/Qs0irdRqh2Ia1EZuFH0kFwg0I/XimT0UAXjL HCuJh8DFQ69SEddP5i6YVIAZcviw/Cex28eCMZqxxHQ3hXOQErZtiPTMkDrInzhMkO ZK9JL58OumY4/UJ3EqQHAne8EEcLXEtndi/EfgblywYralx/2Zvz3O+bW9NpVPATyd nj7BcRIep2wZ3nfdfPSmMBXpOHqyGwiYgScgBGztxzN+pKEOfMEaa4TRZBQZrX8giS G0c3Zj/i2E8tQ== From: Mark Brown Date: Thu, 22 May 2025 18:38:51 +0100 Subject: [PATCH 2/4] selftest/mm: Add helper for logging test start and results 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: quoted-printable Message-Id: <20250522-selftests-mm-cow-dedupe-v1-2-713cee2fdd6d@kernel.org> References: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> In-Reply-To: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> To: Andrew Morton , Shuah Khan , David Hildenbrand Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=2420; i=broonie@kernel.org; h=from:subject:message-id; bh=BfV3xzhjunrMLDK9cWHpUfmqXZar03TrfugoHRogF2k=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoL2E7O39pUMyl3dQ+mcq8nzpDDPVlGvzoAqNsnaJP kuc1PSiJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaC9hOwAKCRAk1otyXVSH0CxUB/ kB2R1vX+3cCm7FLaenjY7igzq8Hh7eHaGLYXArBg5H571Am5bniAKcnivXRgPeUuVslt37mL8BuROS aaDyL+QKrMhKjy5Tr4coNZce7Xaw20QyvfWJvhXCkfyua9huedcQ3f7600VPcdanRDE6XwRfWZPDOQ 08xWB22bzic4y41tqKHz1rNFI3BPQA7HmvMygneY/s/xZBnrKTAV7Q3t7yIbe22X5Uq//Av5zuhot9 5rtiMactb/SJYZ2o2kKXaZAiY/vDuc91RVWZ7KwTfR4/V0po5rAAa8nwlRBfVD/OsPlV163UZJqc7M hDMGlXswISPftH9WB28hrR8BF/y4uC X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Several of the MM tests have a pattern of printing a description of the test to be run then reporting the actual TAP result using a generic string not connected to the specific test, often in a shared function used by many tests. The name reported typically varies depending on the specific result rather than the test too. This causes problems for tooling that works with test results, the names reported with the results are used to deduplicate tests and track them between runs so both duplicated names and changing names cause trouble for things like UIs and automated bisection. As a first step towards matching these tests better with the expectations of kselftest provide helpers which record the test name as part of the initial print and then use that as part of reporting a result. This is not added as a generic kselftest helper partly because the use of a variable to store the test name doesn't fit well with the header only implementation of kselftest.h and partly because it's not really an intended pattern. Ideally at some point the mm tests that use it will be updated to not need it. Signed-off-by: Mark Brown --- tools/testing/selftests/mm/vm_util.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 6effafdc4d8a..4944e4c79051 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -3,6 +3,7 @@ #include #include #include +#include #include /* ffsl() */ #include /* _SC_PAGESIZE */ #include "../kselftest.h" @@ -74,6 +75,25 @@ int uffd_register_with_ioctls(int uffd, void *addr, uint= 64_t len, unsigned long get_free_hugepages(void); bool check_vmflag_io(void *addr); =20 +/* These helpers need to be inline to match the kselftest.h idiom. */ +static char test_name[1024]; + +static inline void log_test_start(const char *name, ...) +{ + va_list args; + va_start(args, name); + + vsnprintf(test_name, sizeof(test_name), name, args); + ksft_print_msg("[RUN] %s\n", test_name); + + va_end(args); +} + +static inline void log_test_result(int result) +{ + ksft_test_result_report(result, "%s\n", test_name); +} + /* * On ppc64 this will only work with radix 2M hugepage size */ --=20 2.39.5 From nobody Fri Dec 19 13:10:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 8775817C21B; Thu, 22 May 2025 17:39:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935559; cv=none; b=bIlazzd+GSOK+gIaSeEzDelMgUnZ/dPTeqIUBHQ03HsApuqCX70xWOXvMxntiCeFR0i1/+rpKXtwkXEyxIMlz6CraUzaHBj33BO8H3u9YsZQ8KSwEUOZVPnAxiVrbccTiRjN1nrshqADKVrnTZKSgAx3pG8hiMX8edkF8LdTfYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935559; c=relaxed/simple; bh=a4C7vo5a8gu9Tr4FRKWkna3ydJ9IfFuiXanLHBA+sJQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CZERVfEY4ie0UQgJGII2xqwxKdVMYrY6LrA+lqEunwawaWdGW7E4kjk5UvF8AQNNVloeynEMsl6QjhoPFLxwhoGLUDuQTqaLSjXnapUIXSYWdjBA4xr1NxlTysbhhs3xZVtEgse9Lo24n4/q7hbl/AE+RpzWRDP+8jwVQ0Bm8uo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PzvtsMUI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="PzvtsMUI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5798AC4CEEA; Thu, 22 May 2025 17:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747935559; bh=a4C7vo5a8gu9Tr4FRKWkna3ydJ9IfFuiXanLHBA+sJQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PzvtsMUIX6KihaWf+v0D8lbfplKlxh+lMnBy7iFQY4UO/kpNZOIWmXYSNNI6F1mO1 c8zVRfiVCrAyktL9tcwd5SBkn005PgEFzqLpcGXwmjhwRe8x20RaPVCNfWCgyTVWC3 a3D1hI1tFAgmdIBsqgU9XbSjqzEX9j3JinAluBtu6IaidROWAjiV1iyxJN9pVDaM4J O2kWESznbO/CXnZlP74na6CiBe7jploFSCwYCN4W+JFY+HH8iYgiRV7p82ibp8iAQb T7vnc1fX3XOms50MeQlpfmjymfXCatnk8vXbURQFVgKj3Of/PGepPuiQ8O+UDJ+LIV yuBDbrPH0luHA== From: Mark Brown Date: Thu, 22 May 2025 18:38:52 +0100 Subject: [PATCH 3/4] selftests/mm: Report unique test names for each cow test 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: quoted-printable Message-Id: <20250522-selftests-mm-cow-dedupe-v1-3-713cee2fdd6d@kernel.org> References: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> In-Reply-To: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> To: Andrew Morton , Shuah Khan , David Hildenbrand Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=32876; i=broonie@kernel.org; h=from:subject:message-id; bh=a4C7vo5a8gu9Tr4FRKWkna3ydJ9IfFuiXanLHBA+sJQ=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoL2E8bQI0SrOgleTojDQl9loG25ciShrnczqlLbvr D9lidvyJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaC9hPAAKCRAk1otyXVSH0JVQB/ 0Ue6h7fsQUXETXjxBaVWCR2gz4De7hXxLQpL3SLtY9FKQFkzl4MfzDy+FQJ6zV8nmx9SkgPGI9TsOx pW1py6O8jifGTvBxC7t17kNR42qrVrAnPi6CKGD1EmvLw5WK1lObmutcn11eKBN3un0KPFXbA6T4Mx d4YVEx+DlmSWnccmOXsZclBvZ7ySk70X3yVPkll6/U4hHpLOGRnLon+MYiAQA12VxJ51SBv/Lrpef6 JtP1Wqd96TwMphkfZ204Uicp0UiG72AzP59XYmZdTa31QioJ2plyVy7fBVrBU3J74qlnDoh4qccihN 3jH2HxVmaeVRrJj4ufb8b2DFWZG33+ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB The kselftest framework uses the string logged when a test result is reported as the unique identifier for a test, using it to track test results between runs. The cow test completely fails to follow this pattern, it runs test functions repeatedly with various parameters with each result report from those functions being a string logging an error message which is fixed between runs. Since the code already logs each test uniquely before it starts refactor to also print this to a buffer, then use that name as the test result. This isn't especially pretty but is relatively straightforward and is a great help to tooling. Signed-off-by: Mark Brown --- tools/testing/selftests/mm/cow.c | 333 +++++++++++++++++++++++++----------= ---- 1 file changed, 217 insertions(+), 116 deletions(-) diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/= cow.c index e70cd3d900cc..a97f5ef79f17 100644 --- a/tools/testing/selftests/mm/cow.c +++ b/tools/testing/selftests/mm/cow.c @@ -112,9 +112,12 @@ struct comm_pipes { =20 static int setup_comm_pipes(struct comm_pipes *comm_pipes) { - if (pipe(comm_pipes->child_ready) < 0) + if (pipe(comm_pipes->child_ready) < 0) { + ksft_perror("pipe()"); return -errno; + } if (pipe(comm_pipes->parent_ready) < 0) { + ksft_perror("pipe()"); close(comm_pipes->child_ready[0]); close(comm_pipes->child_ready[1]); return -errno; @@ -207,13 +210,14 @@ static void do_test_cow_in_parent(char *mem, size_t s= ize, bool do_mprotect, =20 ret =3D setup_comm_pipes(&comm_pipes); if (ret) { - ksft_test_result_fail("pipe() failed\n"); + log_test_result(KSFT_FAIL); return; } =20 ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } else if (!ret) { exit(fn(mem, size, &comm_pipes)); @@ -228,9 +232,18 @@ static void do_test_cow_in_parent(char *mem, size_t si= ze, bool do_mprotect, * write-faults by directly mapping pages writable. */ ret =3D mprotect(mem, size, PROT_READ); - ret |=3D mprotect(mem, size, PROT_READ|PROT_WRITE); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); + write(comm_pipes.parent_ready[1], "0", 1); + wait(&ret); + goto close_comm_pipes; + } + + ret =3D mprotect(mem, size, PROT_READ|PROT_WRITE); + if (ret) { + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -248,16 +261,16 @@ static void do_test_cow_in_parent(char *mem, size_t s= ize, bool do_mprotect, ret =3D -EINVAL; =20 if (!ret) { - ksft_test_result_pass("No leak from parent into child\n"); + log_test_result(KSFT_PASS); } else if (xfail) { /* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ - ksft_test_result_xfail("Leak from parent into child\n"); + log_test_result(KSFT_XFAIL); } else { - ksft_test_result_fail("Leak from parent into child\n"); + log_test_result(KSFT_FAIL); } close_comm_pipes: close_comm_pipes(&comm_pipes); @@ -306,26 +319,29 @@ static void do_test_vmsplice_in_parent(char *mem, siz= e_t size, =20 ret =3D setup_comm_pipes(&comm_pipes); if (ret) { - ksft_test_result_fail("pipe() failed\n"); + log_test_result(KSFT_FAIL); goto free; } =20 if (pipe(fds) < 0) { - ksft_test_result_fail("pipe() failed\n"); + ksft_perror("pipe() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } =20 if (before_fork) { transferred =3D vmsplice(fds[1], &iov, 1, 0); if (transferred <=3D 0) { - ksft_test_result_fail("vmsplice() failed\n"); + ksft_print_msg("vmsplice() failed\n"); + log_test_result(KSFT_FAIL); goto close_pipe; } } =20 ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed\n"); + log_test_result(KSFT_FAIL); goto close_pipe; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -339,7 +355,8 @@ static void do_test_vmsplice_in_parent(char *mem, size_= t size, if (!before_fork) { transferred =3D vmsplice(fds[1], &iov, 1, 0); if (transferred <=3D 0) { - ksft_test_result_fail("vmsplice() failed\n"); + ksft_perror("vmsplice() failed"); + log_test_result(KSFT_FAIL); wait(&ret); goto close_pipe; } @@ -348,7 +365,8 @@ static void do_test_vmsplice_in_parent(char *mem, size_= t size, while (read(comm_pipes.child_ready[0], &buf, 1) !=3D 1) ; if (munmap(mem, size) < 0) { - ksft_test_result_fail("munmap() failed\n"); + ksft_perror("munmap() failed"); + log_test_result(KSFT_FAIL); goto close_pipe; } write(comm_pipes.parent_ready[1], "0", 1); @@ -356,7 +374,8 @@ static void do_test_vmsplice_in_parent(char *mem, size_= t size, /* Wait until the child is done writing. */ wait(&ret); if (!WIFEXITED(ret)) { - ksft_test_result_fail("wait() failed\n"); + ksft_perror("wait() failed"); + log_test_result(KSFT_FAIL); goto close_pipe; } =20 @@ -364,22 +383,23 @@ static void do_test_vmsplice_in_parent(char *mem, siz= e_t size, for (total =3D 0; total < transferred; total +=3D cur) { cur =3D read(fds[0], new + total, transferred - total); if (cur < 0) { - ksft_test_result_fail("read() failed\n"); + ksft_perror("read() failed"); + log_test_result(KSFT_FAIL); goto close_pipe; } } =20 if (!memcmp(old, new, transferred)) { - ksft_test_result_pass("No leak from child into parent\n"); + log_test_result(KSFT_PASS); } else if (xfail) { /* * With hugetlb, some vmsplice() tests are currently expected to * fail because (a) harder to fix and (b) nobody really cares. * Flag them as expected failure for now. */ - ksft_test_result_xfail("Leak from child into parent\n"); + log_test_result(KSFT_XFAIL); } else { - ksft_test_result_fail("Leak from child into parent\n"); + log_test_result(KSFT_FAIL); } close_pipe: close(fds[0]); @@ -416,13 +436,14 @@ static void do_test_iouring(char *mem, size_t size, b= ool use_fork) =20 ret =3D setup_comm_pipes(&comm_pipes); if (ret) { - ksft_test_result_fail("pipe() failed\n"); + log_test_result(KAFT_FAIL); return; } =20 file =3D tmpfile(); if (!file) { - ksft_test_result_fail("tmpfile() failed\n"); + ksft_perror("tmpfile() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } fd =3D fileno(file); @@ -430,14 +451,16 @@ static void do_test_iouring(char *mem, size_t size, b= ool use_fork) =20 tmp =3D malloc(size); if (!tmp) { - ksft_test_result_fail("malloc() failed\n"); + ksft_pring_msg("malloc() failed\n"); + log_test_result(KSFT_FAIL); goto close_file; } =20 /* Skip on errors, as we might just lack kernel support. */ ret =3D io_uring_queue_init(1, &ring, 0); if (ret < 0) { - ksft_test_result_skip("io_uring_queue_init() failed\n"); + ksft_print_msg("io_uring_queue_init() failed\n"); + log_test_result(KSFT_SKIP); goto free_tmp; } =20 @@ -452,7 +475,8 @@ static void do_test_iouring(char *mem, size_t size, boo= l use_fork) iov.iov_len =3D size; ret =3D io_uring_register_buffers(&ring, &iov, 1); if (ret) { - ksft_test_result_skip("io_uring_register_buffers() failed\n"); + ksft_print_msg("io_uring_register_buffers() failed\n"); + log_test_result(KSFT_SKIP); goto queue_exit; } =20 @@ -463,7 +487,8 @@ static void do_test_iouring(char *mem, size_t size, boo= l use_fork) */ ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed"); + log_test_result(KSFT_FAIL); goto unregister_buffers; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -483,10 +508,17 @@ static void do_test_iouring(char *mem, size_t size, b= ool use_fork) * if the page is mapped R/O vs. R/W). */ ret =3D mprotect(mem, size, PROT_READ); + if (ret) { + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); + goto unregister_buffers; + } + clear_softdirty(); - ret |=3D mprotect(mem, size, PROT_READ | PROT_WRITE); + ret =3D mprotect(mem, size, PROT_READ | PROT_WRITE); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto unregister_buffers; } } @@ -498,25 +530,29 @@ static void do_test_iouring(char *mem, size_t size, b= ool use_fork) memset(mem, 0xff, size); sqe =3D io_uring_get_sqe(&ring); if (!sqe) { - ksft_test_result_fail("io_uring_get_sqe() failed\n"); + ksft_print_msg("io_uring_get_sqe() failed\n"); + log_test_result(KSFT_FAIL); goto quit_child; } io_uring_prep_write_fixed(sqe, fd, mem, size, 0, 0); =20 ret =3D io_uring_submit(&ring); if (ret < 0) { - ksft_test_result_fail("io_uring_submit() failed\n"); + ksft_print_msg("io_uring_submit() failed\n"); + log_test_result(KSFT_FAIL); goto quit_child; } =20 ret =3D io_uring_wait_cqe(&ring, &cqe); if (ret < 0) { - ksft_test_result_fail("io_uring_wait_cqe() failed\n"); + ksft_print_msg("io_uring_wait_cqe() failed\n"); + log_test_result(KSFT_FAIL); goto quit_child; } =20 if (cqe->res !=3D size) { - ksft_test_result_fail("write_fixed failed\n"); + ksft_print_msg("write_fixed failed\n"); + log_test_result(KSFT_FAIL); goto quit_child; } io_uring_cqe_seen(&ring, cqe); @@ -526,15 +562,18 @@ static void do_test_iouring(char *mem, size_t size, b= ool use_fork) while (total < size) { cur =3D pread(fd, tmp + total, size - total, total); if (cur < 0) { - ksft_test_result_fail("pread() failed\n"); + ksft_print_msg("pread() failed\n"); + log_test_result(KSFT_FAIL); goto quit_child; } total +=3D cur; } =20 /* Finally, check if we read what we expected. */ - ksft_test_result(!memcmp(mem, tmp, size), - "Longterm R/W pin is reliable\n"); + if (!memcmp(mem, tmp, size)) + log_test_result(KSFT_PASS); + else + log_test_result(KSFT_FAIL); =20 quit_child: if (use_fork) { @@ -582,19 +621,21 @@ static void do_test_ro_pin(char *mem, size_t size, en= um ro_pin_test test, int ret; =20 if (gup_fd < 0) { - ksft_test_result_skip("gup_test not available\n"); + ksft_print_msg("gup_test not available\n"); + log_test_result(KSFT_SKIP); return; } =20 tmp =3D malloc(size); if (!tmp) { - ksft_test_result_fail("malloc() failed\n"); + ksft_print_msg("malloc() failed\n"); + log_test_result(KSFT_FAIL); return; } =20 ret =3D setup_comm_pipes(&comm_pipes); if (ret) { - ksft_test_result_fail("pipe() failed\n"); + log_test_result(KSFT_FAIL); goto free_tmp; } =20 @@ -609,7 +650,8 @@ static void do_test_ro_pin(char *mem, size_t size, enum= ro_pin_test test, */ ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } else if (!ret) { write(comm_pipes.child_ready[1], "0", 1); @@ -646,7 +688,8 @@ static void do_test_ro_pin(char *mem, size_t size, enum= ro_pin_test test, clear_softdirty(); ret |=3D mprotect(mem, size, PROT_READ | PROT_WRITE); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } break; @@ -661,9 +704,11 @@ static void do_test_ro_pin(char *mem, size_t size, enu= m ro_pin_test test, ret =3D ioctl(gup_fd, PIN_LONGTERM_TEST_START, &args); if (ret) { if (errno =3D=3D EINVAL) - ksft_test_result_skip("PIN_LONGTERM_TEST_START failed\n"); + ret =3D KSFT_SKIP; else - ksft_test_result_fail("PIN_LONGTERM_TEST_START failed\n"); + ret =3D KSFT_FAIL; + ksft_perror("PIN_LONGTERM_TEST_START failed"); + log_test_result(ret); goto wait; } =20 @@ -676,22 +721,26 @@ static void do_test_ro_pin(char *mem, size_t size, en= um ro_pin_test test, */ tmp_val =3D (__u64)(uintptr_t)tmp; ret =3D ioctl(gup_fd, PIN_LONGTERM_TEST_READ, &tmp_val); - if (ret) - ksft_test_result_fail("PIN_LONGTERM_TEST_READ failed\n"); - else - ksft_test_result(!memcmp(mem, tmp, size), - "Longterm R/O pin is reliable\n"); + if (ret) { + ksft_perror("PIN_LONGTERM_TEST_READ failed"); + log_test_result(KSFT_FAIL); + } else { + if (!memcmp(mem, tmp, size)) + log_test_result(KSFT_PASS); + else + log_test_result(KSFT_FAIL); + } =20 ret =3D ioctl(gup_fd, PIN_LONGTERM_TEST_STOP); if (ret) - ksft_print_msg("[INFO] PIN_LONGTERM_TEST_STOP failed\n"); + ksft_perror("PIN_LONGTERM_TEST_STOP failed"); wait: switch (test) { case RO_PIN_TEST_SHARED: write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); if (!WIFEXITED(ret)) - ksft_print_msg("[INFO] wait() failed\n"); + ksft_perror("wait() failed"); break; default: break; @@ -746,14 +795,16 @@ static void do_run_with_base_page(test_fn fn, bool sw= apout) mem =3D mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); return; } =20 ret =3D madvise(mem, pagesize, MADV_NOHUGEPAGE); /* Ignore if not around on a kernel. */ if (ret && errno !=3D EINVAL) { - ksft_test_result_fail("MADV_NOHUGEPAGE failed\n"); + ksft_perror("MADV_NOHUGEPAGE failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -763,7 +814,8 @@ static void do_run_with_base_page(test_fn fn, bool swap= out) if (swapout) { madvise(mem, pagesize, MADV_PAGEOUT); if (!pagemap_is_swapped(pagemap_fd, mem)) { - ksft_test_result_skip("MADV_PAGEOUT did not work, is swap enabled?\n"); + ksft_print_msg("MADV_PAGEOUT did not work, is swap enabled?\n"); + log_test_result(KSFT_SKIP); goto munmap; } } @@ -775,13 +827,13 @@ static void do_run_with_base_page(test_fn fn, bool sw= apout) =20 static void run_with_base_page(test_fn fn, const char *desc) { - ksft_print_msg("[RUN] %s ... with base page\n", desc); + log_test_start("%s ... with base page", desc); do_run_with_base_page(fn, false); } =20 static void run_with_base_page_swap(test_fn fn, const char *desc) { - ksft_print_msg("[RUN] %s ... with swapped out base page\n", desc); + log_test_start("%s ... with swapped out base page", desc); do_run_with_base_page(fn, true); } =20 @@ -807,7 +859,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) mmap_mem =3D mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); return; } =20 @@ -816,7 +869,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) =20 ret =3D madvise(mem, thpsize, MADV_HUGEPAGE); if (ret) { - ksft_test_result_fail("MADV_HUGEPAGE failed\n"); + ksft_perror("MADV_HUGEPAGE failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -826,7 +880,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) */ mem[0] =3D 1; if (!pagemap_is_populated(pagemap_fd, mem + thpsize - pagesize)) { - ksft_test_result_skip("Did not get a THP populated\n"); + ksft_print_msg("Did not get a THP populated\n"); + log_test_result(KSFT_SKIP); goto munmap; } memset(mem, 1, thpsize); @@ -846,12 +901,14 @@ static void do_run_with_thp(test_fn fn, enum thp_run = thp_run, size_t thpsize) */ ret =3D mprotect(mem + pagesize, pagesize, PROT_READ); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto munmap; } ret =3D mprotect(mem + pagesize, pagesize, PROT_READ | PROT_WRITE); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto munmap; } break; @@ -863,7 +920,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) */ ret =3D madvise(mem + pagesize, thpsize - pagesize, MADV_DONTNEED); if (ret) { - ksft_test_result_fail("MADV_DONTNEED failed\n"); + ksft_perror("MADV_DONTNEED failed"); + log_test_result(KSFT_FAIL); goto munmap; } size =3D pagesize; @@ -877,13 +935,15 @@ static void do_run_with_thp(test_fn fn, enum thp_run = thp_run, size_t thpsize) mremap_mem =3D mmap(NULL, mremap_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mremap_mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } tmp =3D mremap(mem + mremap_size, mremap_size, mremap_size, MREMAP_MAYMOVE | MREMAP_FIXED, mremap_mem); if (tmp !=3D mremap_mem) { - ksft_test_result_fail("mremap() failed\n"); + ksft_perror("mremap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } size =3D mremap_size; @@ -896,12 +956,14 @@ static void do_run_with_thp(test_fn fn, enum thp_run = thp_run, size_t thpsize) */ ret =3D madvise(mem + pagesize, thpsize - pagesize, MADV_DONTFORK); if (ret) { - ksft_test_result_fail("MADV_DONTFORK failed\n"); + ksft_perror("MADV_DONTFORK failed"); + log_test_result(KSFT_FAIL); goto munmap; } ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed"); + log_test_result(KSFT_FAIL); goto munmap; } else if (!ret) { exit(0); @@ -910,7 +972,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) /* Allow for sharing all pages again. */ ret =3D madvise(mem + pagesize, thpsize - pagesize, MADV_DOFORK); if (ret) { - ksft_test_result_fail("MADV_DOFORK failed\n"); + ksft_perror("MADV_DOFORK failed"); + log_test_result(KSFT_FAIL); goto munmap; } break; @@ -924,7 +987,8 @@ static void do_run_with_thp(test_fn fn, enum thp_run th= p_run, size_t thpsize) case THP_RUN_SINGLE_PTE_SWAPOUT: madvise(mem, size, MADV_PAGEOUT); if (!range_is_swapped(mem, size)) { - ksft_test_result_skip("MADV_PAGEOUT did not work, is swap enabled?\n"); + ksft_print_msg("MADV_PAGEOUT did not work, is swap enabled?\n"); + log_test_result(KSFT_SKIP); goto munmap; } break; @@ -941,56 +1005,56 @@ static void do_run_with_thp(test_fn fn, enum thp_run= thp_run, size_t thpsize) =20 static void run_with_thp(test_fn fn, const char *desc, size_t size) { - ksft_print_msg("[RUN] %s ... with THP (%zu kB)\n", + log_test_start("%s ... with THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PMD, size); } =20 static void run_with_thp_swap(test_fn fn, const char *desc, size_t size) { - ksft_print_msg("[RUN] %s ... with swapped-out THP (%zu kB)\n", + log_test_start("%s ... with swapped-out THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PMD_SWAPOUT, size); } =20 static void run_with_pte_mapped_thp(test_fn fn, const char *desc, size_t s= ize) { - ksft_print_msg("[RUN] %s ... with PTE-mapped THP (%zu kB)\n", + log_test_start("%s ... with PTE-mapped THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PTE, size); } =20 static void run_with_pte_mapped_thp_swap(test_fn fn, const char *desc, siz= e_t size) { - ksft_print_msg("[RUN] %s ... with swapped-out, PTE-mapped THP (%zu kB)\n", + log_test_start("%s ... with swapped-out, PTE-mapped THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PTE_SWAPOUT, size); } =20 static void run_with_single_pte_of_thp(test_fn fn, const char *desc, size_= t size) { - ksft_print_msg("[RUN] %s ... with single PTE of THP (%zu kB)\n", + log_test_start("%s ... with single PTE of THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_SINGLE_PTE, size); } =20 static void run_with_single_pte_of_thp_swap(test_fn fn, const char *desc, = size_t size) { - ksft_print_msg("[RUN] %s ... with single PTE of swapped-out THP (%zu kB)\= n", + log_test_start("%s ... with single PTE of swapped-out THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_SINGLE_PTE_SWAPOUT, size); } =20 static void run_with_partial_mremap_thp(test_fn fn, const char *desc, size= _t size) { - ksft_print_msg("[RUN] %s ... with partially mremap()'ed THP (%zu kB)\n", + log_test_start("%s ... with partially mremap()'ed THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PARTIAL_MREMAP, size); } =20 static void run_with_partial_shared_thp(test_fn fn, const char *desc, size= _t size) { - ksft_print_msg("[RUN] %s ... with partially shared THP (%zu kB)\n", + log_test_start("%s ... with partially shared THP (%zu kB)", desc, size / 1024); do_run_with_thp(fn, THP_RUN_PARTIAL_SHARED, size); } @@ -1000,14 +1064,15 @@ static void run_with_hugetlb(test_fn fn, const char= *desc, size_t hugetlbsize) int flags =3D MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB; char *mem, *dummy; =20 - ksft_print_msg("[RUN] %s ... with hugetlb (%zu kB)\n", desc, + log_test_start("%s ... with hugetlb (%zu kB)", desc, hugetlbsize / 1024); =20 flags |=3D __builtin_ctzll(hugetlbsize) << MAP_HUGE_SHIFT; =20 mem =3D mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_skip("need more free huge pages\n"); + ksft_perror("need more free huge pages"); + log_test_result(KSFT_SKIP); return; } =20 @@ -1020,7 +1085,8 @@ static void run_with_hugetlb(test_fn fn, const char *= desc, size_t hugetlbsize) */ dummy =3D mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, flags, -1, 0); if (dummy =3D=3D MAP_FAILED) { - ksft_test_result_skip("need more free huge pages\n"); + ksft_perror("need more free huge pages"); + log_test_result(KSFT_SKIP); goto munmap; } munmap(dummy, hugetlbsize); @@ -1226,7 +1292,7 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, =20 ret =3D setup_comm_pipes(&comm_pipes); if (ret) { - ksft_test_result_fail("pipe() failed\n"); + log_test_result(KSFT_FAIL); return; } =20 @@ -1236,12 +1302,14 @@ static void do_test_anon_thp_collapse(char *mem, si= ze_t size, */ ret =3D mprotect(mem + pagesize, pagesize, PROT_READ); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } ret =3D mprotect(mem + pagesize, pagesize, PROT_READ | PROT_WRITE); if (ret) { - ksft_test_result_fail("mprotect() failed\n"); + ksft_perror("mprotect() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } =20 @@ -1250,8 +1318,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, /* Collapse before actually COW-sharing the page. */ ret =3D madvise(mem, size, MADV_COLLAPSE); if (ret) { - ksft_test_result_skip("MADV_COLLAPSE failed: %s\n", - strerror(errno)); + ksft_perror("MADV_COLLAPSE failed"); + log_test_result(KSFT_SKIP); goto close_comm_pipes; } break; @@ -1262,7 +1330,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, /* Don't COW-share the upper part of the THP. */ ret =3D madvise(mem + size / 2, size / 2, MADV_DONTFORK); if (ret) { - ksft_test_result_fail("MADV_DONTFORK failed\n"); + ksft_perror("MADV_DONTFORK failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } break; @@ -1270,7 +1339,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, /* Don't COW-share the lower part of the THP. */ ret =3D madvise(mem, size / 2, MADV_DONTFORK); if (ret) { - ksft_test_result_fail("MADV_DONTFORK failed\n"); + ksft_perror("MADV_DONTFORK failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } break; @@ -1280,7 +1350,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, =20 ret =3D fork(); if (ret < 0) { - ksft_test_result_fail("fork() failed\n"); + ksft_perror("fork() failed"); + log_test_result(KSFT_FAIL); goto close_comm_pipes; } else if (!ret) { switch (test) { @@ -1314,7 +1385,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, */ ret =3D madvise(mem, size, MADV_DOFORK); if (ret) { - ksft_test_result_fail("MADV_DOFORK failed\n"); + ksft_perror("MADV_DOFORK failed"); + log_test_result(KSFT_FAIL); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -1324,8 +1396,8 @@ static void do_test_anon_thp_collapse(char *mem, size= _t size, /* Collapse before anyone modified the COW-shared page. */ ret =3D madvise(mem, size, MADV_COLLAPSE); if (ret) { - ksft_test_result_skip("MADV_COLLAPSE failed: %s\n", - strerror(errno)); + ksft_perror("MADV_COLLAPSE failed"); + log_test_result(KSFT_SKIP); write(comm_pipes.parent_ready[1], "0", 1); wait(&ret); goto close_comm_pipes; @@ -1345,7 +1417,10 @@ static void do_test_anon_thp_collapse(char *mem, siz= e_t size, else ret =3D -EINVAL; =20 - ksft_test_result(!ret, "No leak from parent into child\n"); + if (!ret) + log_test_result(KSFT_PASS); + else + log_test_result(KSFT_FAIL); close_comm_pipes: close_comm_pipes(&comm_pipes); } @@ -1430,7 +1505,7 @@ static void run_anon_thp_test_cases(void) for (i =3D 0; i < ARRAY_SIZE(anon_thp_test_cases); i++) { struct test_case const *test_case =3D &anon_thp_test_cases[i]; =20 - ksft_print_msg("[RUN] %s\n", test_case->desc); + log_test_start("%s", test_case->desc); do_run_with_thp(test_case->fn, THP_RUN_PMD, pmdsize); } } @@ -1453,8 +1528,10 @@ static void test_cow(char *mem, const char *smem, si= ze_t size) memset(mem, 0xff, size); =20 /* See if we still read the old values via the other mapping. */ - ksft_test_result(!memcmp(smem, old, size), - "Other mapping not modified\n"); + if (!memcmp(smem, old, size)) + log_test_result(KSFT_PASS); + else + log_test_result(KSFT_FAIL); free(old); } =20 @@ -1472,18 +1549,20 @@ static void run_with_zeropage(non_anon_test_fn fn, = const char *desc) { char *mem, *smem, tmp; =20 - ksft_print_msg("[RUN] %s ... with shared zeropage\n", desc); + log_test_start("%s ... with shared zeropage", desc); =20 mem =3D mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); return; } =20 smem =3D mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0); if (smem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -1504,10 +1583,11 @@ static void run_with_huge_zeropage(non_anon_test_fn= fn, const char *desc) size_t mmap_size; int ret; =20 - ksft_print_msg("[RUN] %s ... with huge zeropage\n", desc); + log_test_start("%s ... with huge zeropage", desc); =20 if (!has_huge_zeropage) { - ksft_test_result_skip("Huge zeropage not enabled\n"); + ksft_print_msg("Huge zeropage not enabled\n"); + log_test_result(KSFT_SKIP); return; } =20 @@ -1516,13 +1596,15 @@ static void run_with_huge_zeropage(non_anon_test_fn= fn, const char *desc) mmap_mem =3D mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); return; } mmap_smem =3D mmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (mmap_smem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -1531,9 +1613,15 @@ static void run_with_huge_zeropage(non_anon_test_fn = fn, const char *desc) smem =3D (char *)(((uintptr_t)mmap_smem + pmdsize) & ~(pmdsize - 1)); =20 ret =3D madvise(mem, pmdsize, MADV_HUGEPAGE); + if (ret !=3D 0) { + ksft_perror("madvise()"); + log_test_result(KSFT_FAIL); + goto munmap; + } ret |=3D madvise(smem, pmdsize, MADV_HUGEPAGE); - if (ret) { - ksft_test_result_fail("MADV_HUGEPAGE failed\n"); + if (ret !=3D 0) { + ksft_perror("madvise()"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -1562,29 +1650,33 @@ static void run_with_memfd(non_anon_test_fn fn, con= st char *desc) char *mem, *smem, tmp; int fd; =20 - ksft_print_msg("[RUN] %s ... with memfd\n", desc); + log_test_start("%s ... with memfd", desc); =20 fd =3D memfd_create("test", 0); if (fd < 0) { - ksft_test_result_fail("memfd_create() failed\n"); + ksft_perror("memfd_create() failed"); + log_test_result(KSFT_FAIL); return; } =20 /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, pagesize)) { - ksft_test_result_fail("fallocate() failed\n"); + ksft_perror("fallocate() failed"); + log_test_result(KSFT_FAIL); goto close; } =20 /* Create a private mapping of the memfd. */ mem =3D mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto close; } smem =3D mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); if (smem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -1607,35 +1699,40 @@ static void run_with_tmpfile(non_anon_test_fn fn, c= onst char *desc) FILE *file; int fd; =20 - ksft_print_msg("[RUN] %s ... with tmpfile\n", desc); + log_test_start("%s ... with tmpfile", desc); =20 file =3D tmpfile(); if (!file) { - ksft_test_result_fail("tmpfile() failed\n"); + ksft_perror("tmpfile() failed"); + log_test_result(KSFT_FAIL); return; } =20 fd =3D fileno(file); if (fd < 0) { - ksft_test_result_skip("fileno() failed\n"); + ksft_perror("fileno() failed"); + log_test_result(KSFT_SKIP); return; } =20 /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, pagesize)) { - ksft_test_result_fail("fallocate() failed\n"); + ksft_perror("fallocate() failed"); + log_test_result(KSFT_FAIL); goto close; } =20 /* Create a private mapping of the memfd. */ mem =3D mmap(NULL, pagesize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto close; } smem =3D mmap(NULL, pagesize, PROT_READ, MAP_SHARED, fd, 0); if (smem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 @@ -1659,20 +1756,22 @@ static void run_with_memfd_hugetlb(non_anon_test_fn= fn, const char *desc, char *mem, *smem, tmp; int fd; =20 - ksft_print_msg("[RUN] %s ... with memfd hugetlb (%zu kB)\n", desc, + log_test_start("%s ... with memfd hugetlb (%zu kB)", desc, hugetlbsize / 1024); =20 flags |=3D __builtin_ctzll(hugetlbsize) << MFD_HUGE_SHIFT; =20 fd =3D memfd_create("test", flags); if (fd < 0) { - ksft_test_result_skip("memfd_create() failed\n"); + ksft_perror("memfd_create() failed"); + log_test_result(KSFT_SKIP); return; } =20 /* File consists of a single page filled with zeroes. */ if (fallocate(fd, 0, 0, hugetlbsize)) { - ksft_test_result_skip("need more free huge pages\n"); + ksft_perror("need more free huge pages"); + log_test_result(KSFT_SKIP); goto close; } =20 @@ -1680,12 +1779,14 @@ static void run_with_memfd_hugetlb(non_anon_test_fn= fn, const char *desc, mem =3D mmap(NULL, hugetlbsize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0); if (mem =3D=3D MAP_FAILED) { - ksft_test_result_skip("need more free huge pages\n"); + ksft_perror("need more free huge pages"); + log_test_result(KSFT_SKIP); goto close; } smem =3D mmap(NULL, hugetlbsize, PROT_READ, MAP_SHARED, fd, 0); if (smem =3D=3D MAP_FAILED) { - ksft_test_result_fail("mmap() failed\n"); + ksft_perror("mmap() failed"); + log_test_result(KSFT_FAIL); goto munmap; } =20 --=20 2.39.5 From nobody Fri Dec 19 13:10:51 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3E43E198E75; Thu, 22 May 2025 17:39:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935563; cv=none; b=Nm5WZtUkFPR1Yd2rKssWYVzb2f3i9M4MP818C1rZqdQpE/V/1CUK8i62Qogs8pOQy8nVvKh6u5VqQbRWq3qmIOfaBNLRUoN5ENXW1OmyKBSAWYGMy6L3rYga7GP3VyMeK1JbtllLdZkAMD6SDZxPZMWyEwR1myLV6Oo3br0na58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747935563; c=relaxed/simple; bh=cHjqIjTqNNckbvYuzAVxs6zjA2YNzuxtFHwb8hivo1k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lYIqPqazgZz9xuQta+Qh1XtYs9+N3JN8mf7BxiRMWY8090L5/WHtiZGgbucZTV0xEwGzRkIlsjMTiON18H8MUHcAgN2v5VZaPjxcU0qmtYB+TgweKS1gdx/xLt2PwgQULBhat4n0GnQWEBg8ASAtPOawHAyXzHL6VKP4Dfdo49M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OPMm+v0C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OPMm+v0C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03F50C4CEF5; Thu, 22 May 2025 17:39:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1747935561; bh=cHjqIjTqNNckbvYuzAVxs6zjA2YNzuxtFHwb8hivo1k=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OPMm+v0Cnq0C5+AAGfHtutPNGqMIJn+4/l/UdX/Q2R9bl1e45NmHuqeF6fHMXyzN8 4e7pZRBsHnxPafCEenbO6z2uwnDjOcJLAXUwo1vKCE1Am9O99ThZB+0mXsJn2UzQIR 03Ss1Ic7s+QV+lcBt6VWtat59crRNvNSqV5mSBOaa/pq3dS0Kd7OXe2b0FKOXp0kB6 AHnaAO34cV/PJ0d9peSoSZdqRINPP1gcrSTdvrE8kc2PL4MUz4x2bhTQJu9PfAPWL+ y6yXSQS+HsFo+0ZQkN9Yn/eGxE1hU/OeyKUFP+oPePWcGYMznHk7vcF3w3ioA44xKb zpNnubg0KoRAw== From: Mark Brown Date: Thu, 22 May 2025 18:38:53 +0100 Subject: [PATCH 4/4] selftests/mm: Fix test result reporting in gup_longterm 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: quoted-printable Message-Id: <20250522-selftests-mm-cow-dedupe-v1-4-713cee2fdd6d@kernel.org> References: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> In-Reply-To: <20250522-selftests-mm-cow-dedupe-v1-0-713cee2fdd6d@kernel.org> To: Andrew Morton , Shuah Khan , David Hildenbrand Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.15-dev-c25d1 X-Developer-Signature: v=1; a=openpgp-sha256; l=9917; i=broonie@kernel.org; h=from:subject:message-id; bh=cHjqIjTqNNckbvYuzAVxs6zjA2YNzuxtFHwb8hivo1k=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBoL2E9Z3GLvXX9j/Zj6pEPY2WH14S5p6WXILcc5xZG LZTnACWJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCaC9hPQAKCRAk1otyXVSH0E1wB/ 9H9L+ofO7mB7KQHgFVq4IYJkW1aqTTPwMDZjTc/HvZmislDF7jBRyHsv5YD0/HagCbRTp6Y8lIB0G/ lBY4iVg1uhtjIzdMepIYj6/PsyK193og0OAe7h60Au4Tznz5a/IUYLHShC4+HW4e6lXD9knCmVlGDP EQIGTj4fqVxKwqdU7cwGKnhjz1VGT8dbqxY3VzBLQnhwo3zP/VBtU5QQrxsxSs1t8sc7eYQDdhI8kY b97E0V/1Y+i9cHfkwFVBLer41yWIKysF2Ejgi+Ue45KPImIDAC1MB7LX3+a4b1WhjEbvwbXwTukvoU 6OxbzxrOfUDfMb9pAsLD0x7nc256x1 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB The kselftest framework uses the string logged when a test result is reported as the unique identifier for a test, using it to track test results between runs. The gup_longterm test fails to follow this pattern, it runs a single test function repeatedly with various parameters but each result report is a string logging an error message which is fixed between runs. Since the code already logs each test uniquely before it starts refactor to also print this to a buffer, then use that name as the test result. This isn't especially pretty but is relatively straightforward and is a great help to tooling. Signed-off-by: Mark Brown --- tools/testing/selftests/mm/gup_longterm.c | 150 +++++++++++++++++++-------= ---- 1 file changed, 94 insertions(+), 56 deletions(-) diff --git a/tools/testing/selftests/mm/gup_longterm.c b/tools/testing/self= tests/mm/gup_longterm.c index e60e62809186..f84ea97c2543 100644 --- a/tools/testing/selftests/mm/gup_longterm.c +++ b/tools/testing/selftests/mm/gup_longterm.c @@ -93,33 +93,48 @@ static void do_test(int fd, size_t size, enum test_type= type, bool shared) __fsword_t fs_type =3D get_fs_type(fd); bool should_work; char *mem; + int result =3D KSFT_PASS; int ret; =20 + if (fd < 0) { + result =3D KSFT_FAIL; + goto report; + } + if (ftruncate(fd, size)) { if (errno =3D=3D ENOENT) { skip_test_dodgy_fs("ftruncate()"); } else { - ksft_test_result_fail("ftruncate() failed (%s)\n", strerror(errno)); + ksft_print_msg("ftruncate() failed (%s)\n", + strerror(errno)); + result =3D KSFT_FAIL; + goto report; } return; } =20 if (fallocate(fd, 0, 0, size)) { - if (size =3D=3D pagesize) - ksft_test_result_fail("fallocate() failed (%s)\n", strerror(errno)); - else - ksft_test_result_skip("need more free huge pages\n"); - return; + if (size =3D=3D pagesize) { + ksft_print_msg("fallocate() failed (%s)\n", strerror(errno)); + result =3D KSFT_FAIL; + } else { + ksft_print_msg("need more free huge pages\n"); + result =3D KSFT_SKIP; + } + goto report; } =20 mem =3D mmap(NULL, size, PROT_READ | PROT_WRITE, shared ? MAP_SHARED : MAP_PRIVATE, fd, 0); if (mem =3D=3D MAP_FAILED) { - if (size =3D=3D pagesize || shared) - ksft_test_result_fail("mmap() failed (%s)\n", strerror(errno)); - else - ksft_test_result_skip("need more free huge pages\n"); - return; + if (size =3D=3D pagesize || shared) { + ksft_print_msg("mmap() failed (%s)\n", strerror(errno)); + result =3D KSFT_FAIL; + } else { + ksft_print_msg("need more free huge pages\n"); + result =3D KSFT_SKIP; + } + goto report; } =20 /* Fault in the page such that GUP-fast can pin it directly. */ @@ -134,7 +149,8 @@ static void do_test(int fd, size_t size, enum test_type= type, bool shared) */ ret =3D mprotect(mem, size, PROT_READ); if (ret) { - ksft_test_result_fail("mprotect() failed (%s)\n", strerror(errno)); + ksft_print_msg("mprotect() failed (%s)\n", strerror(errno)); + result =3D KSFT_FAIL; goto munmap; } /* FALLTHROUGH */ @@ -147,12 +163,14 @@ static void do_test(int fd, size_t size, enum test_ty= pe type, bool shared) type =3D=3D TEST_TYPE_RW_FAST; =20 if (gup_fd < 0) { - ksft_test_result_skip("gup_test not available\n"); + ksft_print_msg("gup_test not available\n"); + result =3D KSFT_SKIP; break; } =20 if (rw && shared && fs_is_unknown(fs_type)) { - ksft_test_result_skip("Unknown filesystem\n"); + ksft_print_msg("Unknown filesystem\n"); + result =3D KSFT_SKIP; return; } /* @@ -169,14 +187,19 @@ static void do_test(int fd, size_t size, enum test_ty= pe type, bool shared) args.flags |=3D rw ? PIN_LONGTERM_TEST_FLAG_USE_WRITE : 0; ret =3D ioctl(gup_fd, PIN_LONGTERM_TEST_START, &args); if (ret && errno =3D=3D EINVAL) { - ksft_test_result_skip("PIN_LONGTERM_TEST_START failed (EINVAL)n"); + ksft_print_msg("PIN_LONGTERM_TEST_START failed (EINVAL)n"); + result =3D KSFT_SKIP; break; } else if (ret && errno =3D=3D EFAULT) { - ksft_test_result(!should_work, "Should have failed\n"); + if (should_work) + result =3D KSFT_FAIL; + else + result =3D KSFT_PASS; break; } else if (ret) { - ksft_test_result_fail("PIN_LONGTERM_TEST_START failed (%s)\n", - strerror(errno)); + ksft_print_msg("PIN_LONGTERM_TEST_START failed (%s)\n", + strerror(errno)); + result =3D KSFT_FAIL; break; } =20 @@ -189,7 +212,10 @@ static void do_test(int fd, size_t size, enum test_typ= e type, bool shared) * some previously unsupported filesystems, we might want to * perform some additional tests for possible data corruptions. */ - ksft_test_result(should_work, "Should have worked\n"); + if (should_work) + result =3D KSFT_PASS; + else + result =3D KSFT_FAIL; break; } #ifdef LOCAL_CONFIG_HAVE_LIBURING @@ -199,8 +225,9 @@ static void do_test(int fd, size_t size, enum test_type= type, bool shared) =20 /* io_uring always pins pages writable. */ if (shared && fs_is_unknown(fs_type)) { - ksft_test_result_skip("Unknown filesystem\n"); - return; + ksft_print_msg("Unknown filesystem\n"); + result =3D KSFT_SKIP; + goto report; } should_work =3D !shared || fs_supports_writable_longterm_pinning(fs_type); @@ -208,8 +235,9 @@ static void do_test(int fd, size_t size, enum test_type= type, bool shared) /* Skip on errors, as we might just lack kernel support. */ ret =3D io_uring_queue_init(1, &ring, 0); if (ret < 0) { - ksft_test_result_skip("io_uring_queue_init() failed (%s)\n", - strerror(-ret)); + ksft_print_msg("io_uring_queue_init() failed (%s)\n", + strerror(-ret)); + result =3D KSFT_SKIP; break; } /* @@ -222,17 +250,28 @@ static void do_test(int fd, size_t size, enum test_ty= pe type, bool shared) /* Only new kernels return EFAULT. */ if (ret && (errno =3D=3D ENOSPC || errno =3D=3D EOPNOTSUPP || errno =3D=3D EFAULT)) { - ksft_test_result(!should_work, "Should have failed (%s)\n", - strerror(errno)); + if (should_work) { + ksft_print_msg("Should have failed (%s)\n", + strerror(errno)); + result =3D KSFT_FAIL; + } else { + result =3D KSFT_PASS; + } } else if (ret) { /* * We might just lack support or have insufficient * MEMLOCK limits. */ - ksft_test_result_skip("io_uring_register_buffers() failed (%s)\n", - strerror(-ret)); + ksft_print_msg("io_uring_register_buffers() failed (%s)\n", + strerror(-ret)); + result =3D KSFT_SKIP; } else { - ksft_test_result(should_work, "Should have worked\n"); + if (should_work) { + result =3D KSFT_PASS; + } else { + ksft_print_msg("Should have worked\n"); + result =3D KSFT_FAIL; + } io_uring_unregister_buffers(&ring); } =20 @@ -246,6 +285,8 @@ static void do_test(int fd, size_t size, enum test_type= type, bool shared) =20 munmap: munmap(mem, size); +report: + log_test_result(result); } =20 typedef void (*test_fn)(int fd, size_t size); @@ -254,13 +295,11 @@ static void run_with_memfd(test_fn fn, const char *de= sc) { int fd; =20 - ksft_print_msg("[RUN] %s ... with memfd\n", desc); + log_test_start("%s ... with memfd", desc); =20 fd =3D memfd_create("test", 0); - if (fd < 0) { - ksft_test_result_fail("memfd_create() failed (%s)\n", strerror(errno)); - return; - } + if (fd < 0) + ksft_print_msg("memfd_create() failed (%s)\n", strerror(errno)); =20 fn(fd, pagesize); close(fd); @@ -271,23 +310,23 @@ static void run_with_tmpfile(test_fn fn, const char *= desc) FILE *file; int fd; =20 - ksft_print_msg("[RUN] %s ... with tmpfile\n", desc); + log_test_start("%s ... with tmpfile", desc); =20 file =3D tmpfile(); if (!file) { - ksft_test_result_fail("tmpfile() failed (%s)\n", strerror(errno)); - return; - } - - fd =3D fileno(file); - if (fd < 0) { - ksft_test_result_fail("fileno() failed (%s)\n", strerror(errno)); - goto close; + ksft_print_msg("tmpfile() failed (%s)\n", strerror(errno)); + fd =3D -1; + } else { + fd =3D fileno(file); + if (fd < 0) { + ksft_print_msg("fileno() failed (%s)\n", strerror(errno)); + } } =20 fn(fd, pagesize); -close: - fclose(file); + + if (file) + fclose(file); } =20 static void run_with_local_tmpfile(test_fn fn, const char *desc) @@ -295,22 +334,22 @@ static void run_with_local_tmpfile(test_fn fn, const = char *desc) char filename[] =3D __FILE__"_tmpfile_XXXXXX"; int fd; =20 - ksft_print_msg("[RUN] %s ... with local tmpfile\n", desc); + log_test_start("%s ... with local tmpfile", desc); =20 fd =3D mkstemp(filename); - if (fd < 0) { - ksft_test_result_fail("mkstemp() failed (%s)\n", strerror(errno)); - return; - } + if (fd < 0) + ksft_print_msg("mkstemp() failed (%s)\n", strerror(errno)); =20 if (unlink(filename)) { - ksft_test_result_fail("unlink() failed (%s)\n", strerror(errno)); - goto close; + ksft_print_msg("unlink() failed (%s)\n", strerror(errno)); + close(fd); + fd =3D -1; } =20 fn(fd, pagesize); -close: - close(fd); + + if (fd >=3D 0) + close(fd); } =20 static void run_with_memfd_hugetlb(test_fn fn, const char *desc, @@ -319,15 +358,14 @@ static void run_with_memfd_hugetlb(test_fn fn, const = char *desc, int flags =3D MFD_HUGETLB; int fd; =20 - ksft_print_msg("[RUN] %s ... with memfd hugetlb (%zu kB)\n", desc, + log_test_start("%s ... with memfd hugetlb (%zu kB)", desc, hugetlbsize / 1024); =20 flags |=3D __builtin_ctzll(hugetlbsize) << MFD_HUGE_SHIFT; =20 fd =3D memfd_create("test", flags); if (fd < 0) { - ksft_test_result_skip("memfd_create() failed (%s)\n", strerror(errno)); - return; + ksft_print_msg("memfd_create() failed (%s)\n", strerror(errno)); } =20 fn(fd, hugetlbsize); --=20 2.39.5