From nobody Thu Sep 18 09:59:47 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4291C4708D for ; Thu, 8 Dec 2022 01:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229761AbiLHBlL (ORCPT ); Wed, 7 Dec 2022 20:41:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229694AbiLHBlH (ORCPT ); Wed, 7 Dec 2022 20:41:07 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB3964E695; Wed, 7 Dec 2022 17:41:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 50F0761D23; Thu, 8 Dec 2022 01:41:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8A16C4347C; Thu, 8 Dec 2022 01:41:04 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.96) (envelope-from ) id 1p35uJ-000FSx-2H; Wed, 07 Dec 2022 20:41:03 -0500 Message-ID: <20221208014103.573704155@goodmis.org> User-Agent: quilt/0.66 Date: Wed, 07 Dec 2022 20:40:43 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: "John Warthog9 Hawley" , stable@vger.kernel.org, "John Warthog9 Hawley (VMware)" Subject: [for-next][PATCH 2/2] kest.pl: Fix grub2 menu handling for rebooting References: <20221208014041.842742311@goodmis.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Steven Rostedt grub2 has submenus where to use grub-reboot, it requires: grub-reboot X>Y where X is the main index and Y is the submenu. Thus if you have: menuentry 'Debian GNU/Linux' --class debian --class gnu-linux ... [...] } submenu 'Advanced options for Debian GNU/Linux' $menuentry_id_option ... menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64' --class debi= an --class gnu-linux ... [...] } menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64 (recovery mod= e)' --class debian --class gnu-linux ... [...] } menuentry 'Debian GNU/Linux, with Linux test' --class debian --clas= s gnu-linux ... [...] } And wanted to boot to the "Linux test" kernel, you need to run: # grub-reboot 1>2 As 1 is the second top menu (the submenu) and 2 is the third of the sub menu entries. Have the grub.cfg parsing for grub2 handle such cases. Cc: stable@vger.kernel.org Fixes: a15ba91361d46 ("ktest: Add support for grub2") Reviewed-by: John 'Warthog9' Hawley (VMware) Signed-off-by: Steven Rostedt --- tools/testing/ktest/ktest.pl | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index d391bf7abeee..1737c59e4ff6 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1963,7 +1963,7 @@ sub run_scp_mod { =20 sub _get_grub_index { =20 - my ($command, $target, $skip) =3D @_; + my ($command, $target, $skip, $submenu) =3D @_; =20 return if (defined($grub_number) && defined($last_grub_menu) && $last_grub_menu eq $grub_menu && defined($last_machine) && @@ -1980,11 +1980,16 @@ sub _get_grub_index { =20 my $found =3D 0; =20 + my $submenu_number =3D 0; + while () { if (/$target/) { $grub_number++; $found =3D 1; last; + } elsif (defined($submenu) && /$submenu/) { + $submenu_number++; + $grub_number =3D -1; } elsif (/$skip/) { $grub_number++; } @@ -1993,6 +1998,9 @@ sub _get_grub_index { =20 dodie "Could not find '$grub_menu' through $command on $machine" if (!$found); + if ($submenu_number > 0) { + $grub_number =3D "$submenu_number>$grub_number"; + } doprint "$grub_number\n"; $last_grub_menu =3D $grub_menu; $last_machine =3D $machine; @@ -2003,6 +2011,7 @@ sub get_grub_index { my $command; my $target; my $skip; + my $submenu; my $grub_menu_qt; =20 if ($reboot_type !~ /^grub/) { @@ -2017,8 +2026,9 @@ sub get_grub_index { $skip =3D '^\s*title\s'; } elsif ($reboot_type eq "grub2") { $command =3D "cat $grub_file"; - $target =3D '^menuentry.*' . $grub_menu_qt; - $skip =3D '^menuentry\s|^submenu\s'; + $target =3D '^\s*menuentry.*' . $grub_menu_qt; + $skip =3D '^\s*menuentry'; + $submenu =3D '^\s*submenu\s'; } elsif ($reboot_type eq "grub2bls") { $command =3D $grub_bls_get; $target =3D '^title=3D.*' . $grub_menu_qt; @@ -2027,7 +2037,7 @@ sub get_grub_index { return; } =20 - _get_grub_index($command, $target, $skip); + _get_grub_index($command, $target, $skip, $submenu); } =20 sub wait_for_input { @@ -2090,7 +2100,7 @@ sub reboot_to { if ($reboot_type eq "grub") { run_ssh "'(echo \"savedefault --default=3D$grub_number --once\" | grub --= batch)'"; } elsif (($reboot_type eq "grub2") or ($reboot_type eq "grub2bls")) { - run_ssh "$grub_reboot $grub_number"; + run_ssh "$grub_reboot \"'$grub_number'\""; } elsif ($reboot_type eq "syslinux") { run_ssh "$syslinux --once \\\"$syslinux_label\\\" $syslinux_path"; } elsif (defined $reboot_script) { --=20 2.35.1