Exemplo n.º 1
0
def test_validate_state_no_reward():
    state = CompilerEnvState(
        benchmark="cBench-v0/dijkstra",
        walltime=1,
        commandline="opt  input.bc -o output.bc",
    )
    env = gym.make("llvm-v0")
    try:
        result = validate_state(env, state)
    finally:
        env.close()

    assert result.success
    assert not result.failed
    assert not result.reward_validated
    assert str(result) == "✅  cBench-v0/dijkstra"
Exemplo n.º 2
0
def test_validate_state_with_reward():
    state = CompilerEnvState(
        benchmark="cBench-v0/crc32",
        walltime=1,
        reward=0,
        commandline="opt  input.bc -o output.bc",
    )
    env = gym.make("llvm-v0", reward_space="IrInstructionCount")
    try:
        env.require_dataset("cBench-v0")
        result = validate_state(env, state)
    finally:
        env.close()

    assert result.success
    assert not result.failed
    assert result.reward_validated
    assert not result.reward_validation_failed
    assert str(result) == "✅  cBench-v0/crc32  0.0000"
Exemplo n.º 3
0
def test_validate_state_invalid_reward():
    state = CompilerEnvState(
        benchmark="cBench-v0/dijkstra",
        walltime=1,
        reward=1,
        commandline="opt  input.bc -o output.bc",
    )
    env = gym.make("llvm-v0", reward_space="IrInstructionCount")
    try:
        result = validate_state(env, state)
    finally:
        env.close()

    assert not result.success
    assert result.failed
    assert result.reward_validated
    assert result.reward_validation_failed
    assert (
        str(result) ==
        "❌  cBench-v0/dijkstra  Expected reward 1.0000 but received reward 0.0000"
    )