From patchwork Thu Apr 6 16:19:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 670911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3EAEBC76196 for ; Thu, 6 Apr 2023 16:19:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238657AbjDFQTs (ORCPT ); Thu, 6 Apr 2023 12:19:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239409AbjDFQTr (ORCPT ); Thu, 6 Apr 2023 12:19:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7A526B2; Thu, 6 Apr 2023 09:19:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 672CB63E6A; Thu, 6 Apr 2023 16:19:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B02FC433A1; Thu, 6 Apr 2023 16:19:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680797985; bh=hamVzMz9fjIydQKzWnoxc8ljm2X/SGTmnnWMknPU8qo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=L/eHlr/0i1MzCIAN1gHxc/YruWy3HG/FCt5fT8+ediYZVUMjiy/ecDx3D3dAkjtnJ hOkNU1KOAW24YeiYfm+qrEdwMkuNxVoKL0ZSBn8VHjb4vE7o8WNLJIGJ4gSYVGhvLa 6ip7Rt8HWIkeMcOT2aVm0/5ZhxNqqW+gJo9o/lwIKwahWAD00jPZPfBCnZyFukutdt fyRDHY+JIrRwXEXH5P6R1sb4D4NFNQ+/L8DtVX/ui9faJmwETABC3pEBVL9KJoNXdM krGbIoMTE0yXG5fCZn97ywZ76FkoHdCMqzo1Q2DfmC0LdcGwR9eX4IvcwvfJDxD4K2 IjKqX6Hiee6Rw== From: Mark Brown Date: Thu, 06 Apr 2023 17:19:10 +0100 Subject: [PATCH v2 1/3] tools/nolibc/stdio: Implement vprintf() MIME-Version: 1.0 Message-Id: <20230405-kselftest-nolibc-v2-1-2ac2495814b5@kernel.org> References: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> In-Reply-To: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> To: Shuah Khan , Catalin Marinas , Will Deacon , "Paul E. McKenney" , Willy Tarreau Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=867; i=broonie@kernel.org; h=from:subject:message-id; bh=hamVzMz9fjIydQKzWnoxc8ljm2X/SGTmnnWMknPU8qo=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLvEb/1QElH3jcf6mGR0Yr87YFxIWpB05FFQCPzUj d6UsAiOJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7xGwAKCRAk1otyXVSH0E9VB/ 42fwyW20SjTj5Mg8Kks8LM/BQ3Rju1MQCEqx/puiJcz9ORzkHriIPJwp9O38Cij4AjZrb1JKVrSFi+ q8sePpQWXhEVu0NSjFJEg4ASrufsht6yNYSKLzeYS9GfOrHdWAa/46bRqWcp6Cay6qHtahrgfHXcV5 Lm0yyFGNzR8BikcOeAfljY3fydwpW08lyuHf1ig1EvBiDBsnoq+GxFm3URSgxvpKJ5laouaoV/c1zb RqnxACr9T90ChkaB/Y5L11TBfBMGDemXGsDvqwSrn3exOuFkP7+n0o9Puiraf+zbBwWc+tcybdgnwV 3QBfbxocQdxADvPwS9xH9Ace4PvXfZ X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org vprintf() is equivalent to vfprintf() to stdout so implement it as a simple wrapper for the existing vfprintf(), allowing us to build kselftest.h. Suggested-by: Willy Tarreau Signed-off-by: Mark Brown Acked-by: Willy Tarreau Acked-by: Shuah Khan --- tools/include/nolibc/stdio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/include/nolibc/stdio.h b/tools/include/nolibc/stdio.h index 96ac8afc5aee..6cbbb52836a0 100644 --- a/tools/include/nolibc/stdio.h +++ b/tools/include/nolibc/stdio.h @@ -273,6 +273,12 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) return written; } +static __attribute__((unused)) +int vprintf(const char *fmt, va_list args) +{ + return vfprintf(stdout, fmt, args); +} + static __attribute__((unused, format(printf, 2, 3))) int fprintf(FILE *stream, const char *fmt, ...) { From patchwork Thu Apr 6 16:19:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 672217 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20331C76196 for ; Thu, 6 Apr 2023 16:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229674AbjDFQUB (ORCPT ); Thu, 6 Apr 2023 12:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239465AbjDFQTt (ORCPT ); Thu, 6 Apr 2023 12:19:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20DC1900C; Thu, 6 Apr 2023 09:19:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AC43664768; Thu, 6 Apr 2023 16:19:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AD67C433A0; Thu, 6 Apr 2023 16:19:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680797988; bh=++zNwcSvxuvcUruv0Gya29HZho1aCqvr9WTM7oScMPk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=KHX9RlDeOcOSZPjOEdA39fogBMLXNJUCWUwoeXThX1YV9iAO+6fchFnoB/LoP8WwI w+0tbpzOa5q2/lBrCIaBlI87IJ+3/vcf/h9gGAxsKUepkSy691HM+vckt7ZkKICgxW 03K9RpGL3JEsZG54jXV+E1pxZfCSJwcRKJoC06SYPa2re3c2C61IBK8GbZEwgXeO0m sU0CrQTC7D/jbA43E1zD35szpsQaKuRKH+sex0fUENsp0yaO3YTaB14T+a7YBe9g63 w+S1VoPkwF9LY0PizFIEA4RgkLyDLxnik2Q1Chpk2XGCufWvzDfhMtAd1AuekTDBJn AGkSvq8q7E8KA== From: Mark Brown Date: Thu, 06 Apr 2023 17:19:11 +0100 Subject: [PATCH v2 2/3] kselftest: Support nolibc MIME-Version: 1.0 Message-Id: <20230405-kselftest-nolibc-v2-2-2ac2495814b5@kernel.org> References: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> In-Reply-To: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> To: Shuah Khan , Catalin Marinas , Will Deacon , "Paul E. McKenney" , Willy Tarreau Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=1350; i=broonie@kernel.org; h=from:subject:message-id; bh=++zNwcSvxuvcUruv0Gya29HZho1aCqvr9WTM7oScMPk=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLvEbGBPMa+8eLFOunlnQO2Bnog/OzyRVZ8UQpN5/ cpoY/2CJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7xGwAKCRAk1otyXVSH0A6WB/ 95MDc2pK0/NSwOlf16ZLbXjyO1/x6E8GByQsIfG/binvjX22FR0u8nWSBDyo63QrXGXH8LgGnpG/dX iLs7g3al8Sg/EZKYhaDKelNiyEXjBmwp81lbdGUM/C+dS0a5Qhrg1SUo5sF0VgLoQs4tyAEJdb6d+N keUQZ5kKSjlfjpqKtX8JS71GF3ayw6MWD5T2OuvUHG2KT1XY5BPjQ7o7eiEsFJ2SI1oZBKnyyHOgzd bsXE89JxwbQIKULckk9wX0qEbX7kVHSpffbGHuxGxtihh126yHgG0njGnRC60W/gJ6bNZtjOM/cxnW bq0o1cqUpBow8nCFce74tvFQhztkI0 X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Rather than providing headers for inclusion which replace any offered by the system nolibc is provided in the form of a header which should be added to the build via the compiler command line. In order to build with nolibc we need to not include the standard C headers, especially not stdio.h where the definitions of stdout, stdin and stderr will actively conflict with nolibc. Add an include guard which suppresses the inclusion of the standard headers when building with nolibc, allowing us to build tests using the nolibc headers. This allows us to avoid open coding of KTAP output for selftests that need to use nolibc in order to test interfaces that are controlled by libc. Signed-off-by: Mark Brown --- tools/testing/selftests/kselftest.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h index 33a0dbd26bd3..829be379545a 100644 --- a/tools/testing/selftests/kselftest.h +++ b/tools/testing/selftests/kselftest.h @@ -43,11 +43,13 @@ #ifndef __KSELFTEST_H #define __KSELFTEST_H +#ifndef NOLIBC #include #include #include #include #include +#endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) From patchwork Thu Apr 6 16:19:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Brown X-Patchwork-Id: 670910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3264C7618D for ; Thu, 6 Apr 2023 16:20:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238965AbjDFQUC (ORCPT ); Thu, 6 Apr 2023 12:20:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239389AbjDFQTw (ORCPT ); Thu, 6 Apr 2023 12:19:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50F04A5FC; Thu, 6 Apr 2023 09:19:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E17F7646C0; Thu, 6 Apr 2023 16:19:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87717C433A1; Thu, 6 Apr 2023 16:19:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1680797990; bh=ctRu6msB5JIznj81GZbzXgzXuTcVzlGA+tngyr+H/mY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IQiOC/CVGkURNDZxkl6qkU9IxAW8eP7cygxchHZtokf9sk1y+nCYSDmBbTIIidnSl E3PWrXYqJ6rNq38HFsgHye9e6RwC/m9xaFCiN9Dymv/fXvULl/KXBs+y7yPh2kqRgk I6SavtSMeonbekE95u1OwCHPYLt4/MxU3ClTG7QGcuc+mjaKGQLv3Vw7x+OMHp7Adx eEedezFwI8J/nrHB/aFBRPsepu+lfiDJ1MlqRMHKf5kVtk0nScJC1oPVHFluAORPLk w+uUAoL1iRgrj/sY+YfV9d77e0Lf1LBIsCnFYLwLvSbY9fNVD9eBqC2AQiN/8O1EOd 4/vGKZOiydaDw== From: Mark Brown Date: Thu, 06 Apr 2023 17:19:12 +0100 Subject: [PATCH v2 3/3] kselftest/arm64: Convert za-fork to use kselftest.h MIME-Version: 1.0 Message-Id: <20230405-kselftest-nolibc-v2-3-2ac2495814b5@kernel.org> References: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> In-Reply-To: <20230405-kselftest-nolibc-v2-0-2ac2495814b5@kernel.org> To: Shuah Khan , Catalin Marinas , Will Deacon , "Paul E. McKenney" , Willy Tarreau Cc: linux-arm-kernel@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mark Brown X-Mailer: b4 0.13-dev-00303 X-Developer-Signature: v=1; a=openpgp-sha256; l=5208; i=broonie@kernel.org; h=from:subject:message-id; bh=ctRu6msB5JIznj81GZbzXgzXuTcVzlGA+tngyr+H/mY=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBkLvEcPx4jvnr6eH3Ki5gJOKHiqY6kQBLF6woV6R/o jcbn0XqJATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCZC7xHAAKCRAk1otyXVSH0PtHCA CFIedgHsIXCFtN3YaBooWd9OIblsqU/PA6X1PGQo303pnCgLAUAm/Jb10Po1IfYw6BmlfMD9obEmzU K6WJErNWqq7+hypTP67Wp14yXE+2msQJ2QXbQ1T8890upnKrN+NxBpW444RXRGrn0ZzZxEiGleWksi 6hLdvM0ZhqfmbNrBBAFT1Zd7gytZQ0RXKGYgSXz2m8zqCOm3AwgR/S3+kRwJgSxOwde1PRC/bx+me4 b0i9G1syu+YX0v4vKDSuI/Goq/hzOQokTUBk2jjZm62n8KbZBH8R3CbsFMjye4qRs0Qu88kldAC5FR dTs7RxqLFWPP8o4wMhvRngqzsyOWfY X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Now that kselftest.h can be used with nolibc convert the za-fork test to use it. We do still have to open code ksft_print_msg() but that's not the end of the world. Some of the advantage comes from using printf() which we could have been using already. This does change the output when tests are skipped, bringing it in line with the standard kselftest output by removing the test name - we move from ok 0 skipped to ok 1 # SKIP fork_test The old output was not following KTAP format for skips, and the numbering was not standard or consistent with the reported plan. Signed-off-by: Mark Brown --- tools/testing/selftests/arm64/fp/Makefile | 2 +- tools/testing/selftests/arm64/fp/za-fork.c | 88 ++++++------------------------ 2 files changed, 17 insertions(+), 73 deletions(-) diff --git a/tools/testing/selftests/arm64/fp/Makefile b/tools/testing/selftests/arm64/fp/Makefile index 48f56c86ad45..b413b0af07f9 100644 --- a/tools/testing/selftests/arm64/fp/Makefile +++ b/tools/testing/selftests/arm64/fp/Makefile @@ -38,7 +38,7 @@ $(OUTPUT)/vec-syscfg: vec-syscfg.c $(OUTPUT)/rdvl.o $(OUTPUT)/vlset: vlset.c $(OUTPUT)/za-fork: za-fork.c $(OUTPUT)/za-fork-asm.o $(CC) -fno-asynchronous-unwind-tables -fno-ident -s -Os -nostdlib \ - -include ../../../../include/nolibc/nolibc.h \ + -include ../../../../include/nolibc/nolibc.h -I../..\ -static -ffreestanding -Wall $^ -o $@ $(OUTPUT)/za-ptrace: za-ptrace.c $(OUTPUT)/za-test: za-test.S $(OUTPUT)/asm-utils.o diff --git a/tools/testing/selftests/arm64/fp/za-fork.c b/tools/testing/selftests/arm64/fp/za-fork.c index ff475c649e96..b86cb1049497 100644 --- a/tools/testing/selftests/arm64/fp/za-fork.c +++ b/tools/testing/selftests/arm64/fp/za-fork.c @@ -9,42 +9,9 @@ #include #include -#define EXPECTED_TESTS 1 - -static void putstr(const char *str) -{ - write(1, str, strlen(str)); -} - -static void putnum(unsigned int num) -{ - char c; - - if (num / 10) - putnum(num / 10); - - c = '0' + (num % 10); - write(1, &c, 1); -} +#include "kselftest.h" -static int tests_run; -static int tests_passed; -static int tests_failed; -static int tests_skipped; - -static void print_summary(void) -{ - if (tests_passed + tests_failed + tests_skipped != EXPECTED_TESTS) - putstr("# UNEXPECTED TEST COUNT: "); - - putstr("# Totals: pass:"); - putnum(tests_passed); - putstr(" fail:"); - putnum(tests_failed); - putstr(" xfail:0 xpass:0 skip:"); - putnum(tests_skipped); - putstr(" error:0\n"); -} +#define EXPECTED_TESTS 1 int fork_test(void); int verify_fork(void); @@ -63,22 +30,21 @@ int fork_test_c(void) if (newpid == 0) { /* In child */ if (!verify_fork()) { - putstr("# ZA state invalid in child\n"); + ksft_print_msg("ZA state invalid in child\n"); exit(0); } else { exit(1); } } if (newpid < 0) { - putstr("# fork() failed: -"); - putnum(-newpid); - putstr("\n"); + ksft_print_msg("fork() failed: %d\n", newpid); + return 0; } parent_result = verify_fork(); if (!parent_result) - putstr("# ZA state invalid in parent\n"); + ksft_print_msg("ZA state invalid in parent\n"); for (;;) { waiting = waitpid(newpid, &child_status, 0); @@ -86,18 +52,16 @@ int fork_test_c(void) if (waiting < 0) { if (errno == EINTR) continue; - putstr("# waitpid() failed: "); - putnum(errno); - putstr("\n"); + ksft_print_msg("waitpid() failed: %d\n", errno); return 0; } if (waiting != newpid) { - putstr("# waitpid() returned wrong PID\n"); + ksft_print_msg("waitpid() returned wrong PID\n"); return 0; } if (!WIFEXITED(child_status)) { - putstr("# child did not exit\n"); + ksft_print_msg("child did not exit\n"); return 0; } @@ -105,29 +69,14 @@ int fork_test_c(void) } } -#define run_test(name) \ - if (name()) { \ - tests_passed++; \ - } else { \ - tests_failed++; \ - putstr("not "); \ - } \ - putstr("ok "); \ - putnum(++tests_run); \ - putstr(" " #name "\n"); - int main(int argc, char **argv) { int ret, i; - putstr("TAP version 13\n"); - putstr("1.."); - putnum(EXPECTED_TESTS); - putstr("\n"); + ksft_print_header(); + ksft_set_plan(EXPECTED_TESTS); - putstr("# PID: "); - putnum(getpid()); - putstr("\n"); + ksft_print_msg("PID: %d\n", getpid()); /* * This test is run with nolibc which doesn't support hwcap and @@ -136,21 +85,16 @@ int main(int argc, char **argv) */ ret = open("/proc/sys/abi/sme_default_vector_length", O_RDONLY, 0); if (ret >= 0) { - run_test(fork_test); + ksft_test_result(fork_test(), "fork_test"); } else { - putstr("# SME support not present\n"); - + ksft_print_msg("SME not supported\n"); for (i = 0; i < EXPECTED_TESTS; i++) { - putstr("ok "); - putnum(i); - putstr(" skipped\n"); + ksft_test_result_skip("fork_test\n"); } - - tests_skipped += EXPECTED_TESTS; } - print_summary(); + ksft_finished(); return 0; }