From 8092073a2b6ca4432f4391b6f38258356f144332 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Mon, 9 Jun 2025 17:44:19 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testbot/testbot.py | 115 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 8 deletions(-) diff --git a/testbot/testbot.py b/testbot/testbot.py index edb75ed..148b6be 100644 --- a/testbot/testbot.py +++ b/testbot/testbot.py @@ -8,6 +8,7 @@ import abc import json import schedule +from datetime import datetime CONFIG_JSON = "config.json" @@ -213,22 +214,120 @@ def install(self, config_flags=""): raise def run_python_tests(self, flags=""): - name = "运行算子python测试" + timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") + log_file = os.path.join(self.project_dir, f"python_test_{timestamp}.log") + try: - os.chdir(self.project_dir) - self.test_cmd( - f"python scripts/python_test.py {flags}", - name=name, - break_on_error=False, - ) + cmd = f"python scripts/python_test.py {flags}".strip() + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + result = subprocess.run( + cmd, + shell=True, + cwd=self.project_dir, + stdout=log, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace", + ) + if result.returncode != 0: + log.write(f"\n[ERROR] Python tests failed with return code {result.returncode}\n") + raise subprocess.CalledProcessError(result.returncode, cmd) + except Exception as e: + raise - except: + + def run_gguf_tests(self, flags=""): + timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") + log_file = os.path.join(self.project_dir, f"gguf_test_{timestamp}.log") + + try: + cmd = f"python scripts/gguf_test.py {flags}".strip() + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + result = subprocess.run( + cmd, + shell=True, + cwd=self.project_dir, + stdout=log, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace" + ) + if result.returncode != 0: + log.write(f"\n[ERROR] GGUF test failed with return code {result.returncode}\n") + raise subprocess.CalledProcessError(result.returncode, cmd) + + except Exception as e: raise + + def run_infiniccl_test(self, flags=""): + os.chdir(self.project_dir) + timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") + log_file = os.path.join(self.project_dir, f"infiniccl_test_{timestamp}.log") + + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + + def run_and_log(cmd, header): + log.write(f"\n=== {header} ===\n") + result = subprocess.run( + cmd, + shell=True, + cwd=self.project_dir, + stdout=log, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace", + ) + if result.returncode != 0: + log.write(f"\n[ERROR] '{cmd}' exited with code {result.returncode}\n") + raise subprocess.CalledProcessError(result.returncode, cmd) + + run_and_log("xmake build infiniccl-test", "Building infiniccl-test") + run_and_log("xmake install", "Installing infiniccl-test") + exe_cmd = f"build/linux/x86_64/release/infiniccl-test {flags}" + run_and_log(exe_cmd, "Running infiniccl-test") + + + def run_infinirt_test(self, flags=""): + os.chdir(self.project_dir) + timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") + log_file = os.path.join(self.project_dir, f"infinirt_test_{timestamp}.log") + + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + + def run_and_log(cmd, header): + log.write(f"\n=== {header} ===\n") + result = subprocess.run( + cmd, + shell=True, + stdout=log, + stderr=subprocess.STDOUT, + cwd=self.project_dir, + text=True, + encoding="utf-8", + errors="replace", + ) + if result.returncode != 0: + log.write(f"\n[ERROR] Command failed with exit code {result.returncode}\n") + raise subprocess.CalledProcessError(result.returncode, cmd) + + run_and_log("xmake build infinirt-test", "Building infinirt-test") + run_and_log("xmake install", "Installing infinirt-test") + + exe_cmd = f"build/linux/x86_64/release/infinirt-test {flags}" + run_and_log(exe_cmd, "Running infinirt-test") + + def run_tests(self): def _run_test(): self.install(self.get_xmake_config_flags()) self.run_python_tests(self.get_python_test_flags()) + self.run_gguf_tests(self.get_python_test_flags()) + self.run_infiniccl_test(self.get_python_test_flags()) + self.run_infinirt_test(self.get_python_test_flags()) try: self.clone_or_update() From 3626ffd9a6feec0f01fbf96e41d766951ba81cf6 Mon Sep 17 00:00:00 2001 From: Catheriany Date: Fri, 13 Jun 2025 17:17:20 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E8=BF=87=E7=A8=8BLog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- testbot/testbot.py | 121 ++++++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/testbot/testbot.py b/testbot/testbot.py index 148b6be..e531bba 100644 --- a/testbot/testbot.py +++ b/testbot/testbot.py @@ -6,10 +6,9 @@ from io import BytesIO import platform import abc -import json import schedule from datetime import datetime - +import sys CONFIG_JSON = "config.json" @@ -27,7 +26,6 @@ class Notifier(abc.ABC): def notify_results(self, meta): raise NotImplementedError() - class FeishuNotifier(Notifier): def __init__(self, config): self.webhook_url = config["url"] @@ -206,60 +204,95 @@ def __init__(self, config): def install(self, config_flags=""): name = "安装InfiniCore" - try: - os.chdir(self.project_dir) - self.test_cmd(f"python scripts/install.py {config_flags}", name=name) + timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") + log_file = os.path.join(self.project_dir, f"install_{timestamp}.log") + cmd = f"python scripts/install.py {config_flags}".strip() - except: - raise + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + proc = subprocess.Popen( + cmd, + shell=True, + cwd=self.project_dir, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace", + bufsize=1, + ) + for line in proc.stdout: + log.write(line) + sys.stdout.write(line) + sys.stdout.flush() + + returncode = proc.wait() + if returncode != 0: + err = f"\n[ERROR] {name} failed with return code {returncode}\n" + log.write(err) + sys.stdout.write(err) + raise subprocess.CalledProcessError(returncode, cmd) def run_python_tests(self, flags=""): timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") log_file = os.path.join(self.project_dir, f"python_test_{timestamp}.log") - try: - cmd = f"python scripts/python_test.py {flags}".strip() - with open(log_file, "w", encoding="utf-8", errors="replace") as log: - result = subprocess.run( - cmd, - shell=True, - cwd=self.project_dir, - stdout=log, - stderr=subprocess.STDOUT, - text=True, - encoding="utf-8", - errors="replace", - ) - if result.returncode != 0: - log.write(f"\n[ERROR] Python tests failed with return code {result.returncode}\n") - raise subprocess.CalledProcessError(result.returncode, cmd) - except Exception as e: - raise + cmd = f"python scripts/python_test.py {flags}".strip() + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + process = subprocess.Popen( + cmd, + shell=True, + cwd=self.project_dir, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace", + ) + + for line in process.stdout: + log.write(line) + sys.stdout.write(line) + sys.stdout.flush() + + returncode = process.wait() + + if returncode != 0: + err_msg = f"\n[ERROR] Python tests failed with return code {returncode}\n" + log.write(err_msg) + sys.stdout.write(err_msg) + raise subprocess.CalledProcessError(returncode, cmd) def run_gguf_tests(self, flags=""): timestamp = datetime.now().strftime("%Y%m%d-%H%M%S") log_file = os.path.join(self.project_dir, f"gguf_test_{timestamp}.log") - try: - cmd = f"python scripts/gguf_test.py {flags}".strip() - with open(log_file, "w", encoding="utf-8", errors="replace") as log: - result = subprocess.run( - cmd, - shell=True, - cwd=self.project_dir, - stdout=log, - stderr=subprocess.STDOUT, - text=True, - encoding="utf-8", - errors="replace" - ) - if result.returncode != 0: - log.write(f"\n[ERROR] GGUF test failed with return code {result.returncode}\n") - raise subprocess.CalledProcessError(result.returncode, cmd) + cmd = f"python scripts/gguf_test.py {flags}".strip() + with open(log_file, "w", encoding="utf-8", errors="replace") as log: + proc = subprocess.Popen( + cmd, + shell=True, + cwd=self.project_dir, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + text=True, + encoding="utf-8", + errors="replace", + bufsize=1, + ) - except Exception as e: - raise + # 实时输出并写日志 + for line in proc.stdout: + log.write(line) + sys.stdout.write(line) + sys.stdout.flush() + + returncode = proc.wait() + if returncode != 0: + err_msg = f"\n[ERROR] GGUF test failed with return code {returncode}\n" + log.write(err_msg) + sys.stdout.write(err_msg) + raise subprocess.CalledProcessError(returncode, cmd) def run_infiniccl_test(self, flags=""):