1 # needs-profiler-support
3 # ISSUE(76038): When targeting MSVC, Rust binaries built with both `-Z instrument-coverage` and
4 # `-C link-dead-code` typically crash (with a seg-fault) or at best generate an empty `*.profraw`.
5 # See ../coverage/coverage_tools.mk for more information.
7 -include ../coverage/coverage_tools.mk
9 BASEDIR=../coverage-spanview-base
12 ifeq ($(UNAME),Darwin)
16 all: $(patsubst $(SOURCEDIR)/%.rs,%,$(wildcard $(SOURCEDIR)/*.rs))
18 # Ensure there are no `expected` results for tests that may have been removed or renamed
19 .PHONY: clear_expected_if_blessed
20 clear_expected_if_blessed:
21 ifdef RUSTC_BLESS_TEST
22 rm -rf expected_mir_dump.*/
25 -include clear_expected_if_blessed
28 # Compile the test program with coverage instrumentation and generate relevant MIR.
29 $(RUSTC) $(SOURCEDIR)/$@.rs \
30 -Zinstrument-coverage \
31 -Clink-dead-code=$(LINK_DEAD_CODE) \
32 -Zdump-mir=InstrumentCoverage \
34 -Zdump-mir-dir="$(TMPDIR)"/mir_dump.$@
37 # FIXME(richkadel): MacOS's default sed has some significant limitations. Until I've come up
38 # with a better workaround, I'm disabling this test for MacOS.
40 # For future reference, see if `gsed` is available as an alternative.
41 which gsed || echo "no gsed"
44 for path in "$(TMPDIR)"/mir_dump.$@/*; do \
46 file="$$(basename "$$path")"; \
48 urlescaped="$$("$(PYTHON)" $(BASEDIR)/escape_url.py $$file)" || exit $$?; \
53 Preview this file as rendered HTML from the github source at:\
54 https://htmlpreview.github.io/?https://github.com/rust-lang/rust/blob/master/src/test/run-make-fulldeps/coverage-spanview-base/expected_mir_dump.$@/'"$$urlescaped"'\
56 For revisions in Pull Requests (PR):\
57 * Replace "rust-lang" with the github PR author\
58 * Replace "master" with the PR branch name\
61 done && true # for/done ends in non-zero status
63 ifdef RUSTC_BLESS_TEST
64 mkdir -p expected_mir_dump.$@
65 cp "$(TMPDIR)"/mir_dump.$@/*InstrumentCoverage.0.html expected_mir_dump.$@/
67 # Check that the selected `mir_dump` files match what we expect (`--bless` refreshes `expected`)
68 mkdir -p "$(TMPDIR)"/actual_mir_dump.$@
69 rm -f "$(TMPDIR)"/actual_mir_dump.$@/*
70 cp "$(TMPDIR)"/mir_dump.$@/*InstrumentCoverage.0.html "$(TMPDIR)"/actual_mir_dump.$@/
71 $(DIFF) -r expected_mir_dump.$@/ "$(TMPDIR)"/actual_mir_dump.$@/