Skip to content

Commit a94ca1f

Browse files
committed
RFC: Bring up previous session
1 parent f7ecd7f commit a94ca1f

File tree

8 files changed

+125
-14
lines changed

8 files changed

+125
-14
lines changed

bin/auto_hck

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module AutoHCK
99
run do
1010
cli = CLI.new
1111
cli.parse(ARGV)
12+
cli.restore_session if cli.test.load_session
1213

1314
ENV.store 'LC_ALL', 'en_US.UTF-8'
1415

lib/all.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module AutoHCK
5858
autoload_relative :PhysHCK, 'setupmanagers/physhck/physhck'
5959
autoload_relative :Playlist, 'engines/hcktest/playlist'
6060
autoload_relative :Project, 'project'
61+
autoload_relative :Session, 'session'
6162
autoload_relative :QemuHCK, 'setupmanagers/qemuhck/qemuhck'
6263
autoload_relative :QemuHCKError, 'setupmanagers/qemuhck/exceptions'
6364
autoload_relative :QemuMachine, 'setupmanagers/qemuhck/qemu_machine'

lib/cli.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
module AutoHCK
55
# class CLI
66
class CLI
7-
attr_reader :common, :install, :test, :mode
7+
attr_reader :install, :mode
8+
attr_accessor :common, :test
89

910
def initialize
1011
@common = CommonOptions.new
@@ -85,7 +86,7 @@ class TestOptions
8586
attr_accessor :platform, :drivers, :driver_path, :commit, :diff_file, :svvp, :dump,
8687
:gthb_context_prefix, :gthb_context_suffix, :playlist, :select_test_names,
8788
:reject_test_names, :triggers_file, :reject_report_sections, :boot_device,
88-
:allow_test_duplication, :manual, :package_with_playlist
89+
:allow_test_duplication, :manual, :package_with_playlist, :load_session
8990

9091
def create_parser
9192
OptionParser.new do |parser|
@@ -187,6 +188,10 @@ def define_options(parser)
187188
parser.on('--package-with-playlist', TrueClass,
188189
'Load playlist into HLKX project package',
189190
&method(:package_with_playlist=))
191+
192+
parser.on('--load-session <path>', String,
193+
'Load session from workspace',
194+
&method(:load_session=))
190195
end
191196
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
192197
end
@@ -245,5 +250,9 @@ def parse(args)
245250
@mode = left.shift
246251
@sub_parser[@mode]&.order!(left) unless @mode.nil?
247252
end
253+
254+
def restore_session
255+
AutoHCK::Session.load_session_cli(self)
256+
end
248257
end
249258
end

lib/engines/hcktest/hcktest.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ def run_clients_and_configure_setup(scope, **opts)
170170
retries = 0
171171
begin
172172
scope.transaction do |tmp_scope|
173-
run_clients tmp_scope, keep_alive: true, **opts
173+
run_clients tmp_scope, keep_alive: true,
174+
boot_from_snapshot: @project.restored,
175+
reuse_tpm: @project.restored,
176+
**opts
174177

175178
configure_setup_and_synchronize
176179
end
@@ -188,7 +191,7 @@ def upload_driver_package
188191

189192
r_name = "#{@project.engine_tag}.zip"
190193
zip_path = "#{@project.workspace_path}/#{r_name}"
191-
create_zip_from_directory(zip_path, @driver_path)
194+
create_zip_from_directory(zip_path, @driver_path) unless File.exist?(zip_path)
192195
@project.result_uploader.upload_file(zip_path, r_name)
193196
end
194197

@@ -235,7 +238,7 @@ def prepare_tests
235238

236239
def auto_run
237240
ResourceScope.open do |scope|
238-
run_studio scope
241+
run_studio(scope, boot_from_snapshot: @project.restored, reuse_tpm: @project.restored)
239242
sleep 5 until @studio.up?
240243

241244
run_tests_without_config

lib/engines/hcktest/playlist.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,21 @@ def intersect_select_tests(select_test_names)
9999
end
100100
end
101101

102+
def custom_select_test_names_file(file)
103+
test_names_file_path = "#{@project.workspace_path}/select_test_names.txt"
104+
return File.readlines(test_names_file_path, chomp: true) if File.exist?(test_names_file_path)
105+
106+
@logger.info('Copying custom select test names file to workspace')
107+
FileUtils.cp(file, test_names_file_path)
108+
end
109+
102110
def custom_select_test_names(log)
103111
user_select_test_names_file = @project.options.test.select_test_names
104112

105113
select_test_names = if user_select_test_names_file.nil?
106114
@project.engine.target['select_test_names']
107115
else
108-
File.readlines(user_select_test_names_file, chomp: true)
116+
custom_select_test_names_file(user_select_test_names_file)
109117
end
110118

111119
return unless select_test_names

lib/project.rb

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class Project
99
attr_reader :config, :logger, :timestamp, :setup_manager, :engine, :id,
1010
:workspace_path, :github, :result_uploader, :engine_tag,
1111
:engine_platform, :engine_type, :options, :extra_sw_manager,
12-
:run_terminated
12+
:run_terminated, :restored
1313

1414
def initialize(scope, options)
1515
@scope = scope
1616
@options = options
1717
Json.update_json_override(options.common.config) unless options.common.config.nil?
1818
init_multilog(options.common.verbose)
1919
init_class_variables
20-
init_workspace
20+
init_session
2121
@id = options.common.id
2222
scope << self
2323
end
@@ -157,23 +157,39 @@ def check_run_termination
157157
@github.handle_cancel
158158
end
159159

160-
def init_workspace
161-
unless @options.common.workspace_path.nil?
162-
@workspace_path = @options.common.workspace_path
163-
return
164-
end
160+
def load_session
161+
@workspace_path = @options.test.load_session
165162

163+
raise AutoHCKError, 'Workspace path does not exist could not load session' unless File.directory?(@workspace_path)
164+
165+
@logger.info("Loading session from #{@workspace_path}")
166+
end
167+
168+
def create_session
166169
@workspace_path = File.join(@config['workspace_path'],
167170
@engine_name,
168171
@engine_tag,
169172
@timestamp)
173+
170174
begin
171175
FileUtils.mkdir_p(@workspace_path)
172176
rescue Errno::EEXIST
173177
@logger.warn('Workspace path already exists')
174178
end
175179
@logger.info("Workspace path: #{@workspace_path}")
176180

181+
Session.save(@workspace_path, @options)
182+
end
183+
184+
def init_session
185+
unless @options.common.workspace_path.nil?
186+
@workspace_path = @options.common.workspace_path
187+
@restored = @options.test.load_session
188+
return
189+
end
190+
191+
@options.test.load_session ? load_session : create_session
192+
177193
begin
178194
File.delete("#{@config['workspace_path']}/latest")
179195
rescue Errno::ENOENT

lib/session.rb

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# frozen_string_literal: true
2+
3+
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength, Lint/MissingCopEnableDirective
4+
5+
module AutoHCK
6+
class Session
7+
def self.save(workspace_path, options)
8+
File.write("#{workspace_path}/session.json", compose_session_json(options))
9+
end
10+
11+
def self.load_session_cli(cli)
12+
json_data = JSON.parse(File.read("#{cli.test.load_session}/session.json"))
13+
cli.test.platform = json_data['test']['platform']
14+
cli.test.drivers = json_data['test']['drivers']
15+
cli.test.driver_path = json_data['test']['driver_path']
16+
cli.test.commit = json_data['test']['commit']
17+
cli.test.diff_file = json_data['test']['diff_file']
18+
cli.test.svvp = json_data['test']['svvp']
19+
cli.test.dump = json_data['test']['dump']
20+
cli.test.gthb_context_prefix = json_data['test']['gthb_context_prefix']
21+
cli.test.gthb_context_suffix = json_data['test']['gthb_context_suffix']
22+
cli.test.playlist = json_data['test']['playlist']
23+
cli.test.select_test_names = json_data['test']['select_test_names']
24+
cli.test.reject_test_names = json_data['test']['reject_test_names']
25+
cli.test.triggers_file = json_data['test']['triggers_file']
26+
cli.test.reject_report_sections = json_data['test']['reject_report_sections']
27+
cli.test.boot_device = json_data['test']['boot_device']
28+
cli.test.allow_test_duplication = json_data['test']['allow_test_duplication']
29+
cli.test.manual = json_data['test']['manual']
30+
cli.test.package_with_playlist = json_data['test']['package_with_playlist']
31+
cli.common.verbose = json_data['common']['verbose']
32+
cli.common.config = json_data['common']['config']
33+
cli.common.client_world_net = json_data['common']['client_world_net']
34+
cli.common.id = json_data['common']['id']
35+
cli.common.share_on_host_path = json_data['common']['share_on_host_path']
36+
end
37+
38+
private_class_method def self.compose_session_json(options)
39+
{
40+
'test' => {
41+
'platform' => options.test.platform,
42+
'drivers' => options.test.drivers,
43+
'driver_path' => options.test.driver_path,
44+
'commit' => options.test.commit,
45+
'diff_file' => options.test.diff_file,
46+
'svvp' => options.test.svvp,
47+
'dump' => options.test.dump,
48+
'gthb_context_prefix' => options.test.gthb_context_prefix,
49+
'gthb_context_suffix' => options.test.gthb_context_suffix,
50+
'playlist' => options.test.playlist,
51+
'select_test_names' => options.test.select_test_names,
52+
'reject_test_names' => options.test.reject_test_names,
53+
'triggers_file' => options.test.triggers_file,
54+
'reject_report_sections' => options.test.reject_report_sections,
55+
'boot_device' => options.test.boot_device,
56+
'allow_test_duplication' => options.test.allow_test_duplication,
57+
'manual' => options.test.manual,
58+
'package_with_playlist' => options.test.package_with_playlist
59+
},
60+
'common' => {
61+
'verbose' => options.common.verbose,
62+
'config' => options.common.config,
63+
'client_world_net' => options.common.client_world_net,
64+
'id' => options.common.id,
65+
'share_on_host_path' => options.common.share_on_host_path
66+
}
67+
}.to_json
68+
end
69+
end
70+
end

lib/setupmanagers/qemuhck/qemu_machine.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def close
154154
boot_from_snapshot: false,
155155
attach_iso_list: [],
156156
dump_only: false,
157-
secure: false
157+
secure: false,
158+
reuse_tpm: false
158159
}.freeze
159160

160161
MACHINE_JSON = 'lib/setupmanagers/qemuhck/machine.json'
@@ -581,6 +582,8 @@ def save_run_script(file_name, file_content)
581582

582583
def run_config_commands
583584
device_config_commands.each do |dirty_cmd|
585+
next if dirty_cmd.include?('@swtpm_setup_bin@') && @run_opts[:reuse_tpm]
586+
584587
cmd = full_replacement_map.create_cmd(dirty_cmd)
585588
run_cmd(cmd)
586589
end

0 commit comments

Comments
 (0)