Skip to content

Commit

Permalink
CI: generate data for coverview
Browse files Browse the repository at this point in the history
  • Loading branch information
kgugala committed Jan 1, 2025
1 parent c329ad9 commit 3b3844e
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 52 deletions.
161 changes: 161 additions & 0 deletions .github/scripts/prepare_coverage_data.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
set -e
set -o pipefail

cat <<EOF >> split.py
import sys
files = {}
active_file = None
with open(sys.argv[1], 'r') as file:
for line in file:
if line[0:1] == "#":
continue
elif line[0:3] == "SF:":
active_file = line.replace("\n", "").split(":")[1]
files[active_file] = {}
files[active_file]["da"] = []
files[active_file]["brda"] = []
files[active_file]["brf"] = 0
files[active_file]["brh"] = 0
elif line[0:3] == "DA:":
files[active_file]["da"].append(line.replace("\n", "").split(":")[1:])
elif line[0:5] == "BRDA:":
files[active_file]["brda"].append(line.replace("\n", "").split(":")[1:])
elif line[0:4] == "BRF:":
files[active_file]["brf"] = int(line.replace("\n", "").split(":")[1])
elif line[0:4] == "BRH:":
files[active_file]["brh"] = int(line.replace("\n", "").split(":")[1])
elif "end_of_record" in line:
active_file = None
if sys.argv[2] == "--branch":
print("TN:verilator_coverage")
for f in files:
print("SF:%s" % f)
for brda in files[f]["brda"]:
brda_line = brda[0].split(",")[0]
for da in files[f]["da"]:
da_line = da[0].split(",")[0]
if da_line == brda_line:
print("DA:%s" % (",".join(da)))
files[f]["da"].remove(da)
print("BRDA:%s" % (",".join(brda)))
print("end_of_record")
elif sys.argv[2] == "--line":
print("TN:verilator_coverage")
for f in files:
print("SF:%s" % f)
for da in files[f]["da"]:
da_line = da[0].split(",")[0]
found = False
for brda in files[f]["brda"]:
brda_line = brda[0].split(",")[0]
if da_line == brda_line:
found = True
if not found:
print("DA:%s" % (",".join(da)))
print("end_of_record")
sys.exit(0)
EOF

cat <<EOF >> preprocess.py
import sys
filter = None
in_file = False
if sys.argv[2] == "--filter":
filter = sys.argv[3]
print("TN:verilator_coverage")
with open(sys.argv[1], 'r') as file:
for line in file:
line = line.replace("\n", "")
if line[0:3] == "SF:":
if filter == None or line.startswith("SF:%s" % filter):
in_file = True
print(line)
continue
else:
in_file = False
continue
if not in_file:
continue
if "end_of_record" in line:
in_file = False
print(line)
continue
if line[0:1] == "#":
print(line)
elif line[0:3] == "DA:":
data = line.split(",")
line = "%s,%d" % (data[0], int(data[1]) > 0)
print(line)
elif line[0:5] == "BRDA:":
data = line.split(",")
line = "%s,%s,%s,%d" % (data[0],data[1],data[2], int(data[3]) > 0)
print(line)
else:
print(line)
EOF

mkdir info_files
mv *.info info_files
cd info_files
git clone https://github.com/linux-test-project/lcov -b v2.3-beta
PATH="`pwd`/lcov/bin:$PATH"

ls *_toggle.info | xargs printf -- '-a %s\n' | xargs echo | awk '{ print "lcov "$0" --ignore-errors inconsistent --rc lcov_branch_coverage=1 -o coverage_toggle_verilator.info" }' | bash
ls *_branch.info | xargs printf -- '-a %s\n' | xargs echo | awk '{ print "lcov "$0" --ignore-errors inconsistent --rc lcov_branch_coverage=1 -o coverage_line_verilator.info" }' | bash

cp coverage_toggle_verilator.info ../
cp coverage_line_verilator.info ../

cd ../
rm -rf info_files

mv coverage_line_verilator.info line.info
python3 split.py line.info --branch > coverage_branch_verilator.info
python3 split.py line.info --line > coverage_line_verilator.info

find . -type f -name 'coverage_*.info' -exec sed -i 's_^SF:.*Cores-VeeR-EL2/_SF:_g' {} \;

python3 preprocess.py coverage_line_verilator.info --filter "design/" > _coverage_line.info
python3 preprocess.py coverage_toggle_verilator.info --filter "design/" > _coverage_toggle.info
python3 preprocess.py coverage_branch_verilator.info --filter "design/" > _coverage_branch.info

cp _coverage_line.info coverage_line_verilator.info
cp _coverage_branch.info coverage_branch_verilator.info
cp _coverage_toggle.info coverage_toggle_verilator.info

grep 'SF:' coverage_*.info | cut -d ":" -f 3 | sort | uniq > files.txt

export BRANCH=$GITHUB_HEAD_REF
export COMMIT=$GITHUB_SHA
{
while read file
do
if [ -f $file ]; then
echo "### FILE: $file"
cat "$file"
else
echo "### SKIPPING: $file"
fi
done
} < files.txt > sources.txt

mkdir test_data
cp coverage_line_*.info coverage_toggle_*.info coverage_branch_* sources.txt test_data

# add logo
cp docs/dashboard-styles/assets/chips-alliance-logo-mono.svg test_data/logo.svg

# add config.json
echo -n '{ "datasets": { "verilator": { "line": "coverage_line_verilator.info", "branch": "coverage_branch_verilator.info", "toggle": "coverage_toggle_verilator.info" } }, "title": "VeeR EL2 coverage dashboard", "commit": "' > test_data/config.json
echo -n $COMMIT >> test_data/config.json
echo -n '", "branch": "' >> test_data/config.json
echo -n $BRANCH >> test_data/config.json
echo -n '", "repo": "cores-veer-el2", "timestamp": "' >> test_data/config.json
echo -n `date +"%Y-%m-%dT%H:%M:%S.%3N%z"` >> test_data/config.json
echo -n '" }' >> test_data/config.json

cat test_data/config.json

cd test_data
zip ../data.zip *
cd ..
8 changes: 8 additions & 0 deletions .github/workflows/publish-webpage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ jobs:
- name: Update webpage
if: github.event_name != 'pull_request'
run: |
mv coverage_dashboard/*.zip .
sis -d webpage \
--include-documentation \
--doc-project-name "Cores VeeR EL2" \
Expand All @@ -79,11 +80,15 @@ jobs:
rm -rf public.new/html/main/docs_rendered
mkdir -p public.new/html/main/docs_rendered
mv ./docs_rendered/* public.new/html/main/docs_rendered
mv data.zip public.new/html/main/
mv data_v.zip public.new/html/main/
echo ${GITHUB_RUN_ID} > public.new/html/main/run_id
tar -acf webpage.tar.gz public.new
- name: Update webpage PR
if: github.event_name == 'pull_request'
run: |
mv coverage_dashboard/*.zip .
sis -d webpage \
--include-documentation \
--doc-project-name "Cores VeeR EL2" \
Expand All @@ -94,6 +99,9 @@ jobs:
rm -rf public.new/html/dev/${{ github.event.number }}/docs_rendered
mkdir -p public.new/html/dev/${{ github.event.number }}/docs_rendered
mv ./docs_rendered/* public.new/html/dev/${{ github.event.number }}/docs_rendered
mv data.zip public.new/html/dev/${{ github.event.number }}/
mv data_v.zip public.new/html/dev/${{ github.event.number }}/
echo ${GITHUB_RUN_ID} > public.new/html/dev/${{ github.event.number }}/run_id
tar -acf webpage.tar.gz public.new
- name: Add redirect index page
Expand Down
139 changes: 87 additions & 52 deletions .github/workflows/report-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,16 @@ on:

jobs:

coverage-report:
name: Coverage report
merge-verilator-reports:
name: Merge Verilator info data
runs-on: ubuntu-latest
container: ghcr.io/antmicro/cores-veer-el2:20241230
env:
DEBIAN_FRONTEND: "noninteractive"

steps:
- name: Setup repository
uses: actions/checkout@v3

- name: Install coverage dependencies
shell: bash
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install -r .github/scripts/requirements-coverage.txt
echo "PATH=$PATH" >> $GITHUB_ENV
# This step is needed to have the same VeeR codebase as used in tests
- name: Configure VeeR
shell: bash
run: |
export RV_ROOT=`pwd`
make defines.h -f $RV_ROOT/tools/Makefile
- name: Setup lcov
shell: bash
run: |
git clone https://github.com/linux-test-project/lcov
pushd lcov
git checkout v2.1
echo "LCOV_PATH=`realpath bin`" >> "$GITHUB_ENV"
popd
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Download coverage reports
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -76,38 +52,66 @@ jobs:
name: openocd_coverage_data
path: ./

- name: Generate reports
- name: Merge data
shell: bash
run: |
export PATH=${{ env.LCOV_PATH }}:${PATH}
sis -d reports . --report-dir report --src-pattern \*design\*
cat *_toggle.info > coverage.toggle.info
cat *_branch.info > coverage.branch.info
sudo apt update
sudo apt install -y zip unzip
.github/scripts/prepare_coverage_data.sh
- name: Pack artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage_report
path: ./report
name: verilator_coverage_data
path: |
coverage_toggle_verilator.info
coverage_line_verilator.info
coverage_branch_verilator.info
- name: Pack artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: combined_coverage_data
name: coverview_data
path: |
coverage.toggle.info
coverage.branch.info
data.zip
merge-verilator-reports:
name: Merge Verilator info data
coverage-report:
name: Coverage report
runs-on: ubuntu-latest
container: ghcr.io/antmicro/cores-veer-el2:20241230
needs: [merge-verilator-reports, custom-coverage-report]
env:
DEBIAN_FRONTEND: "noninteractive"

steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup repository
uses: actions/checkout@v3

- name: Install coverage dependencies
shell: bash
run: |
python3 -m venv .venv
source .venv/bin/activate
pip install -r .github/scripts/requirements-coverage.txt
echo "PATH=$PATH" >> $GITHUB_ENV
# This step is needed to have the same VeeR codebase as used in tests
- name: Configure VeeR
shell: bash
run: |
export RV_ROOT=`pwd`
make defines.h -f $RV_ROOT/tools/Makefile
- name: Setup lcov
shell: bash
run: |
git clone https://github.com/linux-test-project/lcov
pushd lcov
git checkout v2.1
echo "LCOV_PATH=`realpath bin`" >> "$GITHUB_ENV"
popd
- name: Download coverage reports
uses: actions/download-artifact@v3
Expand Down Expand Up @@ -145,22 +149,47 @@ jobs:
name: openocd_coverage_data
path: ./

- name: Merge data
- name: Download coverage reports
uses: actions/download-artifact@v3
with:
name: coverview_data
path: ./

- name: Download coverage reports
uses: actions/download-artifact@v3
with:
name: data_v
path: ./

- name: Generate reports
shell: bash
run: |
git clone https://github.com/linux-test-project/lcov -b v2.3-beta
PATH="`pwd`/lcov/bin:$PATH"
ls *_toggle.info | xargs printf -- '-a %s\n' | xargs echo | awk '{ print "lcov "$0" --rc lcov_branch_coverage=1 -o coverage_toggle_verilator.info" }' | bash
ls *_line.info | xargs printf -- '-a %s\n' | xargs echo | awk '{ print "lcov "$0" -o coverage_line_verilator.info" }' | bash
sudo apt update
sudo apt install -y zip unzip
export PATH=${{ env.LCOV_PATH }}:${PATH}
sis -d reports . --report-dir report --src-pattern \*design\*
cp data.zip report
cp data_v.zip report
cat *_toggle.info > coverage.toggle.info
cat *_branch.info > coverage.branch.info
- name: Pack artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: verilator_coverage_data
name: coverage_report
path: ./report

- name: Pack artifacts
if: always()
uses: actions/upload-artifact@v3
with:
name: combined_coverage_data
path: |
coverage_toggle_verilator.info
coverage_line_verilator.info
coverage.toggle.info
coverage.branch.info
custom-coverage-report:
name: Custom coverage report
Expand All @@ -187,3 +216,9 @@ jobs:

- name: Generate custom report
run: _secret_custom_report

- name: Pack artifacts
uses: actions/upload-artifact@v3
with:
name: data_v
path: ./data_v.zip

0 comments on commit 3b3844e

Please sign in to comment.