]> git.lizzy.rs Git - rust.git/blob - src/test/run-make-fulldeps/instrument-coverage/Makefile
Rollup merge of #75485 - RalfJung:pin, r=nagisa
[rust.git] / src / test / run-make-fulldeps / instrument-coverage / Makefile
1 # needs-profiler-support
2 # ignore-msvc
3
4 # FIXME(richkadel): Debug the following problem, and reenable on Windows (by
5 # removing the `# ignore-msvc` directive above). The current implementation
6 # generates a segfault when running the instrumented `testprog` executable,
7 # after the `main()` function completes, but before the process terminates.
8 # This most likely points to a problem generating the LLVM "testprog.profraw"
9 # file.
10
11 -include ../tools.mk
12
13 UNAME = $(shell uname)
14
15 ifeq ($(UNAME),Darwin)
16         INSTR_PROF_DATA_SUFFIX=,regular,live_support
17         DATA_SECTION_PREFIX=__DATA,
18         LLVM_COV_SECTION_PREFIX=__LLVM_COV,
19 else
20         INSTR_PROF_DATA_SUFFIX=
21         DATA_SECTION_PREFIX=
22         LLVM_COV_SECTION_PREFIX=
23 endif
24
25 # This test makes sure that LLVM coverage maps are genereated in LLVM IR.
26
27 COMMON_FLAGS=-Zinstrument-coverage
28
29 all:
30         # Compile the test program with instrumentation, and also generate LLVM IR
31         $(RUSTC) $(COMMON_FLAGS) testprog.rs \
32                         --emit=link,llvm-ir
33
34         # check the LLVM IR
35 ifdef IS_WIN32
36         cat "$(TMPDIR)"/testprog.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt \
37                         -check-prefixes=CHECK,WIN32 \
38                         -DPRIVATE_GLOBAL="internal global" \
39                         -DINSTR_PROF_DATA=".lprfd$$M" \
40                         -DINSTR_PROF_NAME=".lprfn$$M" \
41                         -DINSTR_PROF_CNTS=".lprfc$$M" \
42                         -DINSTR_PROF_VALS=".lprfv$$M" \
43                         -DINSTR_PROF_VNODES=".lprfnd$$M" \
44                         -DINSTR_PROF_COVMAP=".lcovmap$$M" \
45                         -DINSTR_PROF_ORDERFILE=".lorderfile$$M"
46 else
47         cat "$(TMPDIR)"/testprog.ll | "$(LLVM_FILECHECK)" filecheck-patterns.txt \
48                         -check-prefixes=CHECK \
49                         -DPRIVATE_GLOBAL="private global" \
50                         -DINSTR_PROF_DATA="$(DATA_SECTION_PREFIX)__llvm_prf_data$(INSTR_PROF_DATA_SUFFIX)" \
51                         -DINSTR_PROF_NAME="$(DATA_SECTION_PREFIX)__llvm_prf_names" \
52                         -DINSTR_PROF_CNTS="$(DATA_SECTION_PREFIX)__llvm_prf_cnts" \
53                         -DINSTR_PROF_VALS="$(DATA_SECTION_PREFIX)__llvm_prf_vals" \
54                         -DINSTR_PROF_VNODES="$(DATA_SECTION_PREFIX)__llvm_prf_vnds" \
55                         -DINSTR_PROF_COVMAP="$(LLVM_COV_SECTION_PREFIX)__llvm_covmap" \
56                         -DINSTR_PROF_ORDERFILE="$(DATA_SECTION_PREFIX)__llvm_orderfile"
57 endif
58
59         # Run it in order to generate some profiling data,
60         # with `LLVM_PROFILE_FILE=<profdata_file>` environment variable set to
61         # output the coverage stats for this run.
62         LLVM_PROFILE_FILE="$(TMPDIR)"/testprog.profraw \
63                         $(call RUN,testprog)
64
65         # Postprocess the profiling data so it can be used by the llvm-cov tool
66         "$(LLVM_BIN_DIR)"/llvm-profdata merge --sparse \
67                         "$(TMPDIR)"/testprog.profraw \
68                         -o "$(TMPDIR)"/testprog.profdata
69
70         # Generate a coverage report using `llvm-cov show`. The output ordering
71         # can be non-deterministic, so ignore the return status. If the test fails
72         # when comparing the JSON `export`, the `show` output may be useful when
73         # debugging.
74         "$(LLVM_BIN_DIR)"/llvm-cov show \
75                         --Xdemangler="$(RUST_DEMANGLER)" \
76                         --show-line-counts-or-regions \
77                         --instr-profile="$(TMPDIR)"/testprog.profdata \
78                         $(call BIN,"$(TMPDIR)"/testprog) \
79                 > "$(TMPDIR)"/actual_show_coverage.txt
80
81 ifdef RUSTC_BLESS_TEST
82         cp "$(TMPDIR)"/actual_show_coverage.txt typical_show_coverage.txt
83 else
84         # Compare the show coverage output
85         $(DIFF) typical_show_coverage.txt "$(TMPDIR)"/actual_show_coverage.txt || \
86                 >&2 echo 'diff failed for `llvm-cov show` (might not be an error)'
87 endif
88
89         # Generate a coverage report in JSON, using `llvm-cov export`, and fail if
90         # there are differences from the expected output.
91         "$(LLVM_BIN_DIR)"/llvm-cov export \
92                         --summary-only \
93                         --instr-profile="$(TMPDIR)"/testprog.profdata \
94                         $(call BIN,"$(TMPDIR)"/testprog) \
95                 | "$(PYTHON)" prettify_json.py \
96                 > "$(TMPDIR)"/actual_export_coverage.json
97
98 ifdef RUSTC_BLESS_TEST
99         cp "$(TMPDIR)"/actual_export_coverage.json expected_export_coverage.json
100 else
101         # Check that the exported JSON coverage data matches what we expect
102         $(DIFF) expected_export_coverage.json "$(TMPDIR)"/actual_export_coverage.json
103 endif