Tizen 2.1 base
[external/device-mapper.git] / report-generators / memcheck.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 # Reads the schedule files given on the command line.  Runs them and
12 # generates the reports.
13
14 # FIXME: a lot of duplication with unit_test.rb
15
16 require 'schedule_file'
17 require 'pathname'
18 require 'reports'
19 require 'erb'
20 require 'report_templates'
21
22 include ReportTemplates
23
24 schedules = ARGV.map do |f|
25   p = Pathname.new(f)
26   Schedule.read(p.dirname, p)
27 end
28
29 total_passed = 0
30 total_failed = 0
31
32 # We need to make sure the lvm shared libs are in the LD_LIBRARY_PATH
33 ENV['LD_LIBRARY_PATH'] = `pwd`.strip + "/libdm:" + (ENV['LD_LIBRARY_PATH'] || '')
34
35 ENV['TEST_TOOL'] = "valgrind --leak-check=full --show-reachable=yes"
36
37 schedules.each do |s|
38   s.run
39
40   s.schedules.each do |t|
41     if t.status.success?
42       total_passed += 1
43     else
44       total_failed += 1
45     end
46   end
47 end
48
49 def mangle(txt)
50   txt.gsub(/\s+/, '_')
51 end
52
53 MemcheckStats = Struct.new(:definitely_lost, :indirectly_lost, :possibly_lost, :reachable)
54
55 def format(bytes, blocks)
56   "#{bytes} bytes, #{blocks} blocks"
57 end
58
59 # Examines the output for details of leaks
60 def extract_stats(t)
61   d = i = p = r = '-'
62
63   t.output.split("\n").each do |l|
64     case l
65     when /==\d+==    definitely lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
66         d = format($1, $2)
67     when /==\d+==    indirectly lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
68         i = format($1, $2)
69     when /==\d+==    possibly lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
70         p = format($1, $2)
71     when /==\d+==    still reachable: ([0-9,]+) bytes in ([0-9,]+) blocks/
72         r = format($1, $2)
73     end
74   end
75
76   MemcheckStats.new(d, i, p, r)
77 end
78
79 generate_report(:memcheck, binding)
80
81 # now we generate a detail report for each schedule
82 schedules.each do |s|
83   s.schedules.each do |t|
84     generate_report(:unit_detail, binding, Pathname.new("reports/memcheck_#{mangle(t.desc)}.html"))
85   end
86 end