-
Notifications
You must be signed in to change notification settings - Fork 283
/
Copy pathvt_perf_libs.pm
126 lines (96 loc) · 3.89 KB
/
vt_perf_libs.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# SUSE's openQA tests
#
# Copyright 2020 SUSE LLC
# SPDX-License-Identifier: FSFAP
# Summary: library for VT perf testsuites
# Maintainer: James Wang <[email protected]>
package vt_perf_libs;
use warnings;
use strict;
use Mitigation;
use testapi;
use utils;
use bootloader_setup qw(grub_mkconfig change_grub_config add_grub_cmdline_settings remove_grub_cmdline_settings grep_grub_settings set_framebuffer_resolution set_extrabootparams_grub_conf);
use power_action_utils 'power_action';
=head2 prepare_git_repo
prepare_git_repo($git_branch_name, $git_repo_url);
Downlaod git repo.
C<$git_branch_name> Branch name in string.
C<$git_repo_url> URL in string.
=cut
sub prepare_git_repo {
my ($git_branch_name, $git_repo_url) = @_;
#Prepare mitigations-testsuite.git
assert_script_run("git config --global http.sslVerify false");
assert_script_run("rm -rf mitigation-testsuite");
assert_script_run("git clone -q --single-branch -b $git_branch_name --depth 1 $git_repo_url");
assert_script_run("pushd mitigation-testsuite");
assert_script_run("git status");
assert_script_run("PAGER= git log -1");
}
=head2 switch_to_linux_default_enable
switch_to_linux_default_enable($self);
Switch to default enable mode of mitigation on linux kernel.
It would be used in Dom0, kvm hypervisor, baremetal.
C<$git_branch_name> Branch name in string.
C<$git_repo_url> URL in string.
=cut
sub switch_to_linux_default_enable {
my $self = shift;
my $ret = script_run("grep \"mitigations=off\" /proc/cmdline");
if ($ret eq 0) {
#Sometime parameter be writen on the line of GRUB_CMDLINE_LINUX
assert_script_run("sed -i '/GRUB_CMDLINE_LINUX=/s/mitigations=off/ /g' /etc/default/grub");
#This remove can't make sure clean all lines.
remove_grub_cmdline_settings("mitigations=off");
#reboot make new kernel command-line available
Mitigation::reboot_and_wait($self, 150);
#check new kernel command-line
my $ret = script_run("grep \"mitigations=off\" /proc/cmdline");
if ($ret eq 0) {
die 'remove "mitigations=off" from kernel command-line failed';
}
}
}
=head2 switch_to_xen_default_enable
switch_to_linux_default_enable($self);
Switch to default enable mode of mitigation on linux kernel.
It would be used in Dom0, kvm hypervisor, baremetal.
C<$git_branch_name> Branch name in string.
C<$git_repo_url> URL in string.
=cut
sub switch_to_xen_default_enable {
my $self = shift;
my $reboot = 0;
my $ret = script_run("xl info | grep \"xen_commandline\" | grep \"spec-ctrl=off\"");
if ($ret eq 0) {
#Sometime parameter be writen on the line of GRUB_CMDLINE_LINUX
assert_script_run("sed -i '/GRUB_CMDLINE_XEN_DEFAULT=/s/spec-ctrl=off/ /g' /etc/default/grub");
remove_xen_grub_cmdline_settings("spec-ctrl=off");
$reboot = 1;
}
$ret = script_run("grep \"mitigations=off\" /proc/cmdline");
if ($ret eq 0) {
#Sometime parameter be writen on the line of GRUB_CMDLINE_LINUX
assert_script_run("sed -i '/GRUB_CMDLINE_LINUX=/s/mitigations=off/ /g' /etc/default/grub");
assert_script_run("sed -i '/GRUB_CMDLINE_LINUX_XEN_REPLACE_DEFAULT=/s/mitigations=off/ /g' /etc/default/grub");
#This remove can't make sure clean all lines.
remove_grub_cmdline_settings("mitigations=off");
$reboot = 1;
}
#reboot make new kernel command-line available
if ($reboot) {
Mitigation::reboot_and_wait($self, 150);
#check new kernel command-line
$ret = script_run("grep \"mitigations=off\" /proc/cmdline");
if ($ret eq 0) {
die 'remove "mitigations=off" from kernel command-line failed';
}
#check new xen command-line
$ret = script_run("xl info | grep \"spec-ctrl=off\"");
if ($ret eq 0) {
die 'remove "spec-ctrl=off" from xen command-line failed';
}
}
}
1;