3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-07-14 11:15:40 +00:00

Add initial codecov support

This commit is contained in:
Miodrag Milanovic 2026-07-10 12:19:59 +02:00
parent b88b73a99a
commit f2f3f31646
5 changed files with 36 additions and 33 deletions

View file

@ -47,22 +47,18 @@ jobs:
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
echo "SEED=0" >> $GITHUB_ENV
- name: Build Yosys
run: |
rm -rf build Configuration.cmake
rm -rf build Configuration.cmake coverage
echo 'set(CMAKE_C_COMPILER clang CACHE STRING "")' >> Configuration.cmake
echo 'set(CMAKE_CXX_COMPILER clang++ CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_COMPILER_LAUNCHER ccache CACHE STRING "")' >> Configuration.cmake
echo 'set(YOSYS_ENABLE_COVERAGE ON CACHE BOOL "")' >> Configuration.cmake
echo 'set(YOSYS_VERIFIC_DIR "/usr/local/src/verific_lib" CACHE STRING "")' >> Configuration.cmake
cmake -C Configuration.cmake -B build . -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON -DCMAKE_BUILD_TYPE=Debug
cmake -C Configuration.cmake -B build . -DCMAKE_INSTALL_PREFIX=${GITHUB_WORKSPACE}/.local -DCMAKE_BUILD_TYPE=Debug
cmake --build build -j$procs
- name: Install Yosys
@ -80,6 +76,10 @@ jobs:
run: |
make -C sby install DESTDIR=${GITHUB_WORKSPACE}/.local PREFIX=
- name: Run unit tests
run: |
ctest --test-dir build/tests/unit --output-on-failure
- name: Run Yosys tests
run: |
make -C tests -j$procs vanilla-test
@ -89,35 +89,29 @@ jobs:
make -C tests/sva
make -C tests/svtypes
- name: Run SBY tests
if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
run: |
make -C sby run_ci
- name: Run coverage
if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
run: |
make -C tests coverage
make -C tests clean_coverage
- name: Push coverage
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: YosysHQ/yosys
files: build/coverage.info
disable_search: true
override_branch: ${{ github.event_name == 'merge_group' && github.event.merge_group.base_ref || github.ref_name }}
- name: Skip generating files
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#\(<td class="headerItem">Date:</td>[[:space:]]*<td class="headerValue">\)[^<]*\(</td>\)#\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
echo "LLVM_PROFILE_FILE=/dev/null" >> $GITHUB_ENV
- name: Run SBY tests
if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }}
run: |
make -C sby run_ci
test-pyosys:
needs: pre_job

View file

@ -126,7 +126,7 @@ if (YOSYS_ENABLE_COVERAGE)
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-instr-generate -fcoverage-mapping -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-inline -fno-inline-small-functions -fno-default-inline")
else()
message(FATAL_ERROR "Code coverage is not supported on ${CMAKE_CXX_COMPILER_ID} compiler")
endif()

8
codecov.yml Normal file
View file

@ -0,0 +1,8 @@
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true

View file

@ -126,10 +126,11 @@ clean:
.PHONY: coverage
coverage:
@echo "Creating coverage HTML"
@echo "Creating coverage HTML & Codecov report"
@$(YOSYS) -qp 'help; help -all'
@rm -rf $(COVERAGE_HTML)
@llvm-profdata merge -sparse $(COVERAGE_DIR)/coverage_*.profraw -o $(COVERAGE_DIR)/yosys.profdata
@llvm-cov export $(YOSYS) -instr-profile=$(COVERAGE_DIR)/yosys.profdata -format=lcov --compilation-dir=$(SRC_DIR) --ignore-filename-regex='(^|.*/)libs/.*|/usr/include/.*|$(subst /,\/,$(VERIFIC_DIR))/.*' > $(BUILD_DIR)/coverage.info
@llvm-cov show $(YOSYS) -instr-profile=$(COVERAGE_DIR)/yosys.profdata -format=html -output-dir=$(COVERAGE_HTML) --compilation-dir=$(SRC_DIR) --ignore-filename-regex='(^|.*/)libs/.*|/usr/include/.*|$(subst /,\/,$(VERIFIC_DIR))/.*'
.PHONY: clean_coverage

View file

@ -204,12 +204,12 @@ def create_bram(dsc_f, sim_f, ref_f, tb_f, k1, k2, or_next):
v_stmts.append(" %s" % s)
v_stmts.append("end")
print("module bram_%02d_%02d(%s);" % (k1, k2, ", ".join(v_ports)), file=sim_f)
print("module bram_%02d_%02d(%s);" % (k1, k2, ", ".join(sorted(v_ports))), file=sim_f)
for stmt in v_stmts:
print(" %s" % stmt, file=sim_f)
print("endmodule", file=sim_f)
print("module bram_%02d_%02d_ref(%s);" % (k1, k2, ", ".join(v_ports)), file=ref_f)
print("module bram_%02d_%02d_ref(%s);" % (k1, k2, ", ".join(sorted(v_ports))), file=ref_f)
for stmt in v_stmts:
print(" %s" % stmt, file=ref_f)
print("endmodule", file=ref_f)