forked from josch/mmdebstrap
coverage.py: factor out coverage.txt parsing
This commit is contained in:
parent
8cb5b6e0ef
commit
a16937e3e4
2 changed files with 84 additions and 71 deletions
153
coverage.py
153
coverage.py
|
@ -10,6 +10,7 @@ import argparse
|
||||||
import time
|
import time
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from itertools import product
|
||||||
|
|
||||||
have_qemu = os.getenv("HAVE_QEMU", "yes") == "yes"
|
have_qemu = os.getenv("HAVE_QEMU", "yes") == "yes"
|
||||||
have_unshare = os.getenv("HAVE_UNSHARE", "yes") == "yes"
|
have_unshare = os.getenv("HAVE_UNSHARE", "yes") == "yes"
|
||||||
|
@ -66,6 +67,58 @@ def skip(condition, dist, mode, variant, fmt):
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
def parse_config(confname):
|
||||||
|
config_dict = defaultdict(dict)
|
||||||
|
config_order = list()
|
||||||
|
all_vals = {
|
||||||
|
"Dists": all_dists,
|
||||||
|
"Modes": all_modes,
|
||||||
|
"Variants": all_variants,
|
||||||
|
"Formats": all_formats,
|
||||||
|
}
|
||||||
|
with open(confname) as f:
|
||||||
|
for test in Deb822.iter_paragraphs(f):
|
||||||
|
if "Test" not in test.keys():
|
||||||
|
print("Test without name", file=sys.stderr)
|
||||||
|
exit(1)
|
||||||
|
name = test["Test"]
|
||||||
|
config_order.append(name)
|
||||||
|
for k in test.keys():
|
||||||
|
v = test[k]
|
||||||
|
if k not in [
|
||||||
|
"Test",
|
||||||
|
"Dists",
|
||||||
|
"Modes",
|
||||||
|
"Variants",
|
||||||
|
"Formats",
|
||||||
|
"Skip-If",
|
||||||
|
"Needs-QEMU",
|
||||||
|
"Needs-Root",
|
||||||
|
]:
|
||||||
|
print(f"Unknown field name {k} in test {name}")
|
||||||
|
exit(1)
|
||||||
|
if k in all_vals.keys():
|
||||||
|
if v == "default":
|
||||||
|
print(
|
||||||
|
f"Setting {k} to default in Test {name} is redundant",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
if v == "any":
|
||||||
|
v = all_vals[k]
|
||||||
|
else:
|
||||||
|
# else, split the value by whitespace
|
||||||
|
v = v.split()
|
||||||
|
for i in v:
|
||||||
|
if i not in all_vals[k]:
|
||||||
|
print(
|
||||||
|
f"{i} is not a valid value for {k}", file=sys.stderr
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
config_dict[name][k] = v
|
||||||
|
return config_order, config_dict
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("test", nargs="*", help="only run these tests")
|
parser.add_argument("test", nargs="*", help="only run these tests")
|
||||||
|
@ -135,78 +188,38 @@ def main():
|
||||||
"/usr/share/mmdebstrap/hooks", "shared/hooks", dirs_exist_ok=True
|
"/usr/share/mmdebstrap/hooks", "shared/hooks", dirs_exist_ok=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# parse coverage.txt
|
||||||
|
config_order, config_dict = parse_config("coverage.txt")
|
||||||
|
|
||||||
|
# produce the list of tests using the cartesian product of all allowed
|
||||||
|
# dists, modes, variants and formats of a given test
|
||||||
tests = []
|
tests = []
|
||||||
with open("coverage.txt") as f:
|
for name in config_order:
|
||||||
for test in Deb822.iter_paragraphs(f):
|
test = config_dict[name]
|
||||||
name = test["Test"]
|
for dist, mode, variant, fmt in product(
|
||||||
dists = test.get("Dists", default_dist)
|
test.get("Dists", [default_dist]),
|
||||||
if dists == "any":
|
test.get("Modes", [default_mode]),
|
||||||
dists = all_dists
|
test.get("Variants", [default_variant]),
|
||||||
elif dists == "default":
|
test.get("Formats", [default_format]),
|
||||||
print(
|
):
|
||||||
f"Setting Dists to default in Test {name} is redundant",
|
skipreason = skip(test.get("Skip-If"), dist, mode, variant, fmt)
|
||||||
file=sys.stderr,
|
if skipreason:
|
||||||
)
|
tt = ("skip", skipreason)
|
||||||
exit(1)
|
elif have_qemu:
|
||||||
|
tt = "qemu"
|
||||||
|
elif test.get("Needs-QEMU", "false") == "true":
|
||||||
|
tt = ("skip", "test needs QEMU")
|
||||||
|
elif test.get("Needs-Root", "false") == "true":
|
||||||
|
tt = "sudo"
|
||||||
|
elif mode == "auto" and not have_unshare:
|
||||||
|
tt = "sudo"
|
||||||
|
elif mode == "root":
|
||||||
|
tt = "sudo"
|
||||||
|
elif mode == "unshare" and not have_unshare:
|
||||||
|
tt = ("skip", "test needs unshare")
|
||||||
else:
|
else:
|
||||||
dists = dists.split()
|
tt = "null"
|
||||||
modes = test.get("Modes", default_mode)
|
tests.append((tt, name, dist, mode, variant, fmt))
|
||||||
if modes == "any":
|
|
||||||
modes = all_modes
|
|
||||||
elif modes == "default":
|
|
||||||
print(
|
|
||||||
f"Setting Modes to default in Test {name} is redundant",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
modes = modes.split()
|
|
||||||
variants = test.get("Variants", default_variant)
|
|
||||||
if variants == "any":
|
|
||||||
variants = all_variants
|
|
||||||
elif variants == "default":
|
|
||||||
print(
|
|
||||||
f"Setting Variants to default in Test {name} is redundant",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
variants = variants.split()
|
|
||||||
formats = test.get("Formats", default_format)
|
|
||||||
if formats == "any":
|
|
||||||
formats = all_formats
|
|
||||||
elif formats == "default":
|
|
||||||
print(
|
|
||||||
f"Setting Formats to default in Test {name} is redundant",
|
|
||||||
file=sys.stderr,
|
|
||||||
)
|
|
||||||
exit(1)
|
|
||||||
else:
|
|
||||||
formats = formats.split()
|
|
||||||
for dist in dists:
|
|
||||||
for mode in modes:
|
|
||||||
for variant in variants:
|
|
||||||
for fmt in formats:
|
|
||||||
skipreason = skip(
|
|
||||||
test.get("Skip-If"), dist, mode, variant, fmt
|
|
||||||
)
|
|
||||||
if skipreason:
|
|
||||||
tt = ("skip", skipreason)
|
|
||||||
elif have_qemu:
|
|
||||||
tt = "qemu"
|
|
||||||
elif test.get("Needs-QEMU", "false") == "true":
|
|
||||||
tt = ("skip", "test needs QEMU")
|
|
||||||
elif test.get("Needs-Root", "false") == "true":
|
|
||||||
tt = "sudo"
|
|
||||||
elif mode == "auto" and not have_unshare:
|
|
||||||
tt = "sudo"
|
|
||||||
elif mode == "root":
|
|
||||||
tt = "sudo"
|
|
||||||
elif mode == "unshare" and not have_unshare:
|
|
||||||
tt = ("skip", "test needs unshare")
|
|
||||||
else:
|
|
||||||
tt = "null"
|
|
||||||
tests.append((tt, name, dist, mode, variant, fmt))
|
|
||||||
|
|
||||||
torun = []
|
torun = []
|
||||||
num_tests = len(tests)
|
num_tests = len(tests)
|
||||||
|
|
|
@ -45,7 +45,7 @@ Needs-QEMU: true
|
||||||
Test: check-for-bit-by-bit-identical-format-output
|
Test: check-for-bit-by-bit-identical-format-output
|
||||||
Needs-QEMU: true
|
Needs-QEMU: true
|
||||||
Formats: tar squashfs ext2
|
Formats: tar squashfs ext2
|
||||||
Variants: essential apt minbase buildd important standard
|
Variants: essential apt minbase buildd - standard
|
||||||
Skip-If:
|
Skip-If:
|
||||||
variant == "standard" and dist in ["oldstable", "stable"] # #864082, #1004557, #1004558
|
variant == "standard" and dist in ["oldstable", "stable"] # #864082, #1004557, #1004558
|
||||||
variant == "important" and dist == "oldstable" # /var/lib/systemd/catalog/database differs
|
variant == "important" and dist == "oldstable" # /var/lib/systemd/catalog/database differs
|
||||||
|
|
Loading…
Reference in a new issue