Skip to content

Commit 31acb9e

Browse files
committed
bisect test
1 parent c3c0da2 commit 31acb9e

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

.ci/bisect/regression_detector.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import argparse
21
import os
32
import subprocess
43

5-
# The default regression threshold is 10%
4+
from pathlib import Path
5+
# the default regression threshold is 10%
66
REGRESSION_THRESHOLD = float(os.environ.get("REGRESSION_THRESHOLD", 0.1))
7+
# functional or performance regression
8+
FUNCTIONAL = bool(os.environ.get("FUNCTIONAL", False))
9+
# repro command line
710
REPRO_CMDLINE = os.environ.get("REPRO_CMDLINE", None)
8-
FUNCTIONAL = os.environ.get("FUNCTIONAL", False)
11+
# baseline log file
912
BASELINE_LOG = os.environ.get("BASELINE_LOG", None)
1013

14+
REPO_DIR = Path(__file__).parent.parent.parent
15+
1116
def get_baseline(baseline_log) -> float:
1217
with open(baseline_log, "r") as f:
1318
last_line = f.readlines()[-1]
@@ -27,7 +32,7 @@ def get_current_value(stdout_lines) -> float:
2732
# functional regression
2833
if FUNCTIONAL:
2934
try:
30-
subprocess.check_call(cmdline)
35+
subprocess.check_call(cmdline, cwd=REPO_DIR)
3136
except subprocess.CalledProcessError as e:
3237
print(f"cmd line {cmdline} failed: {e}")
3338
exit(e.returncode)
@@ -36,16 +41,18 @@ def get_current_value(stdout_lines) -> float:
3641
has_baseline = True
3742
else:
3843
has_baseline = False
39-
p = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.STDERR)
44+
p = subprocess.Popen(cmdline, cwd=REPO_DIR, stdout=subprocess.PIPE, stderr=None)
4045
assert p.stdout is not None
4146
stdout_lines = []
4247
for line in p.stdout:
43-
print(line)
44-
stdout_lines.append(line)
48+
decoded_line = line.decode("utf-8").strip()
49+
print(decoded_line)
50+
stdout_lines.append(decoded_line)
4551
rc = p.wait()
4652
if not has_baseline:
53+
Path(BASELINE_LOG).touch()
4754
with open(BASELINE_LOG, "w") as f:
48-
f.write("\n".join(stdout_lines))
55+
f.write("\n".join(stdout_lines) + "\n")
4956
exit(rc)
5057
# if subprocess failed, exit with the return code
5158
if not rc == 0:

0 commit comments

Comments
 (0)