aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-11-15 11:51:08 +0000
committerKostya Serebryany <kcc@google.com>2013-11-15 11:51:08 +0000
commit106cb08a2457444e2d66404917ed3bd31b3c0726 (patch)
tree613c643ea7b4d19ffd1729fdd8223f4ae2795142
parent6a58b0078a94195f963fede873068d7a0982c509 (diff)
downloadcompiler-rt-106cb08a2457444e2d66404917ed3bd31b3c0726.tar.gz
[asan] helper script to dump/merge coverage data
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@194809 91177308-0d34-0410-b5e6-96231b3b80d8
-rwxr-xr-xlib/sanitizer_common/scripts/sancov.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/sanitizer_common/scripts/sancov.py b/lib/sanitizer_common/scripts/sancov.py
new file mode 100755
index 000000000..aa791bc4e
--- /dev/null
+++ b/lib/sanitizer_common/scripts/sancov.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+# Merge or print the coverage data collected by asan's coverage.
+# Input files are sequences of 4-byte integers.
+# We need to merge these integers into a set and then
+# either print them (as hex) or dump them into another file.
+import array
+import sys
+
+prog_name = "";
+
+def Usage():
+ print >> sys.stderr, "Usage: \n" + \
+ " " + prog_name + " merge file1 [file2 ...] > output\n" \
+ " " + prog_name + " print file1 [file2 ...]\n"
+ exit(1)
+
+def ReadOneFile(path):
+ f = open(path, mode="rb")
+ f.seek(0, 2)
+ size = f.tell()
+ f.seek(0, 0)
+ s = set(array.array('I', f.read(size)))
+ f.close()
+ print >>sys.stderr, "%s: read %d PCs from %s" % (prog_name, size / 4, path)
+ return s
+
+def Merge(files):
+ s = set()
+ for f in files:
+ s = s.union(ReadOneFile(f))
+ print >> sys.stderr, "%s: %d files merged; %d PCs total" % \
+ (prog_name, len(files), len(s))
+ return sorted(s)
+
+def PrintFiles(files):
+ s = Merge(files)
+ for i in s:
+ print "0x%x" % i
+
+def MergeAndPrint(files):
+ if sys.stdout.isatty():
+ Usage()
+ s = Merge(files)
+ a = array.array('I', s)
+ a.tofile(sys.stdout)
+
+if __name__ == '__main__':
+ prog_name = sys.argv[0]
+ if len(sys.argv) <= 2:
+ Usage();
+ if sys.argv[1] == "print":
+ PrintFiles(sys.argv[2:])
+ elif sys.argv[1] == "merge":
+ MergeAndPrint(sys.argv[2:])
+ else:
+ Usage()