# Traceability Matrix

## Principle

The traceability matrix ensures end-to-end traceability from requirement to test:

```
System requirement → Software requirement → Architecture element → Implementation (PR/file) → Test case → Test result
```

Each level must be traceable in both directions:
- **Forward:** requirement → has it been implemented and tested?
- **Backward:** test case → which requirement does it verify?

## Table structure

| Sys-Req | SW-Req  | ASIL | Arch element | Implementation       | Test case | Test result   | Status       |
|---------|---------|------|--------------|----------------------|-----------|---------------|--------------|
| SYR-001 | SWR-010 | B    | MOD-Timer    | PR !23, timer.c      | TC-010    | Pass (v1.2)   | Complete     |
| SYR-001 | SWR-011 | B    | MOD-Timer    | PR !23, timer.c      | TC-011    | Pass (v1.2)   | Complete     |
| SYR-002 | SWR-020 | A    | MOD-CAN      | PR !31, can_driver.c | TC-020    | Pass (v1.2)   | Complete     |
| SYR-003 | SWR-030 | B    | MOD-Watchdog | —                    | —         | —             | Open         |
| —       | SWR-040 | QM   | MOD-Diag     | PR !35, diag.c       | TC-040    | Fail (v1.1)   | Finding open |

## Column explanation

| Column           | Description                                                    |
|------------------|----------------------------------------------------------------|
| Sys-Req          | System requirement ID (Gitea issue with label `req::system`)   |
| SW-Req           | Software requirement ID (Gitea issue with label `req::software`) |
| ASIL             | Assigned ASIL level                                            |
| Arch element     | Architecture module or component                               |
| Implementation   | Pull request and/or file                                       |
| Test case        | Test case ID (Gitea issue with label `test::*`)                |
| Test result      | Pass/Fail with version/date                                    |
| Status           | Complete / Open / Finding open                                 |

## Gap analysis

The matrix makes gaps visible:

- **Requirement without test:** row without test-case entry → test missing
- **Requirement without implementation:** row without PR → not implemented
- **Test without requirement:** test case not assigned to any requirement → verify
- **Fail without finding:** failed test without a documented finding → rework

## Automatic generation from Gitea

The matrix can be generated automatically from Gitea issues:

1. A Python script reads all issues with `req::*` labels via the Gitea API
2. It follows issue links to architecture issues, PRs, and test issues
3. It reads CI-pipeline results (JUnit XML) for test outcomes
4. It produces the matrix as a Markdown table or CSV

**Precondition:** issues are correctly linked and labelled (see `gitea-aspice-setup.md`).

**Output formats:**
- Markdown (for wiki / documentation)
- CSV (for import into customer systems)
- HTML (for reporting)

An example script lives at `tools/traceability-report.py` in the project repository.

---

*The current traceability matrix is updated on every release and stored in the wiki.*
