[PATCH] ktest: Check kernelrelease return in get_version

Ricardo B. Marliere posted 1 patch 1 year ago
There is a newer version of this series
tools/testing/ktest/ktest.pl | 5 +++++
1 file changed, 5 insertions(+)
[PATCH] ktest: Check kernelrelease return in get_version
Posted by Ricardo B. Marliere 1 year ago
In the case of a test that uses the special option ${KERNEL_VERSION} in one
of its settings but has no configuration available in ${OUTPUT_DIR}, for
example if it's a new empty directory, then the `make kernelrelease` call
will fail and the subroutine will chomp an empty string, silently. Fix that
by adding an empty configuration and retrying.

Signed-off-by: Ricardo B. Marliere <rbm@suse.com>
---
Hi! I'm not sure if this is the best fix, but here's the gist of the
problem:

If the test has something like:
POST_BUILD = echo ${KERNEL_VERSION}

Then the option will be evaluated in __eval_option which calls get_version
before there's any configuration within ${OUTPUT_DIR}. Like if the
following happened:

16:08:09 rbmarliere@opensuse ~/src/linux/kernel/master master
$ git clean -fdx
Removing build/
16:08:13 rbmarliere@opensuse ~/src/linux/kernel/master master
$ make O=build/ kernelrelease
make[1]: Entering directory '~/src/linux/kernel/master/build'
~/src/linux/kernel/master/Makefile:777: include/config/auto.conf: No such file or directory
make[1]: *** [~/src/linux/kernel/master/Makefile:251: __sub-make] Error 2
make[1]: Leaving directory '~/src/linux/kernel/master/build'
make: *** [Makefile:251: __sub-make] Error 2
---
 tools/testing/ktest/ktest.pl | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
index dacad94e2be42a86f9680fcb50b65d1f3a78afb5..a57b6cb9d817e2a3351a64de96092bd47733f5e3 100755
--- a/tools/testing/ktest/ktest.pl
+++ b/tools/testing/ktest/ktest.pl
@@ -2419,6 +2419,11 @@ sub get_version {
     return if ($have_version);
     doprint "$make kernelrelease ... ";
     $version = `$make -s kernelrelease | tail -1`;
+    if (!$version) {
+	run_command "$make allnoconfig" or return 0;
+	doprint "$make kernelrelease ... ";
+	$version = `$make -s kernelrelease | tail -1`;
+    }
     chomp($version);
     doprint "$version\n";
     $have_version = 1;

---
base-commit: 9d6a414ad31e8eb296cd6f2c1834b2c6994960a0
change-id: 20241205-ktest_kver_fallback-d42e62fb8d88

Best regards,
-- 
Ricardo B. Marliere <rbm@suse.com>
Re: [PATCH] ktest: Check kernelrelease return in get_version
Posted by Steven Rostedt 1 year ago
On Thu, 05 Dec 2024 16:20:50 -0300
"Ricardo B. Marliere" <rbm@suse.com> wrote:

> In the case of a test that uses the special option ${KERNEL_VERSION} in one
> of its settings but has no configuration available in ${OUTPUT_DIR}, for
> example if it's a new empty directory, then the `make kernelrelease` call
> will fail and the subroutine will chomp an empty string, silently. Fix that
> by adding an empty configuration and retrying.
> 
> Signed-off-by: Ricardo B. Marliere <rbm@suse.com>
> ---
> Hi! I'm not sure if this is the best fix, but here's the gist of the
> problem:
> 
> If the test has something like:
> POST_BUILD = echo ${KERNEL_VERSION}
> 
> Then the option will be evaluated in __eval_option which calls get_version
> before there's any configuration within ${OUTPUT_DIR}. Like if the
> following happened:
> 
> 16:08:09 rbmarliere@opensuse ~/src/linux/kernel/master master
> $ git clean -fdx
> Removing build/
> 16:08:13 rbmarliere@opensuse ~/src/linux/kernel/master master
> $ make O=build/ kernelrelease
> make[1]: Entering directory '~/src/linux/kernel/master/build'
> ~/src/linux/kernel/master/Makefile:777: include/config/auto.conf: No such file or directory
> make[1]: *** [~/src/linux/kernel/master/Makefile:251: __sub-make] Error 2
> make[1]: Leaving directory '~/src/linux/kernel/master/build'
> make: *** [Makefile:251: __sub-make] Error 2
> ---
>  tools/testing/ktest/ktest.pl | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> index dacad94e2be42a86f9680fcb50b65d1f3a78afb5..a57b6cb9d817e2a3351a64de96092bd47733f5e3 100755
> --- a/tools/testing/ktest/ktest.pl
> +++ b/tools/testing/ktest/ktest.pl
> @@ -2419,6 +2419,11 @@ sub get_version {
>      return if ($have_version);
>      doprint "$make kernelrelease ... ";
>      $version = `$make -s kernelrelease | tail -1`;
> +    if (!$version) {

That should probably instead be:

	if (!length($version)) {
	[..]

-- Steve


> +	run_command "$make allnoconfig" or return 0;
> +	doprint "$make kernelrelease ... ";
> +	$version = `$make -s kernelrelease | tail -1`;
> +    }
>      chomp($version);
>      doprint "$version\n";
>      $have_version = 1;
> 
> ---
> base-commit: 9d6a414ad31e8eb296cd6f2c1834b2c6994960a0
> change-id: 20241205-ktest_kver_fallback-d42e62fb8d88
> 
> Best regards,
Re: [PATCH] ktest: Check kernelrelease return in get_version
Posted by Ricardo B. Marliere 1 year ago
Hi Steve!

On  5 Dec 24 14:48, Steven Rostedt wrote:
> On Thu, 05 Dec 2024 16:20:50 -0300
> "Ricardo B. Marliere" <rbm@suse.com> wrote:
> 
> > In the case of a test that uses the special option ${KERNEL_VERSION} in one
> > of its settings but has no configuration available in ${OUTPUT_DIR}, for
> > example if it's a new empty directory, then the `make kernelrelease` call
> > will fail and the subroutine will chomp an empty string, silently. Fix that
> > by adding an empty configuration and retrying.
> > 
> > Signed-off-by: Ricardo B. Marliere <rbm@suse.com>
> > ---
> > Hi! I'm not sure if this is the best fix, but here's the gist of the
> > problem:
> > 
> > If the test has something like:
> > POST_BUILD = echo ${KERNEL_VERSION}
> > 
> > Then the option will be evaluated in __eval_option which calls get_version
> > before there's any configuration within ${OUTPUT_DIR}. Like if the
> > following happened:
> > 
> > 16:08:09 rbmarliere@opensuse ~/src/linux/kernel/master master
> > $ git clean -fdx
> > Removing build/
> > 16:08:13 rbmarliere@opensuse ~/src/linux/kernel/master master
> > $ make O=build/ kernelrelease
> > make[1]: Entering directory '~/src/linux/kernel/master/build'
> > ~/src/linux/kernel/master/Makefile:777: include/config/auto.conf: No such file or directory
> > make[1]: *** [~/src/linux/kernel/master/Makefile:251: __sub-make] Error 2
> > make[1]: Leaving directory '~/src/linux/kernel/master/build'
> > make: *** [Makefile:251: __sub-make] Error 2
> > ---
> >  tools/testing/ktest/ktest.pl | 5 +++++
> >  1 file changed, 5 insertions(+)
> > 
> > diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl
> > index dacad94e2be42a86f9680fcb50b65d1f3a78afb5..a57b6cb9d817e2a3351a64de96092bd47733f5e3 100755
> > --- a/tools/testing/ktest/ktest.pl
> > +++ b/tools/testing/ktest/ktest.pl
> > @@ -2419,6 +2419,11 @@ sub get_version {
> >      return if ($have_version);
> >      doprint "$make kernelrelease ... ";
> >      $version = `$make -s kernelrelease | tail -1`;
> > +    if (!$version) {
> 
> That should probably instead be:
> 
> 	if (!length($version)) {
> 	[..]

Indeed, that is better. I sent a v2 but forgot to reply this one.
Anyways, thanks for reviewing! :)

-	Ricardo.


> 
> -- Steve
> 
> 
> > +	run_command "$make allnoconfig" or return 0;
> > +	doprint "$make kernelrelease ... ";
> > +	$version = `$make -s kernelrelease | tail -1`;
> > +    }
> >      chomp($version);
> >      doprint "$version\n";
> >      $have_version = 1;
> > 
> > ---
> > base-commit: 9d6a414ad31e8eb296cd6f2c1834b2c6994960a0
> > change-id: 20241205-ktest_kver_fallback-d42e62fb8d88
> > 
> > Best regards,
>