Skip to content

Commit

Permalink
Use driver struct instread of hash
Browse files Browse the repository at this point in the history
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Mar 5, 2024
1 parent 810536e commit 2d234b8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
13 changes: 8 additions & 5 deletions lib/engines/hckinstall/hckinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
require './lib/auxiliary/resource_scope'
require './lib/engines/hckinstall/setup_scripts_helper'

require './lib/models/driver'

# AutoHCK module
module AutoHCK
# HCKInstall class
Expand Down Expand Up @@ -154,7 +156,7 @@ def read_driver(driver)
driver_json = "#{DRIVERS_JSON_DIR}/#{driver}.json"

@logger.info("Loading driver: #{driver}")
Json.read_json(driver_json, @logger)
Models::Driver.from_json_file(driver_json, @logger)
rescue Errno::ENOENT
@logger.fatal("#{driver} does not exist")
raise(InvalidConfigFile, "#{driver} does not exist")
Expand All @@ -164,7 +166,7 @@ def find_drivers
@project.options.install.drivers.map do |short_name|
driver = read_driver(short_name)

driver['short'] = short_name
driver.short = short_name

driver
end
Expand All @@ -175,14 +177,15 @@ def drivers

@need_copy_drivers = false
drivers.each do |driver|
next if driver['install_method'] == 'no-drv'
next if driver.install_method == Models::DriverInstallMethods::NoDrviver

if driver['install_method'] == 'PNP' && File.exist?("#{@project.options.install.driver_path}/#{driver['inf']}")
if driver.install_method == Models::DriverInstallMethods::PNP &&
File.exist?("#{@project.options.install.driver_path}/#{driver.inf}")
@need_copy_drivers = true
next
end

msg = "Can't install #{driver['short']} driver for device #{driver['device']} in install mode"
msg = "Can't install #{driver.short} driver for device #{driver.device} in install mode"
@project.logger.fatal(msg)
raise(InvalidConfigFile, msg)
end
Expand Down
29 changes: 15 additions & 14 deletions lib/engines/hcktest/hcktest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
require './lib/auxiliary/resource_scope'
require './lib/auxiliary/zip_helper'

require './lib/models/driver'

# AutoHCK module
module AutoHCK
# HCKTest class
Expand Down Expand Up @@ -37,10 +39,10 @@ def initialize(project)

def prepare_extra_sw
@drivers.each do |driver|
next if driver['extra_software'].nil?
next if driver.extra_software.nil?

@project.extra_sw_manager.prepare_software_packages(
driver['extra_software'], @platform['kit'], ENGINE_MODE
driver.extra_software, @platform['kit'], ENGINE_MODE
)
end

Expand All @@ -65,15 +67,14 @@ def init_workspace
def validate_paths
normalize_paths
@drivers.each do |driver|
method = driver['install_method']
if method == 'no-drv'
@project.logger.info("Driver paths validation skipped for #{driver['name']}")
if driver.install_method == Models::DriverInstallMethods::NoDrviver
@project.logger.info("Driver paths validation skipped for #{driver.name}")
next
end

paths = [
"#{@driver_path}/#{driver['inf']}",
"#{@driver_path}/#{driver['short']}/#{driver['inf']}"
"#{@driver_path}/#{driver.inf}",
"#{@driver_path}/#{driver.short}/#{driver.inf}"
]
next if paths.any? { |p| File.exist?(p) }

Expand Down Expand Up @@ -102,7 +103,7 @@ def read_driver(driver)
driver_json = "#{DRIVERS_JSON_DIR}/#{driver}.json"

@logger.info("Loading driver: #{driver}")
Json.read_json(driver_json, @logger)
Models::Driver.from_json_file(driver_json, @logger)
rescue Errno::ENOENT
@logger.fatal("#{driver} does not exist")
raise(InvalidConfigFile, "#{driver} does not exist")
Expand All @@ -112,7 +113,7 @@ def find_drivers
driver_names.map do |short_name|
driver = read_driver(short_name)

driver['short'] = short_name
driver.short = short_name

driver
end
Expand All @@ -129,10 +130,10 @@ def target
else
driver = drivers.first
{
'name' => driver['name'],
'type' => driver['type'],
'select_test_names' => driver['select_test_names'],
'reject_test_names' => driver['reject_test_names']
'name' => driver.name,
'type' => driver.type,
'select_test_names' => driver.select_test_names,
'reject_test_names' => driver.reject_test_names
}
end
end
Expand Down Expand Up @@ -160,7 +161,7 @@ def run_clients(scope, run_opts = {})
@clients[client['name']] = @project.setup_manager.run_hck_client(scope, @studio, client['name'], run_opts)

break if @project.options.test.svvp
break unless @drivers.any? { |d| d['support'] }
break unless @drivers.any?(&:support)
end
return unless @clients.empty?

Expand Down
2 changes: 1 addition & 1 deletion lib/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def initialize(scope, options)
end

def diff_checker(drivers, diff, triggers)
diff_checker = DiffChecker.new(@logger, drivers.map { |d| d['short'] },
diff_checker = DiffChecker.new(@logger, drivers.map(&:short),
@options.test.driver_path, diff, triggers)
return true if diff_checker.trigger?

Expand Down
20 changes: 10 additions & 10 deletions lib/setupmanagers/hckclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def set_machine_ready

def run_pre_test_commands
@project.engine.drivers&.each do |driver|
driver['pretestcommands']&.each do |command|
desc = command['desc']
cmd = command['run']
driver.pretestcommands&.each do |command|
desc = command.desc
cmd = command.run

@logger.info("Running command (#{desc}) on client #{@name}")
@tools.run_on_machine(@name, desc, cmd)
Expand All @@ -99,19 +99,19 @@ def install_drivers
path = @project.options.test.driver_path

@project.engine.drivers&.each do |driver|
method = driver['install_method']
if method == 'no-drv'
@project.logger.info("Driver installation skipped for #{driver['name']} in #{@name}")
method = driver.install_method
if method == AutoHCK::Models::DriverInstallMethods::NoDrviver
@project.logger.info("Driver installation skipped for #{driver.name} in #{@name}")
next
end

inf = driver['inf']
inf = driver.inf

@logger.info("Installing #{method} driver #{inf} in #{@name}")
@tools.install_machine_driver_package(@name, method, path, inf,
custom_cmd: driver['install_command'],
sys_file: driver['sys'],
force_install_cert: driver['install_cert'])
custom_cmd: driver.install_command,
sys_file: driver.sys,
force_install_cert: driver.install_cert)
end
end

Expand Down
10 changes: 8 additions & 2 deletions lib/setupmanagers/qemuhck/qemuhck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def initialize_project(project)
@drivers = project.engine.drivers
@platform = project.engine.platform

@devices = @drivers&.map { |driver| driver['device'] }
@devices = @drivers&.map(&:device)
@kit = @platform['kit']
end

Expand All @@ -59,7 +59,13 @@ def drivers_options
options = {}
@drivers&.each do |driver|
OPT_NAMES.each do |name|
options[name] = driver[name] unless driver[name].nil?
options[name] = driver.send(name) unless driver.send(name).nil?
rescue NoMethodError
# We should ignore this exception because it means that the driver
# does not have the requested option. OPT_NAMES contains options
# from driver, platform, etc. So, it is normal that drivers do not
# have all the options.
next
end
end
options
Expand Down

0 comments on commit 2d234b8

Please sign in to comment.