From 6ac8758e7eb42ca498b4dfa93672335344e920e5 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 7 May 2026 09:44:42 +0200 Subject: [PATCH 1/3] Generate coverage for tests --- .github/workflows/test-verific.yml | 26 +++++++++++++++++++++++++- Makefile | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-verific.yml b/.github/workflows/test-verific.yml index 132aac589..6e3284167 100644 --- a/.github/workflows/test-verific.yml +++ b/.github/workflows/test-verific.yml @@ -47,7 +47,7 @@ jobs: - name: Build Yosys run: | - make config-clang + make config-gcov echo "ENABLE_VERIFIC := 1" >> Makefile.conf echo "ENABLE_VERIFIC_EDIF := 1" >> Makefile.conf echo "ENABLE_VERIFIC_LIBERTY := 1" >> Makefile.conf @@ -85,6 +85,30 @@ jobs: run: | make -C sby run_ci + - name: Run coverage + if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} + run: | + make coverage + + - name: Push coverage + if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} + run: | + git clone https://x-access-token:${{ secrets.REPORTS_TOKEN }}@github.com/YosysHQ/reports.git out + rm -rf out/coverage/main + mkdir -p out/coverage/main + cp -r coverage_html/* out/coverage/main/ + cd out + # find . -name "*.html" -type f -print0 | xargs -0 sed -i -z 's#\(Date:[[:space:]]*\)[^<]*\(\)#\1\2#g' + git config user.name "yosyshq-ci" + git config user.email "105224853+yosyshq-ci@users.noreply.github.com" + git add . + if ! git diff --cached --quiet; then + git commit -m "Update coverage" + git push + else + echo "No changes to commit" + fi + test-pyosys: needs: pre_job if: ${{ needs.pre_job.outputs.should_skip != 'true' && github.repository_owner == 'YosysHQ' }} diff --git a/Makefile b/Makefile index 3c5c10cda..f6ba73375 100644 --- a/Makefile +++ b/Makefile @@ -1117,6 +1117,7 @@ coverage: ./$(PROGRAM_PREFIX)yosys -qp 'help; help -all' rm -rf coverage.info coverage_html lcov --capture -d . --no-external -o coverage.info + lcov --remove coverage.info '*/tests/various/*' '*/libs/*' -o coverage.info --ignore-errors unused genhtml coverage.info --output-directory coverage_html clean_coverage: From 8022b5445b5967ea7fd2065629d3574861a099c8 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 15 May 2026 11:59:22 +0200 Subject: [PATCH 2/3] Convert to using LLVM code coverage --- .github/workflows/test-verific.yml | 9 +++++++++ .gitignore | 4 ++-- Makefile | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test-verific.yml b/.github/workflows/test-verific.yml index 6e3284167..bdd35428a 100644 --- a/.github/workflows/test-verific.yml +++ b/.github/workflows/test-verific.yml @@ -44,6 +44,14 @@ jobs: - name: Runtime environment run: | echo "procs=$(nproc)" >> $GITHUB_ENV + mkdir -p "${GITHUB_WORKSPACE}/coverage" + echo "LLVM_PROFILE_FILE=${GITHUB_WORKSPACE}/coverage/coverage_%p.profraw" >> $GITHUB_ENV + echo "LLVM_PROFILE_FILE_BUFFER_SIZE=0" >> $GITHUB_ENV + + - name: Skip generating files + if: ${{ github.event_name != 'merge_group' && github.event_name != 'workflow_dispatch' }} + run: | + echo "LLVM_PROFILE_FILE=/dev/null" >> $GITHUB_ENV - name: Build Yosys run: | @@ -89,6 +97,7 @@ jobs: if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} run: | make coverage + make clean_coverage - name: Push coverage if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} diff --git a/.gitignore b/.gitignore index a8b04ac45..b39088088 100644 --- a/.gitignore +++ b/.gitignore @@ -65,10 +65,10 @@ /viz.js # other -/coverage.info +/yosys.profdata +/coverage /coverage_html - # these really belong in global gitignore since they're not specific to this project but rather to user tool choice # but too many people don't have a global gitignore configured: # https://docs.github.com/en/get-started/git-basics/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer diff --git a/Makefile b/Makefile index f6ba73375..3c9911c1c 100644 --- a/Makefile +++ b/Makefile @@ -456,8 +456,11 @@ endif endif ifeq ($(ENABLE_GCOV),1) -CXXFLAGS += --coverage -LINKFLAGS += --coverage +LLVM_PROFILE_FILE ?= $(realpath $(YOSYS_SRC))/coverage/coverage_%p.profraw +export LLVM_PROFILE_FILE +export LLVM_PROFILE_FILE_BUFFER_SIZE=0 +CXXFLAGS += -fprofile-instr-generate -fcoverage-mapping +LINKFLAGS+= -fprofile-instr-generate endif ifeq ($(ENABLE_GPROF),1) @@ -1115,13 +1118,13 @@ mrproper: clean coverage: ./$(PROGRAM_PREFIX)yosys -qp 'help; help -all' - rm -rf coverage.info coverage_html - lcov --capture -d . --no-external -o coverage.info - lcov --remove coverage.info '*/tests/various/*' '*/libs/*' -o coverage.info --ignore-errors unused - genhtml coverage.info --output-directory coverage_html + rm -rf coverage_html + llvm-profdata merge -sparse coverage/coverage_*.profraw -o yosys.profdata + llvm-cov show ./$(PROGRAM_PREFIX)yosys -instr-profile=yosys.profdata -format=html -output-dir=coverage_html --compilation-dir=. -ignore-filename-regex='(^|.*/)Verific/.*|(^|.*/)libs/.*' clean_coverage: - find . -name "*.gcda" -type f -delete + rm -rf coverage + rm -f yosys.profdata FUNC_KERNEL := functional.cc functional.h sexpr.cc sexpr.h compute_graph.h FUNC_INCLUDES := $(addprefix --include *,functional/* $(FUNC_KERNEL)) @@ -1183,7 +1186,7 @@ config-msys2-64: clean echo "PREFIX := $(MINGW_PREFIX)" >> Makefile.conf config-gcov: clean - echo 'CONFIG := gcc' > Makefile.conf + echo 'CONFIG := clang' > Makefile.conf echo 'ENABLE_GCOV := 1' >> Makefile.conf echo 'ENABLE_DEBUG := 1' >> Makefile.conf From 992eceaaa08ceb4a82e83f2ab286a05ea2057736 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 15 May 2026 12:53:04 +0200 Subject: [PATCH 3/3] Ignore configured location --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3c9911c1c..6fb79624f 100644 --- a/Makefile +++ b/Makefile @@ -1120,7 +1120,7 @@ coverage: ./$(PROGRAM_PREFIX)yosys -qp 'help; help -all' rm -rf coverage_html llvm-profdata merge -sparse coverage/coverage_*.profraw -o yosys.profdata - llvm-cov show ./$(PROGRAM_PREFIX)yosys -instr-profile=yosys.profdata -format=html -output-dir=coverage_html --compilation-dir=. -ignore-filename-regex='(^|.*/)Verific/.*|(^|.*/)libs/.*' + llvm-cov show ./$(PROGRAM_PREFIX)yosys -instr-profile=yosys.profdata -format=html -output-dir=coverage_html --compilation-dir=. -ignore-filename-regex='(^|.*/)libs/.*|/usr/include/.*|$(subst /,\/,$(VERIFIC_DIR))/.*' clean_coverage: rm -rf coverage