diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:48:59 +0000 |
commit | c484829272cd13a738e35412498e12f2c9a194ac (patch) | |
tree | a1f5ec09629ee895bd3963fa8820b45f2f4c574b /bin/run-bulk-tests.py | |
parent | Initial commit. (diff) | |
download | liborcus-c484829272cd13a738e35412498e12f2c9a194ac.tar.xz liborcus-c484829272cd13a738e35412498e12f2c9a194ac.zip |
Adding upstream version 0.19.2.upstream/0.19.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'bin/run-bulk-tests.py')
-rwxr-xr-x | bin/run-bulk-tests.py | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/bin/run-bulk-tests.py b/bin/run-bulk-tests.py new file mode 100755 index 0000000..a2dd6b1 --- /dev/null +++ b/bin/run-bulk-tests.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python3 +######################################################################## +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +######################################################################## + +import argparse +import io +import os +import subprocess +from pathlib import Path + + +def main(): + desc = """Tool to bulk-test a number of files and collect all their results + into a single output directory.""" + + parser = argparse.ArgumentParser(description=desc) + parser.add_argument("--args", type=str, required=True) + parser.add_argument("--ext", "-e", type=str, required=True, help="File extension to use.") + parser.add_argument("--outdir", "-o", type=Path, required=True, help="Output directory to put the run results in.") + parser.add_argument("dirs", nargs='*', type=Path) + args = parser.parse_args() + + args.outdir.joinpath("good").mkdir(parents=True, exist_ok=True) + args.outdir.joinpath("bad").mkdir(parents=True, exist_ok=True) + + ext = args.ext + if ext and ext[0] != '.': + ext = f".{ext}" + + count = 0 + for parent_dir in args.dirs: + for rootdir, _, files in os.walk(parent_dir): + for f in files: + filepath = Path(rootdir) / f + if filepath.suffix != ext: + continue + + buf = io.StringIO() + cmd = args.args.split() + cmd.append(str(filepath)) + res = subprocess.run(cmd, capture_output=True) + outpath = args.outdir + outpath /= "good" if res.returncode == 0 else "bad" + outpath /= f"{count:04d}.txt" + print("-- command --", file=buf) + print(" ".join(cmd), file=buf) + print("-- return-code --", file=buf) + print(res.returncode, file=buf) + print("-- stdout --", file=buf) + print(res.stdout.decode("utf-8"), file=buf) + print("-- stderr --", file=buf) + print(res.stderr.decode("utf-8"), file=buf) + outpath.write_text(buf.getvalue()) + count += 1 + + +if __name__ == "__main__": + main() |