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, or None if undeclared.

needs_fields.depends_field(env, conditions, subject)[source]

Whether to set depends_on for subject’s conditions.

Declare it as a string field: the value is the conditions joined with "; ", verbatim. An array field works too, as long as no condition contains one of ; | , — sphinx-needs would split A || B or IS_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.

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 as label: 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.

fields is a list of (name, label) pairs, in the order to show. If it is None, the card shows every field that has a value, under its own name.

hide_backlinks are link names from needs_config.toml ("covers"), not their incoming titles ("covered by").

pill is the field that the head shows as a pill, next to the ID: the status, or the verdict of an adequacy need. zdocs-needs.css colors 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.MemberInfo[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=; tags maps 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. api is for a tag-file reference tags does not name — the API document the test specification references. local is 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 for plain text: 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_url is 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 \verifies or \satisfies.

relation is the element name, verifies or satisfies: 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 \requirement defines 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 the kconfig_depends xrefitems in dd.

@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. label is the xrefitem’s title as the consumer’s alias spells it (“Depends on”), or "" if there is none.

class doxygen_parser.SymbolInfo[source]
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. With source_pages, source_url is 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 anchor l<line, 5 digits> per line: of every code file with SOURCE_BROWSER = YES, of every header with VERBATIM_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.xml that 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

refid(path: str, tail: bool = False) → str[source]

The refid of the file compound of path, or "".

tail: path is from another root than Doxygen’s paths (kernel/thread.c for zephyr/kernel/thread.c). One path must then end with the other, and only one file may match.

url(html_dir: str, path: str, line, tail: bool = False) → str[source]

<html_dir>/<refid>_source.html#l00290, or "" without a listing.

doxygen_parser.member_source(memberdef, html_dir, source_pages=None)[source]

(source_file, source_url) of a function’s body: "main.c (line 290)" and its line in the source listing under html_dir, or "" without one.

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 the depends_on field (see _depends_on_rst). id_scope: what the fallback id testspec-<scope>-<function> is scoped by — the suite’s Doxygen group name, which differs from suite_name under a testmodule_suite_qualifier; defaults to suite_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 from need_names, where r has 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 implementation role).

info is a doxygen_parser.parse_symbol result. The requirements it satisfies become the satisfies link, 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 the depends_on field (see _depends_on_rst).

rst_builders.build_scenario_table(testcase_yaml_path)[source]

Return RST lines for a list-table of scenarios from a scenario file.

rst_builders.find_scenario_yaml(module_dir)[source]

Return the first scenario file in module_dir that exists, or None.

The names come from SCENARIO_YAML_NAMES. When no file exists, log a warning that names each file it tried.

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 case name in scenario.

Twister names a case <scenario>.<suite>.<fn>, with ztest’s test_ stripped from fn (and so from function here). A parameterized test (ZTEST_P) reports one case per value as <scenario>.<fn>[<instantiation>/ <value>]: no suite segment (suite is ""), and the value may contain anything, dots included, so it is split off before the name is. instance is the part in brackets, or None.

twister_reader.normalise_test_path(path)[source]

A testsuite path in one spelling: forward slashes, no ./, no trailing /.

Twister writes path relative 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_filter matches the scenario name, as a dotted prefix (or exactly with exact). path_filter matches the testsuite directory exactly, looked up in suite_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.timer is tests/kernel/timer/timer_api, and prefixes kernel.timer.error_case from 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 — blocked in 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 with instance). 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 .config of a (platform, scenario) build, or None.

Twister keeps each build under the run directory find_handler_log describes, with the build’s zephyr/.config in it. Unlike the log, the configuration is looked up only where twister puts it (the path layout, or the flat --detailed-test-id one): a .config of another scenario would answer for a build it did not come from.

twister_reader.read_kconfig(path)[source]

The Kconfig symbols a .config sets, as a set of names.

A symbol is set when it has a value (=y, =m, a number, a string); # CONFIG_X is not set and a symbol that is absent are not.

exception twister_reader.UnparseableCondition[source]

A depends_on condition outside the grammar evaluate_condition reads.

twister_reader.evaluate_condition(condition, symbols)[source]

Whether Kconfig condition holds for the set symbols (read_kconfig).

The grammar: CONFIG_X and defined(CONFIG_X) (or defined 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 .config alone.

twister_reader.depends_met(conditions, symbols)[source]

(value, unparseable) for a test case’s depends_on in one build.

conditions are the case’s conditions, all of which must hold (the "; " of depends_on is an and); symbols is the build’s set Kconfig symbols, or None when its .config was 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 — then unparseable lists 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’s depends_on is false in the build. unexplained: anything else, including a ztest skip whose condition holds, cannot be evaluated, or is not recorded.

twister_reader.load_twister_meta(json_path)[source]

Load and validate twister.json; return the dict.

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 verifies link of the case needs.

  • A requirement gets its satisfying symbols through the satisfies link of the implementation needs (<TYPE>-<symbol>, rst_builders.symbol_need_id).

  • A test case gets its matrix keys through the twister.json of 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 used fnmatch on the git ls-tree output. There, **/ needs at least one directory, so include/zephyr/sys/**/*.h did not find sys/slist.h.

  • The run commit comes from zephyr.sha beside the twister output first. Then it comes from environment.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:

true

Every symbol that coverage can judge has a body that the own tests ran.

partial

Some of these symbols have such a body, others do not.

broken

Other tests of the run reach the code. The own tests never do.

unattributed

No test of the run covers any body, so coverage cannot judge the link.

unresolved

Satisfying symbols exist, but none maps to a body (a macro).

no-impl

No symbol satisfies the requirement.

no-cov

The 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.json key of C function function in scenario.

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_]. Give suite for the second form. function keeps its test_ 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/**/*.c adds arch/. 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 a test_matrix.json, for the files under keep.

  • 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, or None.

The first source is zephyr.sha beside the twister output. The second source is the -g<hash> of environment.zephyr_version in 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 uses git show <ref>:<path>. The line ranges are then correct also after the working tree changes. Without ref, read uses the working tree under root, and the caller warns.

list(patterns)[source]

The relative paths that match one of the glob patterns.

read(rel)[source]

The text of the file at the ref, or None.

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] inline is 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 a static line counts: other lines are prototypes or macros. So a macro has no body. A header is a .h file 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.

(spec_lookup, verified_by, satisfied_by, ids) from needs.json files.

  • spec_lookup: a SpecLookup of the test cases (type role case).

  • verified_by[req] = [case ids], through the verifies role.

  • satisfied_by[req] = [symbols]: the implementation needs (type role implementation, ids <TYPE>-<symbol>), through satisfies.

  • 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 its symbols and case_ids.

impls has one entry for each symbol and body, with these keys:

  • sym and variant.

  • file, a and b: None for 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 ids is given, the requirement must also be a need. Each result has verdict and impls (adequacy), evidence, symbols and cases. impl_files: the body files (resolve_impl_symbols).

adequacy.line_ranges(lines)[source]

"79-81, 84" for sorted line numbers.