Skip to content

Commit 0ba68bc

Browse files
committed
Add ability to bring up previous session
Signed-off-by: Vitalii Chulak <[email protected]>
1 parent e542404 commit 0ba68bc

File tree

10 files changed

+177
-33
lines changed

10 files changed

+177
-33
lines changed

lib/all.rb

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

lib/cli.rb

Lines changed: 55 additions & 16 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
@@ -20,8 +21,15 @@ def initialize
2021
end
2122

2223
# class CommonOptions
23-
class CommonOptions
24-
attr_accessor :verbose, :config, :client_world_net, :id, :share_on_host_path, :workspace_path
24+
class CommonOptions < T::Struct
25+
include T::Sig
26+
27+
prop :verbose, T.nilable(T::Boolean), default: false
28+
prop :config, T.nilable(String)
29+
prop :client_world_net, T.nilable(T::Boolean), default: false
30+
prop :id, T.nilable(Integer), default: 2
31+
prop :share_on_host_path, T.nilable(String)
32+
prop :workspace_path, T.nilable(String)
2533

2634
def create_parser(sub_parser)
2735
OptionParser.new do |parser|
@@ -40,12 +48,6 @@ def create_parser(sub_parser)
4048

4149
# rubocop:disable Metrics/MethodLength
4250
def define_options(parser)
43-
@verbose = false
44-
@config = nil
45-
@client_world_net = false
46-
@id = 2
47-
@share_on_host_path = nil
48-
4951
parser.on('--share-on-host-path <path>', String,
5052
'For using Transfer Network specify the directory to share on host machine') do |share_on_host_path|
5153
@share_on_host_path = share_on_host_path
@@ -81,11 +83,27 @@ def define_options(parser)
8183
end
8284

8385
# class TestOptions
84-
class TestOptions
85-
attr_accessor :platform, :drivers, :driver_path, :commit, :svvp, :dump,
86-
:gthb_context_prefix, :gthb_context_suffix, :playlist, :select_test_names,
87-
:reject_test_names, :reject_report_sections, :boot_device,
88-
:allow_test_duplication, :manual, :package_with_playlist
86+
class TestOptions < T::Struct
87+
include T::Sig
88+
89+
prop :platform, T.nilable(String)
90+
prop :drivers, T.nilable(T::Array[String])
91+
prop :driver_path, T.nilable(String)
92+
prop :commit, T.nilable(String)
93+
prop :svvp, T.nilable(T::Boolean)
94+
prop :dump, T.nilable(T::Boolean)
95+
prop :gthb_context_prefix, T.nilable(String)
96+
prop :gthb_context_suffix, T.nilable(String)
97+
prop :playlist, T.nilable(String)
98+
prop :select_test_names, T.nilable(String)
99+
prop :reject_test_names, T.nilable(String)
100+
prop :reject_report_sections, T.nilable(T::Array[String]), default: []
101+
prop :boot_device, T.nilable(String)
102+
prop :allow_test_duplication, T.nilable(T::Boolean)
103+
prop :manual, T.nilable(T::Boolean)
104+
prop :package_with_playlist, T.nilable(T::Boolean)
105+
prop :session, T.nilable(String)
106+
prop :latest_session, T.nilable(T::Boolean)
89107

90108
def create_parser
91109
OptionParser.new do |parser|
@@ -179,13 +197,28 @@ def define_options(parser)
179197
parser.on('--package-with-playlist', TrueClass,
180198
'Load playlist into HLKX project package',
181199
&method(:package_with_playlist=))
200+
201+
parser.on('--session <path>', String,
202+
'Load session from workspace',
203+
&method(:session=))
204+
205+
parser.on('--latest-session', TrueClass,
206+
'Load previous session',
207+
&method(:latest_session=))
182208
end
183209
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
184210
end
185211

186212
# class InstallOptions
187-
class InstallOptions
188-
attr_accessor :platform, :force, :skip_client, :drivers, :driver_path, :debug
213+
class InstallOptions < T::Struct
214+
include T::Sig
215+
216+
prop :platform, T.nilable(String)
217+
prop :force, T::Boolean, default: false
218+
prop :skip_client, T::Boolean, default: false
219+
prop :drivers, T::Array[String], default: []
220+
prop :driver_path, T.nilable(String)
221+
prop :debug, T::Boolean, default: false
189222

190223
def create_parser
191224
OptionParser.new do |parser|
@@ -236,6 +269,12 @@ def parse(args)
236269
left = @parser.order(args)
237270
@mode = left.shift
238271
@sub_parser[@mode]&.order!(left) unless @mode.nil?
272+
273+
restore_session if @test.latest_session || @test.session
274+
end
275+
276+
def restore_session
277+
AutoHCK::Session.load(self)
239278
end
240279
end
241280
end

lib/engines/hcktest/hcktest.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ def run_clients_post_start_host_commands
160160
end
161161

162162
def configure_and_synchronize_clients
163-
run_only = @project.options.test.manual && @project.options.test.driver_path.nil?
163+
run_only = @project.restored || (@project.options.test.manual && @project.options.test.driver_path.nil?)
164164

165165
@clients.each_value do |client|
166166
client.configure(run_only:)
167167
end
168168

169-
run_clients_post_start_host_commands
169+
run_clients_post_start_host_commands unless @project.restored
170170
@clients.each_value(&:synchronize)
171171
end
172172

@@ -183,7 +183,7 @@ def run_clients_and_configure_setup(scope, **opts)
183183
retries = 0
184184
begin
185185
scope.transaction do |tmp_scope|
186-
run_clients tmp_scope, keep_alive: true, **opts
186+
run_clients tmp_scope, keep_alive: true, **opts, **restored_options
187187

188188
configure_setup_and_synchronize
189189
end
@@ -201,7 +201,7 @@ def upload_driver_package
201201

202202
r_name = "#{@project.engine_tag}.zip"
203203
zip_path = "#{@project.workspace_path}/#{r_name}"
204-
create_zip_from_directory(zip_path, @driver_path)
204+
create_zip_from_directory(zip_path, @driver_path) unless File.exist?(zip_path)
205205
@project.result_uploader.upload_file(zip_path, r_name)
206206
end
207207

@@ -245,9 +245,15 @@ def prepare_tests
245245
@test_list = @tests.list_tests(log: true)
246246
end
247247

248+
def restored_options
249+
{ boot_from_snapshot: @project.restored,
250+
reuse_tpm: @project.restored,
251+
create_snapshot: !@project.restored }
252+
end
253+
248254
def auto_run
249255
ResourceScope.open do |scope|
250-
run_studio scope
256+
run_studio(scope, **restored_options)
251257
sleep 5 until @studio.up?
252258

253259
run_tests_without_config
@@ -274,7 +280,7 @@ def run_tests_with_config
274280
next if tests.empty?
275281

276282
ResourceScope.open do |scope|
277-
run_clients_and_configure_setup(scope, group => true, create_snapshot: false, boot_from_snapshot: true)
283+
run_clients_and_configure_setup(scope, group => true)
278284

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

lib/models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Models
1111
autoload_relative :HCKTestConfig, 'models/hcktest_config'
1212
autoload_relative :JsonHelper, 'models/json_helper'
1313
autoload_relative :SVVPConfig, 'models/svvp_config'
14+
autoload_relative :Session, 'models/session'
1415
autoload_relative :QemuHCKDevice, 'models/qemuhck_device'
1516
end
1617
end

lib/models/session.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# typed: strict
2+
# frozen_string_literal: true
3+
4+
module AutoHCK
5+
module Models
6+
class Session < T::Struct
7+
extend T::Sig
8+
extend JsonHelper
9+
10+
const :test, AutoHCK::CLI::TestOptions
11+
const :common, T.nilable(AutoHCK::CLI::CommonOptions)
12+
end
13+
end
14+
end

lib/project.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ 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
@@ -145,12 +145,15 @@ def check_run_termination
145145
@github.handle_cancel
146146
end
147147

148-
def init_workspace
149-
unless @options.common.workspace_path.nil?
150-
@workspace_path = @options.common.workspace_path
151-
return
152-
end
148+
def session
149+
@workspace_path = @options.test.session
153150

151+
raise AutoHCKError, 'Workspace path does not exist could not load session' unless File.directory?(@workspace_path)
152+
153+
@logger.info("Loading session from #{@workspace_path}")
154+
end
155+
156+
def create_session
154157
@workspace_path = File.join(@config['workspace_path'],
155158
@engine_name,
156159
@engine_tag,
@@ -162,14 +165,29 @@ def init_workspace
162165
end
163166
@logger.info("Workspace path: #{@workspace_path}")
164167

168+
Session.save(@workspace_path, @options)
169+
end
170+
171+
def init_workspace
172+
@restored = @options.test.session
173+
unless @options.common.workspace_path.nil?
174+
@workspace_path = @options.common.workspace_path
175+
return
176+
end
177+
178+
@options.test.session ? session : create_session
179+
add_latest_symlink if @options.test.session.nil?
180+
@setup_manager_type&.enter @workspace_path
181+
end
182+
183+
def add_latest_symlink
165184
begin
166185
File.delete("#{@config['workspace_path']}/latest")
167186
rescue Errno::ENOENT
168187
# firts run, no symlink to delete
169188
end
170189

171190
File.symlink(@workspace_path, "#{@config['workspace_path']}/latest")
172-
@setup_manager_type&.enter @workspace_path
173191
end
174192

175193
def handle_cancel

lib/session.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
# rubocop:disable Metrics/AbcSize,Metrics/MethodLength, Lint/MissingCopEnableDirective, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
4+
5+
module AutoHCK
6+
class Session
7+
extend T::Sig
8+
include Helper
9+
10+
def self.save(workspace_path, options)
11+
File.write("#{workspace_path}/session.json", compose_session_json(options))
12+
end
13+
14+
def self.load(cli)
15+
session = Models::Session.from_json_file("#{session_path(cli)}/session.json")
16+
17+
cli.test.platform = session.test.platform
18+
cli.test.drivers = session.test.drivers
19+
cli.test.driver_path ||= session.test.driver_path
20+
cli.test.commit ||= session.test.commit
21+
cli.test.svvp = session.test.svvp
22+
cli.test.dump ||= session.test.dump
23+
cli.test.gthb_context_prefix ||= session.test.gthb_context_prefix
24+
cli.test.gthb_context_suffix ||= session.test.gthb_context_suffix
25+
cli.test.playlist ||= session.test.playlist
26+
cli.test.select_test_names ||= session.test.select_test_names
27+
cli.test.reject_test_names ||= session.test.reject_test_names
28+
cli.test.reject_report_sections ||= session.test.reject_report_sections
29+
cli.test.boot_device ||= session.test.boot_device
30+
cli.test.allow_test_duplication ||= session.test.allow_test_duplication
31+
cli.test.manual ||= true
32+
cli.test.package_with_playlist |= session.test.package_with_playlist
33+
cli.test.session = session_path(cli)
34+
cli.test.latest_session ||= session.test.latest_session
35+
cli.common.verbose ||= session.common.verbose
36+
cli.common.config ||= session.common.config
37+
cli.common.client_world_net ||= session.common.client_world_net
38+
cli.common.id ||= session.common.id
39+
cli.common.share_on_host_path ||= session.common.share_on_host_path
40+
end
41+
42+
def self.session_path(cli)
43+
cli.test.latest_session ? "#{Config.read['workspace_path']}/latest" : cli.test.session
44+
end
45+
46+
private_class_method def self.compose_session_json(options)
47+
{
48+
test: options.test.serialize,
49+
common: options.common.serialize
50+
}.to_json
51+
end
52+
end
53+
end

lib/setupmanagers/hckclient.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def prepare_machine
150150
def configure(run_only: false)
151151
@tools = @studio.tools
152152
@cooldown_thread = Thread.new do
153-
unless pool == @project.engine_tag
154-
return_when_client_up
153+
if @project.restored || pool != @project.engine_tag
154+
return_when_client_up unless @project.restored
155155
if run_only
156156
@logger.info("Preparing client skipped #{@name}...")
157157

lib/setupmanagers/hckstudio.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ def configure(clients)
8080
connect
8181
verify_tools
8282
update_filters
83+
return if @project.restored
84+
8385
create_pool
8486
create_project
8587
end

lib/setupmanagers/qemuhck/qemu_machine.rb

Lines changed: 12 additions & 2 deletions
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'
@@ -329,7 +330,16 @@ def options_replacement_map
329330

330331
sig { returns(T::Array[String]) }
331332
def device_config_commands
332-
@device_infos.map(&:config_commands).flatten.compact
333+
filter_commands(@device_infos.map(&:config_commands).flatten.compact)
334+
end
335+
336+
def filter_commands(commands)
337+
commands.reject do |cmd|
338+
if cmd.include?('@swtpm_setup_bin@') && @run_opts[:reuse_tpm]
339+
@logger.warn('Skipping SWTPM installation')
340+
true
341+
end
342+
end
333343
end
334344

335345
sig { returns(T::Array[String]) }

0 commit comments

Comments
 (0)