forked from intel/lkp-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-local
executable file
·172 lines (137 loc) · 4.44 KB
/
run-local
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env ruby
# SC2174: When used with -p, -m only applies to the deepest directory
# shellcheck disable=SC2174
require 'optparse'
require 'ostruct'
require 'fileutils'
require 'shellwords'
LKP_SRC = ENV['LKP_SRC'] || File.dirname(File.dirname(File.realpath($PROGRAM_NAME)))
LKP_USER = ENV['USER'] || `whoami`.chomp
require "#{LKP_SRC}/lib/distro_info"
TMP = "/tmp/lkp-#{LKP_USER}".freeze
ENV['TMP'] = TMP
require "#{LKP_SRC}/lib/run_env"
set_local_run
require "#{LKP_SRC}/lib/yaml"
require "#{LKP_SRC}/lib/stats"
require "#{LKP_SRC}/lib/matrix"
require "#{LKP_SRC}/lib/job2sh"
require "#{LKP_SRC}/lib/job"
require "#{LKP_SRC}/lib/result_root"
require "#{LKP_SRC}/lib/common"
require "#{LKP_SRC}/lib/log"
ENV['PATH'] = ENV['PATH'] + ":#{LKP_SRC}/bin"
ENV['BENCHMARK_ROOT'] = '/lkp/benchmarks'
$opt_result_root = 'result'
$opt_set_key_value = {}
opt_parser = OptionParser.new do |opts|
opts.banner = 'Usage: run-local [-o RESULT_ROOT] JOBFILE'
opts.separator ''
opts.separator 'options:'
opts.on('-o RESULT_ROOT', '--output RESULT_ROOT', 'link to result directory') do |dir|
$opt_result_root = dir
end
opts.on("-s 'KEY: VALUE'", "--set 'KEY: VALUE'", 'add YAML hash to job') do |key_value|
$opt_set_key_value.merge!(YAML.load(key_value))
end
opts.on_tail('-h', '--help', 'Show this message') do
puts opts
exit
end
end
argv = if ARGV == []
['-h']
else
ARGV
end
opt_parser.parse!(argv)
jobfile = ARGV[0]
unless jobfile
puts 'No jobfile specified'
exit 1
end
# Setup environment for user specified test case
argv = ARGV.drop(1)
argv = argv.drop(1) if argv[0] == '--'
ENV['MY_TEST_CMDLINE'] = Shellwords.join ARGV.drop(1) unless argv.empty?
if !jobfile.index('/') && !File.exist?(jobfile)
file = LKP::Path.src('jobs', jobfile)
jobfile = file if File.exist?(file)
end
def create_result_root(_result_root)
0.upto(99) do |i|
result_root = "#{_result_root}/#{i}"
next if Dir.exist? result_root
FileUtils.mkdir_p result_root, mode: 0o2775
return result_root
end
log_warn "cannot create more result_roots under #{_result_root}"
nil
end
begin
# "#!" is defined by comment_to_symbol
log_warn "Jobfile is a dirty file, better to run 'lkp split-job --compatible #{jobfile}' first" if File.readlines(jobfile).any? { |l| l.start_with?(':#! ') }
job = Job.new
job.load(jobfile)
unless job.atomic_job?
log_error "Looks #{ARGV[0]} isn't a atomic jobfile, only atomic jobfile is supported"
log_error "Please run 'lkp split-job #{ARGV[0]}' first"
exit 1
end
rescue StandardError
log_warn "#{jobfile} is not a valid jobfile"
exit 1
end
distroinfo = LKP::DistroInfo.instance
distro = distroinfo.systemnamel
HOSTNAME ||= ENV['HOSTNAME'] || `hostname`.chomp
job['testbox'] = HOSTNAME
job['tbox_group'] = tbox_group(HOSTNAME)
job['kconfig'] ||= 'defconfig'
job['commit'] ||= `uname -r`.chomp!
job['rootfs'] ||= if File.exist? '/etc/os-release'
`grep -m1 ^ID= /etc/os-release`.split('=')[1].chomp
else
distro
end
job['nr_cpu'] ||= `nproc`.to_i
job['memory'] ||= `grep -w '^memory:' #{LKP_SRC}/hosts/#{HOSTNAME}`.split(' ')[1].chomp
job['compiler'] ||= File.realpath('/usr/bin/gcc').match(/gcc.*/).to_s
job['compiler'] = 'gcc' if job['compiler'].empty?
job['NO_NETWORK'] = 1
job['LKP_LOCAL_RUN'] = 1
$opt_set_key_value.each do |k, v|
job[k] = v
end
_result_root = job._result_root
result_root = create_result_root(_result_root)
exit unless result_root
ENV['RESULT_ROOT'] = result_root
ENV['TMP_RESULT_ROOT'] = result_root
jobx = Job2sh.new(job.to_hash)
unless jobx.expand_params
log_error 'Failed to expand params!'
exit
end
FileUtils.rm_rf TMP
Dir.mkdir TMP
job_script = "#{result_root}/job.sh"
File.open(job_script, 'w', 0o775) do |file|
file.puts jobx.to_shell
end
user = ENV['USER']
save_paths(result_root, user)
system 'killall', '-q', "#{LKP_SRC}/bin/event/wakeup"
system job_script, 'run_job'
system "#{LKP_SRC}/bin/run-with-job", job_script, "#{LKP_SRC}/bin/post-run"
system "#{LKP_SRC}/bin/event/wakeup", 'job-finished'
job.save "#{result_root}/job.yaml"
system job_script, 'extract_stats'
stats = create_stats_matrix ENV['RESULT_ROOT']
stats['stats_source'] = "#{result_root}/stats.json"
unite_to(stats, _result_root)
system("#{LKP_SRC}/sbin/unite-params", result_root)
MResultRootTableSet.create_tables_layout
convert_mrt(_result_root)
FileUtils.rm_f($opt_result_root)
FileUtils.ln_s(result_root, $opt_result_root)