Commit 21d38bcd authored by kytv's avatar kytv
Browse files

Refactor

parent 5135d118
......@@ -18,17 +18,24 @@ When /^I set the system time to "([^"]+)"$/ do |time|
"'#{expected_time_lower_bound}' but is '#{new_time}'")
end
When /^I bump the system time with "([^"]+)"$/ do |timediff|
When /^I bump the (hardware clock's|system) time with "([^"]+)"$/ do |clock_type, timediff|
next if @skip_steps_while_restoring_background
old_time = DateTime.parse(@vm.execute_successfully("date").stdout).to_time
@vm.execute_successfully("date -s 'now #{timediff}'")
new_time = DateTime.parse(@vm.execute_successfully("date").stdout).to_time
case clock_type
when "hardware clock's"
old_time = DateTime.parse(@vm.execute_successfully("hwclock -r").stdout).to_time
@vm.execute_successfully("hwclock --set --date 'now #{timediff}'")
new_time = DateTime.parse(@vm.execute_successfully("hwclock -r").stdout).to_time
when 'system'
old_time = DateTime.parse(@vm.execute_successfully("date").stdout).to_time
@vm.execute_successfully("date -s 'now #{timediff}'")
new_time = DateTime.parse(@vm.execute_successfully("date").stdout).to_time
end
expected_time_lower_bound = DateTime.parse(
cmd_helper(["date", "-d", "#{old_time} #{timediff}"])).to_time
expected_time_upper_bound = expected_time_lower_bound + max_time_drift
assert(expected_time_lower_bound <= new_time &&
new_time <= expected_time_upper_bound,
"The guest's time was supposed to be bumped to " \
"The #{clock_type} time was supposed to be bumped to " \
"'#{expected_time_lower_bound}' but is '#{new_time}'")
end
......@@ -72,20 +79,6 @@ Then /^the hardware clock was not updated when Tails shut down$/ do
assert(diff <= max_time_drift)
end
When /^I bump the hardware clock's time with "([^"]+)"$/ do |timediff|
next if @skip_steps_while_restoring_background
old_time = DateTime.parse(@vm.execute_successfully("hwclock -r").stdout).to_time
@vm.execute_successfully("hwclock --set --date 'now #{timediff}'")
new_time = DateTime.parse(@vm.execute_successfully("hwclock -r").stdout).to_time
expected_time_lower_bound = DateTime.parse(
cmd_helper(["date", "-d", "#{old_time} #{timediff}"])).to_time
expected_time_upper_bound = expected_time_lower_bound + max_time_drift
assert(expected_time_lower_bound <= new_time &&
new_time <= expected_time_upper_bound,
"The host's hwclock was supposed to be bumped to " \
"'#{expected_time_lower_bound}' but is '#{new_time}'")
end
Then /^the hardware clock is still off by "([^"]+)"$/ do |timediff|
next if @skip_steps_while_restoring_background
hwclock = DateTime.parse(@vm.execute_successfully("hwclock -r").stdout.chomp).to_time
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment