From: Petr Mladek <pmladek@suse.com>
To: Siddharth Menon <simeddon@gmail.com>
Cc: shuah@kernel.org, skhan@linuxfoundation.org, mbenes@suse.cz,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 1/2] selftests: Introduce script to validate required configs
Date: Tue, 7 Jan 2025 14:44:39 +0100 [thread overview]
Message-ID: <Z30vxyUi7NYbo4EG@pathway.suse.cz> (raw)
In-Reply-To: <20241220193536.13781-2-simeddon@gmail.com>
On Sat 2024-12-21 01:05:35, Siddharth Menon wrote:
> This patch adds a script to validate that the current kernel configuration
> satisfies the requirements for selftests. The script compares the current
> kernel configs against the required selftest configs.
>
> A config mismatch exits with error value 1 while matching configs or missing
> config files exit with value 0.In order to get debug output, set the
^
missing space before the next sentence
> environment variable LOCALMODCONFIG_DEBUG=1.
I would prefer to print the missing dependencies by default.
Otherwise, it is far from clear why the test was skipped.
Also LOCALMODCONFIG_DEBUG looks like a pretty non-standard way to get
debug output. People will have troubles to discover this way
and memorize the long name.
> diff --git a/tools/testing/selftests/mktest.pl b/tools/testing/selftests/mktest.pl
> new file mode 100755
> index 000000000000..60462f323bde
> --- /dev/null
> +++ b/tools/testing/selftests/mktest.pl
I would give it a more meaningful name.
For example, using the same name as for the makefile target
just with .pl suffix. I mean "check_config_deps.pl".
That said, I have just realized that that there already was
"kselftest_deps.sh". It seems to check missing compile dependencies
by scanning various variants of LDLIBS variables.
It seems that "kselftest_deps.sh" should be called separately.
I mean that it is not integrated with the make files.
It is a bit strange to handle two types of dependencies differently.
It would be nice somehow consolidate the two check scripts
so that they behave similar way and use a similar name.
I personally like the integration with the Makefile.
> @@ -0,0 +1,138 @@
> +#!/usr/bin/env perl
> +# SPDX-License-Identifier: GPL-2.0
> +use warnings;
> +use strict;
> +use Getopt::Long;
> +use File::Spec;
> +
> +# set the environment variable LOCALMODCONFIG_DEBUG to get
> +# debug output.
> +my $debugprint = 0;
> +$debugprint = 1 if (defined($ENV{LOCALMODCONFIG_DEBUG}));
> +
> +sub dprint {
> + return if (!$debugprint);
> + print STDERR @_;
> +}
> +
> +my $uname = `uname -r`;
> +chomp $uname;
> +
> +my @searchconfigs = (
> + {
> + "file" => ".config",
> + "exec" => "cat",
Nit: I would prefer to use a tab instead of 8 spaces. At least, the 8 spaces
are considered a bad formatting in the kernel .c sources.
> + },
> + {
> + "file" => "/proc/config.gz",
> + "exec" => "zcat",
> + },
> + {
> + "file" => "/boot/config-$uname",
> + "exec" => "cat",
> + },
> + {
> + "file" => "/boot/vmlinuz-$uname",
> + "exec" => "scripts/extract-ikconfig",
> + "test" => "scripts/extract-ikconfig",
> + },
> + {
> + "file" => "vmlinux",
> + "exec" => "scripts/extract-ikconfig",
> + "test" => "scripts/extract-ikconfig",
> + },
> + {
> + "file" => "/lib/modules/$uname/kernel/kernel/configs.ko",
> + "exec" => "scripts/extract-ikconfig",
> + "test" => "scripts/extract-ikconfig",
> + },
> + {
> + "file" => "/lib/modules/$uname/build/.config",
> + "exec" => "cat",
> + },
> + {
> + "file" => "kernel/configs.ko",
> + "exec" => "scripts/extract-ikconfig",
> + "test" => "scripts/extract-ikconfig",
> + },
> + {
> + "file" => "kernel/configs.o",
> + "exec" => "scripts/extract-ikconfig",
> + "test" => "scripts/extract-ikconfig",
> + },
> +);
> +
> +sub read_config {
> + foreach my $conf (@searchconfigs) {
> + my $file = $conf->{"file"};
> +
> + next if (! -f "$file");
> +
Nit: There are 4 spaces on the above empty line. "git am" complains
about it.
I guess that also ./scripts/checkpatch.pl would complain about it.
> + if (defined($conf->{"test"})) {
> + `$conf->{"test"} $conf->{"file"} 2>/dev/null`;
> + next if ($?);
> + }
> +
same here
> + my $exec = $conf->{"exec"};
> +
and here
> + dprint "Kernel config: '$file'\n";
> +
and here.
> + open(my $infile, '-|', "$exec $file") || die "Failed to run $exec $file";
> + my @x = <$infile>;
> + close $infile;
> + return @x;
> + }
> + dprint "Unable to find kernel config file, skipping check\n";
> + exit 0;
> +}
> +
> +# Check if selftest path is provided
> +die "Usage: $0 <selftest_path>\n" unless @ARGV == 1;
> +
> +my $file_path = $ARGV[0];
> +
> +my @config_file = read_config();
> +
> +my %kern_configs;
> +my $valid = "A-Za-z_0-9";
> +foreach my $line (@config_file) {
> + chomp $line;
> + next if $line =~ /^\s*$/ || $line =~ /^#/;
> +
another spaces on empty line
> + if ($line =~ /^(CONFIG_\w+)=(.+)$/) {
> + $kern_configs{$1} = $2;
> + }
> +}
> +
> +my %test_configs;
> +# Continue as normal if /config file does not exist
trailing space on the above line.
> +open(my $fh, '<', $file_path) or exit 0;
> +
> +while (my $line = <$fh>) {
> + chomp $line;
> + next if $line =~ /^\s*$/ || $line =~ /^#/;
> +
spaces on empty line
> + if ($line =~ /^(CONFIG_\w+)=(.+)$/) {
> + $test_configs{$1} = $2;
> + }
> +}
> +close $fh;
> +
Best Regards,
Petr
next prev parent reply other threads:[~2025-01-07 13:44 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 19:35 [PATCH v2 0/2] update kselftest framework to check for required configs Siddharth Menon
2024-12-20 19:35 ` [PATCH v2 1/2] selftests: Introduce script to validate " Siddharth Menon
2025-01-07 13:44 ` Petr Mladek [this message]
2024-12-20 19:35 ` [PATCH v2 2/2] selftests/lib.mk: Introduce check " Siddharth Menon
2025-01-07 13:53 ` Petr Mladek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z30vxyUi7NYbo4EG@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=shuah@kernel.org \
--cc=simeddon@gmail.com \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox