Files
avbroot/tests/config.py
T
Andrew Gunnerson 4847ebf27a Merge tests_ci into tests
This commit merges the CI tests from `tests_ci/` into `tests/` so we
have a single way to test against both full OTAs and stripped/dummy
OTAs.

Features kept from tests_ci:

* Support for dummy OTAs. They're now called stripped OTAs to hopefully
  better signify that they're a stripped down version of the original
  file instead of a test file created from scratch.
* Extracting AVB partitions and verifying their hashes.
* Writing sparse files where possible.
* Ability to change the working directory for downloads and output
  files.

Test script changes:

* There are now 4 subcommands:
    strip -i <input> -o <output>
    add -u <url> -d <device> [-H <expected hash>]
    download [--magisk | --no-magisk] [[-d <device>] ... | --no-devices]
    test [[-d <device>] ...]
* Downloads now use the parallel downloader for both full and stripped
  OTAs.

Config file changes:

* It now uses strictyaml instead of configparser/TOML since it's a bit
  more readable now that we have more nesting in the data structure. The
  config loader now also makes use of strictyaml's schema feature.
* All hashes are now SHA-256 for consistency.
* For stripped OTAs, the list of byte ranges now uses half-open
  intervals for easier calculations.
* Use device IDs as the key instead of the marketing model name.

CI changes:

* Compute all cache keys (and prefixes) in the main workflow and pass
  them to the preload scripts.
* Only run on `push` for the `master` branch to avoid double workflow
  runs on PRs from internal branches.
* Increase timeout for patching tests because `tests.py` patches twice
  (once with `--magisk` and once with `--prepatched`).

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-03-04 21:39:08 -05:00

45 lines
999 B
Python

import os
from strictyaml import load, Int, Map, MapPattern, Regex, Seq, Str
CONFIG_PATH = os.path.join(
os.path.realpath(os.path.dirname(__file__)), 'tests.yaml')
SHA256_HEX = Regex('[0-9a-fA-F]{64}')
SCHEMA = Map({
'magisk': Map({
'url': Str(),
'hash': SHA256_HEX,
}),
'device': MapPattern(Str(), Map({
'url': Str(),
'sections': Seq(Map({
'start': Int(),
'end': Int(),
})),
'hash': Map({
'original': Map({
'full': SHA256_HEX,
'stripped': SHA256_HEX,
}),
'patched': Map({
'full': SHA256_HEX,
'stripped': SHA256_HEX,
}),
'avb_images': MapPattern(Str(), SHA256_HEX),
}),
})),
})
def load_config():
with open(CONFIG_PATH, 'r') as f:
return load(f.read(), SCHEMA)
def save_config(data):
with open(CONFIG_PATH, 'w') as f:
f.write(data.as_yaml())