Support modules
The plain Python modules that the Sphinx extensions share: parsers, RST
builders and the coverage logic. None of them is a Sphinx extension; none has
a setup(). Source: sphinx/_scripts/.
needs_fields
Which optional need fields a consumer declared.
Optional need fields: set one only where the consumer declared it.
A need type, a link and a field are the consumer’s vocabulary
(needs_config.toml). The engine can fill some fields the consumer may not
want; setting an undeclared one makes sphinx-needs warn “Unknown option” on
every need. So an optional field is set only when the running sphinx-needs
schema has it, and how it is declared decides whether its value survives.
- needs_fields.DEPENDS_ON = 'depends_on'
The Kconfig conditions of a test case or API symbol (
@kconfig_depends{<condition>}), joined with"; ".
- needs_fields.field_type(env, name)[source]
The declared schema type of need field
name, orNoneif undeclared.
- needs_fields.depends_field(env, conditions, subject)[source]
Whether to set
depends_onforsubject’sconditions.Declare it as a string field: the value is the conditions joined with
"; ", verbatim. Anarrayfield works too, as long as no condition contains one of; | ,— sphinx-needs would splitA || BorIS_ENABLED(A, B)into pieces — so such a need gets no field and a warning instead of a silently wrong value.
need_layouts
Need layouts that a document’s conf.py gets from the engine.
Need layouts that a document’s conf.py gets from the engine.
Not a Sphinx extension: a document calls need_layout() in its
conf.py (re-exported by zdocs_conf) and puts the result in its own
needs_layouts, under a name that starts with zdocs:
from zdocs_conf import configure, need_layout
needs_layouts = {
"zdocs_requirement": need_layout(
fields=[("rtype", "Kind"), ("component", "Component")],
hide_backlinks=["covers"],
)
}
needs_default_layout = "zdocs_requirement"
The layout is a card: a head with the type, the ID, the status and the title;
then the text of the need; then its fields and links. zdocs-needs.css
styles a need whose layout name starts with zdocs (the HTML class
needs_layout_<name>), and the need_cards extension gives each
need type its color from the needs configuration.
The rows stay in the sphinx-needs order (head, fields, text); the CSS shows
the fields last, so a screen reader still gives the fields first. In a PDF,
need_cards writes the card with the macros of zdocs.sty: head, title,
text, then the fields and links.
sphinx-needs shows every incoming link of a need. A requirement can have
hundreds of test results that cover it, and that list hides the rest of the
need. hide_backlinks names the links whose incoming side the layout does
not show. The links stay in the need data, so needs.json, need tables and
need flows still have them.
- need_layouts.links_line(hide_backlinks=())[source]
The layout line that shows the links of a need, without
hide_backlinks.For a document’s own layout: put it in place of
<<meta_links_all()>>.
- need_layouts.field_line(name, label)[source]
The layout line for field
name, shown aslabel: value.The space after the colon is for the PDF, where the label and the value follow each other in one line. In the HTML card, the label is a grid column and the browser drops the space at its end.
- need_layouts.need_layout(fields=None, hide_backlinks=(), pill='status')[source]
The zdocs need card.
fieldsis a list of(name, label)pairs, in the order to show. If it isNone, the card shows every field that has a value, under its own name.hide_backlinksare link names fromneeds_config.toml("covers"), not their incoming titles ("covered by").pillis the field that the head shows as a pill, next to the ID: thestatus, or theverdictof an adequacy need.zdocs-needs.csscolors the pill of a test result status and of a verdict.
doxygen_parser
Doxygen XML parsing, with no Sphinx dependency of its own.
Doxygen XML parsing — no Sphinx dependency.
- class doxygen_parser.RefLinks(api: str = '', local: str = '', tags: Mapping[str, str] | None = None)[source]
Where a <ref> in Doxygen prose points, as HTML directory URLs.
A symbol Doxygen resolved through a tag file carries the tag file’s path in
external=;tagsmaps such a path to the HTML directory of the document that tag file belongs to, so each reference goes to the project that documents the symbol.apiis for a tag-file referencetagsdoes not name — the API document the test specification references.localis for a symbol documented in the parsed project itself, such as a shared test procedure. An empty string leaves that kind unlinked.- api: str
Alias for field number 0
- local: str
Alias for field number 1
- tags: Mapping[str, str] | None
Alias for field number 2
- doxygen_parser.ref_to_rst(ref: Element, links: RefLinks | None) str | None[source]
A <ref> as an RST hyperlink into the Doxygen HTML, or None if it has none.
Doxygen’s refid is
<compound>_1<anchor>for a member and the bare compound for a page or group. The caller decides what an unlinked ref becomes.
- doxygen_parser.elem_text(elem: Element | None) str[source]
Walk the element tree collecting all text nodes (.text and .tail), join them, then normalise any runs of whitespace down to single spaces.
- doxygen_parser.para_text(para: Element | None, links: RefLinks | None = None, plain: bool = False) str[source]
Extract inline text from a <para> as RST, or as plain text with
plain.With
links, a symbol reference becomes a hyperlink into the Doxygen HTML (see ref_to_rst) — the same target the see-also line links to. Without, a member reference becomes a:c:func:role, which resolves only where a C domain defines the symbol; in the test documents nothing does, so it renders as unlinked code, silently. A need title is not parsed, so a caller building one asks forplaintext: code and references as their text, no markup.
- doxygen_parser.list_to_rst_lines(listelem: Element, marker: str, links: RefLinks | None = None) list[str][source]
Convert <orderedlist> or <itemizedlist> children to RST list lines.
Each item’s paragraphs go through para_rst_lines, so a list nested inside a list item survives — mutual recursion between the two functions, matching doxygen’s own nesting (<listitem><para>text<itemizedlist>…). A blank line is what makes an indented block a nested list rather than a continuation of the item’s text, which is why the blank lines para_rst_lines returns are load-bearing and must be indented as blanks (i.e. emitted empty), never dropped.
- doxygen_parser.para_rst_lines(para: Element | None, links: RefLinks | None = None) list[str][source]
One <para> as RST lines: its own prose first, then any lists it contains.
para_text deliberately skips orderedlist/itemizedlist (and parameterlist/simplesect/xrefsect, which callers render separately), so it answers “what does this paragraph SAY” and cannot answer “what does it CONTAIN”. Reading the lists here is what stops an authored list from being dropped: doxygen puts Test steps: and its bullets in two sibling <para> elements, and rendering only the first published the label with nothing under it — a clean exit with the content silently absent.
Handles text and a list in the SAME <para> (prose, blank line, list) as well as the sibling-<para> shape, because both occur and only one of them was ever exercised. Returns no trailing blank line; joining blocks is the caller’s job.
- doxygen_parser.section_to_rst(simplesect: Element, links: RefLinks | None = None) list[str][source]
Render a <simplesect kind=”par”> (Arrange/Act/Assert) into RST lines. Emits a .. rubric:: for the title, then renders each <para> child as an ordered list, unordered list, or plain prose paragraph.
- doxygen_parser.see_to_rst(simplesect_see: Element | Iterable[Element], api_html_dir: str, testspec_html_dir: str = '', tag_dirs: Mapping[str, str] | None = None) str[source]
Render one <simplesect kind=”see”>, or all of a member, into a ‘See also:’ RST line. Each <ref> becomes a hyperlink (see ref_to_rst), a :c:func: role (unlinked member refs), or a plain code span, depending on its attributes. Text that is not in a <ref> becomes a literal: @see irq_offload() gives no <ref> when no Doxygen project documents the symbol, and it was lost. Doxygen 1.16 writes one see section for each @see line, also for lines that follow each other, so a caller gives all sections of a member (
findall), not only the first.tag_dirs: RefLinks.tags.
- doxygen_parser.extract_params(detaileddesc: Element, links: RefLinks | None = None) list[tuple[str, str]][source]
Walk all <parameterlist kind=”param”> elements in the detailed description, collect each parameter’s name(s) and prose description, and return them as (name, description) pairs. Multiple names per item are joined with ‘, ‘.
- doxygen_parser.detail_rst_lines(dd: Element | None, links: RefLinks | None = None) list[str][source]
A <detaileddescription>’s own prose as RST LINES — paragraphs and lists.
Shared by member-level (@details on a ZTEST/function) and compound-level (@details on a @defgroup) descriptions — both are the same <detaileddescription><para>…</para></detaileddescription> shape.
Returns LINES, not one string per paragraph, which is the whole point: a bullet list cannot be represented as a single line. The previous version collapsed each <para> with para_text and dropped the ones that came back empty, so an authored
Test steps:
Return success
published the label and nothing else, because doxygen emits the label and the list as two sibling <para> elements and only the first survives a text-only read. Every caller therefore indents PER LINE and preserves blank lines, exactly as it already did for body_sections.
Structural children stay excluded (parameterlist, simplesect, xrefsect): callers render params, see-also and the test-id/requirement xrefsects separately, and rendering them here would duplicate them.
- doxygen_parser.parse_memberdef(memberdef: Element, compound_id: str, testspec_html_dir: str, api_html_dir: str, tag_dirs: Mapping[str, str] | None = None, source_pages: SourcePages | None = None) MemberInfo[source]
Extract all structured fields from a <memberdef> element — name, source location, Doxygen URL, brief description, test ID, requirement refs, status, see-also, and Arrange/Act/Assert body sections — and return them as a MemberInfo.
tag_dirs: where a tag-file reference links, by tag file (RefLinks.tags).source_pages: the source listings of the run (SourcePages); with them,source_urlis the listing of the function’s file at its first line.
- doxygen_parser.requirement_uids(memberdef: Element, relation: str) list[str][source]
The requirement UIDs of Doxygen’s native
\verifiesor\satisfies.relationis the element name,verifiesorsatisfies: a child of the memberdef itself, not of its description, with the UID only in each<requirement>’s refid, in source order, each UID once.The refid is NOT proof the requirement exists: Doxygen synthesizes
requirement_<UID>from the UID string whether or not any\requirementdefines it, so a typo is byte-identical here to a real link. Doxygen’s “Reference to unknown requirement” warning tells them apart, and so does the link target’s absence among the needs, which sphinx-needs reports for the link these UIDs become.
- doxygen_parser.kconfig_depends(dd: Element | None) tuple[str, list[str]][source]
(label, conditions)of thekconfig_dependsxrefitems indd.@kconfig_depends{<condition>}is an alias for\xrefitem kconfig_depends "Depends on" "Kconfig dependencies" <condition>. Doxygen 1.16 merges adjacent commands into ONE xrefsect with a<para>per condition, while commands elsewhere in the comment get xrefsects of their own; like@testid, they can sit in the last paragraph or in the last list item, so the whole description is searched. Each condition is kept verbatim ((CONFIG_A && !CONFIG_B) || CONFIG_C), once, in source order, without the trailing space Doxygen adds.labelis the xrefitem’s title as the consumer’s alias spells it (“Depends on”), or""if there is none.
- doxygen_parser.parse_symbol(memberdef: Element, html_dir: str, source_pages: SourcePages | None = None) SymbolInfo[source]
An API symbol (function, macro, …) as a need’s data: name, kind, the requirements it satisfies, its brief, where it is declared, and its page in the Doxygen HTML under
html_dir. Withsource_pages,source_urlis the declaration’s line in the source listing.The page is the one Doxygen documents the member on, which its id names:
<compound>_1<anchor>, the same shape ref_to_rst links. A member in a group is documented on the group’s page, not the header’s.
- doxygen_parser.load_group_index(xml_dir: Path) dict[str, str][source]
Parse Doxygen’s index.xml and return a dict mapping each group’s name to its refid, which is used as the filename stem for the group’s XML file.
- class doxygen_parser.SourcePages(xml_dir: Path)[source]
The source listings of a Doxygen run, from its XML output.
Doxygen writes the listing of a file as
<file refid>_source.html, with an anchorl<line, 5 digits>per line: of every code file withSOURCE_BROWSER = YES, of every header withVERBATIM_HEADERS = YES(the default). The XML does not name that page, so this class takes the refid of the file compound whose<location file>is the path, as the member’s<location>gives it. Doxygen’s file name escaping is not rebuilt.The settings come from the
Doxyfile.xmlthat Doxygen writes beside the XML. Without that file, url gives"". A file compound’s XML is read only when a member of a file with its name asks for it.inputs holds every XML file read so far, to note as the inputs of a document after its lookups.
- inputs: set[Path]
a later run can write them) and each file compound read by a lookup.
- Type:
Doxyfile.xml and index.xml (also when missing
rst_builders
RST string builders, with no Sphinx dependency of their own.
RST string builders — no Sphinx dependency.
- rst_builders.slugify(s)[source]
Replace non-alphanumeric runs with ‘-’ and strip leading/trailing dashes.
- rst_builders.build_need_rst(info, suite_name, module_path='', suite_title='', need_names=None, depends_field=False, id_scope=None)[source]
Build the RST block for a single test_case need.
depends_field: set thedepends_onfield (see _depends_on_rst).id_scope: what the fallback idtestspec-<scope>-<function>is scoped by — the suite’s Doxygen group name, which differs fromsuite_nameunder a testmodule_suite_qualifier; defaults tosuite_name.
- rst_builders.build_procedure_need_rst(memberdef, proc_compound_id, proc_group_name, testspec_html_dir, api_html_dir, need_names=None, tag_dirs=None, source_pages=None)[source]
Build a test_procedure needs item for one shared test procedure.
tag_dirs: where a tag-file reference links (doxygen_parser.RefLinks.tags).source_pages: the source listings (doxygen_parser.SourcePages); with them, Source links to the listing at the line.
- rst_builders.build_result_rst(r, spec_id, test_module, req_ids=None, need_names=None, fields=())[source]
Build RST block for one test_result need.
fields: the result-field roles (RESULT_FIELD_ROLES) to set, under their names fromneed_names, whererhas a value for them — the ones the consumer declared; an undeclared option warns per need.
- rst_builders.build_symbol_need_rst(info, need_names=None, depends_field=False)[source]
Build the RST block for one API symbol’s need (the
implementationrole).infois a doxygen_parser.parse_symbol result. The requirements it satisfies become thesatisfieslink, so each requirement’s page lists the symbol under the link’s incoming name, beside its verifying test cases. The kind, declaration and Doxygen page go in the body, where no field has to be declared for them.depends_field: set thedepends_onfield (see _depends_on_rst).
twister_reader
Twister output parsing, with no Sphinx dependency of its own.
Twister output parsing — no Sphinx dependency.
- twister_reader.split_case_name(name, scenario)[source]
(suite, function, instance)of twister test casenameinscenario.Twister names a case
<scenario>.<suite>.<fn>, with ztest’stest_stripped fromfn(and so fromfunctionhere). A parameterized test (ZTEST_P) reports one case per value as<scenario>.<fn>[<instantiation>/ <value>]: no suite segment (suiteis""), and the value may contain anything, dots included, so it is split off before the name is.instanceis the part in brackets, orNone.
- twister_reader.normalise_test_path(path)[source]
A testsuite path in one spelling: forward slashes, no
./, no trailing/.Twister writes
pathrelative to ZEPHYR_BASE with forward slashes; a consumer typing the same directory may add a trailing slash or a leading./, or come from a Windows checkout. None of that changes which directory it is.
- twister_reader.scenario_selected(platform, scenario, module_filter=None, exact=False, path_filter=None, suite_paths=None)[source]
Whether a (platform, scenario) run belongs to the report being built.
module_filtermatches the scenario name, as a dotted prefix (or exactly withexact).path_filtermatches the testsuite directory exactly, looked up insuite_paths(see testsuite_paths). With both, a run must satisfy both. With neither, every run is selected.The scenario prefix alone is not a module: upstream scenario names do not follow the directory layout (
kernel.timeris tests/kernel/timer/timer_api, and prefixeskernel.timer.error_casefrom timer_error_case), so only the path identifies a module’s results reliably.
- twister_reader.testsuite_paths(twister_meta)[source]
{(platform, scenario): normalised path}from a loaded twister.json.twister_report.xml carries no path, only the scenario (
classname) per platform, so the path a result came from is found here, by the same pair.
- twister_reader.testcase_statuses(twister_meta)[source]
{(platform, testcase identifier): status}from a loaded twister.json.twister.json keeps statuses the JUnit XML cannot express —
blockedin particular, which the XML reports as a failure.
- twister_reader.fold_parameterized_results(results, spec_lookup=None, twister_statuses=None)[source]
Attach each parameterized test’s value results to its aggregate result.
Twister reports a ZTEST_P function once as the aggregate
<scenario>.<suite>.<fn>(from ztest’s summary) and once per value as<scenario>.<fn>[<instantiation>/<value>](see parse_twister_results, which marks the latter withinstance). The spec has one test case for the function, so the values belong to the aggregate of the same run (platform and scenario), found by the function name.A run without an aggregate gets one, with the suite taken from the aggregates of other runs of the same scenario and function if they name exactly one, else from the spec (
spec_lookup) if exactly one case carries the function.Returns
(results, unmatched): the results without the value entries, and the function names whose values could not be attached, once each.
- class twister_reader.SpecLookup(entries=())[source]
The spec’s test cases, found by the (suite, function) of a twister result.
ZTEST function names are not unique across suites (some 300 are reused in the Zephyr test tree), so the suite is part of the key. Each entry is a dict with at least id, suite and test_function.
A result’s function has ztest’s
test_prefix stripped, while the spec records the C name as written, so both spellings are tried. When the result’s suite has no such case, the bare function name is used instead — but only if exactly one case carries it. candidates() returns every match, so an ambiguous one (several suites, or one (suite, function) pair documented in several test modules) is visible to the caller; find() returns a case only when there is exactly one.
- twister_reader.load_spec_lookup(json_path, need_names=None)[source]
Read spec needs.json; return a SpecLookup of its test cases.
need_names is the same role->name mapping rst_builders.py emitters take (testmodule_need_types/testmodule_need_links, merged by the caller) — the “case” role’s need type and the “verifies” role’s link name are both consumer-configurable (step 26), and this lookup must filter/read by whatever names the consumer’s spec needs actually carry, not the engine’s own defaults. Passing nothing preserves the original literal behaviour, which is what the unchanged unit tests pin.
- twister_reader.find_handler_log(twister_out_dir, platform, toolchain, test_path, scenario_name)[source]
Return the Path to handler.log for a (platform, scenario) run, or None.
- twister_reader.find_build_config(twister_out_dir, platform, toolchain, test_path, scenario_name)[source]
Return the Path to the Kconfig
.configof a (platform, scenario) build, or None.Twister keeps each build under the run directory find_handler_log describes, with the build’s
zephyr/.configin it. Unlike the log, the configuration is looked up only where twister puts it (the path layout, or the flat--detailed-test-idone): a.configof another scenario would answer for a build it did not come from.
- twister_reader.read_kconfig(path)[source]
The Kconfig symbols a
.configsets, as a set of names.A symbol is set when it has a value (
=y,=m, a number, a string);# CONFIG_X is not setand a symbol that is absent are not.
- exception twister_reader.UnparseableCondition[source]
A
depends_oncondition outside the grammar evaluate_condition reads.
- twister_reader.evaluate_condition(condition, symbols)[source]
Whether Kconfig
conditionholds for the setsymbols(read_kconfig).The grammar:
CONFIG_Xanddefined(CONFIG_X)(ordefined CONFIG_X) are true iff the symbol is set;!,&&,||(in C’s precedence) and parentheses combine them. Anything else — another macro,IS_ENABLED(), a comparison, a number — raises UnparseableCondition: its value in the build is not known from.configalone.
- twister_reader.depends_met(conditions, symbols)[source]
(value, unparseable)for a test case’sdepends_onin one build.conditionsare the case’s conditions, all of which must hold (the"; "ofdepends_onis an and);symbolsis the build’s set Kconfig symbols, or None when its.configwas not found. The value is"yes"or"no", or"n/a"when the case has no condition, the build has no.config, or a condition is outside evaluate_condition’s grammar — thenunparseablelists those conditions, and no value is guessed, even when another condition is false.
- twister_reader.skip_class(result, met)[source]
The class of a skipped result (None for any other), given its depends_met.
build-only: twister built the test but did not run it.platform: the platform could not take it (a memory region overflowed, or it was filtered by platform).config: ztest skipped it and the case’sdepends_onis false in the build.unexplained: anything else, including a ztest skip whose condition holds, cannot be evaluated, or is not recorded.
adequacy
Coverage adequacy, with no Sphinx dependency of its own.
Coverage adequacy: do the own tests of a requirement run the code that satisfies it.
This module has no Sphinx dependency. A verifies link and a satisfies
link are claims. A per-test coverage run (west twister --coverage-per-test)
checks them against execution. For each requirement, the module finds the
bodies of the satisfying symbols in the sources of the run commit. Then it
compares their lines with the lines that the own verifying tests covered.
The port starts from doc/_scripts/traceability_app.py by Anas (zephyr
collab-safety 0cc56a35003). Source, resolve_impl_symbols and the verdicts
(evidence, adequacy) are close to the original. The keys are the keys of
zdocs:
A requirement gets its verifying test cases through the
verifieslink of the case needs.A requirement gets its satisfying symbols through the
satisfieslink of the implementation needs (<TYPE>-<symbol>, rst_builders.symbol_need_id).A test case gets its matrix keys through the
twister.jsonof the run. Each twister case goes to its spec case by (suite, function), as a test result does. The key is built from (scenario, C function name), as twister writes it. The module does not parse keys, because scenario names are prefixes of other scenario names (kernel.lifo,kernel.lifo.usage).
Two changes from the original correct errors:
File patterns use glob rules in both modes:
**/is zero or more directories, and*stays in one directory. The original usedfnmatchon thegit ls-treeoutput. There,**/needs at least one directory, soinclude/zephyr/sys/**/*.hdid not findsys/slist.h.The run commit comes from
zephyr.shabeside the twister output first. Then it comes fromenvironment.zephyr_version.
One change from the original is a setting: the files that hold the bodies.
IMPL_PATTERNS is the set of the original and the default. A consumer gives
its own set to assess (testcoverage_impl_files in Sphinx).
The verdicts are the verdicts of the original:
trueEvery symbol that coverage can judge has a body that the own tests ran.
partialSome of these symbols have such a body, others do not.
brokenOther tests of the run reach the code. The own tests never do.
unattributedNo test of the run covers any body, so coverage cannot judge the link.
unresolvedSatisfying symbols exist, but none maps to a body (a macro).
no-implNo symbol satisfies the requirement.
no-covThe verifying tests have no coverage data in this run.
- adequacy.VERDICTS = ('broken', 'partial', 'unattributed', 'unresolved', 'no-cov', 'no-impl', 'true')
the findings first.
- Type:
In the order a report lists them
- adequacy.matrix_key(scenario, function, suite=None)[source]
The
test_matrix.jsonkey of C functionfunctioninscenario.Twister names a per-test tracefile
<scenario>.<test>. If two suites of one scenario have the same test name, it uses<scenario>.<suite>.<test>. The key is that name, with_for each character outside[A-Za-z0-9_]. Givesuitefor the second form.functionkeeps itstest_prefix.
- adequacy.IMPL_PATTERNS = ('kernel/*.c', 'kernel/**/*.c', 'include/zephyr/kernel.h', 'include/zephyr/kernel/**/*.h', 'include/zephyr/sys/**/*.h')
Where the original looks for bodies. The default of
impl_files.
- adequacy.keep_prefixes(impl_files=('kernel/*.c', 'kernel/**/*.c', 'include/zephyr/kernel.h', 'include/zephyr/kernel/**/*.h', 'include/zephyr/sys/**/*.h'))[source]
_KEEP and the fixed start of each pattern, up to its last
/before a wildcard.A body file must be in the matrix that load_matrix keeps, so that its lines can count as covered.
arch/**/*.caddsarch/. A pattern with a wildcard in its first part adds nothing, so that the matrix does not keep files outside the tree (../modules/...).
- adequacy.load_matrix(matrix_path, keep=('kernel/', 'include/', 'lib/', 'tests/'))[source]
(by_test, by_line)of atest_matrix.json, for the files underkeep.by_test[key] = {file: set of covered lines}by_line[file] = {line (int): [keys]}
keep: path prefixes (_KEEP, or keep_prefixes of the body files).
- adequacy.run_commit(run_dir, environment, root)[source]
The commit that the run built, as a full sha in
root, orNone.The first source is
zephyr.shabeside the twister output. The second source is the-g<hash>ofenvironment.zephyr_versionin twister.json.
- adequacy.run_name(run_dir, sha, root)[source]
The name of the run: the first tag (sorted) on its commit.
If the commit has no tag, the name is the name of the run directory. Each run of characters outside
[A-Za-z0-9_-]becomes one-.
- class adequacy.Source(root, ref=None)[source]
Reads the files of the tree at the commit of the coverage run.
Coverage line numbers are correct only for the sources of the build that made them. With
ref(the run commit, run_commit), read usesgit show <ref>:<path>. The line ranges are then correct also after the working tree changes. Withoutref, read uses the working tree underroot, and the caller warns.
- adequacy.resolve_impl_symbols(source, symbols, impl_files=('kernel/*.c', 'kernel/**/*.c', 'include/zephyr/kernel.h', 'include/zephyr/kernel/**/*.h', 'include/zephyr/sys/**/*.h'))[source]
The function bodies of the satisfying symbols (best effort).
A system call has more than one body.
z_impl_<sym>is the implementation in supervisor mode.z_vrfy_<sym>is the verifier that a ZTEST_USER test reaches instead. The verifier can do the operation itself and never call the z_impl body (z_vrfy_k_thread_create does this). The function collects all bodies. A test that runs one of them runs the implementation.A definition starts at column 0 (
static [ALWAYS_INLINE] inlineis permitted), and its line does not end in;. Its body ends at the first}in column 0, in 500 lines or less. In a header, only astaticline counts: other lines are prototypes or macros. So a macro has no body. A header is a.hfile anywhere in the tree (kernel/include/too).impl_files: the glob patterns of the files to search (IMPL_PATTERNS).Returns {sym: [{“file”, “a”, “b”, “variant”}, …]}.
- class adequacy.CoverageRun(name, sha, environment, by_test, by_line, cases, unmatched)[source]
One per-test coverage run, joined to the test cases of the spec.
cases[case id] = {"statuses": [...], "keys": [matrix keys]}, for each spec case that twister ran in this run.case_of_key[key] = {case ids}: the reverse map, for the question “which tests ran this line”.unmatched: the twister cases with no unique spec case (sorted names).
- adequacy.load_coverage_run(run_dir, spec_lookup, root, name=None, impl_files=('kernel/*.c', 'kernel/**/*.c', 'include/zephyr/kernel.h', 'include/zephyr/kernel/**/*.h', 'include/zephyr/sys/**/*.h'))[source]
Read a coverage run directory: twister.json, coverage/test_matrix.json, zephyr.sha.
impl_files: the body files of resolve_impl_symbols. The matrix keeps their lines (keep_prefixes).Returns
(run, inputs): the CoverageRun and the files that it reads.
- adequacy.collect_links(json_paths, need_names=None)[source]
(spec_lookup, verified_by, satisfied_by, ids)from needs.json files.spec_lookup: a SpecLookup of the test cases (type rolecase).verified_by[req] = [case ids], through theverifiesrole.satisfied_by[req] = [symbols]: the implementation needs (type roleimplementation, ids<TYPE>-<symbol>), throughsatisfies.ids: each need id in the files. A link target that is not a need gets no assessment.
If several files export one need, it counts once.
- adequacy.need_titles(json_paths)[source]
{need id: title}of the needs in the needs.json files (the first file wins).
- adequacy.evidence(case_ids, run)[source]
The state of the verifying cases: untested, no-run, failing, passing or skipped.
- adequacy.adequacy(symbols, case_ids, run, impl_loc)[source]
{"verdict", "impls"}of a requirement from itssymbolsandcase_ids.implshas one entry for each symbol and body, with these keys:symandvariant.file,aandb:Nonefor a symbol with no body.own: the number of body lines that the own tests ran.any: the number of body lines that any test of the run ran.own_tests:{case id: [lines]}.other_tests:{matrix key: [lines]}, for the keys of other tests.
- adequacy.assess(run, verified_by, satisfied_by, source, ids=None, impl_files=('kernel/*.c', 'kernel/**/*.c', 'include/zephyr/kernel.h', 'include/zephyr/kernel/**/*.h', 'include/zephyr/sys/**/*.h'))[source]
The assessment of each requirement in the scope of the run:
({req: result}, impl_loc).A requirement is in the scope if twister ran at least one of its verifying cases in this run. If
idsis given, the requirement must also be a need. Each result hasverdictandimpls(adequacy),evidence,symbolsandcases.impl_files: the body files (resolve_impl_symbols).