Skip to content

Commit 61bf69a

Browse files
committed
fix: improve ISA regex validation and add comprehensive test suite
- Fix ISA regex pattern to properly handle sub-extensions like 'RV32I_Zicsr' - Add comprehensive pytest-based test suite with 100% coverage - Create developer-friendly Makefile with self-documenting help - Add TESTING.md with quickstart and usage instructions - Include test dependencies (pytest, pytest-cov) and configuration - Add run_tests.py alternative test runner - Improve regex to handle extension combinations correctly
1 parent 54171f2 commit 61bf69a

File tree

12 files changed

+291
-3
lines changed

12 files changed

+291
-3
lines changed

.coverage

52 KB
Binary file not shown.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [3.20.1] - 2025-07-04
6+
- Fix ISA regex pattern to properly handle sub-extensions like 'RV32I_Zicsr' and add comprehensive test suite
7+
58
## [3.20.0] - 2024-07-08
69
- Add Sdtrig support
710

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Makefile for riscv-config project
2+
3+
.PHONY: help test test-coverage clean install-test
4+
5+
help: ## Show this help message
6+
@echo "Available targets:"
7+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
8+
9+
install-test: ## Install test dependencies
10+
pip install pytest pytest-cov
11+
12+
test: ## Run all tests
13+
pytest tests/test_constants.py -v
14+
15+
test-coverage: ## Run tests with coverage report
16+
python -W ignore::SyntaxWarning -m pytest tests/test_constants.py --cov=riscv_config --cov-report=html
17+
@echo "Coverage report generated in htmlcov/index.html"
18+
19+
test-coverage-constants: ## Run tests with coverage for constants module only
20+
pytest tests/test_constants.py --cov=riscv_config.constants --cov-report=html --cov-report=term-missing
21+
@echo "Focused coverage report for constants module"
22+
23+
clean: ## Clean up generated files
24+
rm -rf htmlcov/
25+
rm -rf .pytest_cache/
26+
rm -rf __pycache__/
27+
rm -rf tests/__pycache__/
28+
rm -rf riscv_config/__pycache__/
29+
find . -name "*.pyc" -delete
30+
find . -name ".coverage" -delete

TESTING.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Testing
2+
3+
Tests for the RISC-V ISA regex pattern.
4+
5+
## Quick Start
6+
7+
```bash
8+
make help # See all commands
9+
make install-test # Install dependencies
10+
make test # Run tests
11+
```
12+
13+
## What's Tested
14+
15+
- Valid ISA strings: `RV32I`, `RV64IG`, `RV32I_Zicsr`
16+
- Invalid patterns: `RV64G`, `rv32i`, `RV32IZicsr`
17+
- Edge cases and real configs
18+
19+
## Running Tests
20+
21+
```bash
22+
make test # Basic test run
23+
make test-coverage # Full coverage report
24+
make test-coverage-constants # Coverage for regex only
25+
```
26+
27+
## Adding Tests
28+
29+
Edit `tests/test_constants.py`:
30+
31+
```python
32+
# Valid patterns
33+
("RV32I_NewExt", True),
34+
35+
# Invalid patterns
36+
("RV32I_BadExt", False),
37+
```
38+
39+
## CI Setup
40+
41+
```yaml
42+
# .github/workflows/test.yml
43+
name: Tests
44+
on: [push, pull_request]
45+
jobs:
46+
test:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v3
50+
- uses: actions/setup-python@v4
51+
- run: make install-test
52+
- run: make test
53+
```
54+
55+
## Troubleshooting
56+
57+
**Import errors?** Make sure you're in project root:
58+
```bash
59+
cd /workspaces/riscv-config
60+
export PYTHONPATH=.
61+
```
62+
63+
**Coverage report?** Open `htmlcov/index.html` after running coverage tests.

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[tool:pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
addopts = -v --tb=short --cov=riscv_config

requirements-test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pytest>=7.0.0
2+
pytest-cov>=4.0.0

riscv_config/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from pkgutil import extend_path
22
__path__ = extend_path(__path__, __name__)
3-
__version__ = '3.20.0'
3+
__version__ = '3.20.1'

riscv_config/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
sub_extensions = Z_extensions + S_extensions
3939

4040
isa_regex = \
41-
re.compile("^RV(32|64|128)[IE][ACDFGHJLMNPQSTUV]*(("+'|'.join(sub_extensions)+")(_("+'|'.join(sub_extensions)+"))*){,1}(X[a-z0-9]*)*(_X[a-z0-9]*)*$")
41+
re.compile("^RV(32|64|128)[IE][ACDFGHJLMNPQSTUV]*(_("+'|'.join(sub_extensions)+")+)*(_X[a-zA-Z0-9]+)*$")

run_tests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
"""Simple test runner for ISA regex tests."""
3+
4+
import sys
5+
import os
6+
7+
# Add project root to path
8+
sys.path.insert(0, os.path.dirname(__file__))
9+
10+
if __name__ == "__main__":
11+
try:
12+
import pytest
13+
sys.exit(pytest.main([
14+
"tests/test_constants.py",
15+
"-v",
16+
"--tb=short"
17+
]))
18+
except ImportError:
19+
print("pytest not installed. Install with: pip install pytest")
20+
sys.exit(1)

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 3.20.0
2+
current_version = 3.20.1
33
commit = True
44
tag = True
55

0 commit comments

Comments
 (0)