Skip to content

Commit 7e1ff8a

Browse files
committed
WIP: Bring up previous session
1 parent f7ecd7f commit 7e1ff8a

File tree

8 files changed

+149
-17
lines changed

8 files changed

+149
-17
lines changed

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: 16 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, :session, :latest_session
8990

9091
def create_parser
9192
OptionParser.new do |parser|
@@ -187,6 +188,13 @@ 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('--session <path>', String,
193+
'Load session from workspace',
194+
&method(:session=))
195+
parser.on('--latest-session', TrueClass,
196+
'Load previous session',
197+
&method(:latest_session=))
190198
end
191199
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
192200
end
@@ -244,6 +252,12 @@ def parse(args)
244252
left = @parser.order(args)
245253
@mode = left.shift
246254
@sub_parser[@mode]&.order!(left) unless @mode.nil?
255+
256+
restore_session if @test.latest_session || @test.session
257+
end
258+
259+
def restore_session
260+
AutoHCK::Session.load(self)
247261
end
248262
end
249263
end

lib/engines/hcktest/hcktest.rb

Lines changed: 9 additions & 4 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,8 @@ 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,
242+
create_snapshot: !@project.restored)
239243
sleep 5 until @studio.up?
240244

241245
run_tests_without_config
@@ -262,7 +266,8 @@ def run_tests_with_config
262266
next if tests.empty?
263267

264268
ResourceScope.open do |scope|
265-
run_clients_and_configure_setup(scope, group => true, create_snapshot: false, boot_from_snapshot: true)
269+
run_clients_and_configure_setup(scope, group => true, create_snapshot: !@project.restored,
270+
boot_from_snapshot: @project.restored)
266271

267272
@logger.info("Clients ready, running #{group} tests")
268273
@tests.run(tests)

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/engines/hcktest/tools.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ def delete_project(tag)
135135
end
136136
end
137137

138+
def load_project(tag)
139+
retry_tools_command(__method__) do
140+
act_with_tools { _1.load_project(tag) }
141+
end
142+
end
143+
138144
def list_pools
139145
retry_tools_command(__method__) do
140146
act_with_tools(&:list_pools)

lib/project.rb

Lines changed: 27 additions & 8 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,31 +157,50 @@ 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 session
161+
@workspace_path = @options.test.session
162+
163+
raise AutoHCKError, 'Workspace path does not exist could not load session' unless File.directory?(@workspace_path)
165164

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.session
188+
return
189+
end
190+
191+
@options.test.session ? session : create_session
192+
add_latest_alias if @options.test.session.nil?
193+
@setup_manager_type&.enter @workspace_path
194+
end
195+
196+
def add_latest_alias
177197
begin
178198
File.delete("#{@config['workspace_path']}/latest")
179199
rescue Errno::ENOENT
180200
# firts run, no symlink to delete
181201
end
182202

183203
File.symlink(@workspace_path, "#{@config['workspace_path']}/latest")
184-
@setup_manager_type&.enter @workspace_path
185204
end
186205

187206
def handle_cancel

lib/session.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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(cli)
12+
json_data = JSON.parse(File.read("#{session_path(cli)}/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 = true
30+
cli.test.package_with_playlist = json_data['test']['package_with_playlist']
31+
cli.test.session = session_path(cli)
32+
cli.test.latest_session = json_data['test']['latest_session']
33+
cli.common.verbose = json_data['common']['verbose']
34+
cli.common.config = json_data['common']['config']
35+
cli.common.client_world_net = json_data['common']['client_world_net']
36+
cli.common.id = json_data['common']['id']
37+
cli.common.share_on_host_path = json_data['common']['share_on_host_path']
38+
end
39+
40+
def self.session_path(cli)
41+
cli.test.latest_session ? "#{Config.read['workspace_path']}/latest" : cli.test.session
42+
end
43+
44+
private_class_method def self.compose_session_json(options)
45+
{
46+
'test' => {
47+
'platform' => options.test.platform,
48+
'drivers' => options.test.drivers,
49+
'driver_path' => options.test.driver_path,
50+
'commit' => options.test.commit,
51+
'diff_file' => options.test.diff_file,
52+
'svvp' => options.test.svvp,
53+
'dump' => options.test.dump,
54+
'gthb_context_prefix' => options.test.gthb_context_prefix,
55+
'gthb_context_suffix' => options.test.gthb_context_suffix,
56+
'playlist' => options.test.playlist,
57+
'select_test_names' => options.test.select_test_names,
58+
'reject_test_names' => options.test.reject_test_names,
59+
'triggers_file' => options.test.triggers_file,
60+
'reject_report_sections' => options.test.reject_report_sections,
61+
'boot_device' => options.test.boot_device,
62+
'allow_test_duplication' => options.test.allow_test_duplication,
63+
'manual' => options.test.manual,
64+
'package_with_playlist' => options.test.package_with_playlist
65+
},
66+
'common' => {
67+
'verbose' => options.common.verbose,
68+
'config' => options.common.config,
69+
'client_world_net' => options.common.client_world_net,
70+
'id' => options.common.id,
71+
'share_on_host_path' => options.common.share_on_host_path
72+
}
73+
}.to_json
74+
end
75+
end
76+
end

lib/setupmanagers/qemuhck/qemu_machine.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ def close
150150
DEFAULT_RUN_OPTIONS = {
151151
keep_alive: false,
152152
first_time: false,
153-
create_snapshot: true,
153+
create_snapshot: false,
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)