Skip to content

Commit 060f8ac

Browse files
author
Chris Cummins
authored
Merge pull request #462 from ChrisCummins/fuzzer
[ci] Update the fuzzer jobs
2 parents 4d8e4dd + 597b04c commit 060f8ac

File tree

4 files changed

+51
-28
lines changed

4 files changed

+51
-28
lines changed

.github/workflows/fuzz.yaml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,51 @@ on:
1111
workflow_dispatch:
1212
schedule:
1313
- cron: 0 9 * * 1-5 # every weekday at 9am
14+
# FIXME: Just for debugging:
15+
push:
16+
branches:
17+
- development
18+
- stable
19+
pull_request:
1420

1521
jobs:
1622
fuzz:
17-
runs-on: ${{ matrix.os }}
18-
19-
strategy:
20-
fail-fast: false
21-
matrix:
22-
os: [ubuntu-latest, macos-latest]
23-
python: [3.9]
23+
runs-on: ubuntu-latest
2424

2525
steps:
2626
- uses: actions/checkout@v2
2727

28-
- name: Set up Python ${{ matrix.python }}
28+
- name: Persist the bazel cache
29+
uses: actions/cache@v2
30+
with:
31+
path: ~/.cache/bazel/_bazel_runner
32+
key: bazel-${{ hashFiles('WORKSPACE') }}-${{ hashFiles('**/BUILD') }}
33+
restore-keys: |
34+
bazel-${{ hashFiles('WORKSPACE') }}-
35+
bazel-
36+
37+
- name: Set up Python
2938
uses: actions/setup-python@v2
3039
with:
31-
python-version: ${{ matrix.python }}
40+
python-version: 3.9
3241

3342
- name: Install build dependencies
3443
uses: ./.github/actions/install-build-dependencies
3544

36-
- name: Install
45+
- name: Build and install Python wheel
3746
run: make install
3847
env:
3948
CC: clang
4049
CXX: clang++
4150
BAZEL_OPTS: --batch
4251
BAZEL_FETCH_OPTS: --config=ci
43-
BAZEL_TEST_OPTS: --config=ci
52+
BAZEL_BUILD_OPTS: --config=ci
53+
54+
- name: Install runtime dependencies
55+
uses: ./.github/actions/install-runtime-dependencies
56+
57+
- name: Install test dependencies
58+
run: python -m pip install -r tests/requirements.txt
4459

45-
- name: Test
60+
- name: Fuzz test
4661
run: FUZZ_TIME=600 make install-fuzz

tests/fuzzing/llvm_cbench_validate_fuzz_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_fuzz(env: LlvmEnv):
2323
"""This test generates a random trajectory and validates the semantics."""
2424
benchmark = random.choice(VALIDATABLE_CBENCH_URIS)
2525
num_actions = random.randint(*RANDOM_TRAJECTORY_LENGTH_RANGE)
26+
print(benchmark)
2627

2728
while True:
2829
env.reset(benchmark=benchmark)

tests/fuzzing/llvm_random_actions_fuzz_test.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,20 @@
2020

2121

2222
@pytest.mark.timeout(600)
23-
def test_fuzz(benchmark_name: str):
23+
def test_fuzz(observation_space: str, reward_space: str):
2424
"""Run randomly selected actions on a benchmark until a minimum amount of time has elapsed."""
2525
with gym.make(
2626
"llvm-v0",
27-
reward_space="IrInstructionCount",
28-
observation_space="Autophase",
29-
benchmark=benchmark_name,
27+
reward_space=reward_space,
3028
) as env:
31-
env.reset()
29+
# TODO(github.com/facebookresearch/CompilerGym/issues/461): Merge into
30+
# constructor arguments.
31+
env.observation_space = observation_space
32+
33+
benchmark = env.datasets["generator://llvm-stress-v0"].random_benchmark()
34+
print(benchmark.uri) # For debugging in case of failure.
35+
36+
env.reset(benchmark=benchmark)
3237

3338
# Take a random step until a predetermined amount of time has elapsed.
3439
end_time = time() + FUZZ_TIME_SECONDS
@@ -42,10 +47,12 @@ def test_fuzz(benchmark_name: str):
4247
assert isinstance(reward, float)
4348
env = gym.make(
4449
"llvm-v0",
45-
reward_space="IrInstructionCount",
46-
observation_space="Autophase",
47-
benchmark=benchmark_name,
50+
reward_space=reward_space,
51+
benchmark=benchmark,
4852
)
53+
# TODO(github.com/facebookresearch/CompilerGym/issues/461):
54+
# Merge into constructor arguments.
55+
env.observation_space = observation_space
4956
env.reset()
5057
else:
5158
assert isinstance(observation, np.ndarray)

tests/fuzzing/llvm_stress_fuzz_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ def test_fuzz(env: LlvmEnv, observation_space: str, reward_space: str):
2929

3030
try:
3131
env.reset(benchmark=benchmark)
32-
apply_random_trajectory(
33-
env,
34-
random_trajectory_length_range=RANDOM_TRAJECTORY_LENGTH_RANGE,
35-
timeout=10,
36-
)
37-
print(env.state) # For debugging in case of failure.
3832
except BenchmarkInitError:
39-
# Benchmark is invalid.
40-
pass
33+
return # Benchmark is invalid.
34+
35+
apply_random_trajectory(
36+
env,
37+
random_trajectory_length_range=RANDOM_TRAJECTORY_LENGTH_RANGE,
38+
timeout=10,
39+
)
40+
print(env.state) # For debugging in case of failure.
4141

4242

4343
if __name__ == "__main__":

0 commit comments

Comments
 (0)