1 # needs-profiler-support
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"
13 UNAME
= $(shell uname
)
15 ifeq ($(UNAME
),Darwin
)
16 INSTR_PROF_DATA_SUFFIX
=,regular
,live_support
17 DATA_SECTION_PREFIX
=__DATA
,
18 LLVM_COV_SECTION_PREFIX
=__LLVM_COV
,
20 INSTR_PROF_DATA_SUFFIX
=
22 LLVM_COV_SECTION_PREFIX
=
25 # This test makes sure that LLVM coverage maps are genereated in LLVM IR.
27 COMMON_FLAGS
=-Zinstrument-coverage
30 # Compile the test program with instrumentation, and also generate LLVM IR
31 $(RUSTC
) $(COMMON_FLAGS
) testprog.rs \
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"
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"
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 \
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
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
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
81 ifdef RUSTC_BLESS_TEST
82 cp
"$(TMPDIR)"/actual_show_coverage.txt typical_show_coverage.txt
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)'
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 \
93 --instr-profile
="$(TMPDIR)"/testprog.profdata \
94 $(call BIN
,"$(TMPDIR)"/testprog
) \
95 |
"$(PYTHON)" prettify_json.py \
96 > "$(TMPDIR)"/actual_export_coverage.json
98 ifdef RUSTC_BLESS_TEST
99 cp
"$(TMPDIR)"/actual_export_coverage.json expected_export_coverage.json
101 # Check that the exported JSON coverage data matches what we expect
102 $(DIFF
) expected_export_coverage.json
"$(TMPDIR)"/actual_export_coverage.json