This is an automated email from the ASF dual-hosted git repository.

jimjag pushed a commit to branch odf-devel
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit fee4d277cbe84edb84b03e060d5f63d36dbd2172
Author: Jim Jagielski <[email protected]>
AuthorDate: Wed Oct 28 12:59:39 2026 -0400

    test/odf-validate: redo gate dumps lost to an office crash
---
 test/odf-validate/gate.py     | 63 ++++++++++++++++++++++++++++++-------------
 test/odf-validate/selftest.py | 20 ++++++++++++++
 2 files changed, 64 insertions(+), 19 deletions(-)

diff --git a/test/odf-validate/gate.py b/test/odf-validate/gate.py
index c71bddec7d..bbf6e0f23f 100644
--- a/test/odf-validate/gate.py
+++ b/test/odf-validate/gate.py
@@ -104,6 +104,15 @@ def run_with_stall(cmd, progress, stall, poll=2.0, 
log=None):
             out.close()
 
 
+def bridge_dead(path):
+    """True for a dump that only records that the office died under an earlier 
document."""
+    try:
+        d = json.load(open(path))
+    except Exception:
+        return False
+    return isinstance(d, dict) and str(d.get("error", "")).startswith("Binary 
URP bridge")
+
+
 def dump_dir(src, dest, profile, port, stall, log, tool=None, poll=2.0):
     """Reloads every package in src into dest/*.json. A document that stalls 
the office or kills it gets an error
     marker only after `stall` seconds without progress, never because the 
whole batch took long.
@@ -112,27 +121,41 @@ def dump_dir(src, dest, profile, port, stall, log, 
tool=None, poll=2.0):
     files = sorted(os.path.join(src, f) for f in os.listdir(src) if not 
f.startswith("."))
     count = lambda: len([f for f in os.listdir(dest) if f.endswith(".json")])
     stalls = 0
-    while count() < len(files):
-        if tool is None and not listening(port):
-            if run([os.path.join(D, "start.sh"), profile, str(port)], log) != 
0:
-                return {"error": "office did not start", "stalls": stalls}
-        before = count()
-        marker = os.path.join(dest, ".current")
-        argv = tool(port, dest, files) if tool else [os.path.join(D, 
"runpy.sh"), os.path.join(D, "dump7.py"), str(port), dest] + files
-        how, rc = run_with_stall(argv, lambda: (count(), 
os.path.getmtime(marker) if os.path.exists(marker) else 0), stall, poll, 
log=log)
-        if how == "stalled" or rc != 0:
-            cur = open(marker).read().strip() if os.path.exists(marker) else ""
-            if cur and not os.path.exists(os.path.join(dest, 
os.path.basename(cur) + ".json")):
-                reason = ("HANG: no progress for %ds" % stall) if how == 
"stalled" else "CRASH: rc=%s" % rc
-                json.dump({"error": reason}, open(os.path.join(dest, 
os.path.basename(cur) + ".json"), "w"))
-                stalls += 1
-            if tool is None:
-                kill_office(profile)
-        elif count() == before:
-            return {"error": "dump7.py made no progress", "stalls": stalls}
+    retried = 0
+    for attempt in range(4):
+        while count() < len(files):
+            if tool is None and not listening(port):
+                if run([os.path.join(D, "start.sh"), profile, str(port)], log) 
!= 0:
+                    return {"error": "office did not start", "stalls": stalls}
+            before = count()
+            marker = os.path.join(dest, ".current")
+            argv = tool(port, dest, files) if tool else [os.path.join(D, 
"runpy.sh"), os.path.join(D, "dump7.py"), str(port), dest] + files
+            how, rc = run_with_stall(argv, lambda: (count(), 
os.path.getmtime(marker) if os.path.exists(marker) else 0), stall, poll, 
log=log)
+            if how == "stalled" or rc != 0:
+                cur = open(marker).read().strip() if os.path.exists(marker) 
else ""
+                if cur and not os.path.exists(os.path.join(dest, 
os.path.basename(cur) + ".json")):
+                    reason = ("HANG: no progress for %ds" % stall) if how == 
"stalled" else "CRASH: rc=%s" % rc
+                    json.dump({"error": reason}, open(os.path.join(dest, 
os.path.basename(cur) + ".json"), "w"))
+                    stalls += 1
+                if tool is None:
+                    kill_office(profile)
+            elif count() == before:
+                return {"error": "dump7.py made no progress", "stalls": stalls}
+        # dump7.py records "bridge disposed" for every document after an 
office crash; those are not dumps, so redo them
+        gone = [f for f in os.listdir(dest) if f.endswith(".json") and 
bridge_dead(os.path.join(dest, f))]
+        if not gone or attempt == 3:
+            break
+        if tool is None:
+            kill_office(profile)
+        for f in gone:
+            os.remove(os.path.join(dest, f))
+        retried += len(gone)
     if tool is None:
         kill_office(profile)
-    return {"documents": count(), "stalls": stalls}
+    res = {"documents": count(), "stalls": stalls}
+    if retried:
+        res["bridge_retried"] = retried
+    return res
 
 
 def count_done(done):
@@ -268,6 +291,8 @@ class Gate:
         res["ok"] = all("error" not in r for r in res.values())
         for mode in self.modes:
             md = os.path.join(self.run, mode, "dump")
+            res[mode]["bridge_errors"] = sorted(f for f in os.listdir(md) if 
f.endswith(".json") and bridge_dead(os.path.join(md, f)))
+            res["ok"] = res["ok"] and not res[mode]["bridge_errors"]
             res[mode]["hang_markers"] = sorted(f for f in os.listdir(md) if 
f.endswith(".json") and "error" in json.load(open(os.path.join(md, f))) and
                                                
str(json.load(open(os.path.join(md, f)))["error"]).startswith(("HANG", 
"CRASH")))
         return res
diff --git a/test/odf-validate/selftest.py b/test/odf-validate/selftest.py
index 36d4773202..77443f0f37 100644
--- a/test/odf-validate/selftest.py
+++ b/test/odf-validate/selftest.py
@@ -165,6 +165,26 @@ for n in ("d", "e", "f"):
 t0 = time.time()
 r2 = gt.dump_dir(gsrc, os.path.join(gtmp, "d2"), "p", 0, 2, os.path.join(gtmp, 
"l2"), tool=mk, poll=0.3)
 checks["gate: a batch longer than the stall limit that keeps progressing is 
not killed"] = r2 == {"documents": 6, "stalls": 0} and time.time() - t0 > 2
+stub2 = os.path.join(gtmp, "stub2.py")   # a document that "kills the office": 
it and the rest get a bridge error, once
+open(stub2, "w").write("import 
sys,os,json\ndest=sys.argv[1]\nonce=os.path.join(dest,'.once')\nbad=False\nfor 
f in sys.argv[2:]:\n    d=os.path.join(dest,os.path.basename(f)+'.json')\n"
+                       "    if os.path.exists(d): continue\n    if 
os.path.basename(f)=='bad' and not os.path.exists(once): 
open(once,'w').write('x'); bad=True\n"
+                       "    json.dump({'error':'Binary URP bridge already 
disposed'} if bad else {'type':'x'},open(d,'w'))\n")
+stub3 = os.path.join(gtmp, "stub3.py")   # the same document always kills the 
office
+open(stub3, "w").write("import sys,os,json\ndest=sys.argv[1]\nbad=False\nfor f 
in sys.argv[2:]:\n    d=os.path.join(dest,os.path.basename(f)+'.json')\n"
+                       "    if os.path.exists(d): continue\n    bad = bad or 
os.path.basename(f)=='bad'\n"
+                       "    json.dump({'error':'Binary URP bridge already 
disposed'} if bad else {'type':'x'},open(d,'w'))\n")
+gsrc2 = os.path.join(gtmp, "src2")
+os.makedirs(gsrc2)
+for n in ("a", "bad", "c", "d"):
+    open(os.path.join(gsrc2, n), "w").write("x")
+mk2 = lambda port, dest, files: [sys.executable, stub2, dest] + files
+mk3 = lambda port, dest, files: [sys.executable, stub3, dest] + files
+r3 = gt.dump_dir(gsrc2, os.path.join(gtmp, "d3"), "p", 0, 5, 
os.path.join(gtmp, "l3"), tool=mk2, poll=0.3)
+checks["gate: dumps that only say 'bridge disposed' are redone and counted"] = 
r3 == {"documents": 4, "stalls": 0, "bridge_retried": 3} \
+    and not any(gt.bridge_dead(os.path.join(gtmp, "d3", n + ".json")) for n in 
("a", "bad", "c", "d"))
+r4 = gt.dump_dir(gsrc2, os.path.join(gtmp, "d4"), "p", 0, 5, 
os.path.join(gtmp, "l4"), tool=mk3, poll=0.3)
+checks["gate: a document that always kills the office stays an error after the 
retries (negative control)"] = r4["documents"] == 4 \
+    and r4["bridge_retried"] == 9 and gt.bridge_dead(os.path.join(gtmp, "d4", 
"bad.json")) and not gt.bridge_dead(os.path.join(gtmp, "d4", "a.json"))
 for k, ok in checks.items():
     print(("PASS " if ok else "FAIL ") + k)
 sys.exit(0 if all(checks.values()) else 1)

Reply via email to