This repository was archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvalgrind.py
executable file
·82 lines (59 loc) · 2.19 KB
/
valgrind.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/env python3
import subprocess
import json
from functools import partial
from os import path
import os
from pathlib import Path
ignored = ["sessions", "libsignal-protocol-c-tests", "skeptic"]
PROJECT_ROOT = Path(__file__).parent.parent
CARGO_TOML = PROJECT_ROOT.joinpath("libsignal-protocol", "Cargo.toml")
def examples(target_dir: Path):
"""
Use `cargo manifest` to find the executable that corresponds to each of
the library's examples.
"""
manifest = get_manifest()
for pkg in manifest["packages"]:
if pkg["name"] == "libsignal-protocol":
targets = pkg["targets"]
for target in targets:
if "example" in target["kind"] and target["name"] not in ignored:
yield target_dir.joinpath("debug", "examples", target["name"])
def get_manifest():
args = ["cargo", "metadata", "--no-deps", "--format-version=1",
"--manifest-path", str(CARGO_TOML)]
output = subprocess.check_output(args)
return json.loads(output.decode("utf-8"))
def integration_tests():
"""
Get the executable corresponding to the crate's tests (excluding doc-tests).
"""
args = ["cargo", "test", "--tests", "--no-run", "--message-format=json",
"--manifest-path", str(CARGO_TOML)]
output = subprocess.check_output(args)
stdout = output.decode("utf-8")
for line in stdout.splitlines():
line = json.loads(line)
target = line.get("target")
if not target:
continue
is_test = "test" in target["kind"]
not_ignored = target["name"] not in ignored
if line["reason"] == "compiler-artifact" and is_test and not_ignored:
yield line["executable"]
def run_valgrind(original_cmd):
args = ["valgrind", "--leak-check=full", "--show-leak-kinds=all",
"--error-exitcode=1"]
args.extend(original_cmd)
env = os.environ.copy()
env["RUST_BACKTRACE"] = "full"
subprocess.check_call(args, env=env)
def main():
binaries = []
binaries.extend(examples(Path("target")))
binaries.extend(integration_tests())
for binary in binaries:
run_valgrind([str(binary)])
if __name__ == "__main__":
main()