Skip to content

Commit

Permalink
Support pre/post_test_commands for host/guest
Browse files Browse the repository at this point in the history
Signed-off-by: Vitalii Chulak <[email protected]>
  • Loading branch information
Jedoku committed Sep 29, 2024
1 parent 7c2b3f3 commit 71a83ee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
29 changes: 26 additions & 3 deletions lib/engines/hcktest/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,29 @@ def read_test_config(test_name, config)

def test_parameters(test_name)
read_test_config(test_name, :parameters)
.to_h { |parameter| [parameter.name, parameter.value] }
.to_h { |parameter| [parameter.name, parameter.value] }
end

def run_guest_commands(test, commands)
return unless commands.guest_run

@logger.info("Running command (#{commands.desc}) on clients")
@tools.run_on_machine(@client.name, commands.desc, commands.guest_run)
@tools.run_on_machine(@support.name, commands.desc, commands.guest_run) if support_needed?(test)
end

def run_host_commands(commands)
return unless commands.host_run

@logger.info("Running command (#{commands.desc}) on host")
Process.wait spawn(*commands.host_run, out: :err)
end

def run_test_commands(test, type)
read_test_config(test['name'], type).each do |commands|
run_guest_commands(test, commands)
run_host_commands(commands)
end
end

def queue_test(test, wait: false)
Expand Down Expand Up @@ -437,12 +459,13 @@ def load_clients_system_info
build_system_info(support_sysinfo)
end

def run(tests)
def run(tests) # rubocop:disable Metrics/AbcSize
@total = @tests.count
load_clients_system_info
update_summary_results_log
@last_done = [] if @last_done.nil?
tests.each do |test|
run_test_commands(test, :pre_test_commands)
run_count = test['run_count']

(1..run_count).each do |run_number|
Expand All @@ -451,7 +474,7 @@ def run(tests)
queue_test(test, wait: true)
list_tests
handle_test_running

run_test_commands(test, :post_test_commands)
break if @project.run_terminated
end

Expand Down
2 changes: 2 additions & 0 deletions lib/models/hcktest_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TestConfig < T::Struct
const :tests, T::Array[String]
const :secure, T.nilable(T::Boolean)
const :parameters, T::Array[Parameter], default: []
const :pre_test_commands, T::Array[CommandInfo], default: []
const :post_test_commands, T::Array[CommandInfo], default: []
end

# HCKTestConfig class
Expand Down

0 comments on commit 71a83ee

Please sign in to comment.