Tizen 2.1 base
[external/device-mapper.git] / report-generators / lib / schedule_file.rb
1 # Copyright (C) 2010 Red Hat, Inc. All rights reserved.
2 #
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
6 #
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10
11 # Parses the simple colon delimited test schedule files.
12
13 ScheduledTest = Struct.new(:desc, :command_line, :status, :output)
14
15 class Schedule
16   attr_reader :dir, :schedules
17
18   def initialize(dir, ss)
19     @dir = dir
20     @schedules = ss
21   end
22
23   def run
24     Dir::chdir(@dir.to_s) do
25       @schedules.each do |s|
26         reader, writer = IO.pipe
27         print "#{s.desc} ... "
28         pid = spawn(s.command_line, [ STDERR, STDOUT ] => writer)
29         writer.close
30         _, s.status = Process::waitpid2(pid)
31         puts (s.status.success? ? "pass" : "fail")
32         s.output = reader.read
33       end
34     end
35   end
36
37   def self.read(dir, io)
38     ss = Array.new
39
40     io.readlines.each do |line|
41       case line.strip
42       when /^\#.*/
43         next
44
45       when /([^:]+):(.*)/
46         ss << ScheduledTest.new($1.strip, $2.strip)
47
48       else
49         raise RuntimeError, "badly formatted schedule line"
50       end  
51     end
52
53     Schedule.new(dir, ss)
54   end
55 end
56