|
| 1 | +""" |
| 2 | +Check that the integration instrumentation handles correctly filenames that |
| 3 | +contain spaces. |
| 4 | +""" |
| 5 | + |
| 6 | +import os |
| 7 | +import os.path |
| 8 | + |
| 9 | +from e3.fs import cp |
| 10 | + |
| 11 | +from SUITE.control import env |
| 12 | +from SUITE.cutils import Wdir |
| 13 | +from SCOV.minicheck import check_xcov_reports |
| 14 | +from SUITE.tutils import cmdrun, srctracename_for, thistest, xcov |
| 15 | + |
| 16 | +Wdir("tmp_") |
| 17 | + |
| 18 | +# Copy the sources in the temporary directory. Note that we cannot test the |
| 19 | +# case of a filename containing a double quote or a backslash on Windows |
| 20 | +# because of filename restrictions on that platform. |
| 21 | +copy_map = { |
| 22 | + "bar.c": 'src bar.c' if env.build.os.name == "windows" else 'src\\"bar.c', |
| 23 | + |
| 24 | + "test.c": "test.c", |
| 25 | +} |
| 26 | +for src, dest in copy_map.items(): |
| 27 | + cp(os.path.join("..", src), dest) |
| 28 | + |
| 29 | +# Compute the expected coverage report from the actual source filenames. Note |
| 30 | +# that in xcov filenames, "gnatcov coverage" first turns '\' to '/' (during |
| 31 | +# path separator canonicalization) and then the unique filename machinery turns |
| 32 | +# '/' to '-'. |
| 33 | +coverage_data = { |
| 34 | + "test.c": {"+": {7, 8, 9}}, |
| 35 | + "foo.c": {"+": {4, 7}, "-": {5}}, |
| 36 | + "bar.c": {"+": {4}}, |
| 37 | +} |
| 38 | +expected_report = { |
| 39 | + "{}.xcov".format(copy_map[filename].replace("\\", "-")): report |
| 40 | + for filename, report in coverage_data.items() |
| 41 | +} |
| 42 | + |
| 43 | +# Setup the instrumentation process |
| 44 | +sources = [os.path.abspath(filename) for filename in copy_map.values()] |
| 45 | +files = [f"--files={filename}" for filename in sources] |
| 46 | +xcov( |
| 47 | + ["setup-integration", "--level=stmt", "--compilers=gcc", "--output-dir=."] |
| 48 | + + files |
| 49 | +) |
| 50 | + |
| 51 | +# Shadow the compiler driver with the generated wrapper |
| 52 | +env.add_search_path(env_var="PATH", path=os.getcwd()) |
| 53 | + |
| 54 | +# Build the test program and run it |
| 55 | +cmdrun(["gcc", "-o", "test program"] + sources, for_pgm=False) |
| 56 | +cmdrun(["test program"], for_pgm=False) |
| 57 | + |
| 58 | +# Check coverage expectations |
| 59 | +sid_args = [f"--sid={filename}.sid" for filename in sources] |
| 60 | +xcov( |
| 61 | + ["coverage", "-cstmt", "-axcov", srctracename_for("test")] |
| 62 | + + sid_args |
| 63 | +) |
| 64 | +check_xcov_reports("*.xcov", expected_report) |
| 65 | + |
| 66 | +thistest.result() |
0 commit comments