Message ID | 20231220-send-lp-kselftests-v4-1-3458ec1b1a38@suse.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp2777649dyi; Wed, 20 Dec 2023 08:58:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlSBz93VQwmp/byhd1tR9UseiXFnoSbASbpf5MLx7Ljr3kd2nx3CFpebYO+pFj2XB93lR8 X-Received: by 2002:a17:902:e84d:b0:1d3:b2f5:f40 with SMTP id t13-20020a170902e84d00b001d3b2f50f40mr4230090plg.14.1703091535236; Wed, 20 Dec 2023 08:58:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703091535; cv=none; d=google.com; s=arc-20160816; b=IFHGGXipsoC/JWi+2vwS8qqRLAvsgGcXutaqRgp/Il6/jBALXmkxzj+9lLuuGtmmPs iaTdmpAC8QaIA2m3ky5Brs/97OiPtEhUTbwbWjIYmgfuJq/ZU5CnWpWDQGHBhyDVGIQn HY4/Q6FdlcF49F9ja0FypnuzXVluyJn8xAyFIC5AR/WpIPPnPIrXvRQUWqeSXzhD7Yxa +uvyI9szXWbwBrYZpGJw6q55ask08f71bUjtDTU6t4j8rzfACM1BRWiKaYD252mOjKBA W8/F1SvXS3wehV5Ckn4nuHHTQlrLuhdMnBi3HeGtKpEdcpXgwVVxTmhXAMDE/sHMgFG0 BBMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature:dkim-signature; bh=bowR7VTv0DP9Zwvvuc76K5HhtGrhPhlCbmsYd4zANDM=; fh=Mq58102248fM07I0WalrZ/nXtmtKWhasuGO5B/rfF9E=; b=V4qY6dtyB3ESSAFrmkVpwtwL/VFhlN+6AB+puuN6TGEjgYVrR/OJsxtP/gjNWt6Pcn Ee/XT7Xbs8TeqHiuwMNXjzC7wS91uq4VClsA81bMNRGYCwp92xh4YpTqoO5eqPlHAgWx 77HFzhDPuHc/Fk6MIiLXkvwR/00r9I+LUN7g1+piE/khZD3gUv/ilPSCVSWPgTlKIfK1 ohKAs42HLHlzs/1zhZiFQRRRW+W2lQNuvZx4SCSYNOolXxUAAeaX/0Z0p9mbsDo2Y6FQ a7Z4y2LO+gvD9r8Pb2CT6m/9xhTY3NzousyLtRR9vdekJGfP2PPG7gMucObddVu4wLQQ hWEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oUUWN6PQ; dkim=pass header.i=@suse.com header.s=susede1 header.b=oUUWN6PQ; spf=pass (google.com: domain of linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id g1-20020a170902fe0100b001d3f285561asi961200plj.29.2023.12.20.08.58.54 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 08:58:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=oUUWN6PQ; dkim=pass header.i=@suse.com header.s=susede1 header.b=oUUWN6PQ; spf=pass (google.com: domain of linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7321-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 48862B21218 for <ouuuleilei@gmail.com>; Wed, 20 Dec 2023 16:54:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC4A147A42; Wed, 20 Dec 2023 16:53:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="oUUWN6PQ"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="oUUWN6PQ" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2CEF846535; Wed, 20 Dec 2023 16:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 54D411F83D; Wed, 20 Dec 2023 16:53:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1703091206; h=from:from:reply-to: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=bowR7VTv0DP9Zwvvuc76K5HhtGrhPhlCbmsYd4zANDM=; b=oUUWN6PQlKgNAqWrl2+EfsqaO9QF8G/2sLA0cd1t1QW8GfA6SXsTV7E0GJ2ape2r3rXngx TO0PBogPy6p+NuiqyY9nBCEayy1KYq7LEso0JLB5Vy+6rT+OI6e4yfn1cSKyPpixg2Z74I nDRH2KdeV/pCl5pyl+2ExycgWSu8meY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1703091206; h=from:from:reply-to: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=bowR7VTv0DP9Zwvvuc76K5HhtGrhPhlCbmsYd4zANDM=; b=oUUWN6PQlKgNAqWrl2+EfsqaO9QF8G/2sLA0cd1t1QW8GfA6SXsTV7E0GJ2ape2r3rXngx TO0PBogPy6p+NuiqyY9nBCEayy1KYq7LEso0JLB5Vy+6rT+OI6e4yfn1cSKyPpixg2Z74I nDRH2KdeV/pCl5pyl+2ExycgWSu8meY= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id D377413722; Wed, 20 Dec 2023 16:53:25 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 4L3HIgUcg2V/SQAAD6G6ig (envelope-from <mpdesouza@suse.com>); Wed, 20 Dec 2023 16:53:25 +0000 From: Marcos Paulo de Souza <mpdesouza@suse.com> Date: Wed, 20 Dec 2023 13:53:12 -0300 Subject: [PATCH RESEND v4 1/3] kselftests: lib.mk: Add TEST_GEN_MODS_DIR variable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20231220-send-lp-kselftests-v4-1-3458ec1b1a38@suse.com> References: <20231220-send-lp-kselftests-v4-0-3458ec1b1a38@suse.com> In-Reply-To: <20231220-send-lp-kselftests-v4-0-3458ec1b1a38@suse.com> To: Shuah Khan <shuah@kernel.org>, Jonathan Corbet <corbet@lwn.net>, Heiko Carstens <hca@linux.ibm.com>, Vasily Gorbik <gor@linux.ibm.com>, Alexander Gordeev <agordeev@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Sven Schnelle <svens@linux.ibm.com>, Josh Poimboeuf <jpoimboe@kernel.org>, Jiri Kosina <jikos@kernel.org>, Miroslav Benes <mbenes@suse.cz>, Petr Mladek <pmladek@suse.com>, Joe Lawrence <joe.lawrence@redhat.com> Cc: linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, live-patching@vger.kernel.org, Marcos Paulo de Souza <mpdesouza@suse.com> X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1703091199; l=4750; i=mpdesouza@suse.com; s=20231031; h=from:subject:message-id; bh=7aSXvLR/NeW1yOAkbvMqXIcbput29MVpoSQ3ccB2cy0=; b=Kaej+YHwR4OPMDedsWA7d1qhh7Uj70EktwPkwbsl8tOpHNnWw3Sq3SN59uT2zZxN5nZ+vSADL mIrGpFX/PFZCVIq8zDxTAuwKL0CA0o0bDVE5Yy7SwUPv5Q6ckUymabL X-Developer-Key: i=mpdesouza@suse.com; a=ed25519; pk=/Ni/TsKkr69EOmdZXkp1Q/BlzDonbOBRsfPa18ySIwU= X-Spam-Level: X-Spam-Level: X-Spamd-Result: default: False [-7.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_HAM(-3.00)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; R_RATELIMIT(0.00)[to_ip_from(RL64puoyk87hsyf83pd56xsc3m)]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_TWELVE(0.00)[18]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[] Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: -7.10 X-Spam-Flag: NO X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785820909723063467 X-GMAIL-MSGID: 1785820909723063467 |
Series |
livepatch: Move modules to selftests and add a new test
|
|
Commit Message
Marcos Paulo de Souza
Dec. 20, 2023, 4:53 p.m. UTC
Add TEST_GEN_MODS_DIR variable for kselftests. It can point to
a directory containing kernel modules that will be used by
selftest scripts.
The modules are built as external modules for the running kernel.
As a result they are always binary compatible and the same tests
can be used for older or newer kernels.
The build requires "kernel-devel" package to be installed.
For example, in the upstream sources, the rpm devel package
is produced by "make rpm-pkg"
The modules can be built independently by
make -C tools/testing/selftests/livepatch/
or they will be automatically built before running the tests via
make -C tools/testing/selftests/livepatch/ run_tests
Note that they are _not_ built when running the standalone
tests by calling, for example, ./test-state.sh.
Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com>
---
Documentation/dev-tools/kselftest.rst | 4 ++++
tools/testing/selftests/lib.mk | 20 +++++++++++++++-----
2 files changed, 19 insertions(+), 5 deletions(-)
Comments
On Wed, Dec 20, 2023 at 01:53:12PM -0300, Marcos Paulo de Souza wrote: > Add TEST_GEN_MODS_DIR variable for kselftests. It can point to > a directory containing kernel modules that will be used by > selftest scripts. > > The modules are built as external modules for the running kernel. > As a result they are always binary compatible and the same tests > can be used for older or newer kernels. > > The build requires "kernel-devel" package to be installed. > For example, in the upstream sources, the rpm devel package > is produced by "make rpm-pkg" > > The modules can be built independently by > > make -C tools/testing/selftests/livepatch/ > > or they will be automatically built before running the tests via > > make -C tools/testing/selftests/livepatch/ run_tests > > Note that they are _not_ built when running the standalone > tests by calling, for example, ./test-state.sh. > > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> > --- > Documentation/dev-tools/kselftest.rst | 4 ++++ > tools/testing/selftests/lib.mk | 20 +++++++++++++++----- > 2 files changed, 19 insertions(+), 5 deletions(-) > > diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst > index ab376b316c36..7f3582a67318 100644 > --- a/Documentation/dev-tools/kselftest.rst > +++ b/Documentation/dev-tools/kselftest.rst > @@ -245,6 +245,10 @@ Contributing new tests (details) > TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested by > default. > > + TEST_GEN_MODS_DIR should be used by tests that require modules to be built > + before the test starts. The variable will contain the name of the directory > + containing the modules. > + > TEST_CUSTOM_PROGS should be used by tests that require custom build > rules and prevent common build rule use. > > diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk > index 118e0964bda9..6c7c5a0112cf 100644 > --- a/tools/testing/selftests/lib.mk > +++ b/tools/testing/selftests/lib.mk > @@ -70,12 +70,15 @@ KHDR_INCLUDES := -isystem $(KHDR_DIR) > # TEST_PROGS are for test shell scripts. > # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests > # and install targets. Common clean doesn't touch them. > +# TEST_GEN_MODS_DIR is used to specify a directory with modules to be built > +# before the test executes. These modules are cleaned on the clean target as well. > TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) > TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) > TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) > +TEST_GEN_MODS_DIR := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_MODS_DIR)) > > all: kernel_header_files $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) \ > - $(TEST_GEN_FILES) > + $(TEST_GEN_FILES) $(if $(TEST_GEN_MODS_DIR),gen_mods_dir) > > kernel_header_files: > @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ > @@ -105,8 +108,8 @@ endef > > run_tests: all > ifdef building_out_of_srctree > - @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ > - rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ > + @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)$(TEST_GEN_MODS_DIR)" != "X" ]; then \ > + rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(TEST_GEN_MODS_DIR) $(OUTPUT); \ > fi > @if [ "X$(TEST_PROGS)" != "X" ]; then \ > $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ > @@ -118,6 +121,12 @@ else > @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) > endif > > +gen_mods_dir: > + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) > + > +clean_mods_dir: > + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) clean > + > define INSTALL_SINGLE_RULE > $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) > $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/) > @@ -131,6 +140,7 @@ define INSTALL_RULE > $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) > $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) > $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) > + $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) $(INSTALL_SINGLE_RULE) Hi Marcos, Sorry for the late reply on this, but I'm reviewing this version by trying to retrofit it into our selftest packaging (pre-build the test module .ko's and stash those into an rpm rather than building on the test host). Since $TEST_GEN_MODS_DIR is treated as a directory, I found that the selftest install target copies a bunch of intermediate object and kbuild files: $ mkdir /tmp/test-install $ make KDIR=$(pwd) INSTALL_PATH=/tmp/test-install TARGETS=livepatch \ -C tools/testing/selftests/ install [ ... builds livepatch selftests ... ] the rsync in question: rsync -a --copy-unsafe-links /home/jolawren/src/kernel/tools/testing/selftests/livepatch/test_modules /tmp/test-install/livepatch/ ... and then looking at the destination: $ tree -a /tmp/test-install/ /tmp/test-install/ ├── kselftest │ ├── module.sh │ ├── prefix.pl │ └── runner.sh ├── kselftest-list.txt ├── livepatch │ ├── config │ ├── functions.sh │ ├── settings │ ├── test-callbacks.sh │ ├── test-ftrace.sh │ ├── test_klp-call_getpid │ ├── test-livepatch.sh │ ├── test_modules │ │ ├── Makefile │ │ ├── modules.order │ │ ├── .modules.order.cmd │ │ ├── Module.symvers │ │ ├── .Module.symvers.cmd │ │ ├── test_klp_atomic_replace.c │ │ ├── test_klp_atomic_replace.ko │ │ ├── .test_klp_atomic_replace.ko.cmd │ │ ├── test_klp_atomic_replace.mod │ │ ├── test_klp_atomic_replace.mod.c │ │ ├── .test_klp_atomic_replace.mod.cmd │ │ ├── test_klp_atomic_replace.mod.o │ │ ├── .test_klp_atomic_replace.mod.o.cmd │ │ ├── test_klp_atomic_replace.o │ │ ├── .test_klp_atomic_replace.o.cmd ... On the other hand, variables like $TEST_GEN_FILES specify individual files, so only final binaries like test_klp-call_getpid (and not test_klp-call_getpid.c) are copied to $INSTALL_PATH. Since the selftest module builds appear to ignore CONFIG_MODULE_COMPRESS_* the smallest tweak I can think of to avoid the above scenario is: --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -106,7 +106,7 @@ define INSTALL_RULE $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) - $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) $(INSTALL_SINGLE_RULE) + $(eval INSTALL_LIST = $(shell sed 's/.o$$/.ko/' $(TEST_GEN_MODS_DIR)/modules.order)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) endef However, that will copy .ko's directly into $INSTALL_PATH and out of the $TEST_GEN_MODS_DIR subdirectory(s), so maybe not a great solution after all. Anyway, I thought I might mention this in case it runs against the spirit of the selftest install target. I only tripped over it while digging into the bowels of our kernel specfile and discovered that it invoked this target. -- Joe
On 1/2/24 15:31, Joe Lawrence wrote: > On Wed, Dec 20, 2023 at 01:53:12PM -0300, Marcos Paulo de Souza wrote: >> Add TEST_GEN_MODS_DIR variable for kselftests. It can point to >> a directory containing kernel modules that will be used by >> selftest scripts. >> >> The modules are built as external modules for the running kernel. >> As a result they are always binary compatible and the same tests >> can be used for older or newer kernels. >> >> The build requires "kernel-devel" package to be installed. >> For example, in the upstream sources, the rpm devel package >> is produced by "make rpm-pkg" >> >> The modules can be built independently by >> >> make -C tools/testing/selftests/livepatch/ >> >> or they will be automatically built before running the tests via >> >> make -C tools/testing/selftests/livepatch/ run_tests >> >> Note that they are _not_ built when running the standalone >> tests by calling, for example, ./test-state.sh. >> >> Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> >> --- >> Documentation/dev-tools/kselftest.rst | 4 ++++ >> tools/testing/selftests/lib.mk | 20 +++++++++++++++----- >> 2 files changed, 19 insertions(+), 5 deletions(-) >> >> diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst >> index ab376b316c36..7f3582a67318 100644 >> --- a/Documentation/dev-tools/kselftest.rst >> +++ b/Documentation/dev-tools/kselftest.rst >> @@ -245,6 +245,10 @@ Contributing new tests (details) >> TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested by >> default. >> >> + TEST_GEN_MODS_DIR should be used by tests that require modules to be built >> + before the test starts. The variable will contain the name of the directory >> + containing the modules. >> + >> TEST_CUSTOM_PROGS should be used by tests that require custom build >> rules and prevent common build rule use. >> >> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk >> index 118e0964bda9..6c7c5a0112cf 100644 >> --- a/tools/testing/selftests/lib.mk >> +++ b/tools/testing/selftests/lib.mk >> @@ -70,12 +70,15 @@ KHDR_INCLUDES := -isystem $(KHDR_DIR) >> # TEST_PROGS are for test shell scripts. >> # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests >> # and install targets. Common clean doesn't touch them. >> +# TEST_GEN_MODS_DIR is used to specify a directory with modules to be built >> +# before the test executes. These modules are cleaned on the clean target as well. >> TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) >> TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) >> TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) >> +TEST_GEN_MODS_DIR := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_MODS_DIR)) >> >> all: kernel_header_files $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) \ >> - $(TEST_GEN_FILES) >> + $(TEST_GEN_FILES) $(if $(TEST_GEN_MODS_DIR),gen_mods_dir) >> >> kernel_header_files: >> @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ >> @@ -105,8 +108,8 @@ endef >> >> run_tests: all >> ifdef building_out_of_srctree >> - @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ >> - rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ >> + @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)$(TEST_GEN_MODS_DIR)" != "X" ]; then \ >> + rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(TEST_GEN_MODS_DIR) $(OUTPUT); \ >> fi >> @if [ "X$(TEST_PROGS)" != "X" ]; then \ >> $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ >> @@ -118,6 +121,12 @@ else >> @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) >> endif >> >> +gen_mods_dir: >> + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) >> + >> +clean_mods_dir: >> + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) clean >> + >> define INSTALL_SINGLE_RULE >> $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) >> $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/) >> @@ -131,6 +140,7 @@ define INSTALL_RULE >> $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) >> $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) >> $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) >> + $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) $(INSTALL_SINGLE_RULE) > > Hi Marcos, > > Sorry for the late reply on this, but I'm reviewing this version by > trying to retrofit it into our selftest packaging (pre-build the test > module .ko's and stash those into an rpm rather than building on the > test host). > > Since $TEST_GEN_MODS_DIR is treated as a directory, I found that the > selftest install target copies a bunch of intermediate object and kbuild > files: > > $ mkdir /tmp/test-install > $ make KDIR=$(pwd) INSTALL_PATH=/tmp/test-install TARGETS=livepatch \ > -C tools/testing/selftests/ install > > [ ... builds livepatch selftests ... ] > > the rsync in question: > > rsync -a --copy-unsafe-links /home/jolawren/src/kernel/tools/testing/selftests/livepatch/test_modules /tmp/test-install/livepatch/ > ... > > and then looking at the destination: > > $ tree -a /tmp/test-install/ > /tmp/test-install/ > ├── kselftest > │ ├── module.sh > │ ├── prefix.pl > │ └── runner.sh > ├── kselftest-list.txt > ├── livepatch > │ ├── config > │ ├── functions.sh > │ ├── settings > │ ├── test-callbacks.sh > │ ├── test-ftrace.sh > │ ├── test_klp-call_getpid > │ ├── test-livepatch.sh > │ ├── test_modules > │ │ ├── Makefile > │ │ ├── modules.order > │ │ ├── .modules.order.cmd > │ │ ├── Module.symvers > │ │ ├── .Module.symvers.cmd > │ │ ├── test_klp_atomic_replace.c > │ │ ├── test_klp_atomic_replace.ko > │ │ ├── .test_klp_atomic_replace.ko.cmd > │ │ ├── test_klp_atomic_replace.mod > │ │ ├── test_klp_atomic_replace.mod.c > │ │ ├── .test_klp_atomic_replace.mod.cmd > │ │ ├── test_klp_atomic_replace.mod.o > │ │ ├── .test_klp_atomic_replace.mod.o.cmd > │ │ ├── test_klp_atomic_replace.o > │ │ ├── .test_klp_atomic_replace.o.cmd > ... > > On the other hand, variables like $TEST_GEN_FILES specify individual > files, so only final binaries like test_klp-call_getpid (and not > test_klp-call_getpid.c) are copied to $INSTALL_PATH. Thank you Joe for finding this problem. Copying source files and object files doesn't sound right. This isn't how the ksleftest installs work. Let's fix this. thanks, --Shuah
On Wed, 2024-01-03 at 15:09 -0700, Shuah Khan wrote: > On 1/2/24 15:31, Joe Lawrence wrote: > > On Wed, Dec 20, 2023 at 01:53:12PM -0300, Marcos Paulo de Souza > > wrote: > > > Add TEST_GEN_MODS_DIR variable for kselftests. It can point to > > > a directory containing kernel modules that will be used by > > > selftest scripts. > > > > > > The modules are built as external modules for the running kernel. > > > As a result they are always binary compatible and the same tests > > > can be used for older or newer kernels. > > > > > > The build requires "kernel-devel" package to be installed. > > > For example, in the upstream sources, the rpm devel package > > > is produced by "make rpm-pkg" > > > > > > The modules can be built independently by > > > > > > make -C tools/testing/selftests/livepatch/ > > > > > > or they will be automatically built before running the tests via > > > > > > make -C tools/testing/selftests/livepatch/ run_tests > > > > > > Note that they are _not_ built when running the standalone > > > tests by calling, for example, ./test-state.sh. > > > > > > Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> > > > --- > > > Documentation/dev-tools/kselftest.rst | 4 ++++ > > > tools/testing/selftests/lib.mk | 20 +++++++++++++++----- > > > 2 files changed, 19 insertions(+), 5 deletions(-) > > > > > > diff --git a/Documentation/dev-tools/kselftest.rst > > > b/Documentation/dev-tools/kselftest.rst > > > index ab376b316c36..7f3582a67318 100644 > > > --- a/Documentation/dev-tools/kselftest.rst > > > +++ b/Documentation/dev-tools/kselftest.rst > > > @@ -245,6 +245,10 @@ Contributing new tests (details) > > > TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested > > > by > > > default. > > > > > > + TEST_GEN_MODS_DIR should be used by tests that require > > > modules to be built > > > + before the test starts. The variable will contain the name of > > > the directory > > > + containing the modules. > > > + > > > TEST_CUSTOM_PROGS should be used by tests that require > > > custom build > > > rules and prevent common build rule use. > > > > > > diff --git a/tools/testing/selftests/lib.mk > > > b/tools/testing/selftests/lib.mk > > > index 118e0964bda9..6c7c5a0112cf 100644 > > > --- a/tools/testing/selftests/lib.mk > > > +++ b/tools/testing/selftests/lib.mk > > > @@ -70,12 +70,15 @@ KHDR_INCLUDES := -isystem $(KHDR_DIR) > > > # TEST_PROGS are for test shell scripts. > > > # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common > > > run_tests > > > # and install targets. Common clean doesn't touch them. > > > +# TEST_GEN_MODS_DIR is used to specify a directory with modules > > > to be built > > > +# before the test executes. These modules are cleaned on the > > > clean target as well. > > > TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) > > > TEST_GEN_PROGS_EXTENDED := $(patsubst > > > %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) > > > TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) > > > +TEST_GEN_MODS_DIR := $(patsubst > > > %,$(OUTPUT)/%,$(TEST_GEN_MODS_DIR)) > > > > > > all: kernel_header_files $(TEST_GEN_PROGS) > > > $(TEST_GEN_PROGS_EXTENDED) \ > > > - $(TEST_GEN_FILES) > > > + $(TEST_GEN_FILES) $(if $(TEST_GEN_MODS_DIR),gen_mods_dir) > > > > > > kernel_header_files: > > > @ls $(KHDR_DIR)/linux/*.h >/dev/null > > > 2>/dev/null; \ > > > @@ -105,8 +108,8 @@ endef > > > > > > run_tests: all > > > ifdef building_out_of_srctree > > > - @if [ > > > "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; > > > then \ > > > - rsync -aq --copy-unsafe-links $(TEST_PROGS) > > > $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ > > > + @if [ > > > "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)$(TEST_GEN_MODS > > > _DIR)" != "X" ]; then \ > > > + rsync -aq --copy-unsafe-links $(TEST_PROGS) > > > $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(TEST_GEN_MODS_DIR) > > > $(OUTPUT); \ > > > fi > > > @if [ "X$(TEST_PROGS)" != "X" ]; then \ > > > $(call RUN_TESTS, $(TEST_GEN_PROGS) > > > $(TEST_CUSTOM_PROGS) \ > > > @@ -118,6 +121,12 @@ else > > > @$(call RUN_TESTS, $(TEST_GEN_PROGS) > > > $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) > > > endif > > > > > > +gen_mods_dir: > > > + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) > > > + > > > +clean_mods_dir: > > > + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) clean > > > + > > > define INSTALL_SINGLE_RULE > > > $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) > > > $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links > > > $(INSTALL_LIST) $(INSTALL_PATH)/) > > > @@ -131,6 +140,7 @@ define INSTALL_RULE > > > $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) > > > $(INSTALL_SINGLE_RULE) > > > $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) > > > $(INSTALL_SINGLE_RULE) > > > $(eval INSTALL_LIST = $(TEST_GEN_FILES)) > > > $(INSTALL_SINGLE_RULE) > > > + $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) > > > $(INSTALL_SINGLE_RULE) > > > > Hi Marcos, > > > > Sorry for the late reply on this, but I'm reviewing this version by > > trying to retrofit it into our selftest packaging (pre-build the > > test > > module .ko's and stash those into an rpm rather than building on > > the > > test host). > > > > Since $TEST_GEN_MODS_DIR is treated as a directory, I found that > > the > > selftest install target copies a bunch of intermediate object and > > kbuild > > files: > > > > $ mkdir /tmp/test-install > > $ make KDIR=$(pwd) INSTALL_PATH=/tmp/test-install > > TARGETS=livepatch \ > > -C tools/testing/selftests/ install > > > > [ ... builds livepatch selftests ... ] > > > > the rsync in question: > > > > rsync -a --copy-unsafe-links > > /home/jolawren/src/kernel/tools/testing/selftests/livepatch/test_mo > > dules /tmp/test-install/livepatch/ > > ... > > > > and then looking at the destination: > > > > $ tree -a /tmp/test-install/ > > /tmp/test-install/ > > ├── kselftest > > │ ├── module.sh > > │ ├── prefix.pl > > │ └── runner.sh > > ├── kselftest-list.txt > > ├── livepatch > > │ ├── config > > │ ├── functions.sh > > │ ├── settings > > │ ├── test-callbacks.sh > > │ ├── test-ftrace.sh > > │ ├── test_klp-call_getpid > > │ ├── test-livepatch.sh > > │ ├── test_modules > > │ │ ├── Makefile > > │ │ ├── modules.order > > │ │ ├── .modules.order.cmd > > │ │ ├── Module.symvers > > │ │ ├── .Module.symvers.cmd > > │ │ ├── test_klp_atomic_replace.c > > │ │ ├── test_klp_atomic_replace.ko > > │ │ ├── .test_klp_atomic_replace.ko.cmd > > │ │ ├── test_klp_atomic_replace.mod > > │ │ ├── test_klp_atomic_replace.mod.c > > │ │ ├── .test_klp_atomic_replace.mod.cmd > > │ │ ├── test_klp_atomic_replace.mod.o > > │ │ ├── .test_klp_atomic_replace.mod.o.cmd > > │ │ ├── test_klp_atomic_replace.o > > │ │ ├── .test_klp_atomic_replace.o.cmd > > ... > > > > On the other hand, variables like $TEST_GEN_FILES specify > > individual > > files, so only final binaries like test_klp-call_getpid (and not > > test_klp-call_getpid.c) are copied to $INSTALL_PATH. Hi Joe, thanks for catching this issue. I crafted the attached patch and it fixes the issue for me, copying only the resulting .ko objects as expected. Can you please check if this fixes the issue for you? > > > Thank you Joe for finding this problem. > > Copying source files and object files doesn't sound right. This isn't > how the ksleftest installs work. Let's fix this. Hi Shuah, what do you think about the proposed solution? Could you please amend the fix into the first patch if you think it's the right approach? Thanks in advance! Marcos > > thanks, > --Shuah >
On 1/8/24 10:13, Marcos Paulo de Souza wrote: > On Wed, 2024-01-03 at 15:09 -0700, Shuah Khan wrote: >> >> Copying source files and object files doesn't sound right. This isn't >> how the ksleftest installs work. Let's fix this. > > Hi Shuah, > > what do you think about the proposed solution? Could you please amend > the fix into the first patch if you think it's the right approach? > I would like to see a new revision of the patch series with the fix to the problem. I will pull this into a separate test branch for us all to test different scenarios. I would like to make sure the repo will stay clean after install in the case of when out of tree builds. Sorry I can't amend the patch as this isn't a trivial merge change. This change requires more testing. thanks, -- Shuah
On Tue, 2024-01-09 at 12:31 -0700, Shuah Khan wrote: > On 1/8/24 10:13, Marcos Paulo de Souza wrote: > > On Wed, 2024-01-03 at 15:09 -0700, Shuah Khan wrote: > > > > > > > Copying source files and object files doesn't sound right. This > > > isn't > > > how the ksleftest installs work. Let's fix this. > > > > Hi Shuah, > > > > what do you think about the proposed solution? Could you please > > amend > > the fix into the first patch if you think it's the right approach? > > > > I would like to see a new revision of the patch series with the fix > to > the problem. I will pull this into a separate test branch for us all > to test different scenarios. I would like to make sure the repo will > stay clean after install in the case of when out of tree builds. > > Sorry I can't amend the patch as this isn't a trivial merge change. > This change requires more testing. I sent a v5 of the patches. This new version has that diff that I sent earlier to avoid copying the Kbuild files. It worked on make install and with gen_tar. Feel free to use this version in your test branch then. Thanks in advance, Marcos > > thanks, > -- Shuah > > >
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst index ab376b316c36..7f3582a67318 100644 --- a/Documentation/dev-tools/kselftest.rst +++ b/Documentation/dev-tools/kselftest.rst @@ -245,6 +245,10 @@ Contributing new tests (details) TEST_PROGS, TEST_GEN_PROGS mean it is the executable tested by default. + TEST_GEN_MODS_DIR should be used by tests that require modules to be built + before the test starts. The variable will contain the name of the directory + containing the modules. + TEST_CUSTOM_PROGS should be used by tests that require custom build rules and prevent common build rule use. diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk index 118e0964bda9..6c7c5a0112cf 100644 --- a/tools/testing/selftests/lib.mk +++ b/tools/testing/selftests/lib.mk @@ -70,12 +70,15 @@ KHDR_INCLUDES := -isystem $(KHDR_DIR) # TEST_PROGS are for test shell scripts. # TEST_CUSTOM_PROGS and TEST_PROGS will be run by common run_tests # and install targets. Common clean doesn't touch them. +# TEST_GEN_MODS_DIR is used to specify a directory with modules to be built +# before the test executes. These modules are cleaned on the clean target as well. TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) +TEST_GEN_MODS_DIR := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_MODS_DIR)) all: kernel_header_files $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) \ - $(TEST_GEN_FILES) + $(TEST_GEN_FILES) $(if $(TEST_GEN_MODS_DIR),gen_mods_dir) kernel_header_files: @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ @@ -105,8 +108,8 @@ endef run_tests: all ifdef building_out_of_srctree - @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \ - rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(OUTPUT); \ + @if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)$(TEST_GEN_MODS_DIR)" != "X" ]; then \ + rsync -aq --copy-unsafe-links $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(TEST_GEN_MODS_DIR) $(OUTPUT); \ fi @if [ "X$(TEST_PROGS)" != "X" ]; then \ $(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) \ @@ -118,6 +121,12 @@ else @$(call RUN_TESTS, $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS)) endif +gen_mods_dir: + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) + +clean_mods_dir: + $(Q)$(MAKE) -C $(TEST_GEN_MODS_DIR) clean + define INSTALL_SINGLE_RULE $(if $(INSTALL_LIST),@mkdir -p $(INSTALL_PATH)) $(if $(INSTALL_LIST),rsync -a --copy-unsafe-links $(INSTALL_LIST) $(INSTALL_PATH)/) @@ -131,6 +140,7 @@ define INSTALL_RULE $(eval INSTALL_LIST = $(TEST_CUSTOM_PROGS)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_PROGS_EXTENDED)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(TEST_GEN_FILES)) $(INSTALL_SINGLE_RULE) + $(eval INSTALL_LIST = $(TEST_GEN_MODS_DIR)) $(INSTALL_SINGLE_RULE) $(eval INSTALL_LIST = $(wildcard config settings)) $(INSTALL_SINGLE_RULE) endef @@ -156,7 +166,7 @@ define CLEAN $(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) endef -clean: +clean: $(if $(TEST_GEN_MODS_DIR),clean_mods_dir) $(CLEAN) # Enables to extend CFLAGS and LDFLAGS from command line, e.g. @@ -187,4 +197,4 @@ $(OUTPUT)/%:%.S $(LINK.S) $^ $(LDLIBS) -o $@ endif -.PHONY: run_tests all clean install emit_tests +.PHONY: run_tests all clean install emit_tests gen_mods_dir clean_mods_dir