diff options
| author | Masayoshi Mizuma <m.mizuma@jp.fujitsu.com> | 2019-05-09 17:36:43 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2023-01-18 11:30:53 +0100 |
| commit | 42fe78564a0d1dfa9b140d8ba82e59c934a064e9 (patch) | |
| tree | 0dc85052bc0be968fe0a304d702bf23424607d48 | |
| parent | 5f2956dcdbab203246160653d2bfeab6a6752d1b (diff) | |
ktest: cleanup get_grub_index
[ Upstream commit 38891392916c42d4ba46f474d553c76d1ed329ca ]
Cleanup get_grub_index().
Link: http://lkml.kernel.org/r/20190509213647.6276-3-msys.mizuma@gmail.com
Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Stable-dep-of: 26df05a8c142 ("kest.pl: Fix grub2 menu handling for rebooting")
Signed-off-by: Sasha Levin <sashal@kernel.org>
| -rwxr-xr-x | tools/testing/ktest/ktest.pl | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/tools/testing/ktest/ktest.pl b/tools/testing/ktest/ktest.pl index 5fa60b3c564f..a1067469ba0e 100755 --- a/tools/testing/ktest/ktest.pl +++ b/tools/testing/ktest/ktest.pl @@ -1925,46 +1925,30 @@ sub get_grub2_index { sub get_grub_index { - if ($reboot_type eq "grub2") { - get_grub2_index; - return; - } + my $command; + my $target; + my $skip; + my $grub_menu_qt; - if ($reboot_type ne "grub") { + if ($reboot_type !~ /^grub/) { return; } - return if (defined($grub_number) && defined($last_grub_menu) && - $last_grub_menu eq $grub_menu && defined($last_machine) && - $last_machine eq $machine); - - doprint "Find grub menu ... "; - $grub_number = -1; - my $ssh_grub = $ssh_exec; - $ssh_grub =~ s,\$SSH_COMMAND,cat /boot/grub/menu.lst,g; - - open(IN, "$ssh_grub |") - or dodie "unable to get menu.lst"; + $grub_menu_qt = quotemeta($grub_menu); - my $found = 0; - my $grub_menu_qt = quotemeta($grub_menu); - - while (<IN>) { - if (/^\s*title\s+$grub_menu_qt\s*$/) { - $grub_number++; - $found = 1; - last; - } elsif (/^\s*title\s/) { - $grub_number++; - } + if ($reboot_type eq "grub") { + $command = "cat /boot/grub/menu.lst"; + $target = '^\s*title\s+' . $grub_menu_qt . '\s*$'; + $skip = '^\s*title\s'; + } elsif ($reboot_type eq "grub2") { + $command = "cat $grub_file"; + $target = '^menuentry.*' . $grub_menu_qt; + $skip = '^menuentry\s|^submenu\s'; + } else { + return; } - close(IN); - dodie "Could not find '$grub_menu' in /boot/grub/menu on $machine" - if (!$found); - doprint "$grub_number\n"; - $last_grub_menu = $grub_menu; - $last_machine = $machine; + _get_grub_index($command, $target, $skip); } sub wait_for_input |
