Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6810183rdb; Tue, 2 Jan 2024 14:31:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IEArnxAPS0QClaLdLmENEmi7gEEXmOzkN1LN67Lt1BMHAbKWtcl3+/Ugpi7H9bM4MutlpPH X-Received: by 2002:a05:6359:5e83:b0:174:c5ee:46d with SMTP id px3-20020a0563595e8300b00174c5ee046dmr12174342rwb.57.1704234694955; Tue, 02 Jan 2024 14:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704234694; cv=none; d=google.com; s=arc-20160816; b=AWJTNNxfaMjUtnhmOZFGSvkKp5Da/fTrslVC+CCvSGQpAR7yPLn/miqEn0bpUmyGb9 J5IUl8xdJdlFSCkh0zm2LLr5dP3dzCObJK9OuIXDAXxg4gpSAM6z4soOl/bcV/umZbkd sDcREakbf6yMSsG0KsC9Z81veduSrnIfOK8Z9IhTz432GfkXwngx0etCGmM2jwF4QtKu GoG+Myx3V70aMKMH5oU+ajsnwGfn5zizjGyNCGTz2yNo2ZVQ1ZplMws85EhGMPA7KNEd OUV8ktUthk+NZlODhbWpx1xa0fgBIUoZMTgqt9tBV0DVHiTKWSERUjDR/ui2JCarvtoi 4o9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WxX/DwYRiytQqrsyv6xPbUj6O86YcsayJdMC1Rh079w=; fh=AVcDjkUJxfLqccDpSqDsyB61e5Ah3btJrSDABd7gpo0=; b=FOL9iNVI/tfGm+vxEv2dtofbpwxvQ4Fac/BFSQJBLxDIhOrTWFsaflLxbSJ1qAPhMa WPK1F9g8vuFRD2aUB8V/tMcvLxgvc7BNQZCmxq8gT8mGwoSEBK8qrdOBOZQjmwRStu8/ S+3/Bfn5m/xr/rLhEvS6Key0kpWHhZqn++KfEBjoyCsEiKwWkWIJ7lE0rJJ+nMRibQik 9TH4CQkNdSw8+6kj0XOxoS2HBNFKa3sCDHJ0CqBBA/LLOJIJtk9Bc49sV9KsbI/Xj5NS R9hHg5NNpJUhvb/KrMi+yxwvXy51NVtrwTfqZyob+CNXTgzCHm7wzYmHsA7M3LEHK1Aa 64Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TM9Jwa1p; spf=pass (google.com: domain of linux-kernel+bounces-14938-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14938-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bx41-20020a056a02052900b005ce097ce679si16841435pgb.741.2024.01.02.14.31.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:31:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14938-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TM9Jwa1p; spf=pass (google.com: domain of linux-kernel+bounces-14938-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14938-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8E5252845DF for ; Tue, 2 Jan 2024 22:31:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A11D617722; Tue, 2 Jan 2024 22:31:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TM9Jwa1p" X-Original-To: linux-kernel@vger.kernel.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 3CD7817728 for ; Tue, 2 Jan 2024 22:31:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704234685; 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=WxX/DwYRiytQqrsyv6xPbUj6O86YcsayJdMC1Rh079w=; b=TM9Jwa1psXALhsjwGR1vRVu0TzU07A3kPdV1UKoGZI81ae/VkbBs44unakvJ3W3Dgnv+QR vWH52G6l40d/stVWjVB4DO9IWOXdx6NRhg+HEUcptKlxRgf6ksQrjnEbLCqqmTeRZinLtv FKYZCHDutwoRmU/t0PMmD24ZTCEJBIc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-102-41CIv6mVMvuFpQ2fC74M9w-1; Tue, 02 Jan 2024 17:31:21 -0500 X-MC-Unique: 41CIv6mVMvuFpQ2fC74M9w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E456D848A64; Tue, 2 Jan 2024 22:31:20 +0000 (UTC) Received: from redhat.com (unknown [10.22.9.153]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3ED1040C6EB9; Tue, 2 Jan 2024 22:31:20 +0000 (UTC) Date: Tue, 2 Jan 2024 17:31:18 -0500 From: Joe Lawrence To: Marcos Paulo de Souza Cc: Shuah Khan , Jonathan Corbet , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , 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 Subject: Re: [PATCH RESEND v4 1/3] kselftests: lib.mk: Add TEST_GEN_MODS_DIR variable Message-ID: References: <20231220-send-lp-kselftests-v4-0-3458ec1b1a38@suse.com> <20231220-send-lp-kselftests-v4-1-3458ec1b1a38@suse.com> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20231220-send-lp-kselftests-v4-1-3458ec1b1a38@suse.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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 > --- > 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