8 def delete_snapshot(snapshot)
9 if snapshot and File.exist?(snapshot)
12 rescue Errno::EACCES => e
13 STDERR.puts "Couldn't delete background snapshot: #{e.to_s}"
16 def delete_all_snapshots
17 Dir.glob("#{$tmp_dir}/*.state").each do |snapshot|
18 delete_snapshot(snapshot)
22 BeforeFeature('@product') do |feature|
23 if File.exist?($tmp_dir)
24 if !File.directory?($tmp_dir)
25 raise "Temporary directory '#{$tmp_dir}' exists but is not a " +
28 if !File.owned?($tmp_dir)
29 raise "Temporary directory '#{$tmp_dir}' must be owned by the " +
32 FileUtils.chmod(0755, $tmp_dir)
36 rescue Errno::EACCES => e
37 raise "Cannot create temporary directory: #{e.to_s}"
40 delete_all_snapshots if !$keep_snapshots
42 raise "No Tails ISO image specified, and none could be found in the " +
45 if File.exist?($tails_iso)
46 # Workaround: when libvirt takes ownership of the ISO image it may
47 # become unreadable for the live user inside the guest in the
48 # host-to-guest share used for some tests.
50 if !File.world_readable?($tails_iso)
51 if File.owned?($tails_iso)
52 File.chmod(0644, $tails_iso)
54 raise "warning: the Tails ISO image must be world readable or be " +
55 "owned by the current user to be available inside the guest " +
56 "VM via host-to-guest shares, which is required by some tests"
60 raise "The specified Tails ISO image '#{$tails_iso}' does not exist"
62 puts "Testing ISO image: #{File.basename($tails_iso)}"
63 base = File.basename(feature.file, ".feature").to_s
64 $background_snapshot = "#{$tmp_dir}/#{base}_background.state"
67 AfterFeature('@product') do
68 delete_snapshot($background_snapshot) if !$keep_snapshots
69 VM.storage.clear_volumes if VM.storage
72 BeforeFeature('@product', '@old_iso') do
73 if $old_tails_iso.nil?
74 raise "No old Tails ISO image specified, and none could be found in the " +
77 if !File.exist?($old_tails_iso)
78 raise "The specified old Tails ISO image '#{$old_tails_iso}' does not exist"
80 if $tails_iso == $old_tails_iso
81 raise "The old Tails ISO is the same as the Tails ISO we're testing"
83 puts "Using old ISO image: #{File.basename($old_tails_iso)}"
88 @screen = Sikuli::Screen.new
89 if File.size?($background_snapshot)
90 @skip_steps_while_restoring_background = true
92 @skip_steps_while_restoring_background = false
99 After('@product') do |scenario|
100 if (scenario.status != :passed)
101 time_of_fail = Time.now - $time_at_start
102 secs = "%02d" % (time_of_fail % 60)
103 mins = "%02d" % ((time_of_fail / 60) % 60)
104 hrs = "%02d" % (time_of_fail / (60*60))
105 STDERR.puts "Scenario failed at time #{hrs}:#{mins}:#{secs}"
106 base = File.basename(scenario.feature.file, ".feature").to_s
107 tmp = @screen.capture.getFilename
108 out = "#{$tmp_dir}/#{base}-#{DateTime.now}.png"
109 FileUtils.mv(tmp, out)
110 STDERR.puts("Took screenshot \"#{out}\"")
113 STDERR.puts "Press ENTER to continue running the test suite"
124 After('@product', '~@keep_volumes') do
125 VM.storage.clear_volumes
134 @git_clone = Dir.mktmpdir 'tails-apt-tests'
141 FileUtils.remove_entry_secure @git_clone
148 BeforeFeature('@product', '@source') do |feature|
149 raise "Feature #{feature.file} is tagged both @product and @source, " +
150 "which is an impossible combination"
154 delete_all_snapshots if !$keep_snapshots
155 VM.storage.clear_pool if VM.storage