forked from chipsalliance/i3c-core
-
Notifications
You must be signed in to change notification settings - Fork 1
482 lines (424 loc) · 18.1 KB
/
tests-and-docs.yml
File metadata and controls
482 lines (424 loc) · 18.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# SPDX-License-Identifier: Apache-2.0
#
# I3C Core - Parallel Test and Documentation Workflow
#
# This workflow runs cocotb verification tests in parallel for both AHB and AXI
# bus configurations, then builds and deploys documentation.
#
# Architecture:
# 1. generate-matrix: Uses nox's JSON output to discover test sessions
# 2. tests-ahb: Runs all AHB-tagged tests in parallel (one job per test)
# 3. tests-axi: Runs all AXI-tagged tests in parallel (one job per test)
# 4. test-results: Aggregates results from all test jobs
# 5. docs-build: Builds and deploys documentation (only after tests pass)
#
# Optional: Long-running tests (i3c_ahb_verify, i3c_axi_verify) can be split
# into individual parametrized runs by enabling SPLIT_TESTS in generate-matrix.
#
# The parallel execution reduces total CI time from ~80 minutes to ~25 minutes.
name: Run Tests
on:
push:
pull_request:
permissions:
contents: write
env:
DEBIAN_FRONTEND: "noninteractive"
VERILATOR_VERSION: "v5.024"
WAVES: "0"
jobs:
# ===========================================================================
# Job: Generate Test Matrix
# ===========================================================================
# Dynamically discovers test sessions using nox's native JSON output.
# Tests are categorized by their tags (ahb, axi, or both).
# This allows adding new tests without modifying the workflow.
# ===========================================================================
generate-matrix:
name: Generate test matrix
runs-on: ubuntu-latest
outputs:
ahb-matrix: ${{ steps.gen.outputs.ahb_matrix }}
axi-matrix: ${{ steps.gen.outputs.axi_matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install nox and dependencies
run: |
pip install nox==2023.4.22 pyyaml
pip install -e tools/nox_utils
- name: Query nox for test sessions
id: gen
run: |
cd verification/cocotb
python3 << 'EOF'
import json
import subprocess
import os
import sys
# Long-running tests that should be split into individual parametrized runs
# These tests have multiple test_name parameters and take the most time
SPLIT_TESTS = {"i3c_ahb_verify", "i3c_axi_verify"}
# Use nox's native JSON output to list all sessions
# Note: nox -l doesn't execute sessions, just lists them, so no --no-venv needed
result = subprocess.run(
["nox", "-l", "--json", "-f", "noxfile.py"],
capture_output=True, text=True,
env={**os.environ, "PYTHONDONTWRITEBYTECODE": "1"}
)
# Debug: show any errors from nox
if result.returncode != 0:
print(f"nox failed with return code {result.returncode}", file=sys.stderr)
print(f"stderr: {result.stderr}", file=sys.stderr)
sys.exit(1)
if not result.stdout.strip():
print("nox returned empty output", file=sys.stderr)
print(f"stderr: {result.stderr}", file=sys.stderr)
sys.exit(1)
try:
sessions = json.loads(result.stdout)
except json.JSONDecodeError as e:
print(f"Failed to parse JSON: {e}", file=sys.stderr)
print(f"stdout was: {result.stdout[:500]}", file=sys.stderr)
print(f"stderr was: {result.stderr[:500]}", file=sys.stderr)
sys.exit(1)
ahb_tests = set()
axi_tests = set()
for session in sessions:
tags = session.get("tags", [])
# Only process test sessions (tagged with 'tests')
if "tests" not in tags:
continue
name = session["name"]
has_ahb = "ahb" in tags
has_axi = "axi" in tags
# For long-running tests, use full session string to run each variant separately
# For others, use just the name to run all variants together
if name in SPLIT_TESTS:
# Use full parametrized session string (e.g., "i3c_ahb_verify(simulator='vcs', ...)")
session_id = session["session"]
else:
# Use just the name (e.g., "ccc_verify")
session_id = name
# Categorize tests by bus configuration
if has_ahb:
ahb_tests.add(session_id)
if has_axi:
axi_tests.add(session_id)
# Sort for consistent ordering
ahb_tests = sorted(ahb_tests)
axi_tests = sorted(axi_tests)
print(f"Discovered {len(ahb_tests)} AHB tests and {len(axi_tests)} AXI tests")
# Output matrices for subsequent jobs
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f"ahb_matrix={json.dumps(ahb_tests)}\n")
f.write(f"axi_matrix={json.dumps(axi_tests)}\n")
EOF
# ===========================================================================
# Job: Run AHB Tests (Parallel)
# ===========================================================================
# Runs each AHB test as a separate parallel job using GitHub Actions matrix.
# Each job:
# 1. Builds/caches Verilator
# 2. Sets up Python environment via install.sh and activate.sh
# 3. Configures RTL for AHB bus
# 4. Runs the specific test via nox
# ===========================================================================
tests-ahb:
name: "AHB: ${{ matrix.test }}"
needs: [generate-matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false # Continue running other tests even if one fails
matrix:
test: ${{ fromJson(needs.generate-matrix.outputs.ahb-matrix) }}
steps:
# --- System Dependencies ---
- name: Install system dependencies
run: |
sudo apt -qqy update
sudo apt -qqy --no-install-recommends install \
help2man libfl-dev make g++ git bison flex gperf \
libreadline-dev libbz2-dev autoconf
# --- Repository Setup ---
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize submodules
run: git submodule update --init --recursive
# --- Verilator (cached) ---
- name: Cache Verilator installation
id: cache-verilator
uses: actions/cache@v4
with:
path: ~/verilator-install
key: verilator-install-${{ env.VERILATOR_VERSION }}-${{ runner.os }}
- name: Build Verilator (if not cached)
if: steps.cache-verilator.outputs.cache-hit != 'true'
run: |
git clone https://github.com/verilator/verilator -b ${{ env.VERILATOR_VERSION }}
cd verilator
autoconf
./configure --prefix=$HOME/verilator-install
make -j$(nproc)
make install
- name: Add Verilator to PATH
run: |
echo "$HOME/verilator-install/bin" >> $GITHUB_PATH
echo "VERILATOR_ROOT=$HOME/verilator-install/share/verilator" >> $GITHUB_ENV
# --- Python Environment ---
- name: Setup Python environment (pyenv + dependencies)
run: ./install.sh
# --- Run Test ---
# Combined step ensures environment variables from activate.sh persist
# Note: Using env var to preserve quotes in parametrized session names
- name: Configure RTL and run test
id: run-test
env:
TEST_SESSION: ${{ matrix.test }}
run: |
source activate.sh
make config CFG_NAME=ahb
cd verification/cocotb && python -m nox -R -s "$TEST_SESSION" --no-venv --forcecolor
# --- Debug: Show logs on failure ---
- name: Display test logs on failure
if: failure() && steps.run-test.outcome == 'failure'
run: |
echo "=== Test failed - displaying log files ==="
find verification/cocotb -name "*.log" -type f -exec sh -c \
'echo ""; echo "========================================"; echo "=== {} ==="; echo "========================================"; cat "{}"' \;
# --- Upload Results ---
# Sanitize artifact name: replace special chars for parametrized test names
- name: Sanitize artifact name
if: always()
id: sanitize
run: |
NAME='${{ matrix.test }}'
# Replace problematic characters with underscores/remove them
SANITIZED=$(echo "$NAME" | sed "s/[()='\" ,]/_/g" | sed 's/__*/_/g' | sed 's/_$//')
echo "name=$SANITIZED" >> $GITHUB_OUTPUT
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-ahb-${{ steps.sanitize.outputs.name }}
path: |
verification/cocotb/**/results*.xml
verification/cocotb/**/*.log
# ===========================================================================
# Job: Run AXI Tests (Parallel)
# ===========================================================================
# Same structure as tests-ahb, but configured for AXI bus.
# ===========================================================================
tests-axi:
name: "AXI: ${{ matrix.test }}"
needs: [generate-matrix]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test: ${{ fromJson(needs.generate-matrix.outputs.axi-matrix) }}
steps:
# --- System Dependencies ---
- name: Install system dependencies
run: |
sudo apt -qqy update
sudo apt -qqy --no-install-recommends install \
help2man libfl-dev make g++ git bison flex gperf \
libreadline-dev libbz2-dev autoconf
# --- Repository Setup ---
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize submodules
run: git submodule update --init --recursive
# --- Verilator (cached) ---
- name: Cache Verilator installation
id: cache-verilator
uses: actions/cache@v4
with:
path: ~/verilator-install
key: verilator-install-${{ env.VERILATOR_VERSION }}-${{ runner.os }}
- name: Build Verilator (if not cached)
if: steps.cache-verilator.outputs.cache-hit != 'true'
run: |
git clone https://github.com/verilator/verilator -b ${{ env.VERILATOR_VERSION }}
cd verilator
autoconf
./configure --prefix=$HOME/verilator-install
make -j$(nproc)
make install
- name: Add Verilator to PATH
run: |
echo "$HOME/verilator-install/bin" >> $GITHUB_PATH
echo "VERILATOR_ROOT=$HOME/verilator-install/share/verilator" >> $GITHUB_ENV
# --- Python Environment ---
- name: Setup Python environment (pyenv + dependencies)
run: ./install.sh
# --- Run Test ---
# Note: Using env var to preserve quotes in parametrized session names
- name: Configure RTL and run test
id: run-test
env:
TEST_SESSION: ${{ matrix.test }}
run: |
source activate.sh
make config CFG_NAME=axi
cd verification/cocotb && python -m nox -R -s "$TEST_SESSION" --no-venv --forcecolor
# --- Debug: Show logs on failure ---
- name: Display test logs on failure
if: failure() && steps.run-test.outcome == 'failure'
run: |
echo "=== Test failed - displaying log files ==="
find verification/cocotb -name "*.log" -type f -exec sh -c \
'echo ""; echo "========================================"; echo "=== {} ==="; echo "========================================"; cat "{}"' \;
# --- Upload Results ---
# Sanitize artifact name: replace special chars for parametrized test names
- name: Sanitize artifact name
if: always()
id: sanitize
run: |
NAME='${{ matrix.test }}'
# Replace problematic characters with underscores/remove them
SANITIZED=$(echo "$NAME" | sed "s/[()='\" ,]/_/g" | sed 's/__*/_/g' | sed 's/_$//')
echo "name=$SANITIZED" >> $GITHUB_OUTPUT
- name: Upload test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-axi-${{ steps.sanitize.outputs.name }}
path: |
verification/cocotb/**/results*.xml
verification/cocotb/**/*.log
# ===========================================================================
# Job: Aggregate Test Results
# ===========================================================================
# Collects all test artifacts into a single combined artifact.
# Provides a single point to check overall test status.
# ===========================================================================
test-results:
name: Aggregate test results
needs: [tests-ahb, tests-axi]
if: always()
runs-on: ubuntu-latest
steps:
- name: Download all test artifacts
uses: actions/download-artifact@v4
with:
pattern: test-results-*
path: test-results
merge-multiple: true
- name: Debug downloaded artifacts
run: |
echo "=== Files downloaded from test jobs ==="
find test-results -type f 2>/dev/null | head -30 || echo "No files found"
echo ""
echo "=== XML files specifically ==="
find test-results -name "*.xml" -type f 2>/dev/null | head -20 || echo "No XML files"
- name: Upload combined test results
uses: actions/upload-artifact@v4
with:
name: tests-results
path: test-results
- name: Verify all tests passed
run: |
if [ "${{ needs.tests-ahb.result }}" != "success" ] || \
[ "${{ needs.tests-axi.result }}" != "success" ]; then
echo "❌ Some tests failed!"
echo " AHB tests: ${{ needs.tests-ahb.result }}"
echo " AXI tests: ${{ needs.tests-axi.result }}"
exit 1
fi
echo "✅ All tests passed!"
# ===========================================================================
# Job: Build and Deploy Documentation
# ===========================================================================
# Builds Sphinx documentation including verification results.
# Only runs after all tests pass successfully.
# Deploys to GitHub Pages on main branch.
# ===========================================================================
docs-build:
name: Build documentation
runs-on: ubuntu-latest
needs: [test-results]
if: always() && needs.test-results.result == 'success'
steps:
- name: Install system dependencies
run: |
sudo apt -qqy update
sudo apt -qqy --no-install-recommends install \
python3 python3-pip python3-venv git
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize submodules
run: git submodule update --init --recursive
- name: Download test results
uses: actions/download-artifact@v4
with:
name: tests-results
path: tests-results
- name: Debug downloaded artifacts
run: |
echo "=== Full structure of tests-results ==="
find tests-results -type f 2>/dev/null | head -30 || echo "No files found or directory doesn't exist"
echo ""
echo "=== Directory listing ==="
ls -laR tests-results 2>/dev/null | head -50 || echo "tests-results directory not found"
- name: Setup Python virtual environment
run: |
python3 -m venv .venv
source .venv/bin/activate
export I3C_ROOT_DIR="$(pwd)"
pip3 install -r requirements.txt
pip3 install -r doc/requirements.txt
- name: Generate verification documentation
run: |
source .venv/bin/activate
# Copy XML files to the expected location, handling nested structure
# The artifact contains paths like verification/cocotb/block/*/results*.xml
if [ -d "tests-results/verification/cocotb" ]; then
echo "Found nested structure, copying from tests-results/verification/cocotb/"
cp -r tests-results/verification/cocotb/* verification/cocotb/
elif [ -d "tests-results" ] && [ "$(ls -A tests-results 2>/dev/null)" ]; then
echo "Found flat structure, copying from tests-results/"
cp -r tests-results/* verification/cocotb/
else
echo "WARNING: No test results found to copy!"
fi
echo "=== XML files in verification/cocotb ==="
find verification/cocotb -name "*.xml" -type f | head -10
# Only run verification docs if XML files exist
XML_COUNT=$(find verification/cocotb -name "*.xml" -type f | wc -l)
if [ "$XML_COUNT" -gt 0 ]; then
echo "Found $XML_COUNT XML files, generating verification docs..."
REPO_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/$GITHUB_REF_NAME/" \
make verification-docs-with-sim
else
echo "WARNING: No XML files found, skipping verification-docs-with-sim"
echo "Running verification-docs without sim results instead..."
REPO_URL="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/tree/$GITHUB_REF_NAME/" \
make verification-docs || true
fi
- name: Build Sphinx documentation
run: |
pushd doc
pip3 install -r requirements.txt
TZ=UTC make html
popd
# Include coverage results if available
git clone https://github.com/antmicro/i3c-core-coverage-results || true
cp i3c-core-coverage-results/*html doc/build/html 2>/dev/null || true
- name: Upload documentation artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: docs
path: ./doc/build
- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./doc/build/html