Class: ATP::Flow
- Inherits:
-
Object
- Object
- ATP::Flow
- Defined in:
- lib/atp/flow.rb
Overview
Implements the main user API for building and interacting with an abstract test program
Constant Summary collapse
- CONDITION_KEYS =
{ if_enabled: :if_enabled, if_enable: :if_enabled, enabled: :if_enabled, enable_flag: :if_enabled, enable: :if_enabled, unless_enabled: :unless_enabled, not_enabled: :unless_enabled, disabled: :unless_enabled, disable: :unless_enabled, unless_enable: :unless_enabled, if_failed: :if_failed, unless_passed: :if_failed, failed: :if_failed, if_passed: :if_passed, unless_failed: :if_passed, passed: :if_passed, if_any_failed: :if_any_failed, unless_all_passed: :if_any_failed, if_all_failed: :if_all_failed, unless_any_passed: :if_all_failed, if_any_passed: :if_any_passed, unless_all_failed: :if_any_passed, if_all_passed: :if_all_passed, unless_any_failed: :if_all_passed, if_ran: :if_ran, if_executed: :if_ran, unless_ran: :unless_ran, unless_executed: :unless_ran, job: :if_job, jobs: :if_job, if_job: :if_job, if_jobs: :if_job, unless_job: :unless_job, unless_jobs: :unless_job, if_flag: :if_flag, unless_flag: :unless_flag, group: :group }
- CONDITION_NODE_TYPES =
CONDITION_KEYS.values.uniq
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#program ⇒ Object
readonly
Returns the value of attribute program.
-
#source_file ⇒ Object
Returns the value of attribute source_file.
-
#source_line_number ⇒ Object
Returns the value of attribute source_line_number.
Instance Method Summary collapse
-
#ast(options = {}) ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow.
- #bin(number, options = {}) ⇒ Object
-
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
- #continue(options = {}) ⇒ Object
- #cz(instance, cz_setup, options = {}) ⇒ Object (also: #characterize)
-
#disable(var, options = {}) ⇒ Object
Disable a flow control variable.
-
#enable(var, options = {}) ⇒ Object
Enable a flow control variable.
-
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block.
-
#initialize(program, name = nil, options = {}) ⇒ Flow
constructor
A new instance of Flow.
- #inspect ⇒ Object
-
#log(message, options = {}) ⇒ Object
Append a log message line to the flow.
- #marshal_dump ⇒ Object private
- #marshal_load(array) ⇒ Object private
- #pass(number, options = {}) ⇒ Object
-
#raw ⇒ Object
Returns the raw AST.
-
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow.
-
#run(options = {}) ⇒ Object
Execute the given flow in the console.
- #set_flag(flag, options = {}) ⇒ Object
-
#sub_test(instance, options = {}) ⇒ Object
Equivalent to calling test, but returns a sub_test node instead of adding it to the flow.
-
#test(instance, options = {}) ⇒ Object
Add a test line to the flow.
-
#volatile(*flags) ⇒ Object
Indicate the that given flags should be considered volatile (can change at any time), which will prevent them from been touched by the optimization algorithms.
Constructor Details
#initialize(program, name = nil, options = {}) ⇒ Flow
Returns a new instance of Flow.
65 66 67 68 69 70 71 |
# File 'lib/atp/flow.rb', line 65 def initialize(program, name = nil, = {}) name, = nil, name if name.is_a?(Hash) () @program = program @name = name @pipeline = [n1(:flow, n1(:name, name))] end |
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
7 8 9 |
# File 'lib/atp/flow.rb', line 7 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def name @name end |
#program ⇒ Object (readonly)
Returns the value of attribute program.
5 6 7 |
# File 'lib/atp/flow.rb', line 5 def program @program end |
#source_file ⇒ Object
Returns the value of attribute source_file.
7 8 9 |
# File 'lib/atp/flow.rb', line 7 def source_file @source_file end |
#source_line_number ⇒ Object
Returns the value of attribute source_line_number.
7 8 9 |
# File 'lib/atp/flow.rb', line 7 def source_line_number @source_line_number end |
Instance Method Details
#ast(options = {}) ⇒ Object
Returns a processed/optimized AST, this is the one that should be used to build and represent the given test flow
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 173 174 175 176 177 178 179 180 |
# File 'lib/atp/flow.rb', line 99 def ast( = {}) = { apply_relationships: true, # Supply a unique ID to append to all IDs unique_id: nil, # Set to :smt, or :igxl optimization: :runner, # These options are not intended for application use, but provide the ability to # turn off certain processors during test cases add_ids: true, optimize_flags: true, one_flag_per_test: true, implement_continue: true }.merge() ############################################################################### ## Common pre-processing and validation ############################################################################### ast = Processors::PreCleaner.new.run(raw) Validators::DuplicateIDs.new(self).run(ast) Validators::MissingIDs.new(self).run(ast) Validators::Jobs.new(self).run(ast) # Ensure everything has an ID, this helps later if condition nodes need to be generated ast = Processors::AddIDs.new.run(ast) if [:add_ids] ast = Processors::FlowID.new.run(ast, [:unique_id]) if [:unique_id] ############################################################################### ## Optimization for a C-like flow target, e.g. V93K ############################################################################### if [:optimization] == :smt || [:optimization] == :runner # This applies all the relationships by setting flags in the referenced test and # changing all if_passed/failed type nodes to if_flag type nodes ast = Processors::Relationship.new.run(ast) if [:apply_relationships] ast = Processors::Condition.new.run(ast) unless [:optimization] == :runner ast = Processors::ContinueImplementer.new.run(ast) if [:implement_continue] end ast = Processors::FlagOptimizer.new.run(ast) if [:optimize_flags] ast = Processors::AdjacentIfCombiner.new.run(ast) ############################################################################### ## Optimization for a row-based target, e.g. UltraFLEX ############################################################################### elsif [:optimization] == :igxl # Un-nest everything embedded in else nodes ast = Processors::ElseRemover.new.run(ast) # Un-nest everything embedded in on_pass/fail nodes except for binning and # flag setting ast = Processors::OnPassFailRemover.new.run(ast) # This applies all the relationships by setting flags in the referenced test and # changing all if_passed/failed type nodes to if_flag type nodes ast = Processors::Relationship.new.run(ast) if [:apply_relationships] ast = Processors::Condition.new.run(ast) ast = Processors::ApplyPostGroupActions.new.run(ast) ast = Processors::OneFlagPerTest.new.run(ast) if [:one_flag_per_test] ast = Processors::RedundantConditionRemover.new.run(ast) ############################################################################### ## Not currently used, more of a test case ############################################################################### elsif [:optimization] == :flat # Un-nest everything embedded in else nodes ast = Processors::ElseRemover.new.run(ast) # Un-nest everything embedded in on_pass/fail nodes except for binning and # flag setting ast = Processors::OnPassFailRemover.new.run(ast) ast = Processors::Condition.new.run(ast) ast = Processors::Flattener.new.run(ast) ############################################################################### ## Default Optimization ############################################################################### else ast = Processors::Condition.new.run(ast) end ############################################################################### ## Common cleanup ############################################################################### # Removes any empty on_pass and on_fail branches ast = Processors::EmptyBranchRemover.new.run(ast) ast end |
#bin(number, options = {}) ⇒ Object
339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/atp/flow.rb', line 339 def bin(number, = {}) if number.is_a?(Hash) fail 'The bin number must be passed as the first argument' end [:bin_description] ||= .delete(:description) () apply_conditions() do [:type] ||= :fail [:bin] = number [:softbin] ||= [:soft_bin] || [:sbin] set_result([:type], ) end end |
#context_changed?(options) ⇒ Boolean
Returns true if the test context generated from the supplied options + existing condition wrappers, is different from that which was applied to the previous test.
424 425 426 427 |
# File 'lib/atp/flow.rb', line 424 def context_changed?() [:_dont_delete_conditions_] = true last_conditions != clean_conditions(open_conditions + [extract_conditions()]) end |
#continue(options = {}) ⇒ Object
409 410 411 412 413 414 |
# File 'lib/atp/flow.rb', line 409 def continue( = {}) () apply_conditions() do n0(:continue) end end |
#cz(instance, cz_setup, options = {}) ⇒ Object Also known as: characterize
361 362 363 364 365 366 367 |
# File 'lib/atp/flow.rb', line 361 def cz(instance, cz_setup, = {}) () apply_conditions() do node = n1(:cz, cz_setup) append_to(node) { test(instance, ) } end end |
#disable(var, options = {}) ⇒ Object
Disable a flow control variable
387 388 389 390 391 392 |
# File 'lib/atp/flow.rb', line 387 def disable(var, = {}) () apply_conditions() do n1(:disable, var) end end |
#enable(var, options = {}) ⇒ Object
Enable a flow control variable
379 380 381 382 383 384 |
# File 'lib/atp/flow.rb', line 379 def enable(var, = {}) () apply_conditions() do n1(:enable, var) end end |
#group(name, options = {}) ⇒ Object
Group all tests generated within the given block
197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/atp/flow.rb', line 197 def group(name, = {}) () apply_conditions() do children = [n1(:name, name)] children << id([:id]) if [:id] children << on_fail([:on_fail]) if [:on_fail] children << on_pass([:on_pass]) if [:on_pass] g = n(:group, children) append_to(g) { yield } end end |
#inspect ⇒ Object
449 450 451 |
# File 'lib/atp/flow.rb', line 449 def inspect "<ATP::Flow:#{object_id} #{name}>" end |
#log(message, options = {}) ⇒ Object
Append a log message line to the flow
371 372 373 374 375 376 |
# File 'lib/atp/flow.rb', line 371 def log(, = {}) () apply_conditions() do n1(:log, .to_s) end end |
#marshal_dump ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 |
# File 'lib/atp/flow.rb', line 74 def marshal_dump [@name, @program, Processors::Marshal.new.process(raw)] end |
#marshal_load(array) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 82 |
# File 'lib/atp/flow.rb', line 79 def marshal_load(array) @name, @program, raw = array @pipeline = [raw] end |
#pass(number, options = {}) ⇒ Object
353 354 355 356 357 358 359 |
# File 'lib/atp/flow.rb', line 353 def pass(number, = {}) if number.is_a?(Hash) fail 'The bin number must be passed as the first argument' end [:type] = :pass bin(number, ) end |
#raw ⇒ Object
Returns the raw AST
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/atp/flow.rb', line 85 def raw n = nil @pipeline.reverse_each do |node| if n n = node.updated(nil, node.children + [n]) else n = node end end n end |
#render(str, options = {}) ⇒ Object
Insert explicitly rendered content in to the flow
402 403 404 405 406 407 |
# File 'lib/atp/flow.rb', line 402 def render(str, = {}) () apply_conditions() do n1(:render, str) end end |
#run(options = {}) ⇒ Object
Execute the given flow in the console
417 418 419 420 |
# File 'lib/atp/flow.rb', line 417 def run( = {}) Formatters::Datalog.run_and_format(ast, ) nil end |
#set_flag(flag, options = {}) ⇒ Object
394 395 396 397 398 399 |
# File 'lib/atp/flow.rb', line 394 def set_flag(flag, = {}) () apply_conditions() do set_flag_node(flag) end end |
#sub_test(instance, options = {}) ⇒ Object
Equivalent to calling test, but returns a sub_test node instead of adding it to the flow.
This is a helper to create sub_tests for inclusion in a top-level test node.
334 335 336 337 |
# File 'lib/atp/flow.rb', line 334 def sub_test(instance, = {}) temp = append_to(n0(:temp)) { test(instance, ) } temp.children.first.updated(:sub_test, nil) end |
#test(instance, options = {}) ⇒ Object
Add a test line to the flow
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/atp/flow.rb', line 218 def test(instance, = {}) () apply_conditions() do # Allows any continue, bin, or soft bin argument passed in at the options top-level to be assumed # to be the action to take if the test fails if b = .delete(:bin) [:on_fail] ||= {} [:on_fail][:bin] = b end if b = .delete(:bin_description) [:on_fail] ||= {} [:on_fail][:bin_description] = b end if b = .delete(:softbin) || b = .delete(:sbin) || b = .delete(:soft_bin) [:on_fail] ||= {} [:on_fail][:softbin] = b end if b = .delete(:softbin_description) || .delete(:sbin_description) || .delete(:soft_bin_description) [:on_fail] ||= {} [:on_fail][:softbin_description] = b end if .delete(:continue) [:on_fail] ||= {} [:on_fail][:continue] = true end if f = .delete(:flag_pass) [:on_pass] ||= {} [:on_pass][:set_flag] = f end if f = .delete(:flag_fail) [:on_fail] ||= {} [:on_fail][:set_flag] = f end children = [n1(:object, instance)] name = ([:name] || [:tname] || [:test_name]) unless name [:name, :tname, :test_name].each do |m| name ||= instance.respond_to?(m) ? instance.send(m) : nil end end children << n1(:name, name) if name num = ([:number] || [:num] || [:tnum] || [:test_number]) unless num [:number, :num, :tnum, :test_number].each do |m| num ||= instance.respond_to?(m) ? instance.send(m) : nil end end children << number(num) if num children << id([:id]) if [:id] if levels = [:level] || [:levels] levels = [levels] unless levels.is_a?(Array) levels.each do |l| children << level(l[:name], l[:value], l[:unit] || l[:units]) end end if lims = [:limit] || [:limits] lims = [lims] unless lims.is_a?(Array) lims.each do |l| if l.is_a?(Hash) children << limit(l[:value], l[:rule], l[:unit] || l[:units]) end end end if pins = [:pin] || [:pins] pins = [pins] unless pins.is_a?(Array) pins.each do |p| if p.is_a?(Hash) children << pin(p[:name]) else children << pin(p) end end end if pats = [:pattern] || [:patterns] pats = [pats] unless pats.is_a?(Array) pats.each do |p| if p.is_a?(Hash) children << pattern(p[:name], p[:path]) else children << pattern(p) end end end if [:meta] attrs = [] [:meta].each { |k, v| attrs << attribute(k, v) } children << n(:meta, attrs) end if subs = [:sub_test] || [:sub_tests] subs = [subs] unless subs.is_a?(Array) subs.each do |s| children << s.updated(:sub_test, nil) end end children << on_fail([:on_fail]) if [:on_fail] children << on_pass([:on_pass]) if [:on_pass] save_conditions n(:test, children) end end |
#volatile(*flags) ⇒ Object
Indicate the that given flags should be considered volatile (can change at any time), which will prevent them from been touched by the optimization algorithms
184 185 186 187 188 |
# File 'lib/atp/flow.rb', line 184 def volatile(*flags) = flags.pop if flags.last.is_a?(Hash) flags = flags.flatten @pipeline[0] = add_volatile_flags(@pipeline[0], flags) end |