From patchwork Mon Feb 17 10:59:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977596 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A7947217716; Mon, 17 Feb 2025 11:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790039; cv=none; b=jIoEpQAP3HJDOPBUhOesyHnlHypyzJpMH+glHswg8eSsy7OAztJkOiHFiCMaj/oBW8Hek5+abPd+nmWIoFVUowI0VHtSEZwFsAa2xSWAC6WEnd/g+VlLcuhn3o8+TBK+/ktcIxugZH1K2qStFV/rVojtRx1+DDc9LzdCggQiX+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790039; c=relaxed/simple; bh=1eJaz8tcbhUuEkRn5XBcnGfKRMXHc58fjTtiPznAV8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RtvRAO16/T+uoBkRQg/tZspmNT3Y+1qQjchQGXY3Q2/GtqZsP7Xad8P7FwxEZ6YVL1By/AZvwh/nZIxFt6u/V/7Vaadio2NBJmRoNOkhA95qacRMUtGRHxvUDOznl8/+AGPrslSVh42IureJGufIRAcYi56VEtjgScOmcILtubI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=FVZxORj/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nAO4g1Rk; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="FVZxORj/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nAO4g1Rk" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gvsyEkTJZdl7d2gno8A3VI/QC8RYoPkLuhmYx+KvTqY=; b=FVZxORj/uTMmrkQMCreUB30ZVjbRynx1FL6ZsBFWpMaqwWPbm6w3KtlSCLRcOJk9NRHfmN 5EE31keem3dX1UaT71Q3RHxeATk2xJfnsE3WuSIGfdkEg3VpXeRGO/p69Wie0SmyjayAAA wU86BXB7Axn7qc2HF3dGag9EjgFEVNvevsRjrFh/q/6O4Hj3xabZn9Vji3i67krBWGmTsu qSlNHnsIdzjVRxkqa8+wdfpZHAus1er+xOQsJC9dwO2JU4ojELbq6wYCW9Lf8IyXlIEAh9 U/v+S/qNQFjLST8laYzkNeR44GFB31EvFSPcCRT+RcXCj4+7CFNYbJwMFawJ2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gvsyEkTJZdl7d2gno8A3VI/QC8RYoPkLuhmYx+KvTqY=; b=nAO4g1RkEz+HslqPucvDyPkYlL1WttU8zh/KpfzPUwoUYbYgO7FrZpkP1bWpgglaBTnyuH XnTwA6FRGFpxgpAw== Date: Mon, 17 Feb 2025 11:59:21 +0100 Subject: [PATCH 01/12] kconfig: implement CONFIG_HEADERS_INSTALL for Usermode Linux Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-1-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=1658; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=1eJaz8tcbhUuEkRn5XBcnGfKRMXHc58fjTtiPznAV8Y=; b=7fXsYl7gDcHgQEPAqhLIu66XKFSSaF7nv8fekpa46pGteZF+TJ/yIfM+WSmpIwfmEZtTSu2IH igakxQE/i5pCghDA2ea6d5Wwuja2iSpMdQohVDC1o9TaAOG7dgX71hZ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= userprogs sometimes need access to UAPI headers. This is currently not possible for Usermode Linux, as UM is only a pseudo architecture built on top of a regular architecture and does not have its own UAPI. Instead use the UAPI headers from the underlying regular architecture. Signed-off-by: Thomas Weißschuh --- Makefile | 5 ++++- lib/Kconfig.debug | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index b4c208ae4041c1f4e32c2a158322422ce7353d06..275185d2ff5d3dc99bd7982abd1de85af0b9621a 100644 --- a/Makefile +++ b/Makefile @@ -1357,9 +1357,12 @@ hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj PHONY += headers headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts - $(if $(filter um, $(SRCARCH)), $(error Headers not exportable for UML)) +ifdef HEADER_ARCH + $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers +else $(Q)$(MAKE) $(hdr-inst)=include/uapi $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi +endif ifdef CONFIG_HEADERS_INSTALL prepare: headers diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index 1af972a92d06f6e3f7beec4bd086c00b412c83ac..60026c8388db82c0055ccd8b8ac8789d6b939b62 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -473,7 +473,6 @@ config READABLE_ASM config HEADERS_INSTALL bool "Install uapi headers to usr/include" - depends on !UML help This option will install uapi headers (headers exported to user-space) into the usr/include directory for use during the kernel build. From patchwork Mon Feb 17 10:59:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977598 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 37263217F35; Mon, 17 Feb 2025 11:00:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790039; cv=none; b=XZSyNVbBW7ExSkx4HOwC4cwfAqc0pZfhtE3VrscJFjbNSF4N0P5TvgqKNydtuZA6AmvrV73TkxEKO9vxHnE6Ziu+X7uLyOk0KkyRkt/YzSc4exTIJA/PBONEHRPXQXl2zL3wR4hqLYpCLuT14OAyvdO5UuNrk5x6EpIqE5StCcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790039; c=relaxed/simple; bh=vHbfeta7IxciYW4Gk1YYlAClVvaYyP5NoHWOvnhRaSo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LjOq9UQEOA4gau6OhEWaDZ+wl+Mfuow8Fcbtxf9262PyyIubHNTM2x9sbAqFFZHM4jJQESl5kMCCiiNy/jLXc80b3PoXfG8t0rgLYizW9VkcxUQ1gCrb/oSP2BC+Xzv0OmzDuv7mbDWn/hGnCy4jgNXfwmHAY0EbSI6T/8P36Pc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hFwqtFfW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sBAv6n/s; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hFwqtFfW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sBAv6n/s" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ckM1+WXE+7gs1LersRHMnMHDoWMSArmyGjQ9a5ribjA=; b=hFwqtFfWJlY2KZmNcWtfC8wUvTcrAKzs+3l9wK6Kgow1NNvcMIJ/583LxTPiKM25ylwQkA 8F+HJzCHk6vIcEcIXt8YOzq9Q9FMjVtiwldg9rCvKdXSOYJGJFltDkVi3OuExBa3fXtwy4 wTfn1dAFueTpHg5pPqGk743fRxSuy59fCnmCvzQ8KWNt7t+gjMv9ktIocpeMj88q0yxRmM PUAiydWIj3qpG1J1d5Q+0TGgYm0ppvBD7aRMkhJhI/vZOrTxuUY44mub2QKJHUKweGyilm u4F/8Tsh3v1ehu+n+28BGlQh+oAAkL+r2S7yzNmVlOuQB5Xha/mJyILXvwXfVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ckM1+WXE+7gs1LersRHMnMHDoWMSArmyGjQ9a5ribjA=; b=sBAv6n/skv+Ld2LQo+R32eLiWcf/Nqp4D4q5MXB44BiT6/GDkgxWEXhsiQXmRn1okM3y51 /zMOTSZwym3A7wBg== Date: Mon, 17 Feb 2025 11:59:22 +0100 Subject: [PATCH 02/12] kconfig: introduce CONFIG_ARCH_HAS_NOLIBC Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-2-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=1938; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=vHbfeta7IxciYW4Gk1YYlAClVvaYyP5NoHWOvnhRaSo=; b=TYupduN4jqDaLPgynjWEwIt+VNHnPl47OPAiGp3TQhDqymup3oDcXXNFc47o8KeDZHof4n0mF Mzwecc/lc5nA7CsVubD7N5RdvPCDozJMyHkd8UFFwS9ACJe9O+93cO3 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Nolibc does not support all architectures. Add a kconfig option, so users can know where it is available. The new option is maintained inside tools/include/nolibc/ as only that directory is responsible for nolibc's availability. Signed-off-by: Thomas Weißschuh --- init/Kconfig | 2 ++ tools/include/nolibc/Kconfig.nolibc | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index d0d021b3fa3b3da5576421b4e1c63baf6c8afc09..794c9516d461ef7a3c5d399d982d3031199f0442 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -92,6 +92,8 @@ config CC_CAN_LINK_STATIC default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag) -static) if 64BIT default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag) -static) +source "tools/include/nolibc/Kconfig.nolibc" + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113921 config GCC_ASM_GOTO_OUTPUT_BROKEN diff --git a/tools/include/nolibc/Kconfig.nolibc b/tools/include/nolibc/Kconfig.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..a29825869d9b49a5502ae32d265b6f9c076f5713 --- /dev/null +++ b/tools/include/nolibc/Kconfig.nolibc @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0 + +config ARCH_HAS_NOLIBC + def_bool n + help + Enabled if nolibc supports the current kernel architecture + +config ENABLE_ARCH_HAS_NOLIBC + def_bool y + select ARCH_HAS_NOLIBC if X86 + select ARCH_HAS_NOLIBC if ARM + select ARCH_HAS_NOLIBC if ARM64 + select ARCH_HAS_NOLIBC if PPC + select ARCH_HAS_NOLIBC if MIPS + select ARCH_HAS_NOLIBC if LOONGARCH + select ARCH_HAS_NOLIBC if RISCV + select ARCH_HAS_NOLIBC if S390 + select ARCH_HAS_NOLIBC if UML && UML_X86 From patchwork Mon Feb 17 10:59:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977599 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 BBF048BE8; Mon, 17 Feb 2025 11:00:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790040; cv=none; b=nZYl6x8mFroO4ICAM2Lmcz3wSUZSFJUMn0gGF0EBFFWPelxAY9b5Fq8MrH671ZYo+KZRO3ft8t/xU3YgpDa8SjVYuBv3CravXug6qwEO+d5Sf65uhHRCrNtS4NkhbgX6cxHqD9a4LNfPPJg7l3JEl/SBUDR3f+zR14Pbk+G7ySE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790040; c=relaxed/simple; bh=rAGgEZdn3WzkyARocDN45a3nXlF+LE9psWomiX3VZbM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q1kIVvMEAJKkShfbIPZl/XOJVaPjH4hX9NRD/eP8F+yxuwNt+zEgW8xQdeHtF8MVDxOoE5zdEPJ2VBzuBZIdm5gx+Uw/+b2cZKKMgeNHVSPpqaD9puKsMNNVMlcW4wtMg3qux6ZhdtJ8qEyZqazNYatvpET7B0IWxYEgHUDRIEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=q79gzYY7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=8IQrGUkI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="q79gzYY7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="8IQrGUkI" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r0KmdHXYAy6wfYle32Vznj1iqwKW38Fdm5LWbDAU9Ds=; b=q79gzYY7H5aQENDnuljxzAOcUW5Bq8UVdCGZlKgS3hvcR/EAz1cG4cJyBBi9aVabOgxQwG ZFJhA2l5oFpEEywIiKgMy1z4hd2UvM+Jo4J3alJiRth0lm/71WuAmHxaPYCcLLuxDoh+0R YFmX1dw9MVjaBJjPGpRmI0sncvtzBPMmklxFvkpNHnXUW5eTMPQVYnBkaU5MxftuEMSq9G rBU5YgiTsTZHmalI5d3c/y3Gp71CAHvu7LWyUV+ICnhYXzz/Kv7bBp58FU28l130BGTEAf 9/n7WxQJm3esT6fE17aXiz1bTOc49s1piqH1p1ViNqoDleJ40hwAXCB7iqXDLw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=r0KmdHXYAy6wfYle32Vznj1iqwKW38Fdm5LWbDAU9Ds=; b=8IQrGUkIUlNndjucwoA1Kbokjbm6nYIGigjozCDlGkIINASF1wIsySLabRVAH4G3UGY7l/ e2Kt8YiLXilwcvBg== Date: Mon, 17 Feb 2025 11:59:23 +0100 Subject: [PATCH 03/12] kbuild: userprogs: respect CONFIG_WERROR Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-3-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=918; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=rAGgEZdn3WzkyARocDN45a3nXlF+LE9psWomiX3VZbM=; b=iCG1DkYz8U7H0zYtB6qsp2O8JjkNFY3/h1Ef41Q1I0Pro/fkc59gYfmIgBKDXUNW/I2EM5jsg vK/dr57TgQfCM0IaRLVkcZhz5Sw1a/J1AA1lLozmVJmoUUF2mL5jtlW X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Reuse the general CONFIG_WERROR to also apply to userprogs. Signed-off-by: Thomas Weißschuh --- scripts/Makefile.userprogs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/Makefile.userprogs b/scripts/Makefile.userprogs index f3a7e1ef3753b54303718fae97f4b3c9d4eac07c..debbf083bcfa01c89c204a322a1b17e2bdbe95a1 100644 --- a/scripts/Makefile.userprogs +++ b/scripts/Makefile.userprogs @@ -21,6 +21,10 @@ user_ccflags = -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \ user_ldflags = $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags) user_ldlibs = $(userldlibs) $($(target-stem)-userldlibs) +ifdef CONFIG_WERROR +KBUILD_USERCFLAGS += -Werror +endif + # Create an executable from a single .c file quiet_cmd_user_cc_c = CC [U] $@ cmd_user_cc_c = $(CC) $(user_ccflags) $(user_ldflags) -o $@ $< \ From patchwork Mon Feb 17 10:59:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977600 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 5B93F21858A; Mon, 17 Feb 2025 11:00:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790041; cv=none; b=aYNd2HWG1C4CMviRgpSjPrJR3XVVabGj4hxOO+7wLe48bkNbr1pQDo3T5jGOaDf0u2RhsvQviQvtbNKtmysZuRv6q3aVVLWzBs0RkNN7qMt7PtVVtZbtDL70PQK/tzSuaQDT9zWxsrgAKssCOG1RZwQU1VDXqNQF5kdgz5dU9A4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790041; c=relaxed/simple; bh=HWe5DWDc72q/BUdcqdWY+r3rAD8bWdOAs1/PuV4Pfm0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=UZN8NHPfV5ArzrBKwmoHlKjMJkf8y1pIhuH5vS2tilnqkD7EEzUfbzQ/R2daBYs5A9oWlfce6hYHwrwWil7yglH8H0dqfBTB49hTd2cX0UmQjZcqCE2uh7/BVcWkOD3d/DdORJcarRvHiujS1Se11DcVW/TPfCVJQDsWbFVUjnI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zSkADrC5; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=6gweMfS6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zSkADrC5"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="6gweMfS6" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B3mOz7h/METJtenXacdJtpoIbaKepOmdU2Mg3BGzeKc=; b=zSkADrC5IegnOX7SsPv69/QD6W6GOarq3AZlGer2Qv1/IxrTtAGj2tHYBeO6AoL8R52hwu v1pKuK4TXPwDc6b42hUCnztyomq1HFMCAXvRO5bVhyHSvETW7JOwi8SDSyyYmuPiXmKiI8 vVY6BbZbTxpCAGg1cIdbRoDkRtYwjmqFilm+V3q73t1MfY3l0VIpmkaOW8ysxR4ks17WuB Ix37y36ExVBWoHFAL3K6SDPMVtAuemIM5NrZw6X1WMQssSByCBtLqbbXoOudIc9Uwq3GFx MwZcY1FiIP8RBc1bfmCtdOY96UjDvQ+T9pxTR8at6qj3jrEUZIxgd+A2/Jtseg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B3mOz7h/METJtenXacdJtpoIbaKepOmdU2Mg3BGzeKc=; b=6gweMfS6ZDrqvYxW6P8kn4DX8lRS85SUqJxdBpaUapk4rbYjuI/Wlm1NY3BR05bAsJEHZZ xziR9bz1jt/IYNCA== Date: Mon, 17 Feb 2025 11:59:24 +0100 Subject: [PATCH 04/12] kbuild: userprogs: add nolibc support Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-4-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=3223; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=HWe5DWDc72q/BUdcqdWY+r3rAD8bWdOAs1/PuV4Pfm0=; b=j5buKJ4rrEz2ldxRKjQ4EpttQPLf4EfeYRomTllmD/oqWMo/iVu0yTAc2Tf5lDPH8vBmMsjnS qzB/K2tGoJbA6hjQS2M1Crs3OrfPQM77o1deNu9AecBT5pNvHEKXahl X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Userprogs are built with the regular kernel compiler $CC. A kernel compiler does not necessarily contain a libc which is required for a normal userspace application. However the kernel tree does contain a minimal libc implementation "nolibc" which can be used to build userspace applications. Introduce support to build userprogs against nolibc instead of the default C of the compiler, which may not exist. Signed-off-by: Thomas Weißschuh --- This could probably be moved out of the generic kbuild makefiles. I think the ergonimics would suffer and this functionality could be used by other users of userprogs. --- Documentation/kbuild/makefiles.rst | 12 ++++++++++++ scripts/Makefile.userprogs | 14 +++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index d36519f194dc0d18b72a6f3ce7f3649f7c1b5637..cb859dc58b579def4995a5aa2efb45ab4ba3c93f 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -959,6 +959,18 @@ When linking bpfilter_umh, it will be passed the extra option -static. From command line, :ref:`USERCFLAGS and USERLDFLAGS ` will also be used. +Bulding userprogs against nolibc +-------------------------------- + +Not all kernel toolchains provide a libc. +Simple userprogs can be built against a very simple libc call "nolibc" provided +by the kernel source tree. + +Example:: + + # lib/kunit/Makefile + uapi-preinit-nolibc := $(CONFIG_ARCH_HAS_NOLIBC) + When userspace programs are actually built ------------------------------------------ diff --git a/scripts/Makefile.userprogs b/scripts/Makefile.userprogs index debbf083bcfa01c89c204a322a1b17e2bdbe95a1..e94f3f2250f531dadbe00f5f5ee6f780bee22487 100644 --- a/scripts/Makefile.userprogs +++ b/scripts/Makefile.userprogs @@ -16,10 +16,18 @@ user-csingle := $(addprefix $(obj)/, $(user-csingle)) user-cmulti := $(addprefix $(obj)/, $(user-cmulti)) user-cobjs := $(addprefix $(obj)/, $(user-cobjs)) +user_nolibc_ccflags := -nostdlib -nostdinc -static -fno-ident -fno-asynchronous-unwind-tables \ + -ffreestanding $(call cc-option,-mstack-protector-guard=global) \ + -isystem $(objtree)/usr/include -include $(srctree)/tools/include/nolibc/nolibc.h -isystem $(srctree)/tools/include/nolibc/ +user_nolibc_ldflags := -nostdlib -nostdinc -static +user_nolibc_ldlibs := $(call cc-option,-lgcc) + user_ccflags = -Wp,-MMD,$(depfile) $(KBUILD_USERCFLAGS) $(userccflags) \ - $($(target-stem)-userccflags) -user_ldflags = $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags) -user_ldlibs = $(userldlibs) $($(target-stem)-userldlibs) + $($(target-stem)-userccflags) $(if $($(target-stem)-nolibc),$(user_nolibc_ccflags)) +user_ldflags = $(KBUILD_USERLDFLAGS) $(userldflags) $($(target-stem)-userldflags) \ + $(if $($(target-stem)-nolibc),$(user_nolibc_ldflags)) +user_ldlibs = $(userldlibs) $($(target-stem)-userldlibs) \ + $(if $($(target-stem)-nolibc),$(user_nolibc_ldlibs)) ifdef CONFIG_WERROR KBUILD_USERCFLAGS += -Werror From patchwork Mon Feb 17 10:59:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977601 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 EC672218EA8; Mon, 17 Feb 2025 11:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; cv=none; b=h9cOrm7GmtNJ33pY3JF+scJX7U2ja074WXGLu7+7FqYg2hEGgXmmCVDQv2AV6jfOgOCPR1i62Jl3jm/hsXKIVurPHPpxxUn5q5vBUV9HNi3E9Qr0puymmkVPb5yrO960aEqu2DydlZTMs1dKfZ4SCHtpStBIZ3l80LS3vTStUY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; c=relaxed/simple; bh=CpCkmbMgLBYAXvposf48tXlYf7KsrlXSlYBVTNHhQME=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T8xU5ylDVbwQ0oiyzxW6Rdxs1EMeKF7HB6RLH7ZskD52tJG8U6RxEuQmk0XEiXwH1QItheVutNvtWVoDLWxCgNdEU8G9qMWomddw+Q4WbxVKWaRCa+kMBmCYLDBmku6wbeCfen7mX/TBu06jxjKGCahtfMhV0B86BuO40bIJjO4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gLDHBea2; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sq0417x/; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gLDHBea2"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sq0417x/" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OYMG4AG4faj0loSjPiu926YoV/r7OSKMUw1XHgOOtZk=; b=gLDHBea2ysl3TC+ewqGA5xFrhH9SipjP6LFwmwpbhRVKWHztb+eC91f7Ixn7S862nN3waP M8laN1Ofvc/VbK3MMeBphg2KmC4QrSmqnieQ2cnmDGWr5jLY38IANQGuUJux9op7ew0UUR XmFIk+tAkOC9EsUVe5bO0SJ3SDWOCvICe7PMNBcauz1TVRdcVYZpnUlv3AUPgPuvgVUOfe ptH1cvSoz3L54YnDRd0jQLdqlNeVIBWmzlBwY9p9vJr4H/IV7SfhRoi1lKjPtgPz0SIOdh v3/O4pcFD2Uge5DjfVVLZv4paOC1YlAF/s2/DjFZOxBj2sVS+Uny4UsEevyrig== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OYMG4AG4faj0loSjPiu926YoV/r7OSKMUw1XHgOOtZk=; b=sq0417x/xJvOEkI0o+EEixKYBcDtm6SUNU3ttvCc1Y3iwBhgTLnax9u7OmZEK39vqGH6nI UyPUGXaV0d24s0Bg== Date: Mon, 17 Feb 2025 11:59:25 +0100 Subject: [PATCH 05/12] kbuild: introduce blob framework Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-5-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=4689; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=CpCkmbMgLBYAXvposf48tXlYf7KsrlXSlYBVTNHhQME=; b=tlNTx5n5HmBXjGzUDgzCIRB0T2czuInanv8C4uglwv6pqewahSisRFz5CjKNPGiwZn4vsO6nr mx8gaXotG+5ASt4wWwvy32sQBcHwRifuEbvL9i9UJTmqvOsNDFZ/KK8 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Various subsystems embed non-code build artifacts into the kernel, for example the initramfs, /proc/config.gz, vDSO image, etc. Currently each user has their own implementation for that. Add a common "blob" framework to provide this functionality. It provides standard kbuild and C APIs to embed and later access non-code build artifacts into the kernel image or modules. Signed-off-by: Thomas Weißschuh --- This is currently lacking a MAINTAINERS entry. Due to its closeness to kbuild I would tend to add it there. But I can also maintain it on its own. --- include/linux/blob.h | 21 +++++++++++++++++++++ scripts/Makefile.blobs | 19 +++++++++++++++++++ scripts/Makefile.build | 6 ++++++ scripts/Makefile.clean | 2 +- scripts/blob-wrap.c | 27 +++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) diff --git a/include/linux/blob.h b/include/linux/blob.h new file mode 100644 index 0000000000000000000000000000000000000000..5749c364f7e9c93eb32a6d8870621e3d6df0683c --- /dev/null +++ b/include/linux/blob.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_BLOB_H +#define _LINUX_BLOB_H + +#include +#include + +struct blob { + const char *const path; + const u8 *data; + const u8 __private *end; +}; + +#define DECLARE_BLOB(_symbol) extern const struct blob _symbol + +static inline size_t blob_size(const struct blob *blob) +{ + return ACCESS_PRIVATE(blob, end) - blob->data; +} + +#endif /* _LINUX_BLOB_H */ diff --git a/scripts/Makefile.blobs b/scripts/Makefile.blobs new file mode 100644 index 0000000000000000000000000000000000000000..fd20ebb41c1d6509750debf7896a08a143d28759 --- /dev/null +++ b/scripts/Makefile.blobs @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Build linkable blobs +# + +blobs := $(addprefix $(obj)/, $(blobs)) + +blob-stem = $(subst -,_,$(subst .blob,,$(basename $(patsubst $(obj)/%,%,$@)))) +blob-symbol = $(or $($(target-stem)-symbol),$(blob-stem)) + +blob-flags = -DBLOB_SYMBOL="$(blob-symbol)" -DBLOB_INPUT=$< + +quiet_cmd_blob = BLOB $@ + cmd_blob = $(CC) $(c_flags) $(blob-flags) -c -o $@ $(srctree)/scripts/blob-wrap.c + +$(blobs): $(obj)/%.blob.o: $(obj)/% $(srctree)/scripts/blob-wrap.c FORCE + $(call if_changed_dep,blob) + +targets += $(blobs) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 993708d1187459f3678d68ec81ef005e6f51d470..def9791523d718552617ef6ef752c1852d40d996 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -440,6 +440,12 @@ ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets) include $(srctree)/scripts/Makefile.dtbs endif +# $(sort ...) is used here to remove duplicated words and excessive spaces. +blobs := $(sort $(blobs)) +ifneq ($(blobs),) +include $(srctree)/scripts/Makefile.blobs +endif + # Build # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean index 6ead00ec7313b3e4330a8de5f1342f2da1d6eb84..536972b0a528d117e17296da9936825c3903af6e 100644 --- a/scripts/Makefile.clean +++ b/scripts/Makefile.clean @@ -25,7 +25,7 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn)) # directory __clean-files := \ - $(clean-files) $(targets) $(hostprogs) $(userprogs) \ + $(clean-files) $(targets) $(hostprogs) $(userprogs) $(blobs) \ $(extra-y) $(extra-m) $(extra-) \ $(always-y) $(always-m) $(always-) \ $(hostprogs-always-y) $(hostprogs-always-m) $(hostprogs-always-) \ diff --git a/scripts/blob-wrap.c b/scripts/blob-wrap.c new file mode 100644 index 0000000000000000000000000000000000000000..715d6981fa94bee309c693c2b937899c982e27b4 --- /dev/null +++ b/scripts/blob-wrap.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include +#include +#include + +#define BLOB_SYMBOL_DATA CONCATENATE(_blob_data_, BLOB_SYMBOL) +#define BLOB_SYMBOL_END CONCATENATE(_blob_end_, BLOB_SYMBOL) + +asm ( +" .pushsection .rodata, \"a\" \n" +" .global " __stringify(BLOB_SYMBOL_DATA) " \n" + __stringify(BLOB_SYMBOL_DATA) ": \n" +" .incbin \"" __stringify(BLOB_INPUT) "\" \n" +" .global " __stringify(BLOB_SYMBOL_END) " \n" + __stringify(BLOB_SYMBOL_END) ": \n" +" .popsection \n" +); + +extern const u8 BLOB_SYMBOL_DATA; +extern const u8 BLOB_SYMBOL_END; + +const struct blob BLOB_SYMBOL = { + .path = __stringify(BLOB_INPUT), + .data = &BLOB_SYMBOL_DATA, + .end = &BLOB_SYMBOL_END, +}; From patchwork Mon Feb 17 10:59:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977603 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 6710D218EBA; Mon, 17 Feb 2025 11:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; cv=none; b=ODxboLlDR8feEk4ZNEUfgKQ4pRC0dGJHYrNvc/Ix6sFzCJJBqw20rmfHkGvl9ZlA8d0oFO8qkIXRKJi0cx8ndnIKf2y4LehZig9uv80mtupAolihrq04N4E3yIq9I9VKBuJbSiozeNeXspHN8D9pFLJ8na5ZYRngDQHVbKIHVKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; c=relaxed/simple; bh=uKV9D/kbwA/0w24XM1UIPsvE/argHIoOFRx9p2whBgg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=icNGTEGDp3SuEeq9jWnu2S2Fkco6JN+Y0GZikKNHxy8R+8sTz91/FrRj8voCXKJEW51Zj3B1+4/RNwaRBRDzlzPXi/KoTS+94VRWaO3AJXruWuL6B8WxyDrQDlT9W45iZ33zHbn+ik0JMgYh7SduYe/e7clwHUOgeIsg14tp7JA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k0GsZCca; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=c1V2aLsn; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k0GsZCca"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="c1V2aLsn" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fY3Dlya9onvQQYursAe4ang3UMW+faOqytZ9fehqmJg=; b=k0GsZCcaz215C+ourChEgCyjdgIKXMeo8ECynEQH6g8/NnEneTzgiRy7SghbZbJRjnryns SoBG2FqBVcbMkLa45cGOiwEEoEsQ/tj0Dgn+j62YRpiso4TUgQroHcmiQteJiUrDfpmU8C croYmBLcv/CzE2GowLkfTYim5fHIHs8dzvHEYvU2CwzR0ku3h/TFTckh6myQt4FvjWMoRh jGIZa/Hkdom0uAQxrLD3tfU/eiRRSm0Qa2InIiSo/nhreC/cd7A5//EddalmDMc/QPTrQW XVWfIdOBlIoSecRr+/5FfiqjVbg4Oab0Ukwcn4MOSPsaFh6aUCdHiyAbmlUzMA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790038; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fY3Dlya9onvQQYursAe4ang3UMW+faOqytZ9fehqmJg=; b=c1V2aLsn3710N2XZq0Bm1ImYDJixu+em9+9qaDUd6Bda1VmD/BdDXrY2kK81QajtZxp/tt hdqBoTgAn42Y1UDw== Date: Mon, 17 Feb 2025 11:59:26 +0100 Subject: [PATCH 06/12] kunit: tool: Add test for nested test result reporting Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-6-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=2070; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=uKV9D/kbwA/0w24XM1UIPsvE/argHIoOFRx9p2whBgg=; b=CqSl6E8Ye9PLDXfeE8wknykLcu+PIhCAS/QBUETQmpdCUzOb02DxXMc27kI6BxAW/GGnPX8FA WkhMrs80BBAAGgV147MC0lId4tqHso/iEIvijP3qivtciZ5qG82sDcA X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Currently there is no test validating the result reporting from nested tests. Add one, it will also be used to validate upcoming changes to the nested test parsing. Signed-off-by: Thomas Weißschuh --- tools/testing/kunit/kunit_tool_test.py | 9 +++++++++ .../kunit/test_data/test_is_test_passed-failure-nested.log | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index 0bcb0cc002f8a7c24b119d59b3e996efc953c626..e71ce88682e137676be49ea9854a5ddaff0dc259 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -165,6 +165,15 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) self.assertEqual(result.counts.errors, 0) + def test_parse_failed_nested_tests_log(self): + nested_log = test_data_path('test_is_test_passed-failure-nested.log') + with open(nested_log) as file: + result = kunit_parser.parse_run_tests(file.readlines(), stdout) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) + self.assertEqual(result.counts.failed, 2) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[0].status) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].status) + def test_no_header(self): empty_log = test_data_path('test_is_test_passed-no_tests_run_no_header.log') with open(empty_log) as file: diff --git a/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log new file mode 100644 index 0000000000000000000000000000000000000000..835816e0a07715a514f5f5afab1b6250037feaf4 --- /dev/null +++ b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log @@ -0,0 +1,7 @@ +KTAP version 1 +1..2 +not ok 1 subtest 1 + KTAP version 1 + 1..1 + not ok 1 test 1 +not ok 2 subtest 2 From patchwork Mon Feb 17 10:59:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977605 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 67198218EBD; Mon, 17 Feb 2025 11:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; cv=none; b=PryJ/5kv0580kFOBIUr+AvOjg9/RVWFqE6QdgLTzw+FiZNb4iX8A26dO3K+hL4X/etT+lGyE0TOT9XKsnKE1Baq85gez99R5It9SnwxBdZs/B+GE0V1Ow/sybsjvZU2XuysAeO5czG2XI6BYXP8R4ugjXIHuhlsI4cWNrKoWRYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; c=relaxed/simple; bh=QSToQJrmgzvhx32HA99kjUNyTCDnqIfjc/O6b1byB3M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NNvqV60I5VZN8u/eSVPqvNsa/ic8jZz825wZClZ+QMUlM4dpyjeCPc/VeKJO6v5iTp44YAgVCTfYeICqjfVPrkzIJQ87s+Nm0iz3CcKQkVGEWqx0Nw2Y7b2K/dBbq3zffTqKq1xL9P4ztvFsOGXe5k0rJr0D+c7WzunRRTcW1U4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=mgjg6+C6; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3EThwlS5; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="mgjg6+C6"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3EThwlS5" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+mxFxM2jcpIj0KVa01PU02wcB6HkTDPMz+vQ79lotg=; b=mgjg6+C6CcEYmfehS7JOdY27EvkY3Ygj3nFY672voUoRCn0l1jlF23G+P06Y1EO4gVjNae WHI5JWC0gnG1HcWZAxp0xLOi2S0EqxOHFNiLsaG9mEH7SzUFQPuNY4i8SxrYxa3U+N+1ev gu2jMTA7ftPiNU/MrWzDMv4jEmxhiC7tJFFjHwoNAXGNPX4Ul9RWdVhuIWiuWjtWkefv17 x2idUcqKhGtYl4vhZjD+HIaKtbDzz6lBJKgv2WxtlkgdSKi99vg1NYdSBm9Dg+mRY3JurP NuQUUKC5lcgaODPIs9DsjFrDo/PeK4zbQkWH6wPXxB53Ehe1CL55ZS/HBQ9R1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/+mxFxM2jcpIj0KVa01PU02wcB6HkTDPMz+vQ79lotg=; b=3EThwlS5kt8uRbM9qAs4lq9EklT1ExC+BU9a6ycJR3+APB3TVhNlBQv83VtI6IErud6GWK V17mJ1TKAY2y/sCA== Date: Mon, 17 Feb 2025 11:59:27 +0100 Subject: [PATCH 07/12] kunit: tool: Don't overwrite test status based on subtest counts Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-7-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=2733; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=QSToQJrmgzvhx32HA99kjUNyTCDnqIfjc/O6b1byB3M=; b=x2bbfjpZ1pSrt8YBRroAEOw1vAHGxDyF1NaVgE3cAU3Vq3Jj/+c+NYXvHkD/Mw7P4m2wGRptu kvvpqVIwD/IASFctTBP/f7/N2Nhr4Hmv/P0PPwZHbeFB4JlSsy/4k48 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= If a subtest itself reports success, but the outer testcase fails, the whole testcase should be reported as a failure. However the status is recalculated based on the test counts, overwriting the outer test result. Synthesize a failed test in this case to make sure the failure is not swallowed. Signed-off-by: Thomas Weißschuh --- tools/testing/kunit/kunit_parser.py | 5 +++++ tools/testing/kunit/kunit_tool_test.py | 2 +- tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 29fc27e8949bd4732448fdd96024624e5350a728..8f597a244b9866528ffb3850e876acb487f3bbd4 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -686,6 +686,11 @@ def bubble_up_test_results(test: Test) -> None: counts.add_status(status) elif test.counts.get_status() == TestStatus.TEST_CRASHED: test.status = TestStatus.TEST_CRASHED + if not test.ok_status(): + for t in subtests: + if not t.ok_status(): + counts.add_status(t.status) + break def parse_test(lines: LineStream, expected_num: int, log: List[str], is_subtest: bool, printer: Printer) -> Test: """ diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py index e71ce88682e137676be49ea9854a5ddaff0dc259..aab38aa0664655c84d633ab15e4818f818b0ce47 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -170,7 +170,7 @@ class KUnitParserTest(unittest.TestCase): with open(nested_log) as file: result = kunit_parser.parse_run_tests(file.readlines(), stdout) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) - self.assertEqual(result.counts.failed, 2) + self.assertEqual(result.counts.failed, 3) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[0].status) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].status) diff --git a/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log index 835816e0a07715a514f5f5afab1b6250037feaf4..cd9033c464792e6294905a5676346684182874ad 100644 --- a/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log +++ b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log @@ -1,5 +1,8 @@ KTAP version 1 1..2 + KTAP version 1 + 1..1 + ok 1 test 1 not ok 1 subtest 1 KTAP version 1 1..1 From patchwork Mon Feb 17 10:59:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977602 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 670AD218EB8; Mon, 17 Feb 2025 11:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; cv=none; b=su6f1eyLY62lasvYYZ3IuLliqSGl5JvPB6DCYrosbmqMHRtsA9O7YSakDEIqF7CGVtY38VPHIfPQZTqa/1UJQntipeL5+/PtTVRlLpJg7MYuK6pI4CK3QMFrWohntkhH43lX/byKe0i3dH2mr5K8IJe4z/p7oswwuM/dUvHeI1s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790043; c=relaxed/simple; bh=VVpiYq/6Re3t0jtT2paYBPSgIav0OJgY8gB31IQtpw0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ebpy4pt3pY0Xxv2Qf+sRZGZ/IESoH1cuqkj3X8T5uP13SIZE0dNRkCwSsGUweQmNT9/Ym+EEIrdz546N2MvrSOvgjMoquhZ1rt6OBRWbc6w9hkakRjBLTiclnRXe5qqDSVi1t6FOu6TOTBC+3cKTYmjr1HSO/95aYkSY935pj34= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=m3RZBLM+; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=+/VFtOcz; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="m3RZBLM+"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="+/VFtOcz" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ygzfGpvhv4BgMLDJbt1hgtavbyQVdT4YW4iOp7XXpFY=; b=m3RZBLM+Eb0RO452llz8lNmp+YV6t0XGK1bzIaBwIxai6p13zYChGtxvr2hPo36uqOuT3M colKZMK81mqJAPKSYQlXMl5WLCD/t0QqsWeLLy84X0EnLyCAmyZ7P8S7XR/l4y988DZVfo BUlrOY3V1FRdeBjClZiPk2h95k/HfExC2NtQ8XSAUzx+eI7cv0KbhNInaJgC/nkKHOhAdR OkxhbK7OSQyJ4MFljmMU1lWYgJauRiFWhZ8fSTin47s/VK97xg4q5qPyQMvenk2pxyXqgG DakgVuQS6DvHmOPeSqSGmDJtAbn321rxvBuC3yu+xcr6ThR1RR1JsNatIkM8Mg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790039; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ygzfGpvhv4BgMLDJbt1hgtavbyQVdT4YW4iOp7XXpFY=; b=+/VFtOczDVdwAk2Qmo3w7ND+/GRqIA737gtzhPJz4cy2L9ceRF84uRebjrArdZjZrXxPDE KI86QOt9gQYMVZAw== Date: Mon, 17 Feb 2025 11:59:28 +0100 Subject: [PATCH 08/12] kunit: tool: Parse skipped tests from kselftest.h Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-8-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=2785; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=VVpiYq/6Re3t0jtT2paYBPSgIav0OJgY8gB31IQtpw0=; b=FAKOhCJCxzDlg60wPSZ9kkfW8+a9pSzLAltwlYM5PmXn79g9RILSVYT5WBXzzxLjBLN8RJ/l3 oGBRUXTGPyGCAoLXd5nsTu2ksf7Nm1G6KEqgAC/I59JDvbB+mZYFVXl X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Skipped tests reported by kselftest.h use a different format than KTAP, there is no explicit test name. Normally the test name is part of the free-form string after the SKIP keyword: ok 3 # SKIP test: some reason Extend the parser to handle those correctly. Use the free-form string as test name instead. Signed-off-by: Thomas Weißschuh --- tools/testing/kunit/kunit_parser.py | 8 +++++--- tools/testing/kunit/test_data/test_is_test_passed-kselftest.log | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kunit_parser.py index 8f597a244b9866528ffb3850e876acb487f3bbd4..096fe0c9740dd8ec528cbc3dabefcd5bc9b40e50 100644 --- a/tools/testing/kunit/kunit_parser.py +++ b/tools/testing/kunit/kunit_parser.py @@ -352,9 +352,9 @@ def parse_test_plan(lines: LineStream, test: Test) -> bool: lines.pop() return True -TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?([^#]*)( # .*)?$') +TEST_RESULT = re.compile(r'^\s*(ok|not ok) ([0-9]+)? ?(- )?([^#]*)( # .*)?$') -TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?(.*) # SKIP(.*)$') +TEST_RESULT_SKIP = re.compile(r'^\s*(ok|not ok) ([0-9]+)? ?(- )?(.*) # SKIP ?(.*)$') def peek_test_name_match(lines: LineStream, test: Test) -> bool: """ @@ -379,6 +379,8 @@ def peek_test_name_match(lines: LineStream, test: Test) -> bool: if not match: return False name = match.group(4) + if not name: + return False return name == test.name def parse_test_result(lines: LineStream, test: Test, @@ -416,7 +418,7 @@ def parse_test_result(lines: LineStream, test: Test, # Set name of test object if skip_match: - test.name = skip_match.group(4) + test.name = skip_match.group(4) or skip_match.group(5) else: test.name = match.group(4) diff --git a/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log b/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log index 65d3f27feaf22a3f47ed831c4c24f6f11c625a92..30d9ef18bcec177067288d5242771236f29b7d56 100644 --- a/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log +++ b/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log @@ -1,5 +1,5 @@ TAP version 13 -1..2 +1..3 # selftests: membarrier: membarrier_test_single_thread # TAP version 13 # 1..2 @@ -12,3 +12,4 @@ ok 1 selftests: membarrier: membarrier_test_single_thread # ok 1 sys_membarrier available # ok 2 sys membarrier invalid command test: command = -1, flags = 0, errno = 22. Failed as expected ok 2 selftests: membarrier: membarrier_test_multi_thread +ok 3 # SKIP selftests: membarrier: membarrier_test_multi_thread From patchwork Mon Feb 17 10:59:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977604 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 D6F90218821; Mon, 17 Feb 2025 11:00:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; cv=none; b=GvYJV+PuC44nUTyC3wtGIMjwEpHbU8ubt8vjNsc+hA70Y6JwkSgPdPzJ+sKZYMWifsq+0YsoqIIJmBp8d2wDFgy9lLfQ4DDNkt6V3coJoSLhfe/mOBLbAcSAbOJaxctTwuzkeUoZiu7ZuBR0PbfdI+jLww5ekZVyYa9KuOYIRK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; c=relaxed/simple; bh=34AMfccJyLcBH84STO1VZXha6yixDc3MiV7ZpqvLAr0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=rC65RXxlFyPLcWIpmUDhuHdxG/COGpGTk4hap7i8qM2XsjOkcfOL4Kpsh+T9hqqq3hMneEif3TT84Z3sK8qLy4gHJ7F0zHywYryYMRaiV0BDvAcD+PazIBgYrWTJ3070mWNl7BxZPwhzGiYhKdWRLcJk7RszZj8UZS1/uT0bkH4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Cvz9N0q/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wkXAKeDK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Cvz9N0q/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wkXAKeDK" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PinOl+NovMq8VEGwrJxMZ57WRxpBIh00nLZNCtv5D2s=; b=Cvz9N0q/aEIFQw5lCdor6zsdxKV7+Jx1Uzqza451bYBAwCxadMDzJhydVpputqb/qSOJn9 NSkU4kZLfl+O4EmeFnYLUd8zDwFq9jqunIkE7p8GiCPKmc4EFGu4vaBEHfSmi1+DPBUZ35 lt9qdJ7609V+oIalVcDodgW1M91EyGqTMZ6b7VNNsh1/j+NuKm/3JTAPJda4v7vBXVECUp NXAxGB3m9EIISpMhPvzj5tsz4HalsmNleZW7QILm5RJx6et7dbX7qbXCJMhslApRmdPSyM DoT1QMZSZ6wmFecTIGvoVFYrxgq7YaMRA4rtGxTMGVIhb+YcvT6cAPDCbNop4A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PinOl+NovMq8VEGwrJxMZ57WRxpBIh00nLZNCtv5D2s=; b=wkXAKeDK6R4Kaz/1mECHOuRFBs2YYcTHhW17BXeEA0LBFGQca+iyvJ1D6YqQ92PXai5FyU iP5cp+jVMRYxhrBA== Date: Mon, 17 Feb 2025 11:59:29 +0100 Subject: [PATCH 09/12] kunit: Introduce UAPI testing framework Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-9-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=8296; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=34AMfccJyLcBH84STO1VZXha6yixDc3MiV7ZpqvLAr0=; b=ughB+neAU8Wvl83YqlOgbkKUbGH66SdIHs9oHvnjU2yTyMptq7+QGFs9Rh+1bW0doTBBYWU6D tUUSwHcvwURA0IpzDpaC1TNS/pwOl65Zl2oMO5iWUOljC2D5AW+TkUy X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Enable running UAPI tests as part of kunit. The selftests are embedded into the kernel image and their output is forwarded to kunit for unified reporting. The implementation reuses parts of usermode drivers and usermode helpers. However these frameworks are not used directly as they make it impossible to retrieve a thread's exit code. Signed-off-by: Thomas Weißschuh --- include/kunit/uapi.h | 17 ++++ lib/kunit/Kconfig | 9 ++ lib/kunit/Makefile | 2 + lib/kunit/uapi.c | 239 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 267 insertions(+) diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 0000000000000000000000000000000000000000..760fad98884e12cbbec33155d3cc8ae083b0882b --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linuxtronix GmbH. + * Author: Thomas Weißschuh + */ + +#ifndef _KUNIT_UAPI_H +#define _KUNIT_UAPI_H + +struct blob; +struct kunit; + +void kunit_uapi_run_executable(struct kunit *test, const struct blob *blob); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..e15b9a678a6ad2b37c898f8b4e17e06567eb7bb5 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -15,6 +15,15 @@ menuconfig KUNIT if KUNIT +config KUNIT_UAPI + def_bool y + depends on CC_CAN_LINK_STATIC || ARCH_HAS_NOLIBC + select HEADERS_INSTALL + select TMPFS + help + Enables support for build and running userspace selftests as part of kunit. + These tests should use kselftest.h for status reporting. + config KUNIT_DEBUGFS bool "KUnit - Enable /sys/kernel/debug/kunit debugfs representation" if !KUNIT_ALL_TESTS default KUNIT_ALL_TESTS diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 5aa51978e456ab3bb60c12071a26cf2bdcb1b508..2b68f9bd20137edb705dcd8cb2dc145f9684cf73 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs += test.o \ device.o \ platform.o +obj-$(CONFIG_KUNIT_UAPI) += uapi.o + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs += debugfs.o endif diff --git a/lib/kunit/uapi.c b/lib/kunit/uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..9fbba13669e8e5cf349e596636f2cdc4adce4978 --- /dev/null +++ b/lib/kunit/uapi.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linuxtronix GmbH. + * Author: Thomas Weißschuh + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static struct vfsmount *kunit_uapi_mount_tmpfs(void) +{ + struct file_system_type *type; + struct vfsmount *mnt; + + type = get_fs_type("tmpfs"); + if (!type) + return ERR_PTR(-ENODEV); + + /* FIXME + * The mount setup is supposed to look like this: + * kunit_uapi_mount_tmpfs() sets up a private mount, + * with nothing visible except the new tmpfs. + * Then each executable execution gets a new namespace on top of that + * on which it can mount whatever it needs. + * However I didn't manage to set this up, so keep everything simple + * for now and let somebody familiar with the VFS figure this out. + */ + + mnt = kern_mount(type); + put_filesystem(type); + + return mnt; +} + +static int kunit_uapi_write_file(struct vfsmount *mnt, const char *name, mode_t mode, + const u8 *data, size_t size) +{ + struct file *file; + ssize_t written; + + file = file_open_root_mnt(mnt, name, O_CREAT | O_WRONLY, mode); + if (IS_ERR(file)) + return PTR_ERR(file); + + written = kernel_write(file, data, size, NULL); + filp_close(file, NULL); + if (written != size) { + if (written >= 0) + return -ENOMEM; + return written; + } + + /* Flush delayed fput so exec can open the file read-only */ + flush_delayed_fput(); + + return 0; +} + +struct kunit_uapi_user_mode_thread_ctx { + const char *executable; + + /* Signals mnt, out, pwd and tgid */ + struct completion setup_done; + struct vfsmount *mnt; + struct file *out; + struct path pwd; + pid_t tgid; + + /* Valid after wait(tgid) */ + int exec_err; +}; + +static int kunit_uapi_user_mode_thread_init(void *data) +{ + struct kunit_uapi_user_mode_thread_ctx *ctx = data; + const char *const argv[] = { + ctx->executable, + NULL + }; + struct file *out[2]; + int err; + + err = create_pipe_files(out, 0); + if (err) + return err; + + err = replace_fd(1, out[1], 0); + if (err < 0) { + fput(out[1]); + return err; + } + + err = replace_fd(2, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + fput(out[1]); + return err; + } + + fput(out[1]); + + ctx->out = out[0]; + ctx->tgid = current->tgid; + + set_fs_pwd(current->fs, &ctx->pwd); + kernel_sigaction(SIGKILL, SIG_DFL); + + complete(&ctx->setup_done); + ctx->exec_err = kernel_execve(ctx->executable, argv, NULL); + if (!ctx->exec_err) + return 0; + do_exit(0); +} + +static size_t kunit_uapi_printk_subtest_lines(char *buf, size_t s) +{ + const char *ptr = buf, *newline; + size_t n; + + while (s) { + newline = strnchr(ptr, s, '\n'); + if (!newline) + break; + + n = newline - ptr + 1; + + pr_info(KUNIT_SUBSUBTEST_INDENT "%.*s", (int)n, ptr); + ptr += n; + s -= n; + } + + memmove(buf, ptr, s); + + return s; +} + +static int kunit_uapi_forward_to_printk(struct file *output) +{ + char buf[512]; + size_t s = 0; + ssize_t n; + + while (1) { + n = kernel_read(output, buf + s, sizeof(buf) - s, NULL); + if (n <= 0) + return n; + s = kunit_uapi_printk_subtest_lines(buf, s + n); + } +} + +static void kunit_uapi_kill_pid(pid_t pid) +{ + struct pid *p; + + p = find_get_pid(pid); + kill_pid(p, SIGKILL, 1); + put_pid(p); +} + +static int kunit_uapi_run_executable_in_mount(struct kunit *test, const char *executable, + struct vfsmount *mnt) +{ + struct kunit_uapi_user_mode_thread_ctx ctx = { + .setup_done = COMPLETION_INITIALIZER_ONSTACK(ctx.setup_done), + .executable = executable, + .pwd = { + .mnt = mnt, + .dentry = mnt->mnt_root, + }, + }; + int forward_err, wait_err, ret; + pid_t pid; + + /* If SIGCHLD is ignored do_wait won't populate the status. */ + kernel_sigaction(SIGCHLD, SIG_DFL); + pid = user_mode_thread(kunit_uapi_user_mode_thread_init, &ctx, SIGCHLD); + if (pid < 0) { + kernel_sigaction(SIGCHLD, SIG_IGN); + return pid; + } + + wait_for_completion(&ctx.setup_done); + + forward_err = kunit_uapi_forward_to_printk(ctx.out); + if (forward_err) + kunit_uapi_kill_pid(ctx.tgid); + + wait_err = kernel_wait(ctx.tgid, &ret); + + /* Restore default kernel sig handler */ + kernel_sigaction(SIGCHLD, SIG_IGN); + + if (ctx.exec_err) + return ctx.exec_err; + if (forward_err) + return forward_err; + if (wait_err < 0) + return wait_err; + return ret; +} + +void kunit_uapi_run_executable(struct kunit *test, const struct blob *blob) +{ + const char *exe_name = kbasename(blob->path); + struct vfsmount *mnt; + int err; + + mnt = kunit_uapi_mount_tmpfs(); + KUNIT_EXPECT_FALSE_MSG(test, IS_ERR(mnt), "Could not mount tmpfs for test: %pe", mnt); + if (IS_ERR(mnt)) + return; + + err = kunit_uapi_write_file(mnt, exe_name, 0700, blob->data, blob_size(blob)); + KUNIT_EXPECT_EQ_MSG(test, 0, err, "Could not add test executable: %pe", ERR_PTR(err)); + + if (!err) { + err = kunit_uapi_run_executable_in_mount(test, exe_name, mnt); + KUNIT_EXPECT_GE_MSG(test, err, 0, "Error when running executable: %pe\n", + ERR_PTR(err)); + KUNIT_EXPECT_EQ_MSG(test, 0, err, "Executable signal/exitcode: %d/%d\n", + err & 0xff, err >> 8); + } + + kern_unmount(mnt); + +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_executable); From patchwork Mon Feb 17 10:59:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977606 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 AECBD219A99; Mon, 17 Feb 2025 11:00:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; cv=none; b=EM5oCXpndsff6IUD6seg9euXgp9cdFEDpoM5oVVokZJsUoU3XMlnW3lKzu+HYrphB1+AyKEgvOWKdIMR4QbCzarShSCS2GFBw2xNiEf1wSSINbtyviDjcWFL76IwIrqkpDZZtWkGTyYbolwkZfFlvZbBiCgSIH0gyHONOb88zvo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790044; c=relaxed/simple; bh=DbWBS4iAgx14/WPjqsLMmarpz0SuT0mGiZYf8mBVqhs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AvXSeEk4jJ4yf5XCncVjW0u4xF4yOr0Hy2yQPA+Mos2V8IotZNxNQbz4+0GyKIqJb8UXndidV18K1PEXDVC3VxomwZz/0MXC3ZpglLyxpvakvuD0G3INi4VkuzKNRjhHRk7k2ZDKdxUWmGOGG1FjZBwF1sMA8z8YwszQxuWPkgM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ldd+9zt9; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=4sm6gbL8; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ldd+9zt9"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="4sm6gbL8" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p6J/q2UBParY1fmd6WOqMsTt/aNnKl9MDGkOwxkh+MM=; b=Ldd+9zt98JHivrEV8+R/YlthmDCL9iDNihl++l80V6fGIVMFWBXVdZ56jvMAFeB2UfDQ5q 6dOjsi0PBbwGkl7JMmbOSrdUcxO0bOctl5lncziM46SBNUgfmufX4ULd0QC0rhjhKR8EI9 MgnTh0UczpPfJy/ba5U82vN4HZfPC77q6Y8IwEq21YWiKjY8NfC68Wlc6KRszamcU8fb6z wXwaR5VTUtq3zByXwM5Qr9siFpoR7bocLr26Yhg8DFPITNbIL5YqFVr3e/82Gt0XvOKnIe odQXMCy88KIH9SE5tEtAdEEQcmixlwJy5ewJcegDM4mrtTPPvjmCwYgHaQOlXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=p6J/q2UBParY1fmd6WOqMsTt/aNnKl9MDGkOwxkh+MM=; b=4sm6gbL8740exSdi0tB3xyOuVtFFda5UljT8HsQm4vUdI7z1tm+1+pzSLVQvU/++cnilqP ZADRqIf0DYtaneCA== Date: Mon, 17 Feb 2025 11:59:30 +0100 Subject: [PATCH 10/12] kunit: uapi: Add example for UAPI tests Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-10-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=3260; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=DbWBS4iAgx14/WPjqsLMmarpz0SuT0mGiZYf8mBVqhs=; b=vsFz67tjcaj/tbebMI1fbfCttAQSq/b0lNdayg4y97RoXEx2pzZoLAFHgcFLYmLSWAEo50e0l TCT8S4ZQigCCtf2xaUsVtqEtji7eIOY0aaV6scquMgjUQWP+OL8mQYC X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Extend the example to show how to run a userspace executable. Signed-off-by: Thomas Weißschuh --- lib/kunit/Makefile | 8 +++++++- lib/kunit/kunit-example-test.c | 17 +++++++++++++++++ lib/kunit/kunit-uapi-example.c | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 2b68f9bd20137edb705dcd8cb2dc145f9684cf73..0d89b666fcad12a542d3e2ffacedd26b122c5449 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -30,4 +30,10 @@ obj-$(CONFIG_KUNIT_TEST) += string-stream-test.o obj-$(CONFIG_KUNIT_TEST) += assert_test.o endif -obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test.o +userprogs += kunit-uapi-example +kunit-uapi-example-userccflags := -static +kunit-uapi-example-nolibc := $(CONFIG_ARCH_HAS_NOLIBC) +blobs += kunit-uapi-example.blob.o +obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-test-mod.o +kunit-example-test-mod-y += kunit-example-test.o +kunit-example-test-mod-$(CONFIG_KUNIT_UAPI) += kunit-uapi-example.blob.o diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 3056d6bc705d0a8f196f0f4412e679dbb0e03114..c5b8b308ed7b10c6ec4f475965205f2ccc4b4ec5 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -6,8 +6,11 @@ * Author: Brendan Higgins */ +#include + #include #include +#include /* * This is the most fundamental element of KUnit, the test case. A test case @@ -277,6 +280,19 @@ static void example_slow_test(struct kunit *test) KUNIT_EXPECT_EQ(test, 1 + 1, 2); } +/* + * This test shows the usage of UAPI tests. + */ +static void example_uapi_test(struct kunit *test) +{ + DECLARE_BLOB(kunit_uapi_example); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_executable(test, &kunit_uapi_example); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI not enabled"); +} + /* * Here we make a list of all the test cases we want to add to the test suite * below. @@ -297,6 +313,7 @@ static struct kunit_case example_test_cases[] = { KUNIT_CASE(example_priv_test), KUNIT_CASE_PARAM(example_params_test, example_gen_params), KUNIT_CASE_SLOW(example_slow_test), + KUNIT_CASE(example_uapi_test), {} }; diff --git a/lib/kunit/kunit-uapi-example.c b/lib/kunit/kunit-uapi-example.c new file mode 100644 index 0000000000000000000000000000000000000000..4ec4b924f29b089cce9ca5b2b08a6ee0117b8ae9 --- /dev/null +++ b/lib/kunit/kunit-uapi-example.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace example test. + * + * Copyright (C) 2025, Linuxtronix GmbH. + * Author: Thomas Weißschuh + */ + +#include "../../tools/testing/selftests/kselftest.h" + +int main(void) +{ + ksft_print_header(); + ksft_set_plan(4); + ksft_test_result_pass("userspace test 1\n"); + ksft_test_result_pass("userspace test 2\n"); + ksft_test_result_skip("userspace test 3: some reason\n"); + ksft_test_result_pass("userspace test 4\n"); + ksft_finished(); +} From patchwork Mon Feb 17 10:59:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977607 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 7A6FC21A43A; Mon, 17 Feb 2025 11:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790045; cv=none; b=U3d4nQEH48ZCXAo1cke67oWHvRBOgolPRBSl71u1uxJ2FdBboqYX1taxgBWWzd1uFgbpj2bxwC/uTVQ76Ss+DjxQaV7ldeUdsSllvSvomDx0+QB1kgKyHWIg/vpjeyjvU0X1VzWozV0sldEhi4MgVnMC37vge5B0nBIaLgW0IUU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790045; c=relaxed/simple; bh=CBzQ5kaZsZ50e4JQy4iRm48GR6StcWRxcndjr8omck8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Le1UHRT2e4xFZ525YmF17mao4pZIESZr6zRvGzRqbotOEDlpDTF/LjO9tq4eggP+SNyWE8L3tOBkUTOXtyHOxOZpUTHyLz6ztRXNlubYJYDWOzkOBU2U9ySkOZmkwOtf60scb26nNPy5wBZ+BOcGO9aWCZnUMS5xkSSBlEjXQfE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=pziicZDT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=A6ZpWf7J; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="pziicZDT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="A6ZpWf7J" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nX2HOx+bJgJaC3JjTaAXzc9i8877zcwuFmMI1HtrRck=; b=pziicZDTc6yyMW5Y/TIlMmn3w96HIf9bfNKaAlY7TXVNWXjjW8CJXF44PMHlIDIZro1Poo knc/gwUQZlINz0kvHEUh503n/tbLcmzx8aO/4WAIV25a0r5MgsjrLQ4eEvKVfRwX6EmurY /Oe5zaG/VJzImYiA+SKzlr0xUm8SEJdC89ShnClMUlG7LZt1mkLo7MqAQxMPtxWNHBwNp8 EvYAMhmUtiv8UdpPyGUYod6u7E4ooZlJPOLcup6Ds8vA/LnZ0dvBxqzHnMmigQURXhDiI5 8Fh9g2uCOWcajdoL7D04JRpavQ3dOclX0OIVuWGx7Ye45nEUUlBu+W4lNZJgcQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nX2HOx+bJgJaC3JjTaAXzc9i8877zcwuFmMI1HtrRck=; b=A6ZpWf7Jg+suU1tB9VpabOZE/P8DL8eUapALNeLtAun/2XgKOH/vLhB8Sm2BWdPZpLqgfW AB0keKAbulOwplDQ== Date: Mon, 17 Feb 2025 11:59:31 +0100 Subject: [PATCH 11/12] kunit: uapi: Introduce preinit executable Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-11-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=5047; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=CBzQ5kaZsZ50e4JQy4iRm48GR6StcWRxcndjr8omck8=; b=3I9kUaQ2vhawRxm4Lyg56ktFvC7y1mumBBb5+MlgW6y+GLdq/rKqek59NOPoCfQLP1to6S/Yl l90hxGkcKNIA+quGEQRuYQdwZo8mn/wcIPIWFiezY/Zll8BNvFaxiu8 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= UAPI selftests may expect a "normal" userspace environment. For example the normal kernel API pseudo-filesystems should be mounted. This could be done from kernel code but it is non-idiomatic. Add a preinit userspace executable which performs these setup steps before running the final test executable. This preinit executable is only ever run from the kernel. Give it access to autoconf.h and kconfig.h to adapt itself to the tested kernel. Signed-off-by: Thomas Weißschuh --- lib/kunit/Makefile | 9 ++++++- lib/kunit/uapi-preinit.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/kunit/uapi.c | 17 +++++++++++--- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 0d89b666fcad12a542d3e2ffacedd26b122c5449..b1d9851f1a14ecd7fb48a20c5500058811259142 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,7 +12,14 @@ kunit-objs += test.o \ device.o \ platform.o -obj-$(CONFIG_KUNIT_UAPI) += uapi.o +userprogs += uapi-preinit +uapi-preinit-nolibc := $(CONFIG_ARCH_HAS_NOLIBC) +uapi-preinit-userccflags += -static \ + -include include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h +blobs += uapi-preinit.blob.o +uapi-preinit.blob-symbol := kunit_uapi_preinit +obj-$(CONFIG_KUNIT_UAPI) += uapi.o uapi-preinit.blob.o ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs += debugfs.o diff --git a/lib/kunit/uapi-preinit.c b/lib/kunit/uapi-preinit.c new file mode 100644 index 0000000000000000000000000000000000000000..748599786aaa802982335e536ddae122f5cc2be5 --- /dev/null +++ b/lib/kunit/uapi-preinit.c @@ -0,0 +1,61 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace environment setup. + * + * Copyright (C) 2025, Linuxtronix GmbH. + * Author: Thomas Weißschuh + */ + +#ifndef NOLIBC +#include +#include +#endif + +#include "../../tools/testing/selftests/kselftest.h" + +static int setup_api_mount(const char *target, const char *fstype) +{ + int ret; + + ret = mkdir(target, 0755); + if (ret && errno != EEXIST) + return -errno; + + ret = mount("none", target, fstype, 0, NULL); + if (ret && errno != EBUSY) + return -errno; + + return 0; +} + +static void exit_failure(const char *stage, int err) +{ + /* If preinit fails synthesize a failed test report. */ + ksft_print_header(); + ksft_set_plan(1); + ksft_test_result_fail("Failed during test setup: %s: %s\n", stage, strerror(-err)); + ksft_finished(); +} + +int main(int argc, char **argv, char **envp) +{ + int ret; + + ret = setup_api_mount("/proc", "proc"); + if (ret) + exit_failure("mount /proc", ret); + ret = setup_api_mount("/sys", "sysfs"); + if (ret) + exit_failure("mount /sys", ret); + if (IS_ENABLED(CONFIG_DEVTMPFS)) { + ret = setup_api_mount("/dev", "devtmpfs"); + if (ret) + exit_failure("mount /dev", ret); + } + + ret = execve(argv[0], argv, envp); + if (ret) + exit_failure("execve", ret); + + return 0; +} diff --git a/lib/kunit/uapi.c b/lib/kunit/uapi.c index 9fbba13669e8e5cf349e596636f2cdc4adce4978..d43a1a1e5084ab1c7c4515e3c44fd3e819524737 100644 --- a/lib/kunit/uapi.c +++ b/lib/kunit/uapi.c @@ -19,6 +19,8 @@ #include #include +#define KUNIT_UAPI_PREINIT "preinit" + static struct vfsmount *kunit_uapi_mount_tmpfs(void) { struct file_system_type *type; @@ -118,7 +120,7 @@ static int kunit_uapi_user_mode_thread_init(void *data) kernel_sigaction(SIGKILL, SIG_DFL); complete(&ctx->setup_done); - ctx->exec_err = kernel_execve(ctx->executable, argv, NULL); + ctx->exec_err = kernel_execve(KUNIT_UAPI_PREINIT, argv, NULL); if (!ctx->exec_err) return 0; do_exit(0); @@ -213,6 +215,8 @@ static int kunit_uapi_run_executable_in_mount(struct kunit *test, const char *ex void kunit_uapi_run_executable(struct kunit *test, const struct blob *blob) { + DECLARE_BLOB(kunit_uapi_preinit); + const char *exe_name = kbasename(blob->path); struct vfsmount *mnt; int err; @@ -222,8 +226,15 @@ void kunit_uapi_run_executable(struct kunit *test, const struct blob *blob) if (IS_ERR(mnt)) return; - err = kunit_uapi_write_file(mnt, exe_name, 0700, blob->data, blob_size(blob)); - KUNIT_EXPECT_EQ_MSG(test, 0, err, "Could not add test executable: %pe", ERR_PTR(err)); + err = kunit_uapi_write_file(mnt, KUNIT_UAPI_PREINIT, 0755, + kunit_uapi_preinit.data, blob_size(&kunit_uapi_preinit)); + KUNIT_EXPECT_EQ_MSG(test, 0, err, "Could not add preinit executable: %pe", ERR_PTR(err)); + + if (!err) { + err = kunit_uapi_write_file(mnt, exe_name, 0755, blob->data, blob_size(blob)); + KUNIT_EXPECT_EQ_MSG(test, 0, err, "Could not add test executable: %pe", + ERR_PTR(err)); + } if (!err) { err = kunit_uapi_run_executable_in_mount(test, exe_name, mnt); From patchwork Mon Feb 17 10:59:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13977608 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 EFD3F21A459; Mon, 17 Feb 2025 11:00:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790045; cv=none; b=Wu56MZUldcf3ORkkol8/FvAWPHf6fQqdAnpQcAu4DTlMM5qRzf0Mwu/uZ7YmYZjGrjXnBD/EDBs3AYDcBRqZU3jlNOWSia6JmktN4HgXb1Hz98iWDIGf53gvog0Of9JbbDdHJO1UpWsTSaAeN2ljAKzBhdQKShPZ0H1dsyiKzEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739790045; c=relaxed/simple; bh=qQOtnhqjbowoR++2Gs0vMxIajpjUcYwkX+qFpvXJshM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uaOkBbFlbfhbvyZ9WfH3vplUKo1xY9LEYoLhcgukmRGYptGXLg9ERQ5iMC9fHtvkG1fvLv6Y1oR0T1j/a+UQI098XQxQFQhGZPUg+9i2moet0P8xEPF6JOggFjitjZRnbC+YfLEcE9M0RiGAV3/x7U2XcYJC0n9qMt/TBDdIJ0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=ONGDfXut; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gpiIGnMv; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="ONGDfXut"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gpiIGnMv" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1739790042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aTa8C4WECe/JmINcH8JHCZeuSOeK2AhNliXotOoWH50=; b=ONGDfXutlPsptMbMJv0b3cQ8/AqBbddswe3f1+x5I+gRAK5MzhF3LM1kZHhGC4Itu4AMHv 1qQsZud/4g+8aefsYzwvB4a1+7I2wyFDX+do7NyBBmzPWSr45dR3b+DjW+eG/s/hk66TwQ zgFb66by21AaVyXpe4SVtkfTH9G1neC5ugNuOEyhOmg23uMenMUYvvjiKhnm8gPzSc0tpa eGTj7NbAiQ1JF/euCZG+PtfqYD3fwJKmrCGWu8tyOpWbxDY/kI4qyjUtdhmGstpW2gjJ0X 9YkQtW4RvwJ5CCQAltlz522O0CRBDmcIEhGN1fF/BWmHttPflwDoyYT/kuwz1A== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1739790042; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aTa8C4WECe/JmINcH8JHCZeuSOeK2AhNliXotOoWH50=; b=gpiIGnMvHhcfubZVMnjoD5cDdhQbaLt4iDJKP4AK1UukjjNPLVGGSss/fVS5poF0c6swo5 9e5d7oFYs52OAaAA== Date: Mon, 17 Feb 2025 11:59:32 +0100 Subject: [PATCH 12/12] kunit: uapi: Validate usability of /proc Precedence: bulk X-Mailing-List: linux-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250217-kunit-kselftests-v1-12-42b4524c3b0a@linutronix.de> References: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> In-Reply-To: <20250217-kunit-kselftests-v1-0-42b4524c3b0a@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-doc@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1739790034; l=1757; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=qQOtnhqjbowoR++2Gs0vMxIajpjUcYwkX+qFpvXJshM=; b=Sk0sCINZHEGGMT3LpKGAEPlP2h61lYlX1X63SvD7xk0roo/+/E3TN8tSXGKAQ9vFoBLwYerNC F1ffVsrfNBbDlOCbhyxzQCOLAOi/Lv+Jjb4eFxHNIyH8gqu0ziJN4pu X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Show that the selftests are executed from a fairly "normal" userspace context. Signed-off-by: Thomas Weißschuh --- lib/kunit/kunit-uapi-example.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/kunit/kunit-uapi-example.c b/lib/kunit/kunit-uapi-example.c index 4ec4b924f29b089cce9ca5b2b08a6ee0117b8ae9..f7376e524b4c76a9c6d474e6ace80a8e2517b84b 100644 --- a/lib/kunit/kunit-uapi-example.c +++ b/lib/kunit/kunit-uapi-example.c @@ -6,13 +6,51 @@ * Author: Thomas Weißschuh */ +#ifndef NOLIBC +#include +#include +#include +#endif + #include "../../tools/testing/selftests/kselftest.h" +static void test_procfs(void) +{ + char buf[256]; + ssize_t r; + int fd; + + fd = open("/proc/self/comm", O_RDONLY); + if (fd == -1) { + ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno)); + return; + } + + r = read(fd, buf, sizeof(buf)); + if (r == -1) { + close(fd); + ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno)); + return; + } + + close(fd); + + if (r > 0 && buf[r - 1] == '\n') + buf[r - 1] = '\0'; + + if (strncmp("kunit-uapi-exam", buf, sizeof(buf)) != 0) { + ksft_test_result_fail("procfs: incorrect comm: %s\n", buf); + return; + } + + ksft_test_result_pass("procfs\n"); +} + int main(void) { ksft_print_header(); ksft_set_plan(4); - ksft_test_result_pass("userspace test 1\n"); + test_procfs(); ksft_test_result_pass("userspace test 2\n"); ksft_test_result_skip("userspace test 3: some reason\n"); ksft_test_result_pass("userspace test 4\n");