Skip to content

Commit 03f0a3b

Browse files
author
Chris Cummins
authored
Merge pull request #420 from ChrisCummins/ci-fixes
Test fixes and improvements
2 parents 6087892 + 348f6ff commit 03f0a3b

File tree

9 files changed

+27
-83
lines changed

9 files changed

+27
-83
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Post-installation Tests
3838
The same as `make install-test`, but with python test coverage
3939
reporting. A summary of test coverage is printed at the end of execution
4040
and the full details are recorded in a coverage.xml file in the project
41-
root directory.
41+
root directory. To print a report of file coverage to stdout at the end
42+
of testing, use argument `PYTEST_ARGS="--cov-report=term"`.
4243

4344
make install-fuzz
4445
Run the fuzz testing suite against an installed CompilerGym package.
@@ -308,7 +309,7 @@ install-test: install-test-setup
308309
# environement. This is to ensure that the reported coverage matches that of
309310
# the value on: https://codecov.io/gh/facebookresearch/CompilerGym
310311
install-test-cov: install-test-setup
311-
export CI=1; $(call pytest,--no-success-flaky-report --benchmark-disable -n auto -k "not fuzz" --durations=5 --cov=compiler_gym --cov-report=xml:$(COV_REPORT) --cov-report=term)
312+
export CI=1; $(call pytest,--no-success-flaky-report --benchmark-disable -n auto -k "not fuzz" --durations=5 --cov=compiler_gym --cov-report=xml:$(COV_REPORT))
312313

313314
# The minimum number of seconds to run the fuzz tests in a loop for. Override
314315
# this at the commandline, e.g. `FUZZ_SECONDS=1800 make fuzz`.

compiler_gym/envs/compiler_env.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ def raw_step(
895895
self.close()
896896
except ServiceError as e:
897897
# close() can raise ServiceError if the service exists with a
898-
# non-zero return code. If so,
898+
# non-zero return code. We swallow the error here but propagate
899+
# the diagnostic message.
899900
info[
900901
"error_details"
901902
] += f". Additional error during environment closing: {e}"

tests/bin/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ py_test(
1616

1717
py_test(
1818
name = "manual_env_bin_test",
19-
timeout = "short",
2019
srcs = ["manual_env_bin_test.py"],
2120
flaky = 1,
2221
deps = [

tests/llvm/BUILD

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ py_test(
118118

119119
py_test(
120120
name = "fresh_environment_observation_reward_test",
121+
timeout = "long",
121122
srcs = ["fresh_environment_observation_reward_test.py"],
122-
shard_count = 8,
123+
shard_count = 12,
123124
deps = [
124125
"//compiler_gym/envs",
125126
"//tests:test_main",
@@ -137,16 +138,6 @@ py_test(
137138
],
138139
)
139140

140-
py_test(
141-
name = "gvn_sink_test",
142-
srcs = ["gvn_sink_test.py"],
143-
deps = [
144-
"//compiler_gym/envs",
145-
"//tests:test_main",
146-
"//tests/pytest_plugins:llvm",
147-
],
148-
)
149-
150141
py_test(
151142
name = "gym_interface_compatability",
152143
timeout = "short",
@@ -217,7 +208,6 @@ py_test(
217208

218209
py_test(
219210
name = "multiprocessing_test",
220-
timeout = "short",
221211
srcs = ["multiprocessing_test.py"],
222212
flaky = 1,
223213
deps = [

tests/llvm/all_actions_single_step_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import numpy as np
88

99
from compiler_gym.envs import CompilerEnv
10+
from compiler_gym.service.connection import ServiceError
1011
from compiler_gym.third_party.autophase import AUTOPHASE_FEATURE_DIM
1112
from tests.test_main import main
1213

@@ -25,6 +26,13 @@ def test_step(env: CompilerEnv, action_name: str):
2526
assert isinstance(reward, float)
2627
assert isinstance(done, bool)
2728

29+
try:
30+
env.close()
31+
except ServiceError as e:
32+
# env.close() will raise an error if the service terminated
33+
# ungracefully. In that case, the "done" flag should have been set.
34+
assert done, f"Service error was raised when 'done' flag not set: {e}"
35+
2836

2937
if __name__ == "__main__":
3038
main()

tests/llvm/fresh_environment_observation_reward_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
# LICENSE file in the root directory of this source tree.
55
"""Integrations tests for the LLVM CompilerGym environments."""
66

7+
from flaky import flaky
8+
79
from compiler_gym.envs import CompilerEnv
810
from tests.test_main import main
911

1012
pytest_plugins = ["tests.pytest_plugins.llvm"]
1113

1214

15+
@flaky # Runtime can timeout
1316
def test_step(env: CompilerEnv, observation_space: str, reward_space: str):
1417
"""Request every combination of observation and reward in a fresh environment."""
1518
env.reward_space = None

tests/llvm/gvn_sink_test.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

tests/llvm/multiprocessing_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import gym
1111
import pytest
12+
from flaky import flaky
1213

1314
from compiler_gym.envs import LlvmEnv
1415
from tests.pytest_plugins.common import macos_only
@@ -37,6 +38,7 @@ def process_worker_with_env(env: LlvmEnv, actions: List[int], queue: mp.Queue):
3738
queue.put((env, observation, reward, done, info))
3839

3940

41+
@flaky # Test contains timeouts.
4042
def test_running_environment_in_background_process():
4143
"""Test launching and running an LLVM environment in a background process."""
4244
queue = mp.Queue(maxsize=3)
@@ -46,8 +48,8 @@ def test_running_environment_in_background_process():
4648
)
4749
process.start()
4850
try:
49-
process.join(timeout=10)
50-
result = queue.get(timeout=10)
51+
process.join(timeout=60)
52+
result = queue.get(timeout=60)
5153
observation, reward, done, info = result
5254

5355
assert not done

tests/llvm/observation_spaces_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import networkx as nx
1111
import numpy as np
1212
import pytest
13+
from flaky import flaky
1314
from gym.spaces import Box
1415
from gym.spaces import Dict as DictSpace
1516

@@ -1165,6 +1166,7 @@ def test_object_text_size_observation_spaces(env: LlvmEnv):
11651166
assert value == crc32_code_sizes[sys.platform][2]
11661167

11671168

1169+
@flaky # Runtimes can timeout
11681170
def test_runtime_observation_space(env: LlvmEnv):
11691171
env.reset("cbench-v1/crc32")
11701172
key = "Runtime"
@@ -1188,6 +1190,7 @@ def test_runtime_observation_space(env: LlvmEnv):
11881190
assert len(set(value)) > 1
11891191

11901192

1193+
@flaky # Runtimes can timeout
11911194
def test_runtime_observation_space_different_observation_count(env: LlvmEnv):
11921195
"""Test setting a custom observation count for LLVM runtimes."""
11931196
env.reset("cbench-v1/crc32")
@@ -1208,6 +1211,7 @@ def test_runtime_observation_space_different_observation_count(env: LlvmEnv):
12081211
assert value.shape == (5,)
12091212

12101213

1214+
@flaky # Runtimes can timeout
12111215
def test_runtime_observation_space_invalid_observation_count(env: LlvmEnv):
12121216
"""Test setting an invalid custom observation count for LLVM runtimes."""
12131217
env.reset("cbench-v1/crc32")
@@ -1233,6 +1237,7 @@ def test_runtime_observation_space_not_runnable(env: LlvmEnv):
12331237
assert space.space.contains(value)
12341238

12351239

1240+
@flaky # Build can timeout
12361241
def test_buildtime_observation_space(env: LlvmEnv):
12371242
env.reset("cbench-v1/crc32")
12381243
key = "Buildtime"

0 commit comments

Comments
 (0)