MCPcopy Create free account
hub / github.com/NVIDIA/SOL-ExecBench / test_example

Function test_example

tests/examples/test_examples.py:196–264  ·  view source on GitHub ↗

End-to-end evaluation: load example -> package -> compile (if C++) -> execute -> assert PASSED.

(tmp_path: Path, case: Example)

Source from the content-addressed store, hash-verified

194 [pytest.param(c, id=c.test_id, marks=_mark_example(c)) for c in _EXAMPLES],
195)
196def test_example(tmp_path: Path, case: Example):
197 """End-to-end evaluation: load example -> package -> compile (if C++) -> execute -> assert PASSED."""
198 definition, solution, workloads = _load_example(
199 case.language, case.problem, case.solution_file
200 )
201 config = BenchmarkConfig(lock_clocks=False)
202
203 pkg = ProblemPackager(
204 definition=definition,
205 workloads=workloads,
206 solution=solution,
207 config=config,
208 output_dir=tmp_path / "staging",
209 keep_output_dir=True,
210 )
211
212 # Phase 1 (C++ only): compile
213 languages = {lang.value for lang in solution.spec.languages}
214 if languages & _CPP_LANGUAGES:
215 cmd, artifact_path = pkg.compile()
216 result = _run_subprocess(cmd, cwd=pkg.output_dir)
217 assert result.returncode == 0, (
218 f"Compilation failed for {case.test_id}:\n"
219 f" stdout={result.stdout}\n stderr={result.stderr}"
220 )
221 assert Path(artifact_path).exists(), (
222 f"benchmark_kernel.so not produced for {case.test_id}"
223 )
224
225 # Phase 2: GPU evaluation
226 cmd = pkg.execute()
227 result = _run_subprocess(cmd, cwd=pkg.output_dir)
228 assert result.returncode == 0, (
229 f"Execution failed for {case.test_id}:\n"
230 f" stdout={result.stdout}\n stderr={result.stderr}"
231 )
232
233 traces = pkg.convert_stdout_to_traces(result.stdout)
234 assert len(traces) == case.expected_count, (
235 f"Expected {case.expected_count} traces for {case.test_id}, got {len(traces)}"
236 )
237
238 failed = [t for t in traces if not t.is_successful()]
239 assert not failed, (
240 f"{case.test_id}: {len(failed)}/{case.expected_count} workloads did not pass:\n"
241 + "\n".join(
242 f" [{t.evaluation.status.value}] uuid={t.workload.uuid} "
243 f"log={t.evaluation.log}"
244 for t in failed
245 )
246 )
247
248 # Per-trace invariants for PASSED workloads
249 for trace in traces:
250 assert trace.definition == definition.name
251
252 ev = trace.evaluation
253 assert ev.correctness is not None, (

Callers

nothing calls this directly

Calls 8

compileMethod · 0.95
executeMethod · 0.95
BenchmarkConfigClass · 0.90
ProblemPackagerClass · 0.90
_load_exampleFunction · 0.85
is_successfulMethod · 0.80
_run_subprocessFunction · 0.70

Tested by

no test coverage detected