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: 866308 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-kselftest@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: 866307 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-kselftest@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: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: 866306 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-kselftest@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: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: 866305 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-kselftest@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: 866304 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-kselftest@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: 866303 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-kselftest@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: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: 866302 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-kselftest@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");