예제 #1
0
def test_reset_invalid_benchmark(env: CompilerEnv):
    with pytest.raises(ValueError) as ctx:
        env.reset(benchmark="foobar")
    assert str(ctx.value) == "Unknown program name"
예제 #2
0
def test_invalid_observation_space(env: CompilerEnv, ):
    with pytest.raises(LookupError):
        env.observation_space = 100
예제 #3
0
def test_reward_spaces(env: CompilerEnv):
    env.reset()
    assert env.reward.spaces.keys() == {"codesize"}
예제 #4
0
def test_takeAction_before_startEpisode(env: CompilerEnv):
    with pytest.raises(Exception):
        env.step(0)
예제 #5
0
def test_getObservation_ir(env: CompilerEnv):
    env.reset()
    assert env.observation["ir"] == "Hello, world!"
예제 #6
0
def test_getReward(env: CompilerEnv):
    env.reset()
    assert env.reward["codesize"] == 0
예제 #7
0
def test_reward(benchmark, env: CompilerEnv, benchmark_name, reward_space):
    env.reset(benchmark_name)
    benchmark(lambda: env.reward[reward_space])
예제 #8
0
def test_observation(
    benchmark, env: CompilerEnv, fast_benchmark_name, observation_space
):
    env.reset(fast_benchmark_name)
    benchmark(lambda: env.observation[observation_space])
예제 #9
0
def test_step(benchmark, env: CompilerEnv, benchmark_name):
    env.reset(benchmark_name)
    benchmark(env.step, 0)
예제 #10
0
def test_autophase_crc32_feature_vector(env: CompilerEnv):
    env.reset(benchmark="cbench-v1/crc32")
    print(env.benchmark)  # For debugging in case of error.
    features = env.observation["AutophaseDict"]
    print(features)  # For debugging on failure.
    assert features == {
        "BBNumArgsHi": 0,
        "BBNumArgsLo": 0,
        "onePred": 16,
        "onePredOneSuc": 12,
        "onePredTwoSuc": 2,
        "oneSuccessor": 16,
        "twoPred": 8,
        "twoPredOneSuc": 2,
        "twoEach": 4,
        "twoSuccessor": 8,
        "morePreds": 0,
        "BB03Phi": 0,
        "BBHiPhi": 0,
        "BBNoPhi": 29,
        "BeginPhi": 0,
        "BranchCount": 24,
        "returnInt": 9,
        "CriticalCount": 2,
        "NumEdges": 32,
        "const32Bit": 44,
        "const64Bit": 41,
        "numConstZeroes": 14,
        "numConstOnes": 36,
        "UncondBranches": 16,
        "binaryConstArg": 13,
        "NumAShrInst": 0,
        "NumAddInst": 5,
        "NumAllocaInst": 26,
        "NumAndInst": 3,
        "BlockMid": 5,
        "BlockLow": 24,
        "NumBitCastInst": 20,
        "NumBrInst": 24,
        "NumCallInst": 33,
        "NumGetElementPtrInst": 5,
        "NumICmpInst": 10,
        "NumLShrInst": 3,
        "NumLoadInst": 51,
        "NumMulInst": 0,
        "NumOrInst": 1,
        "NumPHIInst": 0,
        "NumRetInst": 5,
        "NumSExtInst": 0,
        "NumSelectInst": 0,
        "NumShlInst": 0,
        "NumStoreInst": 42,
        "NumSubInst": 0,
        "NumTruncInst": 1,
        "NumXorInst": 8,
        "NumZExtInst": 5,
        "TotalBlocks": 29,
        "TotalInsts": 242,
        "TotalMemInst": 157,
        "TotalFuncs": 15,
        "ArgsPhi": 0,
        "testUnary": 103,
    }
def test_init_benchmark(env: CompilerEnv, benchmark_name: str):
    """Create an environment for each benchmark and close it."""
    env.reset(benchmark=benchmark_name)