Class: Origen::RegressionManager
Overview
Supports executing code regression testing.
Reference workspace used for comparison will automatically be populated based on tag selected (default: latest).
An instance of this class is hooked up to:
Origen.regression_manager
Basic Usage
options[:target] = %w{target1.rb target2.rb target3.rb}
Origen.regression_manager.run(options) do |options|
Origen.target.loop(options) do |options|
Origen.lsf.submit_origen_job "generate regression.list -t #{options[:target]}"
end
end
Instance Method Summary
collapse
Methods included from Users
#admins, #app_users, #current_user
#find_space, #get_text, #split_long_line
Instance Method Details
#copy_regression_file ⇒ Object
We want the reference workspace to run the same regression as the local workspace, so copy the current version of the regression command file across.
187
188
189
190
191
|
# File 'lib/origen/regression_manager.rb', line 187
def copy_regression_file
path_to_command_file = regression_command_file.relative_path_from(Origen.root)
system "rm -f #{reference_origen_root}/#{path_to_command_file}"
system "cp #{Origen.root}/#{path_to_command_file} #{reference_origen_root}/#{path_to_command_file}"
end
|
#get_reference_workspace(_options = {}) ⇒ Object
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
# File 'lib/origen/regression_manager.rb', line 201
def get_reference_workspace(_options = {})
puts ''
puts 'It looks like this is the first time that you have run a regression from this workspace.'
puts ''
puts 'In order to run a regression test Origen must have access to a secondary workspace in which'
puts 'it can build the reference files.'
puts ''
puts 'Generally all of your developments workspaces should use the same reference workspace.'
puts ''
puts 'Origen will make a suggestion for the reference workspace below, however if you know that'
puts 'you already have an existing one at a different location then please enter the path.'
puts ''
puts 'WHERE SHOULD THE REFERENCE WORKSPACE RESIDE?'
puts ''
get_text(default: ws.reference_workspace_proposal, single: true)
end
|
#get_version(_options = {}) ⇒ Object
218
219
220
221
222
223
224
225
|
# File 'lib/origen/regression_manager.rb', line 218
def get_version(_options = {})
puts ''
puts 'WHAT VERSION DO YOU WANT TO COMPARE AGAINST?'
puts ''
puts "Valid values are 'latest', 'last' (production release), or a tag."
puts ''
get_text(default: Origen.app.version, single: true)
end
|
#load_options ⇒ Object
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/origen/regression_manager.rb', line 131
def load_options
options = {}
if File.exist?(store_file)
File.open(store_file.to_s) do |f|
options = Marshal.load(f)
end
FileUtils.rm_f store_file
end
options
end
|
#prepare_targets(options) ⇒ Object
Cycle through all targets in the upcoming run to ensure that all output directories exist
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/origen/regression_manager.rb', line 116
def prepare_targets(options)
targets = [options[:target], options[:targets]].flatten.compact
if targets.empty?
puts 'You must supply the targets you are going to run in the options'
puts 'passed to regression_manager.run.'
fail
end
Origen.target.loop(options) { |_options| }
targets
end
|
#reference_origen_root ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/origen/regression_manager.rb', line 157
def reference_origen_root
if running_in_reference_workspace?
Origen.root
else
ws.origen_root(@reference_workspace)
end
end
|
#regression_command_file ⇒ Object
Returns a full path to the regression command file within the local application
194
195
196
197
198
199
|
# File 'lib/origen/regression_manager.rb', line 194
def regression_command_file
first_call = caller.find { |line| line =~ /regression_manager.rb.*run/ }
app_caller_line = caller[caller.index(first_call) + 1]
app_caller_line =~ /(.*\.rb)/
path = Pathname.new(Regexp.last_match[1])
end
|
#run(options = {}) ⇒ Object
Serves to execute a regression. Any block of code passed to this method will receive regression check
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
|
# File 'lib/origen/regression_manager.rb', line 35
def run(options = {})
options = {
build_reference: true,
send_email: false,
email_all_developers: false,
report_results: false,
uses_lsf: true
}.merge(options)
options = load_options if running_in_reference_workspace?
targets = prepare_targets(options)
if running_in_reference_workspace?
Origen.lsf.clear_all
yield options
wait_for_completion(options) if options[:uses_lsf]
save_and_delete_output
else
if options[:build_reference]
@reference_tag = version_to_tag(options[:version] || get_version(options))
setup_reference_workspace
save_options(options)
Origen.with_origen_root(reference_origen_root) do
Origen.with_disable_origen_version_check(all_processes: true) do
Dir.chdir reference_origen_root do
Bundler.with_clean_env do
system 'origen -v'
Origen.log.info '######################################################'
Origen.log.info 'running regression command in reference workspace...'
Origen.log.info '######################################################'
Origen.log.info
system 'origen regression'
end
end
end
end
end
Origen.lsf.clear_all
Origen.log.info '######################################################'
Origen.log.info 'running regression command in local workspace...'
Origen.log.info '######################################################'
Origen.log.info
yield options
wait_for_completion(options) if options[:uses_lsf]
summarize_results(options)
end
end
|
#running_in_reference_workspace? ⇒ Boolean
148
149
150
|
# File 'lib/origen/regression_manager.rb', line 148
def running_in_reference_workspace?
File.exist?("#{Origen.root}/.this_is_a_reference_workspace")
end
|
#save_and_delete_output ⇒ Object
Saves all generated output (to the reference dir) and then deletes the output directory to save space
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/origen/regression_manager.rb', line 103
def save_and_delete_output
Origen.lsf.build_log
Origen.log.flush
Dir.chdir reference_origen_root do
Bundler.with_clean_env do
system 'origen save all'
end
end
FileUtils.rm_rf "#{reference_origen_root}/output"
end
|
#save_options(options) ⇒ Object
142
143
144
145
146
|
# File 'lib/origen/regression_manager.rb', line 142
def save_options(options)
File.open(store_file.to_s, 'w') do |f|
Marshal.dump(options, f)
end
end
|
#setup_reference_workspace ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/origen/regression_manager.rb', line 165
def setup_reference_workspace
if ws.reference_workspace_set?
@reference_workspace = ws.reference_workspace
else
@reference_workspace = get_reference_workspace
unless File.exist?(@reference_workspace)
highlight { Origen.log.info 'Building reference workspace...' }
ws.build(@reference_workspace)
end
ws.set_reference_workspace(@reference_workspace)
end
highlight { Origen.log.info "Switching reference workspace to version #{@reference_tag}..." }
ws.switch_version(@reference_workspace, @reference_tag, origen_root_only: true)
unless File.exist?("#{reference_origen_root}/.this_is_a_reference_workspace")
system "touch #{reference_origen_root}/.this_is_a_reference_workspace"
end
copy_regression_file
end
|
#store_file ⇒ Object
127
128
129
|
# File 'lib/origen/regression_manager.rb', line 127
def store_file
@store_file ||= Pathname.new "#{reference_origen_root}/.regression_options"
end
|
#summarize_results(options = {}) ⇒ Object
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/origen/regression_manager.rb', line 83
def summarize_results(options = {})
Origen.lsf.build_log
stats = Origen.app.stats
if options[:report_results]
puts "Regression results: \n"
puts "#{stats.summary_text}\n"
end
if stats.clean_run?
stats.report_pass
else
stats.report_fail
end
if options[:send_email]
to = options[:email_all_developers] ? developers : current_user
Origen.mailer.send_regression_complete_notice(to: to)
end
end
|
#version_to_tag(version) ⇒ Object
227
228
229
230
231
232
233
234
235
236
237
238
239
|
# File 'lib/origen/regression_manager.rb', line 227
def version_to_tag(version)
version = version.strip
if version.downcase == 'last'
Origen.app.version_tracker.versions.last
elsif version.downcase == 'latest'
version
elsif VersionString.new(version).valid?
version
else
puts 'Sorry but that version tag looks to be invalid!'
exit 1
end
end
|
#wait_for_completion(_options = {}) ⇒ Object
152
153
154
155
|
# File 'lib/origen/regression_manager.rb', line 152
def wait_for_completion(_options = {})
highlight { Origen.log.info 'Waiting for all to complete...' }
Origen.lsf.wait_for_completion
end
|
21
22
23
|
# File 'lib/origen/regression_manager.rb', line 21
def ws
Origen.app.workspace_manager
end
|