Test executor

These modules run before a test. collect selects which tests to run, and context builds the test configuration from its config.toml, overwriting from the provided context, for example, the git reference to get the artifacts from or explicit board to run the test on.

Context

Prepare context for a test from tests/**/.

Input: Test to run:

{
  "name": "demo/linux-iio-dac",
  "repository": {
    "linux": {"ref": "010c31d..."}
  }
}

From the config.toml files, [[repository]] is parsed as:

{..., 'repository': [{'name': 'linux', 'ref': 'refs/heads/main', 'files': '...'}]}

It is reformatted to:

{..., 'repository': {'linux': {'ref': 'refs/heads/main', 'files': '...'}}}

before merging into the context.

That is, any [{'name': '...', ...}] list is replaced with a dict, where name is the key (and must exist for each group/list entry).

hw_tests.context.reformat_named_lists(d)

Reformat any list-of-dicts-with-‘name’ into a dict keyed by name.

e.g. [{‘name’: ‘linux’, ‘ref’: ‘…’}, {‘name’: ‘hdl’, ‘ref’: ‘…’}]

-> {‘linux’: {‘ref’: ‘…’}, ‘hdl’: {‘ref’: ‘…’}}

hw_tests.context.deep_merge(base, override)

Return base updated with override, merging nested dicts.

hw_tests.context.parse_set_env()

Parse the set env var into a list of override dicts.

hw_tests.context.test_name(test_dir: Path) → str

Derive the test name from its directory relative to tests/.

hw_tests.context.build_context(test_dir: Path, overrides: list[dict]) → dict

Return the context of the test in test_dir.

Merges, in order: the test name, the test config.toml, and the first override whose name matches the test (or has no name). needs is always a list.

Collect

Match workflow-run-to-context output against tests/**/config.toml metafiles.

Input: JSON by workflow-run-to-context@action, e.g.:

{
  "repository": "linux",
  "head_sha": "010c31d...",
  "changed_files": "drivers/iio/dac/Kconfig\ndrivers/iio/dac/ad3530r.c",
  ...
}

Output: JSON list written to <output_path> (or stdout), one entry per matched test:

[
  {
    "name": "demo/linux-iio-dac",
    "with": {
      "linux": {"ref": "010c31d..."},   <- merge_commit_sha || head_sha: this repo triggered
    }
  }
]
hw_tests.collect.load_test_metas()

Load all tests/**/config.toml files, with the test name as _uid.

hw_tests.collect.paths_match(changed_files, path_block)

Return True if any changed file matches any glob pattern in path_block.

hw_tests.collect.match_tests(context, metas)

For each test metafile, check whether any repo rule fires for the triggering repository. Emit at most one result entry per test.

hw_tests.collect.main()

Log the tests matching the context env var.

In GitHub Actions, also sets the tests step output.