Skip to content

Commit 2d9d5c3

Browse files
authored
Merge pull request #878 from InfiniTensor/issue/877
issue/877 - return saved_file in TestManager.test method
2 parents caa61e9 + 631a1fc commit 2d9d5c3

File tree

6 files changed

+36
-16
lines changed

6 files changed

+36
-16
lines changed

test/infinicore/framework/executor.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def execute(self, file_path, test_args) -> OperatorResult:
5959
test_summary = TestSummary()
6060
test_summary.process_operator_result(result, test_results)
6161

62+
# Store saved report file if available
63+
result.saved_file = runner.saved_file
64+
6265
except Exception as e:
6366
result.success = False
6467
result.error_message = str(e)

test/infinicore/framework/results.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class OperatorResult:
4343
stdout: str = ""
4444
stderr: str = ""
4545
timing: TestTiming = field(default_factory=TestTiming)
46+
saved_file: str = "" # Path to the saved report file
4647

4748
@property
4849
def status_icon(self):
@@ -262,11 +263,12 @@ def collect_report_entry(self, op_name, test_cases, args, op_paths, results_list
262263
def save_report(self, save_path):
263264
"""
264265
Delegates the actual writing to save_json_report.
266+
Returns the actual file path that was saved (with timestamp).
265267
"""
266268
if not self.report_entries:
267-
return
268-
# Call the external utility
269-
save_json_report(save_path, self.report_entries)
269+
return None
270+
# Call the external utility and get the actual saved path
271+
return save_json_report(save_path, self.report_entries)
270272

271273
def _prepare_entry_logic(self, op_name, test_cases, args, op_paths, results_list):
272274
"""

test/infinicore/framework/runner.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def __init__(self, operator_test_class, args=None):
2020
"""
2121
self.operator_test = operator_test_class()
2222
self.args = args or get_args()
23+
self.saved_file = None # Store the path of saved report
2324

2425
def run(self):
2526
"""Execute the complete test suite
@@ -56,7 +57,7 @@ def run(self):
5657
summary_passed = runner.print_summary()
5758

5859
if getattr(self.args, "save", None):
59-
self._save_report(runner)
60+
self.saved_file = self._save_report(runner)
6061

6162
# Both conditions must be True for overall success
6263
# - has_no_failures: no test failures during execution
@@ -98,14 +99,15 @@ def _save_report(self, runner):
9899
results_list=runner.test_results,
99100
)
100101

101-
# 4. Save to File
102-
test_summary.save_report(self.args.save)
102+
# 3. Save to File and return the file name
103+
return test_summary.save_report(self.args.save)
103104

104105
except Exception as e:
105106
import traceback
106107

107108
traceback.print_exc()
108109
print(f"⚠️ Failed to save report: {e}")
110+
return None
109111

110112
def _infer_op_path(self, method, lib_prefix):
111113
"""

test/infinicore/framework/test_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def test(self, target_ops=None, json_cases_list=None, global_exec_args=None):
138138

139139
self.summary.print_header(display_location, len(test_files))
140140

141+
saved_files = []
141142
for f, run_args in zip(test_files, test_configs):
142143

143144
# Inject prepared args (whether from JSON or Local global) into Executor
@@ -146,6 +147,10 @@ def test(self, target_ops=None, json_cases_list=None, global_exec_args=None):
146147
self.results.append(result)
147148
self.summary.print_live_result(result)
148149

150+
# Collect saved report files
151+
if hasattr(result, "saved_file") and result.saved_file:
152+
saved_files.append(result.saved_file)
153+
149154
if result.success:
150155
self._accumulate_timing(result.timing)
151156

@@ -160,7 +165,8 @@ def test(self, target_ops=None, json_cases_list=None, global_exec_args=None):
160165
ops_dir=display_location,
161166
total_expected=len(test_files),
162167
)
163-
return all_passed
168+
169+
return all_passed, saved_files
164170

165171
def _accumulate_timing(self, timing):
166172
self.cumulative_timing.torch_host += timing.torch_host

test/infinicore/framework/utils/json_utils.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ def save_json_report(save_path, total_results):
77
"""
88
Saves the report list to a JSON file with specific custom formatting
99
(Compact for short lines, Expanded for long lines).
10+
11+
Returns:
12+
str: The actual file path that was saved (with timestamp), or None if failed.
1013
"""
1114
directory, filename = os.path.split(save_path)
1215
name, ext = os.path.splitext(filename)
@@ -85,11 +88,13 @@ def _to_json(obj):
8588
f.write(f"{I4}{close_entry}\n")
8689
f.write("]\n")
8790
print(f" ✅ Saved.")
91+
return final_path
8892
except Exception as e:
8993
import traceback
9094

9195
traceback.print_exc()
9296
print(f" ❌ Save failed: {e}")
97+
return None
9398

9499

95100
def _write_field(f, key, value, indent, sub_indent, close_comma=""):

test/infinicore/run.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,24 +130,24 @@ def load_and_override_cases(load_paths, args):
130130

131131
for f_path in files_to_read:
132132
try:
133-
with open(f_path, 'r', encoding='utf-8') as f:
133+
with open(f_path, "r", encoding="utf-8") as f:
134134
data = json.load(f)
135-
135+
136136
# Unify as a list to handle both single dict and list of dicts
137137
current_batch = data if isinstance(data, list) else [data]
138-
138+
139139
valid_batch = []
140140
for item in current_batch:
141141
# We only require the 'operator' field to identify the test case.
142142
if isinstance(item, dict) and "operator" in item:
143143
valid_batch.append(item)
144144
else:
145145
skipped_count += 1
146-
146+
147147
if valid_batch:
148148
cases.extend(valid_batch)
149149
loaded_count += 1
150-
150+
151151
except Exception as e:
152152
# Log warning only; do not crash the program on bad files to ensure flow continuity.
153153
print(f"❌ Error loading {f_path.name}: {e}")
@@ -173,7 +173,7 @@ def load_and_override_cases(load_paths, args):
173173
cli_active_devices.append(device_name)
174174

175175
print(f"\n[Config Processing]")
176-
176+
177177
for case in cases:
178178
if "args" not in case or case["args"] is None:
179179
case["args"] = {}
@@ -283,9 +283,11 @@ def main():
283283
print(f"Benchmark mode: {args.bench.upper()} timing")
284284

285285
# 3. Initialize and Execute
286-
test_manager = TestManager(ops_dir=args.ops_dir, verbose=verbose, bench_mode=bench)
286+
test_manager = TestManager(
287+
ops_dir=args.ops_dir, verbose=verbose, bench_mode=bench
288+
)
287289

288-
success = test_manager.test(json_cases_list=json_cases)
290+
success, _ = test_manager.test(json_cases_list=json_cases)
289291

290292
# ==========================================================================
291293
# Branch 2: Local Scan Mode
@@ -330,7 +332,7 @@ def main():
330332
ops_dir=args.ops_dir, verbose=args.verbose, bench_mode=args.bench
331333
)
332334

333-
success = test_manager.test(
335+
success, _ = test_manager.test(
334336
target_ops=target_ops, global_exec_args=global_exec_args
335337
)
336338
sys.exit(0 if success else 1)

0 commit comments

Comments
 (0)