summaryrefslogtreecommitdiffstats
path: root/report-generators/memcheck.rb
diff options
context:
space:
mode:
authorJoe Thornber <thornber@redhat.com>2010-07-20 14:38:44 +0000
committerJoe Thornber <thornber@redhat.com>2010-07-20 14:38:44 +0000
commit1033d120404c0e41ced5f36361e412ac03a3461f (patch)
tree8776b2d0770ad642176c9e079987e621251f1e23 /report-generators/memcheck.rb
parent60f425d1b3508d71883ac1a4501f6ab7f3e32b08 (diff)
downloadlvm2-1033d120404c0e41ced5f36361e412ac03a3461f.tar.gz
lvm2-1033d120404c0e41ced5f36361e412ac03a3461f.tar.xz
lvm2-1033d120404c0e41ced5f36361e412ac03a3461f.zip
Report generators for unit tests and memory checks. Configure with
--enable-testing.
Diffstat (limited to 'report-generators/memcheck.rb')
-rw-r--r--report-generators/memcheck.rb76
1 files changed, 76 insertions, 0 deletions
diff --git a/report-generators/memcheck.rb b/report-generators/memcheck.rb
new file mode 100644
index 00000000..fcc8927e
--- /dev/null
+++ b/report-generators/memcheck.rb
@@ -0,0 +1,76 @@
+# Reads the schedule files given on the command line. Runs them and
+# generates the reports.
+
+# FIXME: a lot of duplication with unit_test.rb
+
+require 'schedule_file'
+require 'pathname'
+require 'reports'
+require 'erb'
+require 'report_templates'
+
+include ReportTemplates
+
+schedules = ARGV.map do |f|
+ p = Pathname.new(f)
+ Schedule.read(p.dirname, p)
+end
+
+total_passed = 0
+total_failed = 0
+
+# We need to make sure the lvm shared libs are in the LD_LIBRARY_PATH
+ENV['LD_LIBRARY_PATH'] = `pwd`.strip + "/libdm:" + (ENV['LD_LIBRARY_PATH'] || '')
+
+ENV['TEST_TOOL'] = "valgrind --leak-check=full --show-reachable=yes"
+
+schedules.each do |s|
+ s.run
+
+ s.schedules.each do |t|
+ if t.status.success?
+ total_passed += 1
+ else
+ total_failed += 1
+ end
+ end
+end
+
+def mangle(txt)
+ txt.gsub(/\s+/, '_')
+end
+
+MemcheckStats = Struct.new(:definitely_lost, :indirectly_lost, :possibly_lost, :reachable)
+
+def format(bytes, blocks)
+ "#{bytes} bytes, #{blocks} blocks"
+end
+
+# Examines the output for details of leaks
+def extract_stats(t)
+ d = i = p = r = '-'
+
+ t.output.split("\n").each do |l|
+ case l
+ when /==\d+== definitely lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
+ d = format($1, $2)
+ when /==\d+== indirectly lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
+ i = format($1, $2)
+ when /==\d+== possibly lost: ([0-9,]+) bytes in ([0-9,]+) blocks/
+ p = format($1, $2)
+ when /==\d+== still reachable: ([0-9,]+) bytes in ([0-9,]+) blocks/
+ r = format($1, $2)
+ end
+ end
+
+ MemcheckStats.new(d, i, p, r)
+end
+
+generate_report(:memcheck, binding)
+
+# now we generate a detail report for each schedule
+schedules.each do |s|
+ s.schedules.each do |t|
+ generate_report(:unit_detail, binding, Pathname.new("reports/memcheck_#{mangle(t.desc)}.html"))
+ end
+end