Skip to content

Commit

Permalink
lib: refactor to replace warn with log_warn
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Li <[email protected]>
  • Loading branch information
rli9 committed Feb 8, 2021
1 parent dc35423 commit 8674302
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 25 deletions.
5 changes: 3 additions & 2 deletions bin/proc-local
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require "#{LKP_SRC}/lib/matrix"
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'
Expand All @@ -31,13 +32,13 @@ job = Job.new
begin
job.load(jobfile)
rescue StandardError
warn "#{jobfile} is not a valid jobfile"
log_warn "#{jobfile} is not a valid jobfile"
exit 1
end

_result_root = job._result_root
if _result_root != File.dirname(result_root)
warn "_rt doesn't match rt: #{_result_root} vs. #{result_root}"
log_warn "_rt doesn't match rt: #{_result_root} vs. #{result_root}"
exit 1
end

Expand Down
5 changes: 3 additions & 2 deletions bin/run-local
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ 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'
Expand Down Expand Up @@ -81,7 +82,7 @@ def create_result_root(_result_root)
FileUtils.mkdir_p result_root, mode: 0o2775
return result_root
end
warn "cannot create more result_roots under #{_result_root}"
log_warn "cannot create more result_roots under #{_result_root}"
nil
end

Expand All @@ -99,7 +100,7 @@ begin
exit 1
end
rescue StandardError
warn "#{jobfile} is not a valid jobfile"
log_warn "#{jobfile} is not a valid jobfile"
exit 1
end

Expand Down
3 changes: 2 additions & 1 deletion filters/need_kconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require 'yaml'
require "#{LKP_SRC}/lib/kernel_tag"
require "#{LKP_SRC}/lib/log"

def read_kernel_version_from_context
return nil unless self['kernel']
Expand Down Expand Up @@ -33,7 +34,7 @@ def check_kconfig(kconfig_lines, line)
when /^(CONFIG_[A-Z0-9_]+=[ym])/, /^(CONFIG_[A-Z0-9_]+)/, /^(CONFIG_[A-Z0-9_]+=[0-9]+)/
kconfig_lines =~ /^#{$1}/
else
warn "unknown kconfig option: #{line}"
log_warn "unknown kconfig option: #{line}"
true
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'fileutils'
require 'stringio'
require "#{LKP_SRC}/lib/array_ext"
require "#{LKP_SRC}/lib/log"
require 'English'

def deepcopy(o)
Expand Down Expand Up @@ -257,7 +258,7 @@ def copy_and_decompress(src_fullpath, dst)
src_fullpath += '.xz'
%x(xz -cd #{src_fullpath} > #{dst})
else
warn "File doesn't exist: #{src_fullpath}"
log_warn "File doesn't exist: #{src_fullpath}"
return false
end

Expand Down
2 changes: 1 addition & 1 deletion lib/compare.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def each_changed_stat
yield stat
end
rescue StandardError
warn "Error while comparing: #{mresult_roots.map(&:to_s).join ' '}"
log_warn "Error while comparing: #{mresult_roots.map(&:to_s).join ' '}"
raise
end

Expand Down
3 changes: 2 additions & 1 deletion lib/dmesg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "#{LKP_SRC}/lib/constant"
require "#{LKP_SRC}/lib/string_ext"
require "#{LKP_SRC}/lib/lkp_path"
require "#{LKP_SRC}/lib/log"

LKP_SRC_ETC ||= LKP::Path.src('etc')

Expand Down Expand Up @@ -197,7 +198,7 @@ def grep_crash_head(dmesg_file)
next
end

warn "oops pattern mismatch: #{line}"
log_warn "oops pattern mismatch: #{line}"
end

oops_map
Expand Down
3 changes: 1 addition & 2 deletions lib/git_ext/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def linux_last_release_tag_strategy(commit_sha)

[tag, false]
else
warn "Not a kernel tree? Check #{repo}"
warn caller.join "\n"
log_warn e

nil
end
Expand Down
6 changes: 3 additions & 3 deletions lib/lkp_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def __last_linus_release_tag(commit)
elsif version == 2
tag = "v2.#{patch_level}.#{sub_level}"
else
warn "Not a kernel tree? check #{GIT_WORK_TREE}"
warn caller.join "\n"
log_warn "Not a kernel tree? check #{GIT_WORK_TREE}"
log_warn caller.join "\n"
return nil
end

Expand Down Expand Up @@ -232,7 +232,7 @@ def load_remotes
repo_info['maintained_files'] ||= '*'
end

warn "conflict repo name in different projects: #{remote}" if remotes[remote]
log_warn "conflict repo name in different projects: #{remote}" if remotes[remote]

remotes[remote] = repo_info
end
Expand Down
15 changes: 8 additions & 7 deletions lib/yaml.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "#{LKP_SRC}/lib/log"
require "#{LKP_SRC}/lib/erb"
require "#{LKP_SRC}/lib/assert"
require "#{LKP_SRC}/lib/log"
require 'fileutils'
require 'yaml'
require 'json'
Expand Down Expand Up @@ -61,7 +62,7 @@ def load_yaml_merge(files)
yaml = load_yaml(file)
all.update(yaml)
rescue StandardError => e
warn "#{e.class.name}: #{e.message.split("\n").first}: #{file}"
log_warn "#{e.class.name}: #{e.message.split("\n").first}: #{file}"
end
end
all
Expand All @@ -71,7 +72,7 @@ def load_yaml_tail(file)
begin
return YAML.load %x[tail -n 100 #{file}]
rescue Psych::SyntaxError => e
warn "#{file}: " + e.message
log_warn "#{file}: " + e.message
end
nil
end
Expand Down Expand Up @@ -147,7 +148,7 @@ def load_tail(file, lines = 100)
tail = %x[tail -n #{lines} #{file}]
load(tail)
rescue StandardError => e
warn "#{file}: " + e.message
log_warn "#{file}: " + e.message
end
end
end
Expand Down Expand Up @@ -207,17 +208,17 @@ def load_json(file, cache = false)
raise
rescue StandardError
tempfile = file + '-bad'
warn "Failed to load JSON file: #{file}"
warn "Kept corrupted JSON file for debugging: #{tempfile}"
log_warn "Failed to load JSON file: #{file}"
log_warn "Kept corrupted JSON file for debugging: #{tempfile}"
FileUtils.mv file, tempfile, force: true
raise
end
nil
elsif File.exist? file.sub(/\.json(\.gz)?$/, '.yaml')
load_yaml file.sub(/\.json(\.gz)?$/, '.yaml')
else
warn "JSON/YAML file not exist: '#{file}'"
warn caller
log_warn "JSON/YAML file not exist: '#{file}'"
log_warn caller
nil
end
end
Expand Down
3 changes: 2 additions & 1 deletion lkp-exec/stat
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require "#{LKP_SRC}/lib/lkp_git"
require "#{LKP_SRC}/lib/yaml"
require "#{LKP_SRC}/lib/stats"
require "#{LKP_SRC}/lib/result"
require "#{LKP_SRC}/lib/log"

$opt_group = '_rt'
$opt_kernel = ''
Expand Down Expand Up @@ -37,7 +38,7 @@ opt_parser = OptionParser.new do |opts|
when /[0-9]+m$/, /[0-9]+w$/, /[0-9]+d$/, /[0-9]+$/
$opt_pattern = " -d #{date}" + $opt_pattern
else
warn "-d #{date}: parameter is unsuitable."
log_warn "-d #{date}: parameter is unsuitable."
puts opts
exit
end
Expand Down
3 changes: 2 additions & 1 deletion sbin/update-printk-error-messages
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require 'ostruct'
require 'set'
require 'fileutils'
require "#{LKP_SRC}/lib/constant"
require "#{LKP_SRC}/lib/log"

MIN_MSG_LEN = 18
OUTPUT_FILE = "#{KTEST_USER_GENERATED_DIR}/printk-error-messages".freeze
Expand Down Expand Up @@ -155,7 +156,7 @@ kmsg_denylist = File.read(File.join(LKP_SRC, 'etc', 'kmsg-denylist')).split "\n"
if str[0] =~ /[iudsxXpPco]/
str[0] = ''
else
warn 'IGNORE ' + line
log_warn 'IGNORE ' + line
end
end

Expand Down
6 changes: 3 additions & 3 deletions stats/syscalls
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def parse_process_lines(process_lines, time)

if start
if b[3] == '->'
warn 'not a START of syscall\n' + last_line + line if DEBUG
log_warn 'not a START of syscall\n' + last_line + line if DEBUG
find_next = true
last_line = line
next
Expand All @@ -50,14 +50,14 @@ def parse_process_lines(process_lines, time)
start = false
else
if b[3] != '->'
warn 'not a syscall return:\n' + last_line + line if DEBUG
log_warn 'not a syscall return:\n' + last_line + line if DEBUG
find_next = true
last_line = line
next
end
syscall2 = b[2]
if syscall2 != syscall1
warn 'not the same syscall\n' + last_line + line if DEBUG
log_warn 'not the same syscall\n' + last_line + line if DEBUG
find_next = true
last_line = line
next
Expand Down

0 comments on commit 8674302

Please sign in to comment.