File: optimize_test_dirs.py

package info (click to toggle)
cp2k 2025.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 366,832 kB
  • sloc: fortran: 955,049; f90: 21,676; ansic: 18,058; python: 13,378; sh: 12,179; xml: 2,173; makefile: 964; pascal: 845; perl: 492; lisp: 272; cpp: 137; csh: 16
file content (53 lines) | stat: -rwxr-xr-x 1,568 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3

# author: Ole Schuett

import argparse
from pathlib import Path
import re


# ======================================================================================
def main() -> None:
    parser = argparse.ArgumentParser(description="Sorts the test dirs by duration.")
    parser.add_argument("regtest_report")
    args = parser.parse_args()

    report = Path(args.regtest_report).read_text(encoding="utf8")
    match = re.search(">>> (.*?)/UNIT\n", report)
    assert match
    report_basedir = match.group(1)

    timings = {}
    for line in re.findall("<<< (.*?)\n", report):
        parts = line.split()
        name = parts[0][len(report_basedir) + 1 :]
        timings[name] = float(parts[6])

    cp2k_root = Path(__file__).resolve().parent.parent.parent
    test_dirs_fn = cp2k_root / "tests" / "TEST_DIRS"
    header_lines = []
    test_dir_lines = []
    for line in test_dirs_fn.read_text(encoding="utf8").split("\n"):
        if not line.strip():
            pass
        elif line.startswith("#"):
            header_lines.append(line)
        else:
            test_dir_lines.append(line)

    def sort_key(line: str) -> float:
        return timings.get(line.split()[0], float("inf"))

    test_dir_lines.sort(key=sort_key, reverse=True)
    output = "\n".join(header_lines + test_dir_lines) + "\n"
    test_dirs_fn.write_text(output, encoding="utf8")

    print(f"Updated {test_dirs_fn}")


# ======================================================================================
if __name__ == "__main__":
    main()

# EOF