Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / tools / scan-build-py / tests / functional / cases / __init__.py
bloba6a293f73d156b1077caa02058a6cc88d7ba8642
1 # -*- coding: utf-8 -*-
2 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3 # See https://llvm.org/LICENSE.txt for license information.
4 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 import re
7 import os.path
8 import subprocess
11 def load_tests(loader, suite, pattern):
12 from . import test_from_cdb
14 suite.addTests(loader.loadTestsFromModule(test_from_cdb))
15 from . import test_from_cmd
17 suite.addTests(loader.loadTestsFromModule(test_from_cmd))
18 from . import test_create_cdb
20 suite.addTests(loader.loadTestsFromModule(test_create_cdb))
21 from . import test_exec_anatomy
23 suite.addTests(loader.loadTestsFromModule(test_exec_anatomy))
24 return suite
27 def make_args(target):
28 this_dir, _ = os.path.split(__file__)
29 path = os.path.abspath(os.path.join(this_dir, "..", "src"))
30 return [
31 "make",
32 "SRCDIR={}".format(path),
33 "OBJDIR={}".format(target),
34 "-f",
35 os.path.join(path, "build", "Makefile"),
39 def silent_call(cmd, *args, **kwargs):
40 kwargs.update({"stdout": subprocess.PIPE, "stderr": subprocess.STDOUT})
41 return subprocess.call(cmd, *args, **kwargs)
44 def silent_check_call(cmd, *args, **kwargs):
45 kwargs.update({"stdout": subprocess.PIPE, "stderr": subprocess.STDOUT})
46 return subprocess.check_call(cmd, *args, **kwargs)
49 def call_and_report(analyzer_cmd, build_cmd):
50 child = subprocess.Popen(
51 analyzer_cmd + ["-v"] + build_cmd,
52 universal_newlines=True,
53 stdout=subprocess.PIPE,
54 stderr=subprocess.STDOUT,
57 pattern = re.compile("Report directory created: (.+)")
58 directory = None
59 for line in child.stdout.readlines():
60 match = pattern.search(line)
61 if match and match.lastindex == 1:
62 directory = match.group(1)
63 break
64 child.stdout.close()
65 child.wait()
67 return (child.returncode, directory)
70 def check_call_and_report(analyzer_cmd, build_cmd):
71 exit_code, result = call_and_report(analyzer_cmd, build_cmd)
72 if exit_code != 0:
73 raise subprocess.CalledProcessError(exit_code, analyzer_cmd + build_cmd, None)
74 else:
75 return result
78 def create_empty_file(filename):
79 with open(filename, "a") as handle:
80 pass