Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3159714rwb; Wed, 30 Nov 2022 16:29:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf6J8KLV4DXlDC4ZedkC2PC71ZA9VKWE/6ogdz20exxOyDgWCFs5/KaVgSREdnN6Jouke9IS X-Received: by 2002:a17:906:2ccb:b0:7ad:9892:921a with SMTP id r11-20020a1709062ccb00b007ad9892921amr52465510ejr.506.1669854571118; Wed, 30 Nov 2022 16:29:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669854571; cv=none; d=google.com; s=arc-20160816; b=jLN4g2xyoOEEmwlOWg8+dsaneOD988XlkLjBVHxHnegh8vYeFGNWjo8NqYPBfRV3vT 6aWz3ht+f0UUATEFSFyduiMbFKni+jKDA7rIH+pN4dVzqladrmO483vERusqogkShdwd lJQxpXxlxccLIzlvUrblw0zWMUlHBs3yYFkrdKN4n4SVDNje2tjsBPOdosBl3cWdlOyy QKudn/2jxketMn0fFSpN706ewRkVHANsJ3nVThWniUgTHikScrtRb8p03RmLH0Gwwqtw Suvs5F2Zhm8FtPz8dmebKJrlXR1S0T8vYaA67scNj9evK3cp0PkKA8Xwz1jHajbdwZJg BOtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=nRtHxLZDMaLiADrmeOgLU03The4hxkgGfImd7her2kI=; b=UUhBhDAM99yq8J1ApZvw0SGYtRSF65oRAR82rGsjHjnMQUeGuzxL7KVCFm4OlnQIvg tBKT1s0C+dP3SV6EWG5HU6C8DTyP4wLpF5aiT25ZzahQpf/Zq9iu0n0gA9Jq4db5kcXh /msdItzgtJ5AjNvBPi8z7xouWGwCSsRZ27/H5DVvObnQT5+Tls14lYxVJElkhCrDq5Ly scX2CBz53OFLidcOqjzrlvVJmciI9LlJvfxVuOxitJVq110hqKk5PHM7JpORyC7hoGbr uAcH8YCQhfQAV0w92iwhT0QdqnQOnY+PXmQ04K7NFs18/ebuG0h65hxwatZgH0eBkXPB dw4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T7wHujea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr1-20020a1709073f8100b007adb2862222si2620435ejc.828.2022.11.30.16.29.10; Wed, 30 Nov 2022 16:29:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T7wHujea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbiLAAPb (ORCPT + 82 others); Wed, 30 Nov 2022 19:15:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbiLAAPA (ORCPT ); Wed, 30 Nov 2022 19:15:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FDB9A2816 for ; Wed, 30 Nov 2022 16:09: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 293FC60A2A for ; Thu, 1 Dec 2022 00:09:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62BF8C433D7; Thu, 1 Dec 2022 00:09:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669853344; bh=Um3WQhBTYgWaLQy6MGpy/qOcoDY69AWToZC6FBCV2yY=; h=Date:Subject:To:References:From:In-Reply-To:From; b=T7wHujeay5HaWs2My7e+orkGiaJ2roz7fb2Vjfhfx6RY7x9Bn1JblD5G4OuL6N1su RlSSjLC1mCaSTrpTJOHmVCAJBeY/UdB2VkWAqZGMCZNlHFnto4lH63kEPlQ7zyNYxl PDagDJNR7AOrYYl5lIlr/OVho1FuFETOD9Y8uhFHj5vn2z8kmMpI7npyuDAqigFQym iqrGukfWVTiHeE89AKPNCN2VmKYUD+JnNxWtgh6zkLRcRNU22Uc8VeUQvtEavE1N5A qd1cH2d06VQcJxVkFHDjb1gEh1bt9pOJwetV/zoDCkPUeD6k8clusj8fOfUFsp7VcF ciw7obUfuGFOA== Message-ID: <2f8c4d57-1834-146b-07c4-11d6c87d986d@kernel.org> Date: Wed, 30 Nov 2022 16:09:03 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] kest.pl: Fix grub2 menu handling for rebooting Content-Language: en-MW To: Steven Rostedt , LKML References: <20221130175434.555ea650@gandalf.local.home> From: John 'Warthog9' Hawley In-Reply-To: <20221130175434.555ea650@gandalf.local.home> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/30/22 14:54, Steven Rostedt wrote: > 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 debian --class gnu-linux ... > [...] > } > menuentry 'Debian GNU/Linux, with Linux 6.0.0-4-amd64 (recovery mode)' --class debian --class gnu-linux ... > [...] > } > menuentry 'Debian GNU/Linux, with Linux test' --class debian --class 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. > > 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 799cfc4aa12b..590518144167 100755 > --- a/tools/testing/ktest/ktest.pl > +++ b/tools/testing/ktest/ktest.pl > @@ -1963,7 +1963,7 @@ sub run_scp_mod { > > sub _get_grub_index { > > - my ($command, $target, $skip) = @_; > + my ($command, $target, $skip, $submenu) = @_; > > 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 { > > my $found = 0; > > + my $submenu_number = 0; > + > while () { > if (/$target/) { > $grub_number++; > $found = 1; > last; > + } elsif (defined($submenu) && /$submenu/) { > + $submenu_number++; > + $grub_number = -1; > } elsif (/$skip/) { > $grub_number++; > } > @@ -1993,6 +1998,9 @@ sub _get_grub_index { > > dodie "Could not find '$grub_menu' through $command on $machine" > if (!$found); > + if ($submenu_number > 0) { > + $grub_number = "$submenu_number>$grub_number"; > + } > doprint "$grub_number\n"; > $last_grub_menu = $grub_menu; > $last_machine = $machine; > @@ -2003,6 +2011,7 @@ sub get_grub_index { > my $command; > my $target; > my $skip; > + my $submenu; > my $grub_menu_qt; > > if ($reboot_type !~ /^grub/) { > @@ -2017,8 +2026,9 @@ sub get_grub_index { > $skip = '^\s*title\s'; > } elsif ($reboot_type eq "grub2") { > $command = "cat $grub_file"; > - $target = '^menuentry.*' . $grub_menu_qt; > - $skip = '^menuentry\s|^submenu\s'; > + $target = '^\s*menuentry.*' . $grub_menu_qt; > + $skip = '^\s*menuentry'; > + $submenu = '^\s*submenu\s'; > } elsif ($reboot_type eq "grub2bls") { > $command = $grub_bls_get; > $target = '^title=.*' . $grub_menu_qt; > @@ -2027,7 +2037,7 @@ sub get_grub_index { > return; > } > > - _get_grub_index($command, $target, $skip); > + _get_grub_index($command, $target, $skip, $submenu); > } > > sub wait_for_input { > @@ -2090,7 +2100,7 @@ sub reboot_to { > if ($reboot_type eq "grub") { > run_ssh "'(echo \"savedefault --default=$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) { Ahhh the fun of submenus! Reviewed-by: John 'Warthog9' Hawley (VMware)