Skip to content

Commit b4abf40

Browse files
committed
RHELMISC-19957: Provide test info in all commands
Signed-off-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
1 parent 7d3094f commit b4abf40

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

docs/Test-config-behavior.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ Local path can use the following replacements:
5858
- `@workspace@` - Path to current workspace
5959
- `@safe_test_name@` - Safe name of current test
6060
- `@client_name@` - Client name
61+
- `@run_number@` - The current run number of a test that is executed multiple times
6162

6263
Guest run command can use the following replacements:
6364

6465
- `@workspace@` - Path to current workspace
6566
- `@safe_test_name@` - Safe name of current test
6667
- `@client_name@` - Client name
68+
- `@run_number@` - The current run number of a test that is executed multiple times
6769
- `@<driver_short_name>.driver_dir@` - Path to uploaded driver binary

lib/engines/hcktest/tests.rb

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,21 @@ def test_parameters(test_name)
180180
.to_h { |parameter| [parameter.name, parameter.value] }
181181
end
182182

183-
def run_command_on_client(client, command, desc)
183+
def run_command_on_client(client, command, desc, replacement)
184184
@logger.info("Running command (#{desc}) on client #{client.name}")
185185
# Don't use create_cmd because it calls shellescape that performs wrong escaping for Windows commands
186186
# E.g. it escapes backslashes that are used in Windows paths
187-
updated_command = client.replacement_map.merge(@replacement_map).replace(command)
187+
updated_command = client.replacement_map.merge(@replacement_map).merge(replacement).replace(command)
188188
@logger.debug("Running command after replacement (#{desc}) on client #{client.name}: #{updated_command}")
189189

190190
@tools.run_on_machine(client.name, desc, updated_command)
191191
end
192192

193-
def run_guest_test_command(command)
193+
def run_guest_test_command(command, replacement)
194194
return unless command.guest_run
195195

196-
run_command_on_client(@client, command.guest_run, command.desc)
197-
run_command_on_client(@support, command.guest_run, command.desc) unless @support.nil?
196+
run_command_on_client(@client, command.guest_run, command.desc, replacement)
197+
run_command_on_client(@support, command.guest_run, command.desc, replacement) unless @support.nil?
198198
end
199199

200200
def run_host_test_command(command)
@@ -276,13 +276,12 @@ def run_file_actions(files_actions, replacement)
276276
end
277277
end
278278

279-
sig { params(test: Models::HLK::Test, type: Symbol).void }
280-
def run_test_commands(test, type)
279+
sig { params(test: Models::HLK::Test, type: Symbol, replacement: ReplacementMap).void }
280+
def run_test_commands(test, type, replacement)
281281
select_test_config(test.name, type).each do |command|
282-
run_guest_test_command(command)
282+
run_guest_test_command(command, replacement)
283283
run_host_test_command(command)
284284

285-
replacement = @replacement_map.merge({ '@safe_test_name@' => test.safe_name })
286285
run_file_actions(command.files_action, replacement)
287286
end
288287
end
@@ -659,26 +658,37 @@ def load_clients_system_info
659658
build_system_info(support_sysinfo)
660659
end
661660

661+
sig { params(test: Models::HLK::Test, run_number: Integer, run_count: Integer).void }
662+
def one_test_run(test, run_number, run_count)
663+
replacement = @replacement_map.merge(
664+
'@safe_test_name@' => test.safe_name,
665+
'@run_number@' => run_number.to_s
666+
)
667+
668+
run_test_commands(test, :pre_test_commands, replacement)
669+
670+
test_str = "run #{run_number}/#{run_count} #{test.name} (#{test.id})"
671+
@logger.info("Adding to queue: #{test_str}")
672+
queue_test(test, wait: true)
673+
handle_test_running
674+
@project.generate_junit
675+
676+
run_test_commands(test, :post_test_commands, replacement)
677+
end
678+
662679
sig { params(tests: T::Array[Models::HLK::Test]).void }
663680
def run(tests)
664681
load_clients_system_info
665682
update_summary_results_log
666683
tests.each do |test|
667-
run_test_commands(test, :pre_test_commands)
668684
run_count = test.run_count
669685

670686
(1..run_count).each do |run_number|
671-
test_str = "run #{run_number}/#{run_count} #{test.name} (#{test.id})"
672-
@logger.info("Adding to queue: #{test_str}")
673-
queue_test(test, wait: true)
674-
handle_test_running
675-
@project.generate_junit
687+
one_test_run(test, run_number, run_count)
676688

677689
break if @project.run_terminated
678690
end
679691

680-
run_test_commands(test, :post_test_commands)
681-
682692
break if @project.run_terminated
683693
end
684694
end

0 commit comments

Comments
 (0)