From nobody Wed Oct 8 16:06:05 2025 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 C9C7B2264B8; Thu, 26 Jun 2025 06:10:19 +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=1750918221; cv=none; b=I+M7sq6qZP1+AYDIN+mRapTbeaDH6r5sp0ftNad1Nbr2esUBrFmC03J3skHCPgvntUzw5jGwDohFMT2AvvhQosZVlnPD2IOiCQCRyecmEGCt2mtwLA80D8HSp2jFLmnQEu6cGkSIEAKS6VYgfgntAK3pKDaRcLjE0T1SZRNVh78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918221; c=relaxed/simple; bh=VQxsVor9ejvNkW+zMsNv6ylbSNC6UWshMp7dNSJXIGU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cCBZbfoir/sdPfje+jpfusPScJQm5kwGay+6vSkxg+5EkenNrn16mFdqfuD0CkUC1L+gv2y5PZlfPAdntCUAHMQzRIKwj2CQj5gY+jukFAMc4fbgDVz5FdFS8eEbfZplU7fzNy0OuCFWFppwGuXQlLlLwd52FjJQjM8Xo6ILXI8= 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=BZPfXKem; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=kbHAUoSn; 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="BZPfXKem"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="kbHAUoSn" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918217; 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=Glf9QqUKGXuoDH6daia/H7DqVosWzcrmQsY661kVE2s=; b=BZPfXKem4GMLd72sR9kF+JfCnKidqQpdIZIUmKXtGteC8kRiCYgxWo9OT6C4wyVL6swhDd km3AmxdnPFTVG+jYbNGhxbnUQJqMRUjVBW+idNjfvaaV0VMn51IJQpnOO3zDM7lItiztaP iLk8xK4Kh4h3Rbu+WjMJio2lWcdQF84jKrzkWyZ+YXf6hOQfkIa8akJgSLLs7+oPDy1utE V/3BnkQGKYl6vK7XntcFaHTI6tbos2nXJKGxgtxaKLzl32GclaR+rhvhxkbaTzgaAv6Lxe KNXIs9RRgPnXna2m8xLi1KtbWENQS9X+k4pp6eFKj6fm9uN9/93gAEnazzyN9Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918217; 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=Glf9QqUKGXuoDH6daia/H7DqVosWzcrmQsY661kVE2s=; b=kbHAUoSnrWMlRUChL9teVwyAdMmhNZzrCNBCGLIK9guS53cfwvYkdFmGZDU+jv2DD6L55U ZH/ovbQx2o/MbCBw== Date: Thu, 26 Jun 2025 08:10:09 +0200 Subject: [PATCH v4 01/15] kbuild: userprogs: avoid duplication of flags inherited from kernel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-1-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=1184; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=VQxsVor9ejvNkW+zMsNv6ylbSNC6UWshMp7dNSJXIGU=; b=DiOoPDI4CefA9sIOkV5GE9zeB3R/ajtwPY4A++qOT427a7uO6gy/mj89YznvhGL79N/TRjUch CFGD0XKTgSrDmhjgjLwjeuT4KIwMLcEHCa8/IPDjXul4bISUop78vnc X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The duplication makes maintenance harder. Changes need to be done in two places and the lines will grow overly long. Use an intermediary variable instead. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 35e6e5240c61a8a329011929fcd0352b881dccdc..c4293cf91e968ca8ee64452841f= b266e24df63f6 100644 --- a/Makefile +++ b/Makefile @@ -1130,8 +1130,9 @@ LDFLAGS_vmlinux +=3D --emit-relocs --discard-none endif =20 # Align the bit size of userspace programs with the kernel -KBUILD_USERCFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) -KBUILD_USERLDFLAGS +=3D $(filter -m32 -m64 --target=3D%, $(KBUILD_CPPFLAGS= ) $(KBUILD_CFLAGS)) +USERFLAGS_FROM_KERNEL :=3D -m32 -m64 --target=3D% +KBUILD_USERCFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) +KBUILD_USERLDFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) =20 # userspace programs are linked via the compiler, use the correct linker ifeq ($(CONFIG_CC_IS_CLANG)$(CONFIG_LD_IS_LLD),yy) --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 458F422A1D5; Thu, 26 Jun 2025 06:10:19 +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=1750918222; cv=none; b=iPagxAqjW/zLRCYSL4kbz/IMpHxZ9t4a3/A89I+bP2mZLR08XFxT219p5IELkB1bWNe4znDB55y5+PKxaNE1COs5WRMxY3OZRTMNv9apw8stDxwV1gBGKHLJkthEyu5FV7H0J7r/sHGQ8sZrIu9WtEZkLqPmQHOB6m+JdTwOUEc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918222; c=relaxed/simple; bh=a+7kBsO/6ZH8nc37PZdREer0Ot+5+WoWMqnBLoalgfI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GsXzobAsry2CFCFNrXz9vcMhkn4C2URgmdRkA5cibOqS4nRDRjXsQLi9KgBkx4K08SRKILRP+zCCxMCsEo3PKxN4CBNaGXeRWDqJABC7xoYnZDTdkl8Sr4IrFCTKylT8bd5hHrtm3wN4mdKZ2rTgArNB2rIRm76iGkQ47fAZOvw= 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=dPJ7WoDU; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=YVeu/r7m; 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="dPJ7WoDU"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="YVeu/r7m" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918218; 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=B1P/cigZmbp0eEaYiCMikiXLu/FLueV3OD0pJokIijk=; b=dPJ7WoDUJTsvVpEPKQozFiU2R3hUW7mf06fKPQE84oiH061KN39V2bThDkIN0aTlQNqXHq N0n6sLh7sg5JUBCBowVeKgy3KH36lMAXtNm8nmI3MIHvS2gF0U5yyIwYJuf0tsPkBJYUtp qwA5B/m/2t/TtUpUMzNo916FlE/+crTl1JomUYZMPXs04TRNxxNANP4Hu42PILJVJmlhox rxchWjaLFPSD8yflKUYFBw9KGvdOpwAenGCgh89gr19H68MRCCq62tHAh1BX6BbUzI/DDF /xd0AMov9OSmxKnsopK47Du9+MOkDqLRRdOEyxDprHtCzeUgT4xmaXc+8DFxdg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918218; 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=B1P/cigZmbp0eEaYiCMikiXLu/FLueV3OD0pJokIijk=; b=YVeu/r7mUMmk9XxjlZ1ZCx8GHrd9FM/of0QLJahaTZdxkfLMYSHvIzpH/P6/y1svd4lZaf iuOcedoMmFnHmXAg== Date: Thu, 26 Jun 2025 08:10:10 +0200 Subject: [PATCH v4 02/15] kbuild: userprogs: also inherit byte order and ABI from kernel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-2-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=1177; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=a+7kBsO/6ZH8nc37PZdREer0Ot+5+WoWMqnBLoalgfI=; b=13VojceL40ISXBegrEipheICPgswj4vbH+4wycxWWZf1MrEguMSldecKHDktTIA2XogViCz6e 6w669MXsofgAXL7cb3G0VD+4etyheLp7ONrAyKYoR5hmbADgChKXM5H X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Make sure the byte order and ABI of the userprogs matches the one of the kernel, similar to how the bit size is handled. Otherwise the userprogs may not be executable. This happens for example on powerpc little endian, or riscv32. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index c4293cf91e968ca8ee64452841fb266e24df63f6..b9aa1058321dabd3b3dd5610e45= a2807dfa257f4 100644 --- a/Makefile +++ b/Makefile @@ -1129,8 +1129,8 @@ ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),) LDFLAGS_vmlinux +=3D --emit-relocs --discard-none endif =20 -# Align the bit size of userspace programs with the kernel -USERFLAGS_FROM_KERNEL :=3D -m32 -m64 --target=3D% +# Align the bit size, byte order and architecture of userspace programs wi= th the kernel +USERFLAGS_FROM_KERNEL :=3D -m32 -m64 -mlittle-endian -mbig-endian --target= =3D% -march=3D% -mabi=3D% KBUILD_USERCFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) KBUILD_USERLDFLAGS +=3D $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLA= GS) $(KBUILD_CFLAGS)) =20 --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 9183622F76C; Thu, 26 Jun 2025 06:10:20 +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=1750918223; cv=none; b=Wedd3bNRJ4bE+9UZbK1UzVclZIwlf3BoEhvCW6ecOE5N8I0qnxJJ8ktKgr4jk0La4bq5Xebg+440UJQZCkZU8V3dIexUGIepHk4btDpTSOMhT4sf/5XyLiazRMS4He2LdaaLlahtAYm3p4csgKjPA8pw0lxhfT2QIhuu0hSWfM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918223; c=relaxed/simple; bh=gqCHgGkLSpgEpmt5FdZ/9LIL89QW3SDjmv87W9fOnqM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BFNJ4hrsm3x0T0wo9bftUypOhDOdS6+jSrcI5uj1CpXnO1WgcfRl+c/3OEdU4o4WTuhfdJpYr7ZFMB337/8tyIBVYfeJwv1zSHMTYLQEtPDLK+ydW7VoRx66bhhSkz6iZtOAq108dWfVIe3d58B4p+WSEUND0Q9X3VtF0qNsy/k= 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=DUZc0rpi; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=TMEgLlBA; 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="DUZc0rpi"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="TMEgLlBA" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918219; 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=cL5EuxxowNhGrMXgAa2ZH9dASigX1qe/CuVbz0cNCr0=; b=DUZc0rpil97hjeJUL37x1IeCBEDyONTLhfV2DKcWv0QrEI5BwzdQHY23vBulpfI4LjVjh6 JSQ24xId9M2yn+U/3IEhQDTWUDyQuXbQW9gks7iKVR7CZV0KfWe2LZkv0mtERQVwTBNeAk wFP7wJ6m+ePgUgn+xNJIW8vL6OnlgQrRrn2g7mWq5jT11JzWmOF5AdYrUP8zdyo81Jl4x1 OQBCfux1+FYQFhIja30jocCvZP8s2CCMcYru5U9gJzOIKOe+tsQhdUbbk+zeiXo+BfO+4U zWrq8lqswDXNZfEwRaDqUEHYVsyErVaKX/n9IcQXalQQnOB/xm18jn/x0bUgvA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918219; 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=cL5EuxxowNhGrMXgAa2ZH9dASigX1qe/CuVbz0cNCr0=; b=TMEgLlBALqF9uVPWDJip5Gmi+wcDrPKPbsJ7Z+nXUZxN2flh8tbEbaqKKSPpAd0+k3OZpS EhPvDS09ZRPHFIBw== Date: Thu, 26 Jun 2025 08:10:11 +0200 Subject: [PATCH v4 03/15] kbuild: doc: add label for userprogs section Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-3-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=800; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=gqCHgGkLSpgEpmt5FdZ/9LIL89QW3SDjmv87W9fOnqM=; b=5tWW3HhqVrYWVmORDoZv7+oK5gd6ntpqVJW/nHoywkYSOL+8HJEa9ACeSxB7wqrSCy7nJTAL2 OguMoSYpHlWCkemYqaiOBewMmJZ6JzGaRXkuzAfQ8OZ12gSVCKVZFVa X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Some upcoming new documentation should link directly to the userprogs secti= on. Add a label to the section so it can be referenced. Signed-off-by: Thomas Wei=C3=9Fschuh Acked-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- Documentation/kbuild/makefiles.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/kbuild/makefiles.rst b/Documentation/kbuild/make= files.rst index 8aef3650c1f32b6b197e0dc777e26775d371a081..c14c1f632f6069c8751c8388a35= bef539e19f9e8 100644 --- a/Documentation/kbuild/makefiles.rst +++ b/Documentation/kbuild/makefiles.rst @@ -891,6 +891,8 @@ This is possible in two ways: This will tell kbuild to build lxdialog even if not referenced in any rule. =20 +.. _kbuild_userprogs: + Userspace Program support =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =20 --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 917D122DA1F; Thu, 26 Jun 2025 06:10:21 +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=1750918223; cv=none; b=R05aKnKr9L4wO6ryho//9WaxvxuwDhuRAATl0UfGLCDyR1db+mIvIlFStdhygBX/P/cHGJjIZkKK7Nbh+8IRHTTzLDNPvIlQM8KFDvPQhKrZU/X8jMX8c4ExTKcSQoRuXE886eN399jMfmSYaZdIEWubTVAA8SoEj40v41/GBY0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918223; c=relaxed/simple; bh=h7DYdHC1OtpWy7vh2b+uyM13209qgHTI+Y+hFSGtCGA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aq3NVQvU8iHDquJJhZt0XT2KSKbzIAtJhG2qVmCxy+dmS+554hKtQICDTkB3wmF0fv2Hh0uJHypuWe1IZmTs18qMPOschCtyFBVbLDkNT0Bku2cj54mHISqJAKurWKlEnQihOQL72M2tIzkJZYYGtmefJycZKPpqAFIXh22jZok= 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=wmIo2LNf; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=y/6zJfpp; 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="wmIo2LNf"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="y/6zJfpp" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918219; 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=BnuX25+yiOU4QMtDptciO6cM4cnjM1y/MC4HVWlwD98=; b=wmIo2LNfnGV1LMap3Iz/FrTpawbjSABWQzAr+SgTzhraLdEVOkSVLlg95gLVY2Z47dErUt S5h0fkrwsFaWerbmKaAUBvUs9BzvDPqAyCTD+NINUHhs37CJJqOq/AohsNiLLPKHMNRikx Gd2cAfPqabgoX0RxW5mhXYL4vjn2cTUOoVgvyEZ8NVpkwewlEceIab3R9/ytCt4fDh9HuR 9sxQ6qtSN32jQI3F9N8zU4DTwi6fEy7KvD49udib4oQVj2MOAYa/rdQ/y0rIw/xzCvjPrM IUYcW38P92bdkfdZp4Ll9jwtDwWg8O+ukwzY4PvI8HVDaelht2JXnUPL5pyiSQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918219; 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=BnuX25+yiOU4QMtDptciO6cM4cnjM1y/MC4HVWlwD98=; b=y/6zJfppz8B5ZRscW3CJHAC+Wp4SCIH946jtZk0y0je2G0JTs55+vHwHIVfH9ixqMbSgld MFGiHG8nYbn+pDAg== Date: Thu, 26 Jun 2025 08:10:12 +0200 Subject: [PATCH v4 04/15] init: re-add CONFIG_CC_CAN_LINK_STATIC Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-4-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=1194; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=h7DYdHC1OtpWy7vh2b+uyM13209qgHTI+Y+hFSGtCGA=; b=pToUf3ZJV4fZXrlp35p1Dlfk5Td0WAWgKb/+e9jRJmwQVY5tJfcMZS2h/b+tAaEfNTCld+BQQ H0cGVu0I9waADBJz/Ew79uOsYSmn2XoLsDB6m6WYCAe0hIQbVQwJ2I+ X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= For the kunit UAPI functionality this feature is needed. This reverts commit d1b99cdf22e0 ("init: remove unused CONFIG_CC_CAN_LINK_S= TATIC") Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Masahiro Yamada Reviewed-by: Nicolas Schier --- init/Kconfig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/init/Kconfig b/init/Kconfig index af4c2f0854554bbcdf193852cf5c1d2c2accc64f..26cafbad4f1560fb56b4bef31ae= 29baf54175661 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -87,6 +87,11 @@ config CC_CAN_LINK default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m64-flag)) if 64BIT default $(success,$(srctree)/scripts/cc-can-link.sh $(CC) $(CLANG_FLAGS) = $(USERCFLAGS) $(USERLDFLAGS) $(m32-flag)) =20 +config CC_CAN_LINK_STATIC + bool + 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) + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113921 config GCC_ASM_GOTO_OUTPUT_BROKEN --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 11B2E239E61; Thu, 26 Jun 2025 06:10:22 +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=1750918225; cv=none; b=nRcRO8lj0Rlblc5JUbTiKis+4x9ZxGuPJnVtOuMupK0eNdZSAsPSiRKbOm4X0ky8stjAwGG3BlxxG/IXga1e4GQmT8TfKkQCglXDPKvZCz3NddXxU7TUohFOb/pdHOtksVeUu0OtviecPXdIxNu0Wm8U96AHdIshNL3lQRoir/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918225; c=relaxed/simple; bh=j9q82O0F5uqiebw3qSo3efXgJ6wyxTkXdWeLSTmjF+4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NewQ8iE1JIwVF2RzpA6UZXj6jaPMdu/oixzygCZDccYPTqbO4Ky6Q1Ad6TeUQ2Sralu0u2lSaAauqYNXfdIIctvC4XV2Hmruc1J0gLjGd9jsjWg9H+tNSB8+2tdhI88QnEsiLjqd87KCr6QNYxhjcXdi9JK2cnoZHUiyeOewkH0= 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=UnFTasB0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=GHZ7tSqJ; 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="UnFTasB0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="GHZ7tSqJ" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918220; 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=3O+ksBPgEqQWeSBbfJQ4cCno/OA75lx66SsnvePtQs0=; b=UnFTasB0/XzuKmoSBgZsKt6ICGZsdHovMrtJyYOZC83R2IPHPlQdzRSWoqu5aB2xq7rq+e Cmb4Uvx41bZpD8m5qOGmG5sotv04WpHwrQPVonozKmGyg4e9lo8jm15yiP/vGXGbBaEL9t 0+FBvvzoXtZ+q6Tjq3sA+Jv3oYJO+wnKLDhVveY7vVLhHnDBQrp697bqdJO7gdXNoNayiB x0JXQllnwecDZbiaZU7Eove5kKIVr1Pdj3+xyLeZJqhOIMbDTGpExbAgTdQAB0CFnmBEkI eg8LU8DE5SRqDKyHoNREsW8WGscckc3xBzQWktWSdbCeDC5e+hDiOIh5mABR8Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918220; 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=3O+ksBPgEqQWeSBbfJQ4cCno/OA75lx66SsnvePtQs0=; b=GHZ7tSqJxdvwsS8Thi8N5mTLO7DqmX49KwjTiB4mSEpXa2z/pxNC9ILS0e3moKBItpTJBR o16/VXQuTdtXaPBg== Date: Thu, 26 Jun 2025 08:10:13 +0200 Subject: [PATCH v4 05/15] init: add nolibc build support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-5-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=3139; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=j9q82O0F5uqiebw3qSo3efXgJ6wyxTkXdWeLSTmjF+4=; b=+8fwcErVHN9PH59sxOwSP7c7yoRgu4HhMTtG4/nA25VU0z93np1aLXGf288gIwCkzknfs6fGy 1EUjQM+/aWRDrGYr314HS7UzBnptH0lRg/vobyZwcu89gEveB4vJjW7 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= Building userspace applications through the kbuild "userprogs" framework requires a libc. Kernel toolchains often do not contain a libc. In this case it is useful to use the nolibc library from the kernel tree. Nolibc does not support all architectures and requires compiler flags. Add a kconfig option, so users can know where it is available and provide a variable for common options. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: Nicolas Schier --- MAINTAINERS | 2 ++ init/Kconfig | 2 ++ init/Kconfig.nolibc | 15 +++++++++++++++ init/Makefile.nolibc | 13 +++++++++++++ 4 files changed, 32 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index a92290fffa163f9fe8fe3f04bf66426f9a894409..e806158cc6798cf97a4aab58c03= 8fb5351d469aa 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -17702,6 +17702,8 @@ M: Willy Tarreau M: Thomas Wei=C3=9Fschuh S: Maintained T: git git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc.g= it +F: init/Kconfig.nolibc +F: init/Makefile.nolibc F: tools/include/nolibc/ F: tools/testing/selftests/nolibc/ =20 diff --git a/init/Kconfig b/init/Kconfig index 26cafbad4f1560fb56b4bef31ae29baf54175661..0af62f135192e0470e16eb6bb2f= bb45ac38f4b81 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) =20 +source "init/Kconfig.nolibc" + # Fixed in GCC 14, 13.3, 12.4 and 11.5 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113921 config GCC_ASM_GOTO_OUTPUT_BROKEN diff --git a/init/Kconfig.nolibc b/init/Kconfig.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..29cbc5437e70cbc5e256f00b74d= 0ab4801b40de7 --- /dev/null +++ b/init/Kconfig.nolibc @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0 + +config ARCH_HAS_NOLIBC + bool + default y if ARM + default y if ARM64 + default y if LOONGARCH + default y if M68K + default y if MIPS + default y if PPC + default y if RISCV + default y if S390 + default y if SPARC + default y if UML_X86 + default y if X86 diff --git a/init/Makefile.nolibc b/init/Makefile.nolibc new file mode 100644 index 0000000000000000000000000000000000000000..a8a193f78e34e0c4a6004e871bc= 206e06925f88a --- /dev/null +++ b/init/Makefile.nolibc @@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0 +# Compiler flags, which are necessary to build userspace applications with= the +# in-kernel libc "nolibc". + +ifeq ($(and $(CONFIG_ARCH_HAS_NOLIBC),$(CONFIG_HEADERS_INSTALL)),y) + +NOLIBC_USERCFLAGS :=3D -nostdlib -nostdinc -static -ffreestanding \ + -fno-asynchronous-unwind-tables -fno-stack-protector \ + -isystem $(objtree)/usr/include -isystem $(srctree)/tools/include/n= olibc/ + +NOLIBC_USERLDFLAGS :=3D -nostdlib -nostdinc -static + +endif # CONFIG_ARCH_HAS_NOLIBC && CONFIG_HEADERS_INSTALL --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 11BF8239E69; Thu, 26 Jun 2025 06:10:22 +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=1750918225; cv=none; b=NEjJdX3IleZ6Cb26bNH+mwyd4F3yxh7nfE4ADB4UGdcWN3lSBazmgwyO0dYciOU7rWox2xPO1rZACtrOMJMEW6xVRcCE08qMtb0dEQwTN/ugzn5YhSlfDkJDHkV5xjdVvp7Xt+1SvY8EPjnOtTlGDb19X5hZIoUb4+HQYmo+yTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918225; c=relaxed/simple; bh=sBjfYGI0Ye62nwsuUzArqmK5roAkvp0KfDA11tMTt7M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P4H4GskXfB5Tm8gYdl/zv9VEnp98XS8MQZBi0D3It70AoasQ+VXoQlR+Pr4BkF4IKZB8fHNAK0D8LqOCAF9+WFBtRTozoM6pbPjXjGue/WUnC32M5vm3bmCR5Bw6ziCVNnocZQsUSfdBc9BxQrDJ7Fr7/ScOSfaLniKGkguE+xU= 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=lBUemkcT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tO6ZIH+h; 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="lBUemkcT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tO6ZIH+h" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918221; 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=uvxDeHqReCMnKL0ZkklMAI73M6eNLpJ24PnvZxi/D5I=; b=lBUemkcTrECzCAtqtNXrwears5+/0uqhMeUhAZ8T7iXoRP2CS4hfkRVW69OJqophFMggnx 411UniDm6MMffmuuw49Fbegvvc8AVCl8VhnJVr6HRv2XlwlS4oyt/DlgjBLKgpCvIoLnUe VNTCdBDpJYggwmlSRyvZnFkjueruXuhvD49yvfuQaFf1OWrQr3ftsKdz3bkht09PQV/j+e d425AIC9Lo/v58kWbBmn45RwIHJJvvtbAw423lpQlT/3Bs0pyB/9ls+A/YZnOnZvYF1j2b yJx6HKJv+/MSWJudwZmemNnZslJgTIyQizxNL/EcODHyaMGWAdjqoHMbIzRj5w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918221; 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=uvxDeHqReCMnKL0ZkklMAI73M6eNLpJ24PnvZxi/D5I=; b=tO6ZIH+ht1kx3JfAie1o3QKCp5+JqjvIAYyfRyZSwqxPJvW9/YxiS9bM2e/jztjaQyFg/x 0ClAyqEWHohUBiAw== Date: Thu, 26 Jun 2025 08:10:14 +0200 Subject: [PATCH v4 06/15] fs,fork,exit: export symbols necessary for KUnit UAPI support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-6-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=5134; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=sBjfYGI0Ye62nwsuUzArqmK5roAkvp0KfDA11tMTt7M=; b=vrDbmutA8uylluHH9xjOd5CW4G8kx/DVbirsPADi4HdNHbf8GZ+SCKc07p2MdW4kDWDs9XKZi jF6BhMMbyzqCGRSU8X11C2Qv6GxF57woQXwfQI9mbn2dpj5+qiG+U3H X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The KUnit UAPI infrastructure starts userspace processes. As it should be able to be built as a module, export the necessary symbols. Signed-off-by: Thomas Wei=C3=9Fschuh --- To: Kees Cook To: Alexander Viro To: Christian Brauner To: Jan Kara Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org ./get_maintainer.pl would have also Cc-ed all of the memory management and scheduler maintainers. I trimmed the list to only BINFMT/EXEC and VFS. --- fs/exec.c | 2 ++ fs/file.c | 1 + fs/filesystems.c | 2 ++ fs/fs_struct.c | 1 + fs/pipe.c | 2 ++ kernel/exit.c | 3 +++ kernel/fork.c | 2 ++ 7 files changed, 13 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 1f5fdd2e096e392b342f122d35aba4cf035441c7..13f7f27641942eddcb179bdd93d= 99b799d155813 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -68,6 +68,7 @@ #include #include #include +#include =20 #include #include @@ -1919,6 +1920,7 @@ int kernel_execve(const char *kernel_filename, putname(filename); return retval; } +EXPORT_SYMBOL_GPL_FOR_MODULES(kernel_execve, "kunit-uapi"); =20 static int do_execve(struct filename *filename, const char __user *const __user *__argv, diff --git a/fs/file.c b/fs/file.c index 3a3146664cf37115624e12f7f06826d48827e9d7..89d07feb9c328337451ce40cb0f= 368b6cb986c2c 100644 --- a/fs/file.c +++ b/fs/file.c @@ -1317,6 +1317,7 @@ int replace_fd(unsigned fd, struct file *file, unsign= ed flags) spin_unlock(&files->file_lock); return err; } +EXPORT_SYMBOL_GPL_FOR_MODULES(replace_fd, "kunit-uapi"); =20 /** * receive_fd() - Install received file into file descriptor table diff --git a/fs/filesystems.c b/fs/filesystems.c index 95e5256821a53494d88f496193305a2e50e04444..a3a588f387bbd8268246d102638= 9deaadf265d0b 100644 --- a/fs/filesystems.c +++ b/fs/filesystems.c @@ -17,6 +17,7 @@ #include #include #include +#include =20 /* * Handling of filesystem drivers list. @@ -45,6 +46,7 @@ void put_filesystem(struct file_system_type *fs) { module_put(fs->owner); } +EXPORT_SYMBOL_GPL_FOR_MODULES(put_filesystem, "kunit-uapi"); =20 static struct file_system_type **find_filesystem(const char *name, unsigne= d len) { diff --git a/fs/fs_struct.c b/fs/fs_struct.c index 64c2d0814ed6889cc12603410e6e9dc44089586f..26340d225deba3f2ec30252293f= df417235a6a4a 100644 --- a/fs/fs_struct.c +++ b/fs/fs_struct.c @@ -46,6 +46,7 @@ void set_fs_pwd(struct fs_struct *fs, const struct path *= path) if (old_pwd.dentry) path_put(&old_pwd); } +EXPORT_SYMBOL_GPL_FOR_MODULES(set_fs_pwd, "kunit-uapi"); =20 static inline int replace_path(struct path *p, const struct path *old, con= st struct path *new) { diff --git a/fs/pipe.c b/fs/pipe.c index 45077c37bad154ef146b047834d35d489fcc4d8d..d6cb743d2cfc041f08b498a5a76= 4e9a96dc34069 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -27,6 +27,7 @@ #include #include #include +#include =20 #include #include @@ -971,6 +972,7 @@ int create_pipe_files(struct file **res, int flags) file_set_fsnotify_mode(res[1], FMODE_NONOTIFY_PERM); return 0; } +EXPORT_SYMBOL_GPL_FOR_MODULES(create_pipe_files, "kunit-uapi"); =20 static int __do_pipe_flags(int *fd, struct file **files, int flags) { diff --git a/kernel/exit.c b/kernel/exit.c index bd743900354ca5fc6c550f80e30393a632eb9a4e..610dffb1276ac60b475708587ca= 053f315fea9c3 100644 --- a/kernel/exit.c +++ b/kernel/exit.c @@ -70,6 +70,7 @@ #include #include #include +#include =20 #include =20 @@ -1005,6 +1006,7 @@ void __noreturn do_exit(long code) lockdep_free_task(tsk); do_task_dead(); } +EXPORT_SYMBOL_GPL_FOR_MODULES(do_exit, "kunit-uapi"); =20 void __noreturn make_task_dead(int signr) { @@ -1887,6 +1889,7 @@ int kernel_wait(pid_t pid, int *stat) put_pid(wo.wo_pid); return ret; } +EXPORT_SYMBOL_GPL_FOR_MODULES(kernel_wait, "kunit-uapi"); =20 SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr, int, options, struct rusage __user *, ru) diff --git a/kernel/fork.c b/kernel/fork.c index 1ee8eb11f38bae1d2eb6de9494aea94b7a19e6c3..5de7a9bc005ade6dcfbdfe1a63c= adbef8782658c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -105,6 +105,7 @@ #include #include #include +#include =20 #include #include @@ -2676,6 +2677,7 @@ pid_t user_mode_thread(int (*fn)(void *), void *arg, = unsigned long flags) =20 return kernel_clone(&args); } +EXPORT_SYMBOL_GPL_FOR_MODULES(user_mode_thread, "kunit-uapi"); =20 #ifdef __ARCH_WANT_SYS_FORK SYSCALL_DEFINE0(fork) --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 5B2DB23ABAD; Thu, 26 Jun 2025 06:10:23 +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=1750918225; cv=none; b=aUaVtj1jJlLloSb4M7i78vYJa0+SIs2+2sfI1eS7LDzSJqIMbA2LoNQhkLyUNjcDMc4uildwDzDTUrJieLdNqNUG/aujM88CxK76HtFKAvhjrMEyCTtAv2vB4iBFVSbIu78jJW0Eg5dtc5QcKvU3dOsxitGvlGpkJYH3Of9joO4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918225; c=relaxed/simple; bh=2KF4ki0EfgQ+uZ9vsc2VGfGL3iFmSYhOLH35Bex68pw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FPitscsW+oNNyM7Vzqsfo6mvWqRpw6VbZBeUQqKukwTBacqZCOU4JoUskSk0sBMSpqh7jlYMGh7dyWjQIUvpx7SYMJ1/Pg4a4K+Qgc2r1tLDaq+1R8TC5fHqcQWinIDPSxnvLaEerxhFiWERKIXqvB4AJPJhGm4futlaQcOH3zg= 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=wC/+91rk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=p6vH5Aol; 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="wC/+91rk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="p6vH5Aol" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918221; 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=3ky4pl9zyr5S0rAJVm9feSkr8uxE1/z4/7grpknYGBQ=; b=wC/+91rkBgxesWjzSUFrn1aaHrE5XlH3Js+rClZCE1ZGnLWooFFEKbUlYKETTB7a+7d0u6 Vta22cR6rmyxiTluRlSFOJ/vDw+8O+xvpHMP/3KD90QCAkt0EB7CQWLaSNMk2tNL+iHXym Lkgva7xz/YfbCEfYBBqgdnkHw8MojZFe8Py6hphXadmFNJ89FOOXtHyzZgjWq3Gu0E6I4w SunArvd1uYYGKUh93G2LdQ0vPgW+FTFijiMOj2mpYIFXnm5lq2E42i4MwbfeBmTvlbXXDs w471WqX0Ky0qmz70GRZdG9BUkRFlWeP7VWi+9xwtsFq7uovartr6K1WqklpYHA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918221; 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=3ky4pl9zyr5S0rAJVm9feSkr8uxE1/z4/7grpknYGBQ=; b=p6vH5AolL4dgHysWePGcjdNFUhvaIRtWfNGavbj+nbGTm28Mb+fKOz7HKocCaZ6MBRqoVh 2kUoiQ6bPkE5uyCA== Date: Thu, 26 Jun 2025 08:10:15 +0200 Subject: [PATCH v4 07/15] kunit: tool: Add test for nested test result reporting Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-7-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=2214; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=2KF4ki0EfgQ+uZ9vsc2VGfGL3iFmSYhOLH35Bex68pw=; b=95Sids2Fk1QJA76lqNzLJEg412tXs/th72tnsd/qvhZ488+ELoUdj/hSVtxGXdRZSjfHG0N5F KQ4EJaMGUplB8aMrI+ibw3NkyijpWLDgpfwD0LHnsOHxOITO3pfXT/u 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=C3=9Fschuh Reviewed-by: David Gow Reviewed-by: Rae Moar --- tools/testing/kunit/kunit_tool_test.py | 10 ++++++= ++++ .../kunit/test_data/test_is_test_passed-failure-nested.log | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index bbba921e0eacb18663abfcabb2bccf330d8666f5..b74dc05fc2fe5b3ff629172fc7a= afeb5c3d29fb3 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -165,6 +165,16 @@ class KUnitParserTest(unittest.TestCase): self.assertEqual(kunit_parser.TestStatus.FAILURE, result.status) self.assertEqual(result.counts.errors, 0) =20 + def test_parse_failed_nested_tests_log(self): + nested_log =3D test_data_path('test_is_test_passed-failure-nested.log') + with open(nested_log) as file: + result =3D 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].sta= tus) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sta= tus) + self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sub= tests[0].status) + def test_no_header(self): empty_log =3D 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-nest= ed.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.l= og new file mode 100644 index 0000000000000000000000000000000000000000..2e528da39ab5b2be0fca6cf9160= c10929fba3c9e --- /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 subsubtest 1 +not ok 2 subtest 2 --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 E3E2A22F76B; Thu, 26 Jun 2025 06:10:23 +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=1750918225; cv=none; b=IFHu2byrznNrXLY7zRa5SdoZppbtF4nN7cQmtX5X5s+W+vg2WwgYbnLqZQyakdjK9ITV3IvJF4h0mzpMQWpknffvFM7Y2TizmbDQAarHCu0fK2blcNI2zi0HUmzc+aHEbEE9v0fKLO4vgDHq0NdXIMCzmyt3ARkWAGdyoOP8n1A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918225; c=relaxed/simple; bh=3t3Pl5fkB5thDAh5xZvG+YfScEInDEQ30x9tWWJX29Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pfT1EbPpkK6UpRtRwfkyAbmnZOvnw4V9wthFD/npMpDr4ega7xEx+NnCcJltWwcp5KHZO5Am2SHDQhP1VXRSy1X3Kk/NA++Th4LPLnnQzJF4TVbtn9S0YlAJdTSidqTLdSgbXlNRx+rxYpbqKWUNf7cxB5WGjLGjjJdcsAFMrzQ= 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=eJX2G6n7; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Ym+Y9yT1; 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="eJX2G6n7"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Ym+Y9yT1" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918222; 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=Cuf7YUDid13D8VbaJI7N9jiwmxX9iHNgguMQzOAlx2M=; b=eJX2G6n7eeC9OKtPRc45ieNwZQh8Wx5t8lovecgsPYl+3WbTUZytrKWz9jqvPaok5k76C5 lN7kEx7N34smHTZlHZvMYpUztLGzYMfQfFq0ODAPMPNdHsy1vv0yi1SqVi7mUasi/phwIA h6bdBQ4630o7dYNqnuynA+FecAOgSyqqth9vBssCfabyG6Oop9TPRtGOl0pT0Zfne2PHpv 1FTPdAqAz1QpFnZ0WvFe8CsVQ+t40c6bdPxOCXhXuxgmbSe6BU26hvCwUcTdqlLaWdnBJ1 OoDJ08s/n70tpc8uTqFt+QWPT36PqrTNuYvEiafflbq7j6Lm372jWPnj2PJ6jw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918222; 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=Cuf7YUDid13D8VbaJI7N9jiwmxX9iHNgguMQzOAlx2M=; b=Ym+Y9yT1zOvX6xWbDDFNN2oMyk88S+BX7PTskdm/mus9tlK/52fJsn5wGqp8NsL3V7nHM3 cjPkmxt/vd/4QTBA== Date: Thu, 26 Jun 2025 08:10:16 +0200 Subject: [PATCH v4 08/15] kunit: tool: Don't overwrite test status based on subtest counts Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-8-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=2967; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=3t3Pl5fkB5thDAh5xZvG+YfScEInDEQ30x9tWWJX29Y=; b=AvEfUSGHiilGFdZnCu5LHNrjgKchinPsKqlFGPeYLusicAg95dIGWTD6OtUekwAXApKiJs3hW 4iY7/aNOxQMAEVJ4u1Z+05ssCDC4urXBb234SUelMppjBe8W4aqGF9Y 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=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/kunit_parser.py | 5 += ++++ tools/testing/kunit/kunit_tool_test.py | 3 += +- tools/testing/kunit/test_data/test_is_test_passed-failure-nested.log | 3 += ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/testing/kunit/kunit_parser.py b/tools/testing/kunit/kuni= t_parser.py index c176487356e6c94882046b19ea696d750905b8d5..2478beb28fc3db825855ad46200= 340e884da7df1 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() =3D=3D TestStatus.TEST_CRASHED: test.status =3D TestStatus.TEST_CRASHED + if not test.ok_status(): + for t in subtests: + if not t.ok_status(): + counts.add_status(t.status) + break =20 def parse_test(lines: LineStream, expected_num: int, log: List[str], is_su= btest: bool, printer: Printer) -> Test: """ diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/k= unit_tool_test.py index b74dc05fc2fe5b3ff629172fc7aafeb5c3d29fb3..48a0dd0f9c87caf9f018aade161= db90a613fc407 100755 --- a/tools/testing/kunit/kunit_tool_test.py +++ b/tools/testing/kunit/kunit_tool_test.py @@ -170,8 +170,9 @@ class KUnitParserTest(unittest.TestCase): with open(nested_log) as file: result =3D 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].sta= tus) + self.assertEqual(kunit_parser.TestStatus.SUCCESS, result.subtests[0].sub= tests[0].status) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sta= tus) self.assertEqual(kunit_parser.TestStatus.FAILURE, result.subtests[1].sub= tests[0].status) =20 diff --git a/tools/testing/kunit/test_data/test_is_test_passed-failure-nest= ed.log b/tools/testing/kunit/test_data/test_is_test_passed-failure-nested.l= og index 2e528da39ab5b2be0fca6cf9160c10929fba3c9e..5498dfd0b0db24663e1a1e9bf78= c587de6746522 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 --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 9602624DCEB; Thu, 26 Jun 2025 06:10:24 +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=1750918226; cv=none; b=gDSlAsIkFWBQUpTZeKDJugLyn1FCfxvnFKZC3RFj0GInTOLtWpK8Vvj87GIE3Fq7beMYb25hEA3OyJjDqgcee9BzWOa8vOSlFVfMghLEV/rOyVoASnFd+d2/wbU5BQQRl+nD8ZjmOsdcQU7RXUcfDP2Gse2KccJPX/fzhz57958= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918226; c=relaxed/simple; bh=BgHglaR4DzzW2IPxgThAlx+/qqcc0TXML7OsBM4NoBo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DEeS9Ot1mfV/VPKIlzuF5P3JWwQHYgXf2S8M1BDYatDbGe5/YMM79ZRLKHJmbj8+8fS1MFMj3NfYKR3zgO4fu1rsRnB8Isc5me3B6LmBIbBYQYkyyCfwJvztHW9xa6y9O244GqQPFLjrODk37XSWBRGPrbK4ueGGXWhljTmdJW0= 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=nMjS1CG/; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=sxu+ql+R; 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="nMjS1CG/"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="sxu+ql+R" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918222; 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=WKirMxHE1YxM9ynO9swFUkpubSglCQdgwJmIoDy+YxU=; b=nMjS1CG/yxTUVbWKorw/3bOw365XOLYS0ASXjiL6d4n+MPkGmJWi/xsW7AxXB52lfl0teo 1PTskggqq3jfSVE0SwLS7UtoeFmRPKA04+WaL12t/ixW/f3vJuGR6Hlj/6N/pnqshmfoXm B+RtxE7cY5rCK455Zf1t/5VzFlAeFp8BXet061DAYKJjXjfKyGpTX7GLsZsu99S5ORps6T 1dl0iD6MBwj6lEik8hlYXu/wDp8vogij6NffOuCHizJpvY8pU8PVQJ/FkGavE52lseYDfs 79/e84NCkURPDoNjZ8fPLPqHRNu2JjG//fhrvAATGG8cXLKwLKLtvvdszlJdYw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918222; 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=WKirMxHE1YxM9ynO9swFUkpubSglCQdgwJmIoDy+YxU=; b=sxu+ql+RMtIFHfreNZ6cS4cM4zTqlNz2TZb9DgZOr8uXj9jIbnqc1k/ZmrZWk5BprTOvEL ekRjqfZkjP2IiQCQ== Date: Thu, 26 Jun 2025 08:10:17 +0200 Subject: [PATCH v4 09/15] kunit: tool: Parse skipped tests from kselftest.h Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-9-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=2831; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=BgHglaR4DzzW2IPxgThAlx+/qqcc0TXML7OsBM4NoBo=; b=oXs6ENKi5E7FMsucpJTgQ1z8dJdZNVeEliXEubYDgG+sDqIhXI7MdrecBaS2cUZBpr2L3KozY br+7LQg1UPcA8mX4rIyqgmXWpLSiUSd55E77S2Xd0zCCplacX/WFi0k 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=C3=9Fschuh Reviewed-by: David Gow --- 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/kuni= t_parser.py index 2478beb28fc3db825855ad46200340e884da7df1..4599d23c79b79f0e219d655c705= 3c8c3b34f8152 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) -> b= ool: lines.pop() return True =20 -TEST_RESULT =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?([^#]*)( # .*)?= $') +TEST_RESULT =3D re.compile(r'^\s*(ok|not ok) ([0-9]+)? ?(- )?([^#]*)( # .*= )?$') =20 -TEST_RESULT_SKIP =3D re.compile(r'^\s*(ok|not ok) ([0-9]+) (- )?(.*) # SKI= P(.*)$') +TEST_RESULT_SKIP =3D re.compile(r'^\s*(ok|not ok) ([0-9]+)? ?(- )?(.*) # S= KIP ?(.*)$') =20 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 =3D match.group(4) + if not name: + return False return name =3D=3D test.name =20 def parse_test_result(lines: LineStream, test: Test, @@ -416,7 +418,7 @@ def parse_test_result(lines: LineStream, test: Test, =20 # Set name of test object if skip_match: - test.name =3D skip_match.group(4) + test.name =3D skip_match.group(4) or skip_match.group(5) else: test.name =3D match.group(4) =20 diff --git a/tools/testing/kunit/test_data/test_is_test_passed-kselftest.lo= g b/tools/testing/kunit/test_data/test_is_test_passed-kselftest.log index 65d3f27feaf22a3f47ed831c4c24f6f11c625a92..30d9ef18bcec177067288d52427= 71236f29b7d56 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 =3D -1, flags =3D 0, e= rrno =3D 22. Failed as expected ok 2 selftests: membarrier: membarrier_test_multi_thread +ok 3 # SKIP selftests: membarrier: membarrier_test_multi_thread --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 91F8F25B30F; Thu, 26 Jun 2025 06:10:25 +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=1750918227; cv=none; b=HuP3783K7vx37OoTsvE0VnsJRdk6A0qavfldnHL5rQK2US4DQ7s70N7bbIX/w5JPIGAvXUDa0IFW94kqeW8iPQAuGQzUKSc8KBztqG4dcANbcDbVdLk87EM8xo7n5w3EiSml7dj9CQDGj7qOieFB2RGgTOOArASHcQYNixyQ3hU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918227; c=relaxed/simple; bh=uYbDX0tuhfBybp4zBtjmC97SEQNiCLwjFQ5JZf0se98=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LF/owQSlFnPr/ifGAWSL4/6y43Giqf2sxi3CqZMOWKGs2uy6bCtZX58p2ujOUQQNnZdefUCO+e4KZd4PSsy7dxgFr9Vf3Ust8p6EUSVeq60i8H0oY1U56Tfs3UC72DM0eIf6pc1fUR6yGHuh9OvsYOSFwiseMEEIo3KfHMBsIDY= 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=v4++KhTn; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tvtEqPYg; 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="v4++KhTn"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tvtEqPYg" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918223; 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=3coL6itBSAQiKwOZXEjAxfGw4ky2lWtS9inL/ixAlLY=; b=v4++KhTnPPFuPM9Ey/EmHXx78bsZhsVnFmix4Js0ZXIz9El+jb+2FkdDpikYs8KweXtdOE lbJVEHgZDz00XeW3zB4u2fI9Ef4SRrAtzxwP5F6fRouY6XglqJfAVc0b/1YNvrh5PANy69 avbRO2l4/9XWyHkyEoo1J67Qv/s7BoRIn3qbW3KHJcr8MD7o5KIzp6+FczyxEEUjkz5Spk Ofz/Val5jS3NtIq8yABzAmhAHIRcY83x40RAtZeGpF+BS2viF+dCbjlC8t75K6rND1nTQZ pIIaL4TiT879o1B1KamrQE8qHu04IFwwGLg0qzb2L5q2GZgbvxCvZ+Dj9zwWuw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918223; 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=3coL6itBSAQiKwOZXEjAxfGw4ky2lWtS9inL/ixAlLY=; b=tvtEqPYgruJkmvyuACoyC4MeTc51hxk2+VrxAhb0PnKtfTNVZYE/opPti94cdtpx35qUBT dteDwLOErJPWiLCQ== Date: Thu, 26 Jun 2025 08:10:18 +0200 Subject: [PATCH v4 10/15] kunit: Always descend into kunit directory during build Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-10-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=1601; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=uYbDX0tuhfBybp4zBtjmC97SEQNiCLwjFQ5JZf0se98=; b=ntnAXJQ4+rKGjO3MSQAGD41KuCNgl3I6S4GaNRn9BPS5Ax88aMAwmHuszxIGFnGmMUyIgw8HS xO7SWYvAeJJCQXs87k/fDCf3Pv1ArKlXVgGvDeO8uT43wBHBQuldAmi X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= An upcoming change will add 'userprogs' to the kunit subdirectory. For kbuild to properly clean up these build artifacts the subdirectory needs to be always processed. Pushing the special logic for hook.o into the kunit Makefile also makes the logic easier to understand. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- lib/Makefile | 4 ---- lib/kunit/Makefile | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index c38582f187dd81916113319072e5cfef26f26c84..698566135091cc3bf0054f1954b= 434dc3325364a 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -108,11 +108,7 @@ test_fpu-y :=3D test_fpu_glue.o test_fpu_impl.o CFLAGS_test_fpu_impl.o +=3D $(CC_FLAGS_FPU) CFLAGS_REMOVE_test_fpu_impl.o +=3D $(CC_FLAGS_NO_FPU) =20 -# Some KUnit files (hooks.o) need to be built-in even when KUnit is a modu= le, -# so we can't just use obj-$(CONFIG_KUNIT). -ifdef CONFIG_KUNIT obj-y +=3D kunit/ -endif =20 ifeq ($(CONFIG_DEBUG_KOBJECT),y) CFLAGS_kobject.o +=3D -DDEBUG diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 5aa51978e456ab3bb60c12071a26cf2bdcb1b508..656f1fa35abcc635e67d5b4cb1b= c586b48415ac5 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -17,7 +17,7 @@ kunit-objs +=3D debugfs.o endif =20 # KUnit 'hooks' are built-in even when KUnit is built as a module. -obj-y +=3D hooks.o +obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 147F325E461; Thu, 26 Jun 2025 06:10:26 +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=1750918229; cv=none; b=Eh043zChRNXgufBZatWMlhW5m5GbG2yUsJKoPNDNn7gFEmxIqQ0cDzNWxVfyr5eC5OTpi/pKNKC6RZWzuYqQij5/GixLWyYVP+R6FqWDy6PG3cID8w6lypFVkUDOSMQVRW6QyBPeYGE5a5rI2/KgwfYRw+ZBTHjDNC+0QB4MhIk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918229; c=relaxed/simple; bh=zShZPUvddV04nP7ePLLt+JfO552xNTacDebxpq2ayPk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Sd6KTCHAwrz44OXfaKL92K1UcTWpFgmsNnaqGAsLer8txbeRfqw5eFL4AgyUQFDOnWtI+bX9shA1jxEoRYp0m7aQX8y/jDksAIdlQeMdkqS6UtswvcawbiFaAOqJNrLH9l6kc4CpaXD0lXDVg+XJXjv3hFb0nwLMUcxi9wNH17E= 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=NwnELFMT; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NljzIya3; 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="NwnELFMT"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NljzIya3" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918224; 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=nqEciMN5D1yrpF8pzbxqPFErBTdvvekVDOGyFqtNWdk=; b=NwnELFMTLd09ua8co1MShJVkTu7deYuOOcKmawcoBjF4BDE64CWixas+6ZQnMfn5EnOCmg e0WvA4OM+pQ1RNp35Ug2TZrO88/Gpm1m1QVu/0FcjUWx95k3XPyJilAis2f6Iok7EDcelu Yll5CxqBorEuMI6dT5/BbLFO7V+eEU+MTye/eTng4rfKNzVWZoAfV4rOvf6z+65ZCmw18L 5mkIABq2sjRD8fs//QfeK9kLltiK3qCqt/DtdMxd3ENTk/Dm2PIedkYUKL1p5C2/Lfnz6O vGtpjy12pSNVIgO3WqB2Hvz8WCARiP/mKSJcuXWAkudZxxl1Ldky/ItJtAB/uA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918224; 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=nqEciMN5D1yrpF8pzbxqPFErBTdvvekVDOGyFqtNWdk=; b=NljzIya3lvX5KxYMIRyiveDbqLyuMTkYirHvFIt5ODhCM541bWLQl/twTpO34OyPn5gIel sYRtqNAIr1YwcjAA== Date: Thu, 26 Jun 2025 08:10:19 +0200 Subject: [PATCH v4 11/15] kunit: qemu_configs: loongarch: Enable LSX/LSAX Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-11-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=994; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=zShZPUvddV04nP7ePLLt+JfO552xNTacDebxpq2ayPk=; b=zy7JI9OBbmKHVmTKVnWN5D+eAwUIwzJMor3MP3kYnjtE9qfoeMBVikE1fsvrO0omyL5AihCmI 2U1jHW7CtA6Cx+nlT8XSDuZVmFViFDA/S/1DkcNGAg+mbXNp+1HLSxo X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= The upcoming kunit UAPI framework will run userspace executables as part of kunit. These may use the LSX or LASX instructions. Make sure the kunit kernel can handle these instructions. Signed-off-by: Thomas Wei=C3=9Fschuh Reviewed-by: David Gow --- tools/testing/kunit/qemu_configs/loongarch.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/kunit/qemu_configs/loongarch.py b/tools/testing/= kunit/qemu_configs/loongarch.py index a92422967d1da9f1658ef1e80d0d7365ddbae307..1dba755284f11ffc94d8946105b= 0cfa49cb6f604 100644 --- a/tools/testing/kunit/qemu_configs/loongarch.py +++ b/tools/testing/kunit/qemu_configs/loongarch.py @@ -11,6 +11,8 @@ CONFIG_PVPANIC_PCI=3Dy CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_OF_PLATFORM=3Dy +CONFIG_CPU_HAS_LSX=3Dy +CONFIG_CPU_HAS_LASX=3Dy ''', qemu_arch=3D'loongarch64', kernel_path=3D'arch/loongarch/boot/vmlinux.elf', --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 32FEA25FA34; Thu, 26 Jun 2025 06:10:28 +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=1750918231; cv=none; b=SMu+eVPhe4b9rxntUbXTblTJPfUsFB/fu0gDZNGgWLn8E6lXDeMrwClr6cupUsDH1c9dw9GYQRJ/wA8q6X3OJ6OuuwlnTs/Dgzc0+x9I2bmgoHeafXhD3v/o02cU+paBszq0SGb/EXwlLLZbJjfbl4BeS2jaaKBbbj+rpPPdXXc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918231; c=relaxed/simple; bh=Ez0O5tehZeTQJpNtECQ7NQ1Zh99cpPAEJsAxQEXoxtk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=parwxByWWMbe3XFf5nXBcxizQUmSP47qr8dFTX+9QDpoJvaGvhCvyuf0vkLEkegDPq8990A5PWe4eIC2LFYiN9FXsWZ2gk/ul1On8q2VDcJTmO4AZgHVTwIRh4IMHSUiQkiM79L86nDxwjpbRSYzDCbhILur4cuBoBcMEf9cWdY= 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=BICfK/d0; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=E95PjGVw; 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="BICfK/d0"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="E95PjGVw" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918226; 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=m2WfdTt5zLz36UPr6FBV83XX1M+loHxB368/1Vhlmqc=; b=BICfK/d0z+5azVTK89BNiFXrpSOixHMPeOxE7bPONklaJEHobn/SRovAsV9tVTOdNsIFhd Qr+zF+VIr8lZM0JdhaZYC2ALl0TItEe6TLPnBm2Cm6mGNBoC173d4JJYaBo5nACDwwrV+h oFCKirkLIrECCPYTjV3XpYzPDUexC4xQTaHB/p90j/xQFOcEsa8qNw8G1UI0AME4OeGMrL bNdkDBk/by2XaUUVhdNRE4iAKGe9KQZJNpSorFT7xUbpR0B7jJ0WcqsEMPI7j0+rm4Wb5P 0chIF1i72JT6qaXijUfC92HM6/D4xLI4iiA4CyhI9g+M1RWW36kMC59fB844Cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918226; 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=m2WfdTt5zLz36UPr6FBV83XX1M+loHxB368/1Vhlmqc=; b=E95PjGVwXua4YXVx16vuck7uu6Oftdl+zRcNn9PaSGPnZCi1dyToS61iu1HOuSXo1K+RyO oy267dUlk+mh5fDA== Date: Thu, 26 Jun 2025 08:10:20 +0200 Subject: [PATCH v4 12/15] kunit: Introduce UAPI testing framework Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-12-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=15015; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=Ez0O5tehZeTQJpNtECQ7NQ1Zh99cpPAEJsAxQEXoxtk=; b=2kPvgAzvirkOOg8P+bYloREpabP8nhUOzEswtCo+WJOHfhmH7w+uxXJGfMCU3tU+37hd7LGeh nO9lg6GlnQVDwkLrZ1FJdnfkJYlRaiNP/5LAWBz8CiYX07mDnR1ede2 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=C3=9Fschuh --- To: Kees Cook To: Alexander Viro To: Christian Brauner To: Jan Kara Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org --- Documentation/dev-tools/kunit/api/index.rst | 5 + Documentation/dev-tools/kunit/api/uapi.rst | 14 ++ MAINTAINERS | 6 + include/kunit/uapi.h | 77 +++++++ lib/kunit/Kconfig | 14 ++ lib/kunit/Makefile | 2 + lib/kunit/kunit-uapi.c | 300 ++++++++++++++++++++++++= ++++ 7 files changed, 418 insertions(+) diff --git a/Documentation/dev-tools/kunit/api/index.rst b/Documentation/de= v-tools/kunit/api/index.rst index 5cdb552a0808f25baeff5e47a9227b7b62c69e40..34d8fee9a97059d6da919a6fb1a= 7e359b5e0beef 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 =20 - Documents the KUnit Function Redirection API =20 +Documentation/dev-tools/kunit/api/uapi.rst + + - Documents the KUnit Userspace testing API + Driver KUnit API =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 diff --git a/Documentation/dev-tools/kunit/api/uapi.rst b/Documentation/dev= -tools/kunit/api/uapi.rst new file mode 100644 index 0000000000000000000000000000000000000000..1f01b5c6c9db42f603f6507f2f3= 3ef388f5b91d7 --- /dev/null +++ b/Documentation/dev-tools/kunit/api/uapi.rst @@ -0,0 +1,14 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Userspace Test API +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +This file documents all of the userspace testing API. +Userspace tests are built as :ref:`kbuild userprogs `, +linked statically and without any external dependencies. + +For the widest platform compatibility they should use nolibc, as provided = by `init/Makefile.nolibc`. + +.. kernel-doc:: include/kunit/uapi.h + :internal: diff --git a/MAINTAINERS b/MAINTAINERS index e806158cc6798cf97a4aab58c038fb5351d469aa..0f60501c6de570723123b24eb93= 0d15f1bd956eb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13540,6 +13540,12 @@ S: Maintained F: Documentation/devicetree/bindings/leds/backlight/kinetic,ktz8866.yaml F: drivers/video/backlight/ktz8866.c =20 +KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL UNIT TESTING FRAMEWORK) +M: Thomas Wei=C3=9Fschuh +S: Maintained +F: include/kunit/uapi.h +F: lib/kunit/kunit-uapi.c + KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini R: Vitaly Kuznetsov diff --git a/include/kunit/uapi.h b/include/kunit/uapi.h new file mode 100644 index 0000000000000000000000000000000000000000..a5c923f5d82a91e0acd9dc17369= f84f00b7d342f --- /dev/null +++ b/include/kunit/uapi.h @@ -0,0 +1,77 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#ifndef _KUNIT_UAPI_H +#define _KUNIT_UAPI_H + +#include + +struct kunit; + +/** + * struct kunit_uapi_blob - Blob embedded build artifact + * @path: Path of the embedded artifact. + * @data: Start of the embedded data in memory. + * @end: End of the embedded data in memory. + */ +struct kunit_uapi_blob { + const char *const path; + const u8 *data; + const u8 *end; +}; + +#if IS_ENABLED(CONFIG_KUNIT_UAPI) + +/** + * KUNIT_UAPI_EMBED_BLOB() - Embed another build artifact into the kernel + * @_name: The name of symbol under which the artifact is embedded. + * @_path: Path to the artifact on disk. + * + * Embeds a build artifact like a userspace executable into the kernel or = current module. + * The build artifact is read from disk and needs to be already built. + */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + asm ( \ + " .pushsection .rodata, \"a\" \n" \ + " .global " __stringify(CONCATENATE(_name, _data)) " \n" \ + __stringify(CONCATENATE(_name, _data)) ": \n" \ + " .incbin " __stringify(_path) " \n" \ + " .size " __stringify(CONCATENATE(_name, _data)) ", " \ + ". - " __stringify(CONCATENATE(_name, _data)) " \n" \ + " .global " __stringify(CONCATENATE(_name, _end)) " \n" \ + __stringify(CONCATENATE(_name, _end)) ": \n" \ + " .popsection \n" \ + ); \ + \ + extern const char CONCATENATE(_name, _data)[]; \ + extern const char CONCATENATE(_name, _end)[]; \ + \ + static const struct kunit_uapi_blob _name =3D { \ + .path =3D _path, \ + .data =3D CONCATENATE(_name, _data), \ + .end =3D CONCATENATE(_name, _end), \ + } \ + +#else /* !CONFIG_KUNIT_UAPI */ + +/* Unresolved external reference, to be optimized away */ +#define KUNIT_UAPI_EMBED_BLOB(_name, _path) \ + extern const struct kunit_uapi_blob _name + +#endif /* CONFIG_KUNIT_UAPI */ + +/** + * 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 kunit_uapi_= blob *executable); + +#endif /* _KUNIT_UAPI_H */ diff --git a/lib/kunit/Kconfig b/lib/kunit/Kconfig index a97897edd9642f3e5df7fdd9dee26ee5cf00d6a4..c88e6cf5610bc8246c94d16b902= 5461f0cd3b2d2 100644 --- a/lib/kunit/Kconfig +++ b/lib/kunit/Kconfig @@ -93,4 +93,18 @@ 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. =20 +config KUNIT_UAPI + tristate "KUnit UAPI testing framework" + depends on KUNIT + depends on CC_CAN_LINK_STATIC || ARCH_HAS_NOLIBC + depends on !LTO_CLANG # https://github.com/llvm/llvm-project/issues/112920 + select HEADERS_INSTALL + default KUNIT + help + Enables support for building and running userspace selftests as part of= kunit. + These tests should be statically linked and use kselftest.h or kselftes= t_harness.h + for status reporting. + + In most cases this should be left as Y. + endif # KUNIT diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 656f1fa35abcc635e67d5b4cb1bc586b48415ac5..6059621a2d32c8e7384acda5979= 3f05826af8c81 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -12,6 +12,8 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..cfe8440e16fde942a5f0fa7ac9d= 8ab90a737215b --- /dev/null +++ b/lib/kunit/kunit-uapi.c @@ -0,0 +1,300 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace testing API. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + */ + +#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_ramfs(void) +{ + struct file_system_type *type; + struct vfsmount *mnt; + + type =3D get_fs_type("ramfs"); + if (!type) + return ERR_PTR(-ENODEV); + + /* FIXME + * The mount setup is supposed to look like this: + * kunit_uapi_mount_ramfs() 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 =3D kern_mount(type); + put_filesystem(type); + + return mnt; +} + +static int kunit_uapi_write_file(struct vfsmount *mnt, const char *name, m= ode_t mode, + const u8 *data, size_t size) +{ + struct file *file; + ssize_t written; + + file =3D file_open_root_mnt(mnt, name, O_CREAT | O_WRONLY, mode); + if (IS_ERR(file)) + return PTR_ERR(file); + + written =3D kernel_write(file, data, size, NULL); + filp_close(file, NULL); + if (written !=3D size) { + if (written >=3D 0) + return -ENOMEM; + return written; + } + + /* Flush delayed fput so exec can open the file read-only */ + flush_delayed_fput(); + + return 0; +} + +static int kunit_uapi_write_executable(struct vfsmount *mnt, + const struct kunit_uapi_blob *executable) +{ + return kunit_uapi_write_file(mnt, kbasename(executable->path), 0755, + executable->data, executable->end - executable->data); +} + +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 =3D data; + const char *const argv[] =3D { + ctx->executable, + NULL + }; + struct file *out[2]; + int err; + + err =3D create_pipe_files(out, 0); + if (err) + return err; + + /* stdin, use the *write* end to the pipe to have an unreadable input */ + err =3D replace_fd(0, out[1], 0); + if (err < 0) { + fput(out[0]); + fput(out[1]); + return err; + } + + /* stdout */ + err =3D replace_fd(1, out[1], 0); + if (err < 0) { + replace_fd(0, NULL, 0); + fput(out[0]); + fput(out[1]); + return err; + } + + /* stderr */ + err =3D 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 =3D out[0]; + ctx->tgid =3D 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 =3D 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 *bu= f, size_t s) +{ + const char *ptr =3D buf, *newline; + size_t n; + + while (s) { + newline =3D strnchr(ptr, s, '\n'); + if (!newline) + break; + + n =3D newline - ptr + 1; + + kunit_log(KERN_INFO, test, KUNIT_SUBSUBTEST_INDENT "%.*s", (int)n, ptr); + ptr +=3D n; + s -=3D n; + } + + memmove(buf, ptr, s); + + return s; +} + +static int kunit_uapi_forward_to_printk(struct kunit *test, struct file *o= utput) +{ + /* + * 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 =3D 0; + ssize_t n; + + while (1) { + n =3D kernel_read(output, buf + s, sizeof(buf) - s, NULL); + if (n <=3D 0) + return n; + s =3D kunit_uapi_printk_subtest_lines(test, buf, s + n); + } +} + +static void kunit_uapi_kill_pid(pid_t pid) +{ + struct pid *p; + + p =3D find_get_pid(pid); + kill_pid(p, SIGKILL, 1); + put_pid(p); +} + +static int kunit_uapi_run_executable_in_mount(struct kunit *test, const ch= ar *executable, + struct vfsmount *mnt) +{ + struct kunit_uapi_user_mode_thread_ctx ctx =3D { + .setup_done =3D COMPLETION_INITIALIZER_ONSTACK(ctx.setup_done), + .executable =3D executable, + .pwd =3D { + .mnt =3D mnt, + .dentry =3D 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 =3D 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 =3D kunit_uapi_forward_to_printk(test, ctx.out); + if (forward_err) + kunit_uapi_kill_pid(ctx.tgid); + + wait_err =3D 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 kunit_uapi_blob *executable) +{ + const char *exe_name =3D kbasename(executable->path); + struct vfsmount *mnt; + int err; + + mnt =3D kunit_uapi_mount_ramfs(); + if (IS_ERR(mnt)) + return PTR_ERR(mnt); + + err =3D kunit_uapi_write_executable(mnt, executable); + + if (!err) + err =3D 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 kunit_uapi_= blob *executable) +{ + u8 exit_code, exit_signal; + int err; + + err =3D kunit_uapi_run_executable(test, executable); + if (err < 0) + KUNIT_FAIL_AND_ABORT(test, "Could not run test executable: %pe\n", ERR_P= TR(err)); + + exit_code =3D err >> 8; + exit_signal =3D err & 0xff; + + if (exit_signal) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with signal: %d\n", exit_si= gnal); + else if (exit_code =3D=3D KSFT_PASS) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_FAIL) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_FAIL\n"); + else if (exit_code =3D=3D KSFT_XPASS) + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with code KSFT_XPASS\n"); + else if (exit_code =3D=3D KSFT_XFAIL) + ; /* Noop */ + else if (exit_code =3D=3D KSFT_SKIP) + kunit_mark_skipped(test, "kselftest exited with code KSFT_SKIP\n"); + else + KUNIT_FAIL_AND_ABORT(test, "kselftest exited with unknown exit code: %d\= n", + exit_code); +} +EXPORT_SYMBOL_GPL(kunit_uapi_run_kselftest); + +MODULE_DESCRIPTION("KUnit UAPI testing framework"); +MODULE_AUTHOR("Thomas Wei=C3=9Fschuh DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918227; 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=DsDPyS4cN8Rd+7R9ZMNq8bORyKscl6GSeHz3Gu4ppW4=; b=gY8jN+8RXLn1jaHGimp1PswlVRey7Klv8sMfoJrl+TqnQ41sXMrP1RicMOdexINW/jqc7z mrxJNNu6SYt7uy48EfRPVCFurmhrvw2eYUkBe2FAGAWpUU3r4uCfoWVNPTagUes68P0URA nQGqF2O/+6KvLwtd9UGBWCsEyNo91/h0uszmaPm8b1UgILjgICFTmzUo0kRk5kYwIUTQRv LPdl3PxyI+0lQRCjk38oRHv/ZC5C6VqwLqJnDXkFLNoOxWd/UERlinziQIv0+hmKyS+RbX SbB4aRXfmwFGegV26+eBKTVtioQtIrrgFrzTFYjxpWspzVwJtbUgDNlx/RU10Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918227; 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=DsDPyS4cN8Rd+7R9ZMNq8bORyKscl6GSeHz3Gu4ppW4=; b=hCSJ6sJl8sJV+/mE7pW9mxFfvBLIgzvPWfLlWB7Bt6zJikK2LSMMsBbWfrnIt1P2C0DVfP IDDG9iIYsX2OybBQ== Date: Thu, 26 Jun 2025 08:10:21 +0200 Subject: [PATCH v4 13/15] kunit: uapi: Add example for UAPI tests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-13-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=3685; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=zCRVPNHdhdMqDLsoVDpwaBJ7JHwfC8tITyvaL9KjOKo=; b=lz7WNMY7LoBnGCOQrPEp40isJXr8If4yxjNl2RgIm6KXLISeG71v0I05vjauZ34o9D1EiLDBD 1Wq/NVvT3YBD4xMTfwbIS++v48xIMlR5Hbl85XGvZv9NGHhxATqABdd 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=C3=9Fschuh Reviewed-by: David Gow --- MAINTAINERS | 1 + lib/kunit/Makefile | 9 +++++++++ lib/kunit/kunit-example-test.c | 15 +++++++++++++++ lib/kunit/kunit-example-uapi.c | 22 ++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 0f60501c6de570723123b24eb930d15f1bd956eb..b1405f0a0e638d1654d9dc9e51d= 784ddc838cf5b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13544,6 +13544,7 @@ KUNIT UAPI TESTING FRAMEWORK (in addition to KERNEL= UNIT TESTING FRAMEWORK) M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h +F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c =20 KVM PARAVIRT (KVM/paravirt) diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 6059621a2d32c8e7384acda59793f05826af8c81..1bba7965613e36e26939d6b31e1= d65acf5bad0dc 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -1,3 +1,5 @@ +include $(srctree)/init/Makefile.nolibc + obj-$(CONFIG_KUNIT) +=3D kunit.o =20 kunit-objs +=3D test.o \ @@ -31,3 +33,10 @@ obj-$(CONFIG_KUNIT_TEST) +=3D assert_test.o endif =20 obj-$(CONFIG_KUNIT_EXAMPLE_TEST) +=3D kunit-example-test.o + +userprogs +=3D kunit-example-uapi +kunit-example-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +$(obj)/kunit-example-test.o: $(obj)/kunit-example-uapi +endif diff --git a/lib/kunit/kunit-example-test.c b/lib/kunit/kunit-example-test.c index 3056d6bc705d0a8f196f0f4412e679dbb0e03114..0c5e1e59f9358b84aee2621e342= d824a2f99f9aa 100644 --- a/lib/kunit/kunit-example-test.c +++ b/lib/kunit/kunit-example-test.c @@ -8,6 +8,7 @@ =20 #include #include +#include =20 /* * This is the most fundamental element of KUnit, the test case. A test ca= se @@ -277,6 +278,19 @@ static void example_slow_test(struct kunit *test) KUNIT_EXPECT_EQ(test, 1 + 1, 2); } =20 +/* + * This test shows the usage of UAPI tests. + */ +static void example_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_example_uapi, "kunit-example-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &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 su= ite * below. @@ -297,6 +311,7 @@ static struct kunit_case example_test_cases[] =3D { 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), {} }; =20 diff --git a/lib/kunit/kunit-example-uapi.c b/lib/kunit/kunit-example-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..4ce657050dd4a576632a41ca030= 9c4cb5134ce14 --- /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=C3=9Fschuh + * + * 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(); +} --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 DD6C0239E69; Thu, 26 Jun 2025 06:10:30 +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=1750918232; cv=none; b=bB/VO0QgeW9KfVxAULC6LdM9Pmm1q2GtcLU9xT2mvXzmBaE/RygUvJaLeOU8Q0apepZHUP8CAWH/fAv1rm5xRtKQ9ovufFO3La4Q4WmaI2ng6RTvXt5CLLgwdCXmFY7eo6T516+Rx0099sVcQOgrPjb9pnTpiOL5tD5iIVs+PwA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918232; c=relaxed/simple; bh=tfMOCoPEy8rGnsRn5SK9Zft1douhBnfSJv8vwY3PrKo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=g7XXB1hca4mb8y7q25wUp0X7aQuiI9FdEYLcHFUb04eWf7L8obbmAYqBQkGcJQ1QEaMHxaoPcpOrkLgjOfQB/9j+b3m8rPMdT0ain69VC4GMJszbaQ5lr93EZ9ROtEeonpQ3XrrRjDGUUyXYzLP0uJicMOqcyN/0NUefnNEIhhU= 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=zUMnP0Tk; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=zqA1HRQS; 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="zUMnP0Tk"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="zqA1HRQS" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918229; 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=U45zqeUzHXUhAwSREm/gs1f9MtJQvqmX810ZWqy+uwA=; b=zUMnP0Tk0Ri4CbI42WV80apWUu0atA3228mxH6uKIS8xC7D9GzAKWBhzT3hqfEk5G42Wj0 fZQVkAxKh1fDi7biyn2ZDBDStMxFnlVj/j5CU/MpTYQzBSSSFmtF28ztnjJYyw6lmq38hl x0WXxJ6o/Ddrnhu/gID+MTjZS4/dYt9gOXqHseif+O6AHKJ8Sz4t7QvRouMtUmyHGDUndg dKYF+knE/Fn3LK0DeryFzLJA4aBl83vPvGTM5oXkPPn9Ny3Myl/piIDaJ14UGK6NK+Z0Eu KU4FpnI8sv0WrbjdE+yiEIqmdXr6Gy2fsjWOirnvt6/5t5w+po2lZPehm9IK4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918229; 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=U45zqeUzHXUhAwSREm/gs1f9MtJQvqmX810ZWqy+uwA=; b=zqA1HRQSzPo2Iit8MCXNiQFnc9FiTpLS1JPKFp6h3F+q4pTQHDV/0lIzFEifxgEIIgS4XY N2ivAmp2plKcSBAQ== Date: Thu, 26 Jun 2025 08:10:22 +0200 Subject: [PATCH v4 14/15] kunit: uapi: Introduce preinit executable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-14-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=4750; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=tfMOCoPEy8rGnsRn5SK9Zft1douhBnfSJv8vwY3PrKo=; b=0YGi4+FqLMryGFAXD6WQf8Ybx7txIkBbmZMwWQ92jzOOaA6bmFq0o8WaChQMH1YaCh74ld67L FOg0CVdklODBMgouXqgy1m8bI0wwe9xt+4vb9amhD654RuRYYwah6jN 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=C3=9Fschuh Reviewed-by: David Gow Acked-by: Muhammad Usama Anjum --- MAINTAINERS | 1 + lib/kunit/Makefile | 6 +++++ lib/kunit/kunit-uapi.c | 9 +++++-- lib/kunit/uapi-preinit.c | 63 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 77 insertions(+), 2 deletions(-) diff --git a/MAINTAINERS b/MAINTAINERS index b1405f0a0e638d1654d9dc9e51d784ddc838cf5b..e81dfa180ab374ef91c7a45e546= e6e9a8f454fa7 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13546,6 +13546,7 @@ S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c F: lib/kunit/kunit-uapi.c +F: lib/kunit/uapi-preinit.c =20 KVM PARAVIRT (KVM/paravirt) M: Paolo Bonzini diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index 1bba7965613e36e26939d6b31e1d65acf5bad0dc..b50f3bc8bc7f3ade03be4900d91= 63d7a0d96863c 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -14,8 +14,14 @@ kunit-objs +=3D test.o \ device.o \ platform.o =20 +userprogs +=3D uapi-preinit +uapi-preinit-userccflags +=3D -static $(NOLIBC_USERCFLAGS) \ + -include include/generated/autoconf.h \ + -include $(srctree)/tools/include/linux/kconfig.h obj-$(CONFIG_KUNIT_UAPI) +=3D kunit-uapi.o =20 +$(obj)/kunit-uapi.o: $(obj)/uapi-preinit + ifeq ($(CONFIG_KUNIT_DEBUGFS),y) kunit-objs +=3D debugfs.o endif diff --git a/lib/kunit/kunit-uapi.c b/lib/kunit/kunit-uapi.c index cfe8440e16fde942a5f0fa7ac9d8ab90a737215b..7c87605b9ded9dbeb3968af8a8f= 4650ab5938887 100644 --- a/lib/kunit/kunit-uapi.c +++ b/lib/kunit/kunit-uapi.c @@ -25,6 +25,8 @@ #define KSFT_XPASS 3 #define KSFT_SKIP 4 =20 +KUNIT_UAPI_EMBED_BLOB(kunit_uapi_preinit, "uapi-preinit"); + static struct vfsmount *kunit_uapi_mount_ramfs(void) { struct file_system_type *type; @@ -146,7 +148,7 @@ static int kunit_uapi_user_mode_thread_init(void *data) kernel_sigaction(SIGABRT, SIG_DFL); =20 complete(&ctx->setup_done); - ctx->exec_err =3D kernel_execve(ctx->executable, argv, NULL); + ctx->exec_err =3D kernel_execve(kbasename(kunit_uapi_preinit.path), argv,= NULL); if (!ctx->exec_err) return 0; do_exit(0); @@ -255,7 +257,10 @@ static int kunit_uapi_run_executable(struct kunit *tes= t, if (IS_ERR(mnt)) return PTR_ERR(mnt); =20 - err =3D kunit_uapi_write_executable(mnt, executable); + err =3D kunit_uapi_write_executable(mnt, &kunit_uapi_preinit); + + if (!err) + err =3D kunit_uapi_write_executable(mnt, executable); =20 if (!err) err =3D kunit_uapi_run_executable_in_mount(test, exe_name, mnt); diff --git a/lib/kunit/uapi-preinit.c b/lib/kunit/uapi-preinit.c new file mode 100644 index 0000000000000000000000000000000000000000..81182039965a8c93aebb2d5d76f= 4113bfef277a6 --- /dev/null +++ b/lib/kunit/uapi-preinit.c @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace environment setup. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +static int setup_api_mount(const char *target, const char *fstype) +{ + int ret; + + ret =3D mkdir(target, 0755); + if (ret && errno !=3D EEXIST) + return -errno; + + ret =3D mount("none", target, fstype, 0, NULL); + if (ret && errno !=3D 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, strerr= or(-err)); + ksft_finished(); +} + +int main(int argc, char **argv, char **envp) +{ + int ret; + + ret =3D setup_api_mount("/proc", "proc"); + if (ret) + exit_failure("mount /proc", ret); + + ret =3D setup_api_mount("/sys", "sysfs"); + if (ret) + exit_failure("mount /sys", ret); + + if (IS_ENABLED(CONFIG_DEVTMPFS)) { + ret =3D setup_api_mount("/dev", "devtmpfs"); + if (ret) + exit_failure("mount /dev", ret); + } + + ret =3D execve(argv[0], argv, envp); + if (ret) + exit_failure("execve", ret); + + return 0; +} --=20 2.50.0 From nobody Wed Oct 8 16:06:05 2025 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 CCE1125E461; Thu, 26 Jun 2025 06:10:31 +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=1750918234; cv=none; b=nNitNmTiqQzNHaRuEu4e3Tv2IkR8yoop0knE+NAxie2FAk3E+VdkKiaMc7rV9vpflGXYDDD1eWAdUILYiP0gNx8IWR6i8kjdt8eRgAKiIx+lcy77NzrGJPJqMl6MzQKUM0vxh2HtrT4iXrRzrK5IXuFEoENiOkZNL5vaud7K5zI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750918234; c=relaxed/simple; bh=/QnMka8GtzcWlJyc1k0qKztnRSdiplVDLyPIydh5NqE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mMGG43JQbFfVdyXcGLhlBMwcOAfcPWRZWFXAMX2oMmAT+6+tXP1EybxPw0Jfef8k61IO/A8Bj44WYgj0uzcwlpYLnUUBhBnYRbl951Pe8RrXDhxfGpcc4aDs3wS9yLUVgBtVmknm2glkPasY4dmItB58Y83alK2yauCp4uQVRXY= 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=GopqWVnX; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=hvv9muUm; 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="GopqWVnX"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="hvv9muUm" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1750918229; 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=Wcd1PIYjhMZuamuSudKPI/n6bo0/ENxSUBBB9QoiuyI=; b=GopqWVnX6xFlQ7Kx9LSfHAgcfO1bXVmMzglHMjTN5SiIw7UlhYURTvAEuSuT+AxPq3k4oU 3JFfGoVPS4m6RQjL3VjsmLrrBcx2WLx9xgWrxZyEotk36T9mgYsf56JWIoNVRQhe0MKi6i eZCJr7kiNonUUR1AOAj81Z9eKsvG9/VKh7hVXelMamD/4VusIN2JS31i3aaYuGmgYs1ZLn 7xeUp1R9K3fzzyYp/OQ+luAEGlQunqtPK9tO+C+UVBoHHiASArPOAnTjE1fUrM0tb1ZFqx zvAuCYrZdXVVpvp4qvUq/j4AgT3cGr8HB6e+ac2KAvB0IytDj77RMe83pHaMKg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1750918229; 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=Wcd1PIYjhMZuamuSudKPI/n6bo0/ENxSUBBB9QoiuyI=; b=hvv9muUmMjT3RoOZ2ahvBTns7AYlFJQVgiBCUCOxaASmznc+IOeTQZZwURS4JcQ1mKrAr7 RlqvovE88eiPVdDA== Date: Thu, 26 Jun 2025 08:10:23 +0200 Subject: [PATCH v4 15/15] kunit: uapi: Validate usability of /proc Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250626-kunit-kselftests-v4-15-48760534fef5@linutronix.de> References: <20250626-kunit-kselftests-v4-0-48760534fef5@linutronix.de> In-Reply-To: <20250626-kunit-kselftests-v4-0-48760534fef5@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, workflows@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1750918216; l=4198; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=/QnMka8GtzcWlJyc1k0qKztnRSdiplVDLyPIydh5NqE=; b=xB7u5Cp2e4wdBmPvNIDKeczWzFIIV/jDR6yOyqYbQ1SH8M4HoZCTC+imqTH8D829DAdmzvkAY mXqCdf6nCfYABbD4IU+hZPge6uh7tTqbdBktUUvhy/GR2tq5/hV3xZ/ 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=C3=9Fschuh --- MAINTAINERS | 1 + lib/kunit/Makefile | 8 +++++++ lib/kunit/kunit-test-uapi.c | 51 +++++++++++++++++++++++++++++++++++++++++= ++++ lib/kunit/kunit-test.c | 23 +++++++++++++++++++- 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index e81dfa180ab374ef91c7a45e546e6e9a8f454fa7..d86e8e0bfee75acecfeb9569d53= ea8ea99727985 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13545,6 +13545,7 @@ M: Thomas Wei=C3=9Fschuh S: Maintained F: include/kunit/uapi.h F: lib/kunit/kunit-example-uapi.c +F: lib/kunit/kunit-test-uapi.c F: lib/kunit/kunit-uapi.c F: lib/kunit/uapi-preinit.c =20 diff --git a/lib/kunit/Makefile b/lib/kunit/Makefile index b50f3bc8bc7f3ade03be4900d9163d7a0d96863c..25384e5c3c4cd1f92e4ec2c3830= e0be1c6732ac1 100644 --- a/lib/kunit/Makefile +++ b/lib/kunit/Makefile @@ -30,6 +30,14 @@ endif obj-$(if $(CONFIG_KUNIT),y) +=3D hooks.o =20 obj-$(CONFIG_KUNIT_TEST) +=3D kunit-test.o + +userprogs +=3D kunit-test-uapi +kunit-test-uapi-userccflags :=3D -static $(NOLIBC_USERCFLAGS) + +ifdef CONFIG_KUNIT_UAPI +$(obj)/kunit-test.o: $(obj)/kunit-test-uapi +endif + obj-$(CONFIG_KUNIT_TEST) +=3D platform-test.o =20 # string-stream-test compiles built-in only. diff --git a/lib/kunit/kunit-test-uapi.c b/lib/kunit/kunit-test-uapi.c new file mode 100644 index 0000000000000000000000000000000000000000..ec5395d809ee2a4bd3c47a573a5= 76e2f98ef5c1b --- /dev/null +++ b/lib/kunit/kunit-test-uapi.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * KUnit Userspace selftest. + * + * Copyright (C) 2025, Linutronix GmbH. + * Author: Thomas Wei=C3=9Fschuh + * + * This is *userspace* code. + */ + +#include +#include +#include + +#include "../../tools/testing/selftests/kselftest.h" + +static void test_procfs(void) +{ + char buf[256]; + ssize_t r; + int fd; + + fd =3D open("/proc/self/comm", O_RDONLY); + if (fd =3D=3D -1) { + ksft_test_result_fail("procfs: open() failed: %s\n", strerror(errno)); + return; + } + + r =3D read(fd, buf, sizeof(buf)); + close(fd); + + if (r =3D=3D -1) { + ksft_test_result_fail("procfs: read() failed: %s\n", strerror(errno)); + return; + } + + if (r !=3D 16 || strncmp("kunit-test-uapi\n", buf, 16) !=3D 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(1); + test_procfs(); + ksft_finished(); +} diff --git a/lib/kunit/kunit-test.c b/lib/kunit/kunit-test.c index d9c781c859fde1f3623eb71b6829e82aa4803762..03972a3cb172d4af61bec17be80= 0ddfb4bbd7268 100644 --- a/lib/kunit/kunit-test.c +++ b/lib/kunit/kunit-test.c @@ -8,6 +8,7 @@ #include "linux/gfp_types.h" #include #include +#include =20 #include #include @@ -868,10 +869,30 @@ static struct kunit_suite kunit_current_test_suite = =3D { .test_cases =3D kunit_current_test_cases, }; =20 +static void kunit_uapi_test(struct kunit *test) +{ + KUNIT_UAPI_EMBED_BLOB(kunit_test_uapi, "kunit-test-uapi"); + + if (IS_ENABLED(CONFIG_KUNIT_UAPI)) + kunit_uapi_run_kselftest(test, &kunit_test_uapi); + else + kunit_skip(test, "CONFIG_KUNIT_UAPI is not enabled"); +} + +static struct kunit_case kunit_uapi_test_cases[] =3D { + KUNIT_CASE(kunit_uapi_test), + {} +}; + +static struct kunit_suite kunit_uapi_test_suite =3D { + .name =3D "kunit_uapi", + .test_cases =3D kunit_uapi_test_cases, +}; + kunit_test_suites(&kunit_try_catch_test_suite, &kunit_resource_test_suite, &kunit_log_test_suite, &kunit_status_test_suite, &kunit_current_test_suite, &kunit_device_test_suite, - &kunit_fault_test_suite); + &kunit_fault_test_suite, &kunit_uapi_test_suite); =20 MODULE_DESCRIPTION("KUnit test for core test infrastructure"); MODULE_LICENSE("GPL v2"); --=20 2.50.0