"""Check PGO VF availability through the public plugin entry point."""
from contextlib import nullcontext
import pytest
_PGO_VF_UNAVAILABLE = "PGOVFRun is not implemented: the PGO VF implementation is unavailable"
def duration_estimate(seconds: float):
"""Annotate a test case with an estimated duration (seconds)."""
def decorator(func):
func.duration_estimate = seconds
return func
return decorator
@pytest.fixture(scope="session")
def pgo_vf_available():
from pypto_pro import ir
span = ir.Span.unknown()
function = ir.Function("pgo_vf_probe", [], [], ir.ReturnStmt([], span), span)
program = ir.Program([function], "pgo_vf_probe", span)
try:
out_program, out_function = ir.PGOVFRun(program, None)
except RuntimeError as error:
if _PGO_VF_UNAVAILABLE not in str(error):
raise
return False
assert out_program is not None
assert out_function is None
return True
@pytest.fixture
def expect_pgo_vf(pgo_vf_available):
def expectation(required=True):
if not required or pgo_vf_available:
return nullcontext()
return pytest.raises(
RuntimeError,
match=_PGO_VF_UNAVAILABLE,
)
return expectation