Add observation entries to test and implement one test for each
"""Integrations tests for the LLVM CompilerGym environments."""
import os
import sys
-from typing import Any, Dict, List
+from typing import Any, Dict, List, NamedTuple
import gym
import networkx as nx
@@ -62,7 +62,8 @@ def test_observation_spaces(env: LlvmEnv):
"IrSha1",
"IsBuildable",
"IsRunnable",
- "ObjectTextSizeBytes",
+ "LexedIr",
+ "LexedIrTuple" "ObjectTextSizeBytes",
"ObjectTextSizeO0",
"ObjectTextSizeO3",
"ObjectTextSizeOz",
@@ -410,6 +411,31 @@ def test_autophase_dict_observation_space(env: LlvmEnv):
assert not space.platform_dependent
+def test_lexed_ir_observation_space(env: LlvmEnv):
+ env.reset("cbench-v1/crc32")
+ key = "LexedIr"
+ space = env.observation.spaces[key]
+ assert isinstance(space.space, DictSpace)
+ value: Dict[str, np.array] = env.observation[key]
+ print(value) # For debugging in case of error
+ assert len(value) == 4
+
+ assert space.deterministic
+ assert not space.platform_dependent
+
+
+def test_lexed_ir_tuple_observation_space(env: LlvmEnv):
+ env.reset("cbench-v1/crc32")
+ key = "LexedIrTuple"
+ space = env.observation.spaces[key]
+ assert isinstance(space.space, Sequence)
+ value: List[NamedTuple] = env.observation[key]
+ print(value) # For debugging in case of error
+
+ assert space.deterministic
+ assert not space.platform_dependent
+
+
def test_programl_observation_space(env: LlvmEnv):
env.reset("cbench-v1/crc32")
key = "Programl"
