From bc4916d4a7de6a60d8b73ed7e3ccc0ec0695d580 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 19:40:38 +0000 Subject: tests: record the vercmp oracle instead of spawning it 1,089 times The differential against pacman's vercmp is the suite's second biggest process cost, and its verdicts are a function of two strings plus the pacman that produced them. They are recorded in testcorpus/vercmp-oracle.tsv now and compared in process on every run, antisymmetry of the table included. The live differential is still there - AUR_LIVE_VERCMP=1 runs it and says so when it is not run. --- tools/gen-vercmp-oracle.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 tools/gen-vercmp-oracle.py (limited to 'tools/gen-vercmp-oracle.py') diff --git a/tools/gen-vercmp-oracle.py b/tools/gen-vercmp-oracle.py new file mode 100755 index 0000000..992e10c --- /dev/null +++ b/tools/gen-vercmp-oracle.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +"""Regenerate testcorpus/vercmp-oracle.tsv from pacman's `vercmp`. + +The suite used to shell out to `vercmp` 1,090 times per run to differential-test +pkgver::vercmp_string. The verdicts are a function of the two strings and the +pacman version that produced them, so they are recorded once here and compared +in process instead. The live differential still exists — tests/versions.rs runs +it when AUR_LIVE_VERCMP is set — this is the part that runs on every run. + +Usage: tools/gen-vercmp-oracle.py [path] +""" + +import os +import subprocess +import sys + +FRAGMENTS = [ + "1", "1.0", "1.0.0", "1.0.1", "1.1", "2", "2.0", "1.0a", "1.0rc1", "1.0.2a", "1.0.2.1", + "1.0.2.a", "1.0.2.aa", "1.0.2.b", "1.0.2z", "1.0z", "1.0.z", "0.9", "10", "2.24", "2.5", + "1.02", "1.0_2", "1.0.p", "1.0.3a", "1.0.3b", "1.a", "1a", "1.0+git", "1.0~beta", "2.0_1", + "1.0.x", "2024.01", +] + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +OUT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(ROOT, "testcorpus", "vercmp-oracle.tsv") + + +def main(): + pacman = subprocess.run(["pacman", "-Q", "pacman"], capture_output=True, text=True).stdout.strip() + rows = [] + for a in FRAGMENTS: + for b in FRAGMENTS: + verdict = int(subprocess.run(["vercmp", a, b], capture_output=True, text=True).stdout.strip()) + rows.append(f"{a}\t{b}\t{verdict}") + + with open(OUT, "w") as handle: + handle.write("# pkgver::vercmp_string differential, generated by tools/gen-vercmp-oracle.py\n") + handle.write(f"# oracle: {pacman or 'vercmp not owned by pacman'}\n") + handle.write("# columns: a b sign(vercmp a b)\n") + handle.write("\n".join(rows) + "\n") + print(f"{OUT}: {len(rows)} rows") + + +if __name__ == "__main__": + main() -- cgit v1.2.3