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
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
))
27 def make_args(target
):
28 this_dir
, _
= os
.path
.split(__file__
)
29 path
= os
.path
.abspath(os
.path
.join(this_dir
, "..", "src"))
32 "SRCDIR={}".format(path
),
33 "OBJDIR={}".format(target
),
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: (.+)")
59 for line
in child
.stdout
.readlines():
60 match
= pattern
.search(line
)
61 if match
and match
.lastindex
== 1:
62 directory
= match
.group(1)
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
)
73 raise subprocess
.CalledProcessError(exit_code
, analyzer_cmd
+ build_cmd
, None)
78 def create_empty_file(filename
):
79 with
open(filename
, "a") as handle
: