From patchwork Mon Apr 7 07:42:38 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: 878903 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 A925D22425C; Mon, 7 Apr 2025 07:42:59 +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=1744011782; cv=none; b=suR2tGCCCIHLR8qrnFXTBMedvyMipRLAOD36yXMsn9Wjl//nP+aksw7j6AbqlMYbnAqG/yisbPjII+n9DUcQ7ujuxQ4lr/3V59rZeHIhiaicBk9yeKRdYoi2b1gaSz2tjme9uhCOQaagEvGGIV+FbA/qheaSAPEp9R4m9ekjwbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011782; c=relaxed/simple; bh=jxO3E6fY/cRCojmRh56m84xcozUfNDAYCPH6toOUjVU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qokXdZfelpOuqUfaMpFDIlvDJLp78K+0WV8+uq3opDnl1U5y+7vzxzJ8jHvY4I7e9OrjyMO54+5YLUD1K4wCEgFjjolqLFm0GeuCl4OvmlETsBa8MXgl3WvupCnTkFKIYnDZLTCsS6XliLoPoisI5ar9sq6WucLSRlr7nEVO06s= 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=z5Yx9uzH; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=S3nDxtOX; 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="z5Yx9uzH"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="S3nDxtOX" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011777; 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=71yX+dxuZgcMiLhYB0nVTc9ZvKb7jxerOTVN6LgpvkU=; b=z5Yx9uzHqdbvEg81aFKO0Z2AKopLGyzT6tN5p6C+YuVw8+yh4aMeBMjFq8F24hH/4V1ndT jmztDArKwytIE1m9+7vaD9+eKF5HBWuZ8xEg5YzM9BLJ+pgkudHY4i7JLfcJEfMVMu8jDY g5wiL5xFq65+tKMg1ydHaTHFD34i41YKxGgYwzrwGZW2qsPm7xnwgbRKILzWDvJbz/bp3U STiUvBRitKNWnfUxDLag0RPKZ6D+XFUOdmXc/pBiduN3BBr4ucDNaIWbJOMizWnTxwwF5A ra7fVhaiYhxB7GuOHW+b70eq2s5jklZyqMoKcUIQHFi/tZRacWTaJkv1PN+k3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011777; 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=71yX+dxuZgcMiLhYB0nVTc9ZvKb7jxerOTVN6LgpvkU=; b=S3nDxtOXUie7rH30tDNH1w7jDgiKUn44PWhU5pzVN1QgRlD3plAb9rB43+pGbRiXuTSBWc 0+6pGiMyJ+C9sNAg== Date: Mon, 07 Apr 2025 09:42:38 +0200 Subject: [PATCH v2 01/11] 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: <20250407-kunit-kselftests-v2-1-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=3510; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=jxO3E6fY/cRCojmRh56m84xcozUfNDAYCPH6toOUjVU=; b=2YBONPJ+hWofM0Hneh5fSQgoKjbNUqWD/nQZU1IP/AdEfOq4UA6LhG176h1joDjTNVuSLSZLy IYK7pKi5tkIDiVvpeC/ZayKFGgupPDPzH4f1EyMQdwLl44oBDF0zWl0 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 libc 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. Also this does currently not support out-of-tree builds. For that tools/include/nolibc/*.h and usr/include/*.h would need to be installed into the build directory. --- Documentation/kbuild/makefiles.rst | 12 ++++++++++++ scripts/Makefile.userprogs | 16 +++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index 3b9a8bc671e2e92126857059e985d6e5b2c43fd4..f905a6f77c965311c491cfd7ab3103185af7e82e 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -970,6 +970,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 f3a7e1ef3753b54303718fae97f4b3c9d4eac07c..a1447c02b948901631098b585f5cf4d3ea383a57 100644 --- a/scripts/Makefile.userprogs +++ b/scripts/Makefile.userprogs @@ -16,10 +16,20 @@ user-csingle := $(addprefix $(obj)/, $(user-csingle)) user-cmulti := $(addprefix $(obj)/, $(user-cmulti)) user-cobjs := $(addprefix $(obj)/, $(user-cobjs)) +user-libgcc := $(call try-run,$(CC) -Werror $(KBUILD_USERCFLAGS) -lgcc -x c -shared /dev/null -o "$$TMP",-lgcc) + +user_nolibc_ccflags := -nostdlib -nostdinc -static -fno-ident -fno-asynchronous-unwind-tables \ + -ffreestanding -fno-stack-protector \ + -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 := $(user-libgcc) + 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)) # Create an executable from a single .c file quiet_cmd_user_cc_c = CC [U] $@ From patchwork Mon Apr 7 07:42:39 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: 879538 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 F3CCC224259; Mon, 7 Apr 2025 07:42:59 +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=1744011782; cv=none; b=n45xLvGwt2PtBfvgnzXoNo7bCPEZtWzCYzV0pcvX/+R5BOgjhN7tVdlecB1viecOGct/NLFQPL8n4YqnsUgQNb6oX5urUIsm7MTUqZpjTnvOXfqsXoDtREgkqhYfEmiz1/TT/IMgns2poHrKKWz5CMLfWheJmZG6E9zlZZDk3V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011782; c=relaxed/simple; bh=hMsH2whwJq0cQmVjJiNwx2jThvXh8C810oX/uNh66Qs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bvMLCmkUg6s07ZDHBurj8qGEKiCh+8VGQ0VqpDYIzCohv/AVA4oV309H+3DLQKe4AwMdyBuHR6YgsiQ02lSR4/2Klz8SnN6MdqchOfhuQZlWY3bG0KObIJ+uxwMiyJd+TFfM+V3vCHd8PAEojkaMLJ7bq3tU++/9ZJUcIN0SBZI= 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=IN3DPG78; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=X6W2bmZL; 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="IN3DPG78"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="X6W2bmZL" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011778; 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=w3P1ftOqJGlh3OYId8jLnR+64DoJM4jPC3xvoE1umU8=; b=IN3DPG78Bg6HGQX4+Nu23i31mfEiJomhNaCoeTQGtWTBbyQixj7zefW9APzJLSzw7XQ6tq GNl8ZFuHC33po18OrIlHiB+NHqOeutb3bV5T/WEU0VHrO0S5uxRzGG7wFiyo2Y3dOcEWeE vAScPESbFUkYZQNAYv7qFm8HVSnKnggbZaM6NtWltWXxOMuIcLL1CZ5fVdKtXNORxkf17I AyzrtNggH4/l+s/fNWkBDTV13c8Dks3yckCkrBH93WA5V88RX5RuJShOIFudv6MxUbaSWg VsvixZLelBfp4zZah7S8tyjk8U7A7wVn8BCNC+4CGXQnwg+Mc1N7djZY1ifpqQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011778; 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=w3P1ftOqJGlh3OYId8jLnR+64DoJM4jPC3xvoE1umU8=; b=X6W2bmZLzH4IrpQkxP6uK/2tOHeix3Hw8bVFRDVUgjW5OXUKBhBh0GDR9p6UXQaRxtkdbb UUkMb11+OoDlDdCQ== Date: Mon, 07 Apr 2025 09:42:39 +0200 Subject: [PATCH v2 02/11] kbuild: 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: <20250407-kunit-kselftests-v2-2-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=1682; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=hMsH2whwJq0cQmVjJiNwx2jThvXh8C810oX/uNh66Qs=; b=Oyh90OX8Z62DpMfsUaHwzFuY11dxkrcm8TX5qRGZ6JLvARhk6fjYjaFeXgApOGD7K6aT4bj2d 10esdoXtl/AAs280erdcxohKzLguCOs6zYRhJ4NR5ZY2P0ouIZf+i6/ 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 | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index dd2ea3b9a799205daa4c1f0c694a9027e344c690..661079a71f30d8d7894d51726686801f8a25b50b 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..60408f02d0da3275c70f550b98a9e60c1558238f --- /dev/null +++ b/tools/include/nolibc/Kconfig.nolibc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 + +config ARCH_HAS_NOLIBC + bool + default y if X86 + default y if ARM + default y if ARM64 + default y if PPC + default y if MIPS + default y if LOONGARCH + default y if RISCV + default y if S390 + default y if UML_X86 From patchwork Mon Apr 7 07:42:40 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: 879537 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 01C21225765; Mon, 7 Apr 2025 07:43:00 +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=1744011782; cv=none; b=aDpF8av1jlLgatyEsK2Rs68UdbxVhqOiUo2rgPv8EpdcKknXL62eWJ0BkhJy4AbbPeI7W7UFVtqqUlrR/phDXYCoNXMRyDICXxTfLZTiuygWaDqNc/1H/Ep1aFvxubZmEI4R5MwYbPw/X9gMmDfCVmqRrKNNQVrlpDAoBUDYn48= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011782; c=relaxed/simple; bh=UUkGY4o+ifkQsc3DKnXn4uCCR2dbB0RnO9mTqC6cgkY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pE8RSBaboJC6+kpBXSZ68+VcNQ/2ii+GSkVJKcX9xNW8/VwOYzaHdYWTyKQDpFMvMoOwIrBaavQsE2hBSGlQjeVujzntOCQgkQ562dhydZKbw58XcXM4d30U7FzJcSvFMgDYAIYRIoC8MEkbZJaL0SaU7isd+EorSCmSHK9HcPw= 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=Eb++AmGW; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=OWcv17AK; 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="Eb++AmGW"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="OWcv17AK" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011778; 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=k5PnaYTRGYGhHVHk+c6RB1E0+rI4Nljv8ReosjhNj+o=; b=Eb++AmGWuA+Lg/Ixwvxjcytg2Sw9sDuUStHzS23MyBfne6a6+jWwNmjgb2+utfz46JWDbL Z7jYk+UOY7xL1xCz3cSRkUTthtne34JyIjPlJe4mwBkNaGuiBC1teOIrnytVmfkxxjxPQC lZjgwkrgG59ZwvZMN4UKCqnGOKD7ZmOuU7OX228JeS0AXQ2vTKXTI03loJ8xl1SB/8J5Ar qSRuwhI1fEFsNpMa5bHX7qKj9AdHHTreAPW5DL7qSFhehp4ayM/D1CMXN5lZt6v7vVOtZR 0c2eTQ0dvJQprIOhZMhDyHisLr4toRBuzZiLKpXEAkhfTJvUnoYmkKm2uHzR+g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011778; 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=k5PnaYTRGYGhHVHk+c6RB1E0+rI4Nljv8ReosjhNj+o=; b=OWcv17AKsxmJaq6+cw2I+u2TuYKqqpVW02jVmwXS1wJYxYERk424xdM1RsnckZCU1jFQ9o jGvaIe2Sfuq+cWAg== Date: Mon, 07 Apr 2025 09:42:40 +0200 Subject: [PATCH v2 03/11] kbuild: doc: add label for userprogs section Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-kunit-kselftests-v2-3-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=800; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=UUkGY4o+ifkQsc3DKnXn4uCCR2dbB0RnO9mTqC6cgkY=; b=5MrqfIWVi0PU8VDN/+HT1jS+ZIea3w8r0ZB3eiXK9wHl9f08gGQQy5VSExElH91pFnjMaJ+v7 KcQtMG7ewJkAlVksniIxAacYYL3A29yxywvUzwi1wRcAWnXU/HkOI67 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming new documentation should link directly to the userprogs section. Add a label to the section so it can be referenced. Signed-off-by: Thomas Weißschuh --- Documentation/kbuild/makefiles.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index f905a6f77c965311c491cfd7ab3103185af7e82e..d5cd73820e406276ee2e3721e265e3ed3cc299c9 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -887,6 +887,8 @@ This is possible in two ways: This will tell kbuild to build lxdialog even if not referenced in any rule. +.. _kbuild_userprogs: + Userspace Program support ========================= From patchwork Mon Apr 7 07:42:41 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: 878902 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 86E2D225A22; Mon, 7 Apr 2025 07:43:01 +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=1744011783; cv=none; b=i6bwKKwEg9yBg9JnJUy8Hk+LGEUSXvRudR8CrFafpMiLKG1BT6MX5aEVuA9yYsz8xYzT+OIq1lIVX/W3mk2HCv2kVaGuflPPLjKX3q2tjyEWIO71wZRN4McY5oVg4/W8J+MQYga1tS0gfqoU/AZyzyyVeXX3QpwwG4GFGgAaBQw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011783; c=relaxed/simple; bh=wigAJUFJ+V9EVhNSp3BPVdxWuuiUQqmtFd9VHobAqVk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XHWHJtyOk3B7yiI2ownPyyrA7HH+B2wzVOP35rqEp5EGYSulHUB154o1V3xLmT1fnLsDWr4xqxL80sLdeexdRbgvuo9f3FwQxgxMAYJGPU/2rJG5nBH9IH6EzpOPYfU1PT8tZfN6bNNLWAl706fyFQs4VLQQeDzVFnIsnC9qQxA= 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=lwR6wPAy; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=LsFfLANA; 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="lwR6wPAy"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="LsFfLANA" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011779; 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=61AaDAxKbOLaApOgc6P6k2wgx7ZZhb7JXrh4epva6Ak=; b=lwR6wPAyMCnoqtHBjbQX509ibXuppvAPHqwU3w3/XR9MoYll9WTLRMizfjkKewVvYbBLfV 4w9HT11cMOn9Q/Y1tjmkZMWEGddaWeCFxF34PxnI1bFj/7nAtYu9OjWFVnLQBNzpinWwWW /FNISO6VZ0loic3wpQfH2IYVv81xAz7E4sMOGpDKAtLAoIm/LlnUeCfWQ1WPX5LDA3+zQl WUfuiLCLBi/NUMU9j1Dv8Mpg4enZLstU7tVvWCdbSp0mH2AgzEbw7pNN0OHcIeadql+1vW YTP1zRP3ioOm4zQVGTzd8pW09Fk1GH6JVfWLMc85UPpizFe47ZS2QVOXt3F9hQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011779; 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=61AaDAxKbOLaApOgc6P6k2wgx7ZZhb7JXrh4epva6Ak=; b=LsFfLANAiIa1ulCK7XvzhNo/OdTnoA9OhV288y1h/5g3b4SMu0mRTYZ1NGptK77eazmFdc dXPWMqElO1QzWXBQ== Date: Mon, 07 Apr 2025 09:42:41 +0200 Subject: [PATCH v2 04/11] kbuild: introduce blob framework Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-kunit-kselftests-v2-4-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=7377; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=wigAJUFJ+V9EVhNSp3BPVdxWuuiUQqmtFd9VHobAqVk=; b=W53cr/hBF4jP2PzCvJZgWJY4oQ5TqlaFkaGw7u+jGR9Cu1DPovyqhYzOJHDMXsTKszIKeqJdw lddPRiKmgI7DjR/GRuD7iv70BRo3E27/64A0GXV+m/B2dQF1WktVfb/ 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 --- Due to its closeness to kbuild this is currently added to its MAINTAINER entry. But I can also maintain it on its own. --- Documentation/kbuild/makefiles.rst | 23 +++++++++++++++++++++-- MAINTAINERS | 2 ++ include/linux/blob.h | 32 ++++++++++++++++++++++++++++++++ scripts/Makefile.blobs | 19 +++++++++++++++++++ scripts/Makefile.build | 6 ++++++ scripts/Makefile.clean | 2 +- scripts/blob-wrap.c | 27 +++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 3 deletions(-) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/makefiles.rst index d5cd73820e406276ee2e3721e265e3ed3cc299c9..c3a165fcb1ab0bbc090fd61c38ebd78317c7aa85 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -521,8 +521,8 @@ otherwise the command line check will fail, and the target will always be built. If the target is already listed in the recognized syntax such as -obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, Kbuild -automatically adds it to $(targets). Otherwise, the target must be +obj-y/m, lib-y/m, extra-y/m, always-y/m, hostprogs, userprogs, blobs, +Kbuild automatically adds it to $(targets). Otherwise, the target must be explicitly added to $(targets). Assignments to $(targets) are without $(obj)/ prefix. if_changed may be @@ -1014,6 +1014,25 @@ There are two ways to do this. This will tell Kbuild to build binderfs_example when it visits this Makefile. +.. _kbuild_blobs: + +Blob framework +============== + +Kbuild supports wrapping source or generated files into object files which are linked +into the kernel and then accessed at runtime through ``include/linux/blob.h``. + +Example:: + + obj-m := some-module.o + userprogs := some-userprog + blobs := some-userprog.blob.o + some-userprog.blob-symbol := some_userprog + some-module-y += some-userprog.blob.o + +Kbuild will build the :ref:`userprog ` ``some-userprog`` and +link it into ``some-module`` from where it can be accessed as ``BLOB(some_userprog)``. + Kbuild clean infrastructure =========================== diff --git a/MAINTAINERS b/MAINTAINERS index 96b82704950184bd71623ff41fc4df31e4c7fe87..d61e28e289c7027c026a872cd166342a4761b2a4 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -12847,11 +12847,13 @@ Q: https://patchwork.kernel.org/project/linux-kbuild/list/ T: git git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild.git F: Documentation/kbuild/ F: Makefile +F: include/linux/blob.h F: scripts/*vmlinux* F: scripts/Kbuild* F: scripts/Makefile* F: scripts/bash-completion/ F: scripts/basic/ +F: scripts/blob-wrap.c F: scripts/clang-tools/ F: scripts/dummy-tools/ F: scripts/include/ diff --git a/include/linux/blob.h b/include/linux/blob.h new file mode 100644 index 0000000000000000000000000000000000000000..de76cdb76cbab388b62f574b80fb13a4c84d1d2d --- /dev/null +++ b/include/linux/blob.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Linkable blob API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Weißschuh + */ + +#ifndef _LINUX_BLOB_H +#define _LINUX_BLOB_H + +#include +#include +#include + +struct blob { + const char *const path; + const u8 *data; + const u8 __private *end; +}; + +#define BLOB(_symbol) ({ \ + extern const struct blob CONCATENATE(__blob_, _symbol); \ + &CONCATENATE(__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 13dcd86e74ca830ce3fb2587df7f200105490881..c2965ee4002d239bf4e18115e026e7bcd5abb197 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -436,6 +436,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..82ab3bc641bd69ec35029c2f4a9dd6d6c6720a02 --- /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 CONCATENATE(__blob_, BLOB_SYMBOL) = { + .path = __stringify(BLOB_INPUT), + .data = &BLOB_SYMBOL_DATA, + .end = &BLOB_SYMBOL_END, +}; From patchwork Mon Apr 7 07:42:42 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: 878901 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 1A50810FD; Mon, 7 Apr 2025 07:43:02 +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=1744011784; cv=none; b=c7MYMUJW+lhVaL9DAnulh03kfj+Y7jbjR5lk483l9nT78w/VOQZVnzNHz4CvJ35IMfxP8h7TZtzWlgeAoBy1FJ2JXveIvWGuXKux2oYylD8i9Q6KPE9Rt4Y9NLxVYOcvPRkSR2g4JBdiezyURodRGI7oyAAfm/OY13fQB6pJbjk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011784; c=relaxed/simple; bh=pF2fDE3eDjUHyRwGflmFqBi7GrGzIztIWG8dRzLuGZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=SCqJ713dTIWynzIEucBM+Pj4NftwBbaNgZxf+JWi8qbuOJnBOKjVn00UNtXCEC6/zpoxfPRV6ZhfsnjCdlKUTjVspQYm4slOheXQPR3qCDcev5Xzz1ZJ3g2u4vZad+ADcwazFBv5WNmUEAKp3g3wIOPnw+GtNalwnODTgdTu7pg= 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=zSYBkLrD; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=WZOQ0mlm; 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="zSYBkLrD"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="WZOQ0mlm" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011780; 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=FY6zZZGHsbSSDkMNrLVAeMvYjekKEzJp+iUZSDSo7UU=; b=zSYBkLrDhpLu6S1Yu/Lk7b0eLUlw0UYedHqwyrk4IBGBO7Sf+dkvwj91TyKmN4udtvV/K0 7kCvXWGd1PIYCsL08cFFtX08FV0sUoxEQLgsTV2KiitG5Bk1XVx3vNEul3rjXaZfn8sYc+ VGOYwDR/Y9xhxYvSUB87xGiT2+nNBMqFkJC6S7ghBvAIkRWh+BhaMaelQ0/WXxsCX7z+b8 IV0WHs+mgN4mjR7L1N2eAVoOudx2djv9/20WbdZL27Hf3Py9ByD+X+qJvnW/mE+fIYGOer HL6gjLkRJNikfmMynk7txY9S6sg876X88OMhx835XByf1MOgQqLV973ZlpoeFw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011780; 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=FY6zZZGHsbSSDkMNrLVAeMvYjekKEzJp+iUZSDSo7UU=; b=WZOQ0mlmDB1FTVBOZK+LUUvT1r9k/uIkPKVAKtAxIoaK/8G41eyGJZpa/U3pnreF4bGvkp /wX+0F3FzaHieiDg== Date: Mon, 07 Apr 2025 09:42:42 +0200 Subject: [PATCH v2 05/11] kunit: tool: Add test for nested test result reporting Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-kunit-kselftests-v2-5-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=2070; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=pF2fDE3eDjUHyRwGflmFqBi7GrGzIztIWG8dRzLuGZg=; b=8mMXqdsPB4G8FLjMfuB3yG4/1+sTGCM4KvV7meAHqGYhGaK38Y2QZzC7F8cmsgGfGNo6qganY mE7KAefMyf/BGYFAccL4ETd8apFSp1evlnjKBw5opzltxXQ7lTCfvk1 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 5ff4f6ffd8736de3fca17dd9fcceabd7a68f9f98..755dc24350a76306a5b76998646e56fb3e386232 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 Apr 7 07:42:43 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: 879536 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 C20BA226D16; Mon, 7 Apr 2025 07:43:02 +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=1744011784; cv=none; b=YxIN+5m03+eKcLWXoCnv75fOO8dC5ecMXPBTf8dpUYZbx1GYSj15gvl3HG/UmsiFDPkWDU0I1HD2kn/9q7RqCO07HX1/+/QUhsgfZP3jWvxUOgvAncPmfztvovv0QRCl717Nct5EhBr45xitSwE7KXPk4y3TEiSkO1cm8lva7ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011784; c=relaxed/simple; bh=3IB7VI+L3TgsvP1jwdWMbiCaiRt4l4gNK7FQAsl37ak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LIocDjoXYl0un4QWsddowceecdT1FUspONlpYhYLPph8ZzKaa2VVHm1ebvFZRvtq4AIy5kw05yPFQa3AsE5PCaXOg1JSXHfXfyRL1NhRVt2gpYQHvM32hhQ4tdPCau1XzMFTjwNnu7FXKjqtUMAsr6kalp0uwBrfkTDIEcogqWY= 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=lAw70X/q; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ts6H7wde; 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="lAw70X/q"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ts6H7wde" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011780; 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=al7zHswypumXIW9i3yKUwj+oxduEQ9DVcaHemgzr5gY=; b=lAw70X/q7ujZz/WDtwJTfmmmxibi7z2bpRmganrjZ6IQabUgJlw+6Vl4G1kI5won4HJXgs sNWDcY6qDA+ak0o5oMxaknW/qh2kMlVltwLYoeJPheDIyQgw9eXDhK52LbNiE7r4rwdiag W/o5Y08MCCnilgXn+A/3ZSuhrFFzwfoO/Uo58BG+3SsAvzYEgpSZGh0mNkBXd9C2mEZv6c hBZE5Uj5dRdyERZIs/pzSnDBqmORPqVw2f5a/1GfVQORKuyH6FkW02W0tFl/myNcwj5iYT PaJMw6hRI85V3h3aJJWVzwy1MhOhUyIIlNqf0k19FMJJ0TGIS3TTx8M9SqzBmQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011780; 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=al7zHswypumXIW9i3yKUwj+oxduEQ9DVcaHemgzr5gY=; b=Ts6H7wdej6bfnCZeF3OLCeG5AACfWppqTlMwW84lKXSoAn2BYa6k6I0ce8xzkF0iH6Lqu+ KVIyDExQXeLCAUAQ== Date: Mon, 07 Apr 2025 09:42:43 +0200 Subject: [PATCH v2 06/11] kunit: tool: Don't overwrite test status based on subtest counts Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-kunit-kselftests-v2-6-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=2733; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=3IB7VI+L3TgsvP1jwdWMbiCaiRt4l4gNK7FQAsl37ak=; b=iVXjhmHBMWkFjHbit/Hw9b4XCX48EMklfbgbfc5sofkXa7jjiRZPFa/KOSHJwV3sGdbb+/4vF eXam23foLunAwIQ5hCviSrYNBdaUInktQjt21VcmULRBIk9hYpzne88 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 da53a709773a23252703b74109142294899b1bbb..b4a695ed7d2c88120b35b617f0ff2f1cb2be60fb 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 755dc24350a76306a5b76998646e56fb3e386232..946a68eca16467d9a4bae50f5d50985d9765ed54 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 Apr 7 07:42:44 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: 879535 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 A66D8227E96; Mon, 7 Apr 2025 07:43:03 +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=1744011785; cv=none; b=RmLR9NhK64MT2uJJkzCWsBXFD3Qf6EtxX6eRkv8SJUUPaJ6edUPAU5d0efGdKcF0W/Y77YTady+kZ01O0ungIUzzuL9YI3oXzvjRjr95Z4lLMVtSDzbuFDu/5z4nA3E1zt0Ic8fmebgS2ilpe6a0o1NLTIoKa7FhqP0syF3OMdY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011785; c=relaxed/simple; bh=5+9YHZKmXU6mu3ieCn3ti44g1IrXSfzapL+qAM5m2Io=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GRut2c28f3meBzgApwSoC8zhbfLF3UmWyNe/H08f+4lxhbLOZc22L0qRxP781omP+G6FzIG2v7GDK4gRwSzInGJw3ysFWElAG1PNyrTWEVE/JQkfDAdV90MOeXtvlDZxSfbwcoWLQ84r1bf0JTftkGidpXafLJElttswNtlOM1Y= 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=iUQjQmZ4; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=nPfo6cdf; 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="iUQjQmZ4"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="nPfo6cdf" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011781; 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=l6kgYTTgkOaGrAjyvy1nAqnbCYfemdPya6M/+xOGiEc=; b=iUQjQmZ4WLhv8Bj5/LsbYSllLNNiC0ByhwrAdFwfc39flMyavPPOUM6dQuI7mi4KnF6s4o neo5r27sEKMqJifGGFiPyP01Fi9q6VMDhf4s865/COiDHsN8j1e9Xq669GTtN8X/wVwk+t YSMDk1L6is7VccCSrkRCAPsouTHtZN+eU+sb3WP5eV0ZM3MmLy2RJTqbPoLOEzGwIPVOYN pjiSMF9VBmawWqMU58NYUfE2IJFUC5QF/0UDiHaXjgqzWygWKcmdB5cJ1Mr6gagh2sTkFb z85rpFK0Mbu85SXLloKObIZXS/eWWFGcrt4SNfbg+YbLez+UACMzonmXOh9MXg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011781; 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=l6kgYTTgkOaGrAjyvy1nAqnbCYfemdPya6M/+xOGiEc=; b=nPfo6cdfGcoXjaSzliF6IZJmggvMNlZYQMb27T7+3WWDH99HiM2zIHKtCOPq0+WPRcGm1E Wqo1L+wiPA4EDpBA== Date: Mon, 07 Apr 2025 09:42:44 +0200 Subject: [PATCH v2 07/11] 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: <20250407-kunit-kselftests-v2-7-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=2785; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=5+9YHZKmXU6mu3ieCn3ti44g1IrXSfzapL+qAM5m2Io=; b=29XvoBTMRB00a/65QHfQvVAsIXIBH7G5KKROFGXUVpbDYaKm9czWb2Mqti8KnPTC6ddNLcCrB P/fHFMKUu6QDO8VyonYFUsn6Cp9qm4RYAs5YP3YfKCafgYJ+RTmSNaK 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 b4a695ed7d2c88120b35b617f0ff2f1cb2be60fb..41aaa85d249b592efe6227a4c2d9517a5c13dbef 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 Apr 7 07:42:45 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: 878900 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 A6976227E97; Mon, 7 Apr 2025 07:43:03 +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=1744011786; cv=none; b=ENT6aRndKtSJMwnqTC2zaTuamB8Z1/qbIVW2ne2++vaNVHGbOGN+tDDPhg8SwoEa6pJjGLtNs6hjDDyHC+gD6rP1mMvVfXpp3NQOjDwG6W5wdm/kmjIA8RSeaaFqWEqe8T0xeoXGUHUrCEShYUw7ellMkg+vK6tonfHcb0FAMcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011786; c=relaxed/simple; bh=BJjxDVOAScIUTDwIklTYMi6GjYN1Y6hswgbnbM6bCic=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JlQTqtn9aAcjb/oIJpMavriNk4wGX38LyujNzsnRgW51H5WGO4k6TaLrsNDP5PryRgmF7Q9EJtmdVMzu6kL4Uz5Z5gz6mDY8Y8PYa/LwL5+eja7pfQPciqdd1wk8ybbLzdQ/faYmQJw0aqflwXF3sxKmptdVsptVIUWGcal1Loo= 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=Xc9xbUdx; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=eWkI91IU; 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="Xc9xbUdx"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="eWkI91IU" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011781; 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=xWHOXiEgR336RbzqYYV1p85OpVn4Usorgcrpl6yAPSI=; b=Xc9xbUdxRyump+8gfCPyVulGUDomdQHhawumfaDgxVlq6ybZGMuOuhg7QEzlt68vcIWk9y KvgDVPYT15UFLnVSiILRBwB0buKrhKDA2m91/ZXnuNT7q9Ur25sgO/HwtgIYt1gbkH/eeS Qn7qdzGCzBzXo9dA/UTIBD8wLuG58lmhrgu8u/rAzw8XaJNP8nqcyX02cK/E91P3Fe+QNS vzwDlFnn9geGuSU8qecXQr+/wLQ8OvYcMRVy0czRI4Zv9/z0HvRh6adAt0TbLU04z88+Cx zAs0fRxmmI9Vl+s2QWrCif3In/7rp9yQN0igbQPqiVfv2INAC5zszmawWxbYTg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011781; 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=xWHOXiEgR336RbzqYYV1p85OpVn4Usorgcrpl6yAPSI=; b=eWkI91IUG8tdyP7VcMzCTzlONqxNiTcBjsjlCU54tRobZMT1g93wucwKgdGdZR82IpGKWj /jJ8e6KDNcgZIABQ== Date: Mon, 07 Apr 2025 09:42:45 +0200 Subject: [PATCH v2 08/11] 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: <20250407-kunit-kselftests-v2-8-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=11612; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=BJjxDVOAScIUTDwIklTYMi6GjYN1Y6hswgbnbM6bCic=; b=TxVkciELYktAzCZ0/FiXRQDVHJ/mX91C7FEKwy32O821rrsEohzX9n16eShxqXCD5HIw6JELE 6+cYO2dYp6aAjGxi/G0TuDXMOvgS4M+7s2DunvTigz35u0THlNhNqAR 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 --- Currently this depends on CONFIG_KUNIT=y as it uses some non-exported symbols around process management. --- Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/uapi.rst | 12 ++ include/kunit/uapi.h | 24 +++ lib/kunit/Kconfig | 11 ++ lib/kunit/Makefile | 2 + lib/kunit/uapi.c | 287 ++++++++++++++++++++++++++++ 6 files changed, 341 insertions(+) diff --git a/Documentation/dev-tools/kunit/api/index.rst b/Documentation/dev-tools/kunit/api/index.rst index 5cdb552a0808f25baeff5e47a9227b7b62c69e40..34d8fee9a97059d6da919a6fb1a7e359b5e0beef 100644 --- a/Documentation/dev-tools/kunit/api/index.rst +++ b/Documentation/dev-tools/kunit/api/index.rst @@ -9,6 +9,7 @@ API Reference test resource functionredirection + uapi clk of platformdevice @@ -32,6 +33,10 @@ Documentation/dev-tools/kunit/api/functionredirection.rst - Documents the KUnit Function Redirection API +Documentation/dev-tools/kunit/api/uapi.rst + + - Documents the KUnit Userspace testing API + Driver KUnit API ================ diff --git a/Documentation/dev-tools/kunit/api/uapi.rst b/Documentation/dev-tools/kunit/api/uapi.rst new file mode 100644 index 0000000000000000000000000000000000000000..b4764424c629bf69194cf2786f52aef154b02bf8 --- /dev/null +++ b/Documentation/dev-tools/kunit/api/uapi.rst @@ -0,0 +1,12 @@ +.. SPDX-License-Identifier: GPL-2.0 + +================== +Userspace Test API +================== + +This file documents all of the userspace testing API. +Userspace tests should be built as :ref:`userprogs ` and included into the test +module or kernel as :ref:`blobs `. + +.. kernel-doc:: include/kunit/uapi.h + :internal: diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 0000000000000000000000000000000000000000..a6181790c96a42df05839097991c1fbfd889cdbe --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Weißschuh + */ + +#ifndef _KUNIT_UAPI_H +#define _KUNIT_UAPI_H + +struct blob; +struct kunit; + +/** + * kunit_uapi_run_kselftest() - Run a userspace kselftest as part of kunit + * @test: The test context object. + * @executable: kselftest executable to run + * + * Runs the kselftest and forwards its TAP output and exit status to kunit. + */ +void kunit_uapi_run_kselftest(struct kunit *test, const struct blob *executable); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..79fcf0565f60100920b9613199421bf9cae1c2b0 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -93,4 +93,15 @@ config KUNIT_AUTORUN_ENABLED In most cases this should be left as Y. Only if additional opt-in behavior is needed should this be set to N. +config KUNIT_UAPI + def_bool y + depends on KUNIT=y + depends on CC_CAN_LINK_STATIC || ARCH_HAS_NOLIBC + depends on TMPFS + select HEADERS_INSTALL + help + Enables support for building and running userspace selftests as part of kunit. + These tests should be statically linked and use kselftest.h or kselftest_harness.h + for status reporting. + endif # KUNIT diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 5aa51978e456ab3bb60c12071a26cf2bdcb1b508..989933dab9ad2267f376db470b876ce2a88711b4 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs += test.o \ device.o \ platform.o +kunit-$(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..081ddc46e3ccb9ef88f9cb2a66d5e2bf41da2eb4 --- /dev/null +++ b/lib/kunit/uapi.c @@ -0,0 +1,287 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Weißschuh + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define KSFT_PASS 0 +#define KSFT_FAIL 1 +#define KSFT_XFAIL 2 +#define KSFT_XPASS 3 +#define KSFT_SKIP 4 + +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; + + /* stdin, use the *write* end to the pipe to have an unreadable input */ + err = replace_fd(0, out[1], 0); + if (err < 0) { + fput(out[0]); + fput(out[1]); + return err; + } + + /* stdout */ + err = replace_fd(1, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + fput(out[0]); + fput(out[1]); + return err; + } + + /* stderr */ + err = replace_fd(2, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + replace_fd(1, NULL, 0); + fput(out[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); + kernel_sigaction(SIGABRT, 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(struct kunit *test, 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; + + kunit_log(KERN_INFO, test, 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 kunit *test, struct file *output) +{ + /* + * printk() automatically adds a newline after each message. + * Therefore only fully accumulated lines can be forwarded. + * Each line needs to fit into the buffer below. + */ + 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(test, 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(test, 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; +} + +static int kunit_uapi_run_executable(struct kunit *test, const struct blob *executable) +{ + const char *exe_name = kbasename(executable->path); + struct vfsmount *mnt; + int err; + + mnt = kunit_uapi_mount_tmpfs(); + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + err = kunit_uapi_write_file(mnt, exe_name, 0755, executable->data, blob_size(executable)); + + if (!err) + err = kunit_uapi_run_executable_in_mount(test, exe_name, mnt); + + kern_unmount(mnt); + + return err; +} + +void kunit_uapi_run_kselftest(struct kunit *test, const struct blob *executable) +{ + u8 exit_code, exit_signal; + int err; + + err = kunit_uapi_run_executable(test, executable); + if (err < 0) + KUNIT_FAIL(test, "Could not run test executable: %pe\n", ERR_PTR(err)); + + exit_code = err >> 8; + exit_signal = err & 0xff; + + if (exit_signal) + KUNIT_FAIL(test, "kselftest exited with signal: %d\n", exit_signal); + else if (exit_code == KSFT_PASS) + ; /* Noop */ + else if (exit_code == KSFT_FAIL) + KUNIT_FAIL(test, "kselftest exited with code KSFT_FAIL\n"); + else if (exit_code == KSFT_XPASS) + KUNIT_FAIL(test, "kselftest exited with code KSFT_XPASS\n"); + else if (exit_code == KSFT_XFAIL) + ; /* Noop */ + else if (exit_code == KSFT_SKIP) + kunit_mark_skipped(test, "kselftest exited with code KSFT_SKIP\n"); + else + KUNIT_FAIL(test, "kselftest exited with unknown exit code: %d\n", exit_code); +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); From patchwork Mon Apr 7 07:42:46 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: 879534 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 3B92F22839A; Mon, 7 Apr 2025 07:43:03 +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=1744011786; cv=none; b=jxSFNaa5/Mu9fZK7mbgVsGQH9/SGHOnuooJ7S+534/sxhocc9znl3M1JmBYQGyGqLNpnqaXR2EcLCsBT/Gpkk4DUiMVx3I0Mn1ED7r2E5BlDDNWot0v5QW1QLnoYmB+uK/E+qjWOWbgN2wY7wTP4bhM8oDn0huKqaAD+KUPAlOk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011786; c=relaxed/simple; bh=JuaIjS9/HyTR39eTJxdj9heG3qdGFyt4hvgxTOmYfHs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ow18ouU9le4LTIqBSTc+V4M1Uc02Gj5kO60FYqudc18U8in4RjCGKSoE9uMElHFgMkZ5hl+X8ccua9EX3z2ZpcTjPES3ZZhonpE/2FGITxKnBYw10s8Aqrcnf+2IvjMQ4jJgc5c4USp0zUfm4wLxN7L8J8SpFQP6IdxnbPl8fjA= 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=tsZImF8I; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x+RwxxsW; 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="tsZImF8I"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x+RwxxsW" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011782; 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=SlhQKzkZM6Jr36iAYSy0CT5G2SSQr4FADfY/xCw8dbo=; b=tsZImF8IKRFZs9LynGUEysPNfC/cknXyNJce05iqbVB3g/Ee8NQoEt/F4a3SpKL2qnVa/c vEpmRoj9yws4jNTxf4CH+AYvONrIjQNxMQekdsYe4hR35mj4rD+4crf8KSN7JSzL4Fdb+0 X26ziTNBc3EBYKHo+f6QwN7e61ia8GIzcyDjFA9qbCHj+NNJjPqGJWus8mBrWkL2xBK6qx HJklh8aOsuboYT/vyE7i5yF/r1S8N5MQoZTv01PWoWnnrJqYjJk2TiEW7s8HbvxcQskyvX O5XtF2YdmOfmrWJDYRruhrOUPOcPDIzRvPVRzcaIPvJ6D6Drtzy5mtBe6ER3/g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011782; 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=SlhQKzkZM6Jr36iAYSy0CT5G2SSQr4FADfY/xCw8dbo=; b=x+RwxxsWDYfiJ/iTSGu6N6jGVesB6Fat4uppuHmFT0p4wx+Z0A6HsJxvhj03ktcEaAQaM8 ZFANoWpGsiwe1/CA== Date: Mon, 07 Apr 2025 09:42:46 +0200 Subject: [PATCH v2 09/11] 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: <20250407-kunit-kselftests-v2-9-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=3632; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=JuaIjS9/HyTR39eTJxdj9heG3qdGFyt4hvgxTOmYfHs=; b=pQmTBghv8NpE4tuvPIF6Q2FgZ5AQGkatdQ4Q38jAFbpCj6aPC6lSE+zpN3nem/WABJQCcGUHd dU9UOjM9Y6iDkbZ8xStr3Mr961j2CbU5FEbM/PnPAxZRxvN21Kn36MT 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/.kunitconfig | 2 ++ lib/kunit/Makefile | 9 ++++++++- lib/kunit/kunit-example-test.c | 15 +++++++++++++++ lib/kunit/kunit-example-uapi.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/lib/kunit/.kunitconfig b/lib/kunit/.kunitconfig index 9235b7d42d389d2c7bf912546c7bb084eae99235..b7433e691563a3a8442db69874dea88f3b607332 100644 --- a/lib/kunit/.kunitconfig +++ b/lib/kunit/.kunitconfig @@ -1,3 +1,5 @@ CONFIG_KUNIT=y +CONFIG_SHMEM=y +CONFIG_TMPFS=y CONFIG_KUNIT_TEST=y CONFIG_KUNIT_EXAMPLE_TEST=y diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 989933dab9ad2267f376db470b876ce2a88711b4..1b6be12676f89cafa34f0093d8136b36f4cf5532 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -30,4 +30,11 @@ 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-example-uapi +kunit-example-uapi-userccflags := -static +kunit-example-uapi-nolibc := $(CONFIG_ARCH_HAS_NOLIBC) +blobs += kunit-example-uapi.blob.o + +obj-$(CONFIG_KUNIT_EXAMPLE_TEST) += kunit-example-mod.o +kunit-example-mod-y += kunit-example-test.o +kunit-example-mod-$(CONFIG_KUNIT_UAPI) += kunit-example-uapi.blob.o diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 3056d6bc705d0a8f196f0f4412e679dbb0e03114..b2681a6e047dfd6fea4a7cca60e81651d09c2eae 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,17 @@ 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) +{ + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, BLOB(kunit_example_uapi)); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + /* * Here we make a list of all the test cases we want to add to the test suite * below. @@ -297,6 +311,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-example-uapi.c b/lib/kunit/kunit-example-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..4ce657050dd4a576632a41ca0309c4cb5134ce14 --- /dev/null +++ b/lib/kunit/kunit-example-uapi.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace example test. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Weißschuh + * + * This is *userspace* code. + */ + +#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 Apr 7 07:42:47 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: 878899 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 A37B0226170; Mon, 7 Apr 2025 07:43:04 +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=1744011787; cv=none; b=bwOEHoSlbmGkEhBrULxyZhipdi/NHaHjPE1OaocgaECdN9H3DHoX2/o00OQ+rKIDB/ZuN99uwOy/Z1xQ12xwUlY3zaNt7324OszdggF6U1xj5Va6cEiTDkbnR3oGb7yhwKwRi8Y6QvkHZSfLVD1x02Q1TCsCtBascBOXcAZIaug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011787; c=relaxed/simple; bh=xUCaF6k9BYP7TOM/3xFonEKp/BSBo2jOg0KnUhM0Eqw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E+dn04KLz6bui4UQdBnMfOQ9sENS7epHnhMJ9os9R7uZv1R9dyeKa4t9ePyZovuEQoV8UMePVx01Qx+eD8xoz+coSGbTVS5KUfpjPNNfhviA+dZ4NpLbPlDUpOUvexyCzxebiJhXNmpM3YVpC/FcIYSZjcQJxZRtIVHLeKutrKA= 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=unOZspRp; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zKRi9Mbc; 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="unOZspRp"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zKRi9Mbc" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011782; 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=Sxk6G7Z5jRjy2/dO8fPQpjCbk+UdXoRV8wS6B4QQkus=; b=unOZspRpSui6P7RYwIA4YsN7fEn/9Sr90Rg3tWxwjd3FTF8nLDOJbxc6KWibf/NdGEgCms qRK1MxT6s3kc2jv1bCKMrj9t3JA/eCqM+GkNBXcVeFjXlrvNhO4/F0i/u5tkQDBq/PqUj4 sTqfZQ/wivpvd9i3GQfsh0GdSctDEMr7fZSiqhvR8ZBbsjNMyWbQBiLmX2cPTpiLR308dI iAJoT19cBjZ4ZV7pbgZGMXJOuuiG+Pewhk7Bzik7MJpBoPmdjmXi6gu3/xMrj2RDuW7N9T 5NZe6ICLPQShrvQU7yxfTSbruM7EzsMKyQDxCMRPbRAyMMkCkatVGaG981+4sQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011782; 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=Sxk6G7Z5jRjy2/dO8fPQpjCbk+UdXoRV8wS6B4QQkus=; b=zKRi9Mbc+dA/qpsArLYMMY+cbx2KuG6iL/4OluhXXu5tJMtfIv9+IofEX5Yn4iJfcvc3hO X/upn/hbeZPid3Aw== Date: Mon, 07 Apr 2025 09:42:47 +0200 Subject: [PATCH v2 10/11] kunit: uapi: Introduce preinit executable Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250407-kunit-kselftests-v2-10-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=4690; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=xUCaF6k9BYP7TOM/3xFonEKp/BSBo2jOg0KnUhM0Eqw=; b=oiyTkWtQflr5rtCylnwcDKBGvuF5yyQ5gLYJwwUshGhm6oNpqg7mc0B8Co+vgvDWAL3zGow2K ulXHDAvMpK7Dceedd75ai+119iIRNq2keYRuLzqpz8jCFzKtL97gkyF 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 | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/kunit/uapi.c | 11 ++++++-- 3 files changed, 82 insertions(+), 3 deletions(-) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 1b6be12676f89cafa34f0093d8136b36f4cf5532..0e9a26d90bf4d5128e270ecaa8f3465f28da0fa2 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,7 +12,14 @@ kunit-objs += test.o \ device.o \ platform.o -kunit-$(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 +kunit-$(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..56bd50822b91af15d88cb32476fbbe6a85806761 --- /dev/null +++ b/lib/kunit/uapi-preinit.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace environment setup. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Weißschuh + * + * This is *userspace* code. + */ + +#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 081ddc46e3ccb9ef88f9cb2a66d5e2bf41da2eb4..20eba19cbc0d4e1effcc7813df0da6eb5d1ef846 100644 --- a/lib/kunit/uapi.c +++ b/lib/kunit/uapi.c @@ -139,7 +139,7 @@ static int kunit_uapi_user_mode_thread_init(void *data) kernel_sigaction(SIGABRT, SIG_DFL); complete(&ctx->setup_done); - ctx->exec_err = kernel_execve(ctx->executable, argv, NULL); + ctx->exec_err = kernel_execve(kbasename(BLOB(kunit_uapi_preinit)->path), argv, NULL); if (!ctx->exec_err) return 0; do_exit(0); @@ -239,6 +239,7 @@ static int kunit_uapi_run_executable_in_mount(struct kunit *test, const char *ex static int kunit_uapi_run_executable(struct kunit *test, const struct blob *executable) { + const struct blob *preinit = BLOB(kunit_uapi_preinit); const char *exe_name = kbasename(executable->path); struct vfsmount *mnt; int err; @@ -247,7 +248,13 @@ static int kunit_uapi_run_executable(struct kunit *test, const struct blob *exec if (IS_ERR(mnt)) return PTR_ERR(mnt); - err = kunit_uapi_write_file(mnt, exe_name, 0755, executable->data, blob_size(executable)); + err = kunit_uapi_write_file(mnt, kbasename(preinit->path), 0755, + preinit->data, + blob_size(preinit)); + + if (!err) + err = kunit_uapi_write_file(mnt, exe_name, 0755, + executable->data, blob_size(executable)); if (!err) err = kunit_uapi_run_executable_in_mount(test, exe_name, mnt); From patchwork Mon Apr 7 07:42:48 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: 879533 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 11DA1229B37; Mon, 7 Apr 2025 07:43:04 +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=1744011789; cv=none; b=pgcVRkCdtvk0AwsApj61ouK6jEXYKf4RmvaYj+QkKY98pXDxox/+v4JuqIYNRpu9ImCP19XNRWUoBBMChKR2qTJ33GHMik6ED5dz0YzQM1Ftcsh3zDVjD85L4FDlLODmM6wo360tBbbiiamVAoQWLb24TLTzq4hCIYxB8R2EOuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744011789; c=relaxed/simple; bh=Xu0nGb1RBd1CDhyD0m7yCE3cioNquNLySTJFGTDwjao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=E0KQmyMLG3BH8eX5t3Dxdb1/rxXhY7YQPor2oambFViVBGmNJnfjq5CqpDqSTpYRd8eh3t5BuUoHEDL21k9SWdRr8tGV6oWTjUrGhdeoeVxBj9pAq+lk0vmLPxHp1T9Jr5glJWwe3qPw+hnDNJ17NUrGppJN0SqFd6sHex0Xz6k= 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=RVJtXjbw; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=muD2AkzR; 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="RVJtXjbw"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="muD2AkzR" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1744011783; 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=Fh2unyChEPBf9y7CX/RyBwfskSXNSGnqSQiwlf+aj58=; b=RVJtXjbwy7sozind3uDpXZ4nMXH19nxGBDnFxlf2qZ5bawYGkIAmc4G9hM1Kx5gz+nfp2f TCG49yZb6ECoLcr1tSqaQCo4BpH2MclAOXlhJIR7e9tSO7vW7IgUakh03Pyuoo4QSAx/Lk 8xoLgvWl3DMabRfNqL30TiMHGHh3lNIpRQpzUnq4vMl4SBlXtzvERa27DvH5w8ssfiA6ig CRgwoIOy/eGz1Bnkn4AXa3FL5khH2Tjt9ZoUQiAhob1tLxmHwcFexiUcDZn5E60XwMvgEQ whS99NQavWc3JwywfirrRZeOh4SaxZNpCmPnAvQFpe+KgLZOjvgr0P/3+AHyzQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1744011783; 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=Fh2unyChEPBf9y7CX/RyBwfskSXNSGnqSQiwlf+aj58=; b=muD2AkzRJwItNBC+oQNRwwODIMyO4dMt1xuUZ2OqMSAKU8Tcbyy76kUgbVQsCHKjsxgKCT sgP9XK6XYWiyybCg== Date: Mon, 07 Apr 2025 09:42:48 +0200 Subject: [PATCH v2 11/11] 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: <20250407-kunit-kselftests-v2-11-454114e287fd@linutronix.de> References: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> In-Reply-To: <20250407-kunit-kselftests-v2-0-454114e287fd@linutronix.de> To: Masahiro Yamada , Nathan Chancellor , Andrew Morton , Willy Tarreau , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Brendan Higgins , David Gow , Rae Moar , Shuah Khan , Jonathan Corbet , Nicolas Schier Cc: Christophe Leroy , 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=1744011776; l=1637; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=Xu0nGb1RBd1CDhyD0m7yCE3cioNquNLySTJFGTDwjao=; b=9+Ci04x9JPHWfBiiC85eaitNDlilTzJtZJ7o0CBVN3RWJtjvGW+OUEyH06U2XAd4V8XpX5u8Q G1PdRLPg325C8zFfrPvccqNtmTdS1mG4GzXWe6c2tH38ic27egE5NLB 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-example-uapi.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/kunit/kunit-example-uapi.c b/lib/kunit/kunit-example-uapi.c index 4ce657050dd4a576632a41ca0309c4cb5134ce14..d121c4620716aadddc38a1d5845e4b51e721fb67 100644 --- a/lib/kunit/kunit-example-uapi.c +++ b/lib/kunit/kunit-example-uapi.c @@ -8,13 +8,47 @@ * This is *userspace* code. */ +#ifndef NOLIBC +#include +#endif +#include +#include + #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)); + close(fd); + + if (r == -1) { + ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno)); + return; + } + + if (r != 16 || strncmp("kunit-example-u\n", buf, 16) != 0) { + ksft_test_result_fail("procfs: incorrect comm\n"); + 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");