Skip to content

Commit d993ab5

Browse files
committed
Add README
Signed-off-by: Tobias Deiminger <tobias.deiminger@linutronix.de>
1 parent 072eaa8 commit d993ab5

1 file changed

Lines changed: 206 additions & 0 deletions

File tree

README.md

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
# Exploring possibilities for integrating StrictDoc with ELISA’s requirements template approach for the Linux kernel
2+
3+
This demonstrates how to realize the tool-agnostic
4+
[ELISA Kernel Requirements Template](https://docs.google.com/document/d/1c7S7YAledHP2EEQ2nh26Ibegij-XPNuUFkrFLtJPlzs/edit?tab=t.0)
5+
proposal by using [StrictDoc](https://strictdoc.readthedocs.io) as requirements processing tool. The repository contains a filtered (for brevity)
6+
copy of the Linux kernel with requirements and tests from Alessandro Carminat and Gabriele Paoloni ([^1], [^2]) applied on top. ELISA's
7+
[`SPDX-*` tagging scheme]((https://docs.google.com/document/d/1c7S7YAledHP2EEQ2nh26Ibegij-XPNuUFkrFLtJPlzs/edit?tab=t.0#heading=h.9dudo2y6dlhf))
8+
was [added](https://github.com/strictdoc-project/linux-strictdoc/commit/9df9595b) along
9+
with a minimal StrictDoc project configuration.
10+
11+
[^1]: https://lore.kernel.org/all/20250910170000.6475-1-gpaoloni@redhat.com/
12+
[^2]: https://lore.kernel.org/linux-trace-kernel/20250814122206.109096-1-gpaoloni@redhat.com/#r
13+
14+
Go to [rendered requirements](https://strictdoc-project.github.io/linux-strictdoc/).
15+
16+
## Demonstrated features
17+
18+
- Use `strictdoc export .` to generate a nice
19+
[static HTML document tree](https://strictdoc-project.github.io/linux-strictdoc/linux-strictdoc/Documentation/requirements/charmisc.html)
20+
with visual representation of the
21+
[traceability graph](https://strictdoc-project.github.io/linux-strictdoc/linux-strictdoc/Documentation/requirements/charmisc-TRACE.html#DOC-SUBSYS-CHARMISC),
22+
validation results and full-text search. Other output formats as e.g. PDF are available.
23+
- Compile and validate requirements
24+
[in CI](https://github.com/strictdoc-project/linux-strictdoc/blob/lpc25/.github/workflows/ci.yaml).
25+
- Parses source code
26+
[SPDX-Req-* tags proposed by ELISA](https://docs.google.com/document/d/1c7S7YAledHP2EEQ2nh26Ibegij-XPNuUFkrFLtJPlzs/edit?tab=t.0#heading=h.9dudo2y6dlhf)
27+
and translates them to StrictDocs internal model.
28+
- Sidecar: Proposed by ELISA to hold additional requirement meta data outside source code. Realized as
29+
[separate sdoc file](https://github.com/strictdoc-project/linux-strictdoc/blob/lpc25/Documentation/requirements/tracing.sdoc)s
30+
containing requirement stubs. Stubs are merged with source code tags by matching on `SPDX-Req-ID`.
31+
- Use `strictdoc manage auto-assign` to generate SPDX-Req-ID and SPDX-Req-HKey as suggested by Linux kernel
32+
requirements template. The hash generation method is `echo -nE "${PROJECT}${FILE_PATH}${INSTANCE}${CODE}" | sha256sum`.
33+
See [commit 86e7810d](https://github.com/strictdoc-project/linux-strictdoc/commit/86e7810d)
34+
for the auto-generated changes.
35+
- Tracing: Requirements, tests and functions become individual nodes in the traceability graph and are connected
36+
by their stable IDs.
37+
- Custom validations: Use plugin API to
38+
[provide a check](https://github.com/strictdoc-project/linux-strictdoc/blob/lpc25/tools/requirements/validation_plugin.py#L28)
39+
to see if each requirement has at least one associated test, and each function expectations has at least one dedicated
40+
test.
41+
- Drift detection: As kernel development goes on, occasionally rerun `strictdoc manage auto-assign`. If `SPDX-Req-HKey`
42+
changes, this means that some semantic aspect of the requirement may have changed.
43+
44+
For a thorough documentation of StrictDocs features see
45+
[StrictDoc User Guide ](https://strictdoc.readthedocs.io/en/stable/stable/docs/strictdoc_01_user_guide.html)
46+
47+
Experiments unrelated to StrictDoc:
48+
- Semantic search for LLR candidates:
49+
There should be consensus which functions are "most valuable" to document.
50+
Coccinelle allows to
51+
[document that consensus](https://github.com/strictdoc-project/linux-strictdoc/blob/lpc25/scripts/coccinelle/docs/)
52+
in a machine readable and executable way.
53+
54+
## Tutorial: Add a Requirement
55+
56+
### Install StrictDoc
57+
```sh
58+
pipx install strictdoc # note: requires strictdoc >= 0.15.1
59+
git clone https://github.com/strictdoc-project/linux-strictdoc
60+
cd linux-strictdoc
61+
```
62+
63+
### Edit
64+
65+
Add requirement statement and temporary identifier to source code comment
66+
67+
`kernel/trace/trace_events.c`
68+
```c
69+
/*
70+
* SPDX-Req-ID: TMP-trace_events_enabled
71+
* SPDX-Req-Text:
72+
* This function shall check if there are enabled events in the provided list.
73+
*
74+
* Returns:
75+
* 0 : no events exist?
76+
* 1 : all events are disabled
77+
* 2 : all events are enabled
78+
* 3 : some events are enabled and some are enabled
79+
*/
80+
int trace_events_enabled(struct trace_array *tr, const char *system)
81+
```
82+
83+
Add corresponding requirement stub in sidecar file
84+
85+
`Documentation/requirements/tracing.sdoc`
86+
```
87+
[REQUIREMENT]
88+
MID: TMP-trace_events_enabled
89+
TITLE: trace_events_enabled
90+
```
91+
92+
### Finish
93+
94+
Calculate stable identifier and hash value, will be replaced inline
95+
```sh
96+
strictdoc manage auto-uid .
97+
```
98+
99+
Verify new hash values were added and no existing requirement was changed
100+
```sh
101+
git diff
102+
```
103+
104+
```diff
105+
diff --git a/Documentation/requirements/tracing.sdoc b/Documentation/requirements/tracing.sdoc
106+
index 8d1dd2b5..2d86384a 100644
107+
--- a/Documentation/requirements/tracing.sdoc
108+
+++ b/Documentation/requirements/tracing.sdoc
109+
@@ -22,6 +22,11 @@ TITLE: Event Tracing
110+
MID: 1ac497acf75d497f893006853f85fe86
111+
TITLE: Requirements
112+
113+
+[REQUIREMENT]
114+
+MID: b12884ce9b5b3258f1d28026c8aa1526f94030fd9f61ba583560f472015b1abb
115+
+HASH: 5949e5bf7ec43ed2c665d4ffe614dfaa285aafbe73a77df55aef0c099637f65b
116+
+TITLE: trace_events_enabled
117+
+
118+
[REQUIREMENT]
119+
MID: 77958d2a51762caa727e5751d8dfec127c07cb5385f542d7b2fdf26b2a07c8b3
120+
HASH: e8ee84ca42f5626ca9636abb53ded027708fdaabc99c8b935c016dda53130d81
121+
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
122+
index 16dabd1f..d07db4fa 100644
123+
--- a/kernel/trace/trace_events.c
124+
+++ b/kernel/trace/trace_events.c
125+
@@ -2062,6 +2062,9 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
126+
}
127+
128+
/*
129+
+ * SPDX-Req-ID: b12884ce9b5b3258f1d28026c8aa1526f94030fd9f61ba583560f472015b1abb
130+
+ * SPDX-Req-Text: This function shall check if there are enabled events in the provided list.
131+
+ *
132+
* Returns:
133+
* 0 : no events exist?
134+
* 1 : all events are disabled
135+
```
136+
137+
Verify and validate
138+
```sh
139+
strictdoc export .
140+
```
141+
142+
### Send for Review
143+
144+
```sh
145+
git add -u && git commit -m "docs: Add LLR for trace_events_enabled"
146+
git format-patch -n1
147+
```
148+
149+
## Explanation of Content and Processing
150+
151+
```
152+
.
153+
├── Documentation
154+
│ └── requirements
155+
│ ├── charmisc.sdoc # sidecar
156+
│ └── tracing.sdoc # sidecar
157+
├── drivers
158+
│ └── char
159+
│ └── mem.c # Linux code with inlined LLRs
160+
├── kernel
161+
│ └── trace
162+
│ └── trace_events.c # Linux code with inlined LLRs
163+
├── scripts
164+
│ └── coccinelle
165+
│ └── docs
166+
│ └── *.cocci # SmPL to discover LLR candidates
167+
├── strictdoc_config.py # StrictDoc project configuration
168+
└── tools
169+
├── requirements
170+
│ └── validation_plugin.py # custom requirement validations
171+
└── testing
172+
└── selftests
173+
└── devmem
174+
└── tests.c # tests for /dev/mem LLRs
175+
```
176+
177+
StrictDoc performs the following notable process steps:
178+
- parse \*.sdoc files to create the initial traceability index (a DAG structure)
179+
- parse \*.c files using tree-sitter, read SPDX tags from it and merge it into the DAG
180+
- perform built-in validations and calculate built-in statistics
181+
- perform custom validations
182+
* check if all requirements have at least one related test
183+
* check if all function expectations are mentioned by one related test
184+
- render the DAG into a HTML document tree where all nodes are traceable, including
185+
requirements text, visual graph representation and source code view
186+
187+
## Handling Fields with Special Meaning but Different Name in StrictDoc / ELISA
188+
189+
The StrictDoc model assigns special meaning to some reserved field names:
190+
- `UID` Unique, human-readable. May change during requirement life-cycle. Used to refer to child/parents by default.
191+
- `MID`: Unique, not human-readable, stable. Optionally used to refer to child/parents.
192+
Supports changing the human-readable UID during the requirement life-cycle.
193+
- `HASH`: Hash sum over predefined requirement content. Can be auto-calculated.
194+
- `STATEMENT`: Some document views and import/export formats require to select a "most important"
195+
field from the many fields.
196+
- `COMMENT`: Can occur multiple times within one requirement.
197+
198+
The ELISA requirements template defines similar special meaning for fields, but under different name.
199+
This is solved by two StrictDoc features:
200+
- `ProjectConfig(source_nodes=[SourceNodesEntry(sdoc_to_source_map={<sdoc_name>: <elisa_name>, ...})])` let's you define
201+
a mapping for fields that appearing under a different name in source code tags.
202+
Example: The stable ID appears as `SPDX-Req-ID` in source code comments, but must be named `MID` in sdoc.
203+
- Setting `HUMAN_TITLE` in the grammar lets you define a different display name for a field that has special
204+
StrictDoc meaning. Example: ELISA wants `HASH` to be named `SPDX-Req-HKey`. Since the field appears only in sdoc,
205+
but not in source code, it's enough to define `HUMAN_TITLE: SPDX-Req-HKey` for the `HASH` field.
206+
`sdoc_to_source_map` is not needed in this case.

0 commit comments

Comments
 (0)