def test_reset_invalid_benchmark(env: CompilerEnv): with pytest.raises(ValueError) as ctx: env.reset(benchmark="foobar") assert str(ctx.value) == "Unknown program name"
def test_invalid_observation_space(env: CompilerEnv, ): with pytest.raises(LookupError): env.observation_space = 100
def test_reward_spaces(env: CompilerEnv): env.reset() assert env.reward.spaces.keys() == {"codesize"}
def test_takeAction_before_startEpisode(env: CompilerEnv): with pytest.raises(Exception): env.step(0)
def test_getObservation_ir(env: CompilerEnv): env.reset() assert env.observation["ir"] == "Hello, world!"
def test_getReward(env: CompilerEnv): env.reset() assert env.reward["codesize"] == 0
def test_reward(benchmark, env: CompilerEnv, benchmark_name, reward_space): env.reset(benchmark_name) benchmark(lambda: env.reward[reward_space])
def test_observation( benchmark, env: CompilerEnv, fast_benchmark_name, observation_space ): env.reset(fast_benchmark_name) benchmark(lambda: env.observation[observation_space])
def test_step(benchmark, env: CompilerEnv, benchmark_name): env.reset(benchmark_name) benchmark(env.step, 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)