Skip to content

Commit

Permalink
[tests] Only test text size values on CI.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisCummins committed Feb 23, 2022
1 parent 96c9530 commit 27cf83f
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions tests/llvm/observation_spaces_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from compiler_gym.spaces import Box
from compiler_gym.spaces import Dict as DictSpace
from compiler_gym.spaces import Scalar, Sequence
from tests.pytest_plugins.common import ci_only
from tests.test_main import main

pytest_plugins = ["tests.pytest_plugins.llvm"]
Expand Down Expand Up @@ -1211,14 +1212,6 @@ def test_object_text_size_observation_spaces(env: LlvmEnv):
def test_text_size_observation_spaces(env: LlvmEnv):
env.reset("cbench-v1/crc32")

# Expected .text sizes for this benchmark: -O0, -O3, -Oz.
crc32_code_sizes = {"darwin": [16384, 16384, 16384], "linux": [2850, 5652, 4980]}

# Debugging printout in case of test failure.
print(env.observation["TextSizeO0"])
print(env.observation["TextSizeO3"])
print(env.observation["TextSizeOz"])

key = "TextSizeBytes"
space = env.observation.spaces[key]
assert isinstance(space.space, Scalar)
Expand All @@ -1227,7 +1220,6 @@ def test_text_size_observation_spaces(env: LlvmEnv):
value: int = env.observation[key]
print(value) # For debugging in case of error.
assert isinstance(value, int)
assert value == crc32_code_sizes[sys.platform][0]

key = "TextSizeO0"
space = env.observation.spaces[key]
Expand All @@ -1237,7 +1229,7 @@ def test_text_size_observation_spaces(env: LlvmEnv):
value: int = env.observation[key]
print(value) # For debugging in case of error.
assert isinstance(value, int)
assert value == crc32_code_sizes[sys.platform][0]
assert value > 0 # Exact value is system dependent, see below.

key = "TextSizeO3"
space = env.observation.spaces[key]
Expand All @@ -1247,7 +1239,7 @@ def test_text_size_observation_spaces(env: LlvmEnv):
value: int = env.observation[key]
print(value) # For debugging in case of error.
assert isinstance(value, int)
assert value == crc32_code_sizes[sys.platform][1]
assert value > 0 # Exact value is system dependent, see below.

key = "TextSizeOz"
space = env.observation.spaces[key]
Expand All @@ -1257,7 +1249,29 @@ def test_text_size_observation_spaces(env: LlvmEnv):
value: int = env.observation[key]
print(value) # For debugging in case of error.
assert isinstance(value, int)
assert value == crc32_code_sizes[sys.platform][2]
assert value > 0 # Exact value is system dependent, see below.


# NOTE(cummins): The exact values here depend on the system toolchain and
# libraries, so only run this test on the GitHub CI runner environment where we
# can hardcode the values. If this test starts to fail, it may be because the CI
# runner environment has changed.
@ci_only
def test_text_size_observation_space_values(env: LlvmEnv):
env.reset("cbench-v1/crc32")

# Expected .text sizes for this benchmark: -O0, -O3, -Oz.
crc32_code_sizes = {"darwin": [16384, 16384, 16384], "linux": [2850, 5652, 4980]}

# For debugging in case of error.
print(env.observation["TextSizeO0"])
print(env.observation["TextSizeO3"])
print(env.observation["TextSizeOz"])

assert env.observation.TextSizeO0() == crc32_code_sizes[sys.platform][0]
assert env.observation.TextSizeO0() == crc32_code_sizes[sys.platform][0]
assert env.observation.TextSizeO3() == crc32_code_sizes[sys.platform][1]
assert env.observation.TextSizeOz() == crc32_code_sizes[sys.platform][2]


@flaky # Runtimes can timeout
Expand Down

0 comments on commit 27cf83f

Please sign in to comment.