Skip to content

Commit 42436d3

Browse files
committed
update rules_mayhem
1 parent 565222b commit 42436d3

9 files changed

Lines changed: 554 additions & 3348 deletions

File tree

.bazelrc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ startup --windows_enable_symlinks
99
common:windows --enable_runfiles
1010

1111
# Set default Mayhem URL and config home
12-
build --action_env=MAYHEM_URL
13-
build --action_env=XDG_CONFIG_HOME
12+
common --action_env=MAYHEM_URL
13+
common --action_env=XDG_CONFIG_HOME
1414

1515
# Spawn strategy (necessary for rules_mayhem)
1616
build --spawn_strategy=standalone
@@ -24,19 +24,25 @@ common:linux --host_cxxopt=-std=c++17
2424
# Define the --config=asan-libfuzzer configuration.
2525
build:asan-libfuzzer --action_env=CC=clang
2626
build:asan-libfuzzer --action_env=CXX=clang++
27+
build:asan-libfuzzer --repo_env=CC=clang
28+
build:asan-libfuzzer --repo_env=CXX=clang++
2729
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
2830
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
2931
build:asan-libfuzzer --@rules_fuzzing//fuzzing:cc_engine_sanitizer=asan
3032

3133
# Define the --config=libfuzzer configuration.
3234
build:libfuzzer --action_env=CC=clang
3335
build:libfuzzer --action_env=CXX=clang++
36+
build:libfuzzer --repo_env=CC=clang
37+
build:libfuzzer --repo_env=CXX=clang++
3438
build:libfuzzer --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:libfuzzer
3539
build:libfuzzer --@rules_fuzzing//fuzzing:cc_engine_instrumentation=libfuzzer
3640

3741
# Define the --config=uninstrumented configuration.
3842
build:uninstrumented --action_env=CC=clang
3943
build:uninstrumented --action_env=CXX=clang++
44+
build:uninstrumented --repo_env=CC=clang
45+
build:uninstrumented --repo_env=CXX=clang++
4046
build:uninstrumented --@rules_fuzzing//fuzzing:cc_engine=@rules_fuzzing//fuzzing/engines:replay
4147

4248
# Set coverage options

.github/workflows/linux.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ jobs:
7575

7676
- name: Run Bazel for Mayhem with Docker image
7777
run: |
78-
bazel run --config=libfuzzer //mayhem:push_fuzz_calculator_image
79-
bazel build --config=libfuzzer //mayhem:run_fuzz_calculator_image
78+
bazel run --config=libfuzzer //mayhem:run_fuzz_calculator_image
8079
shell: bash
8180
env:
8281
MAYHEM_URL: ${{ env.MAYHEM_URL }}
@@ -85,7 +84,7 @@ jobs:
8584

8685
- name: Run bazel for Mayhem package
8786
run: |
88-
bazel build //mayhem:run_test_calculator_package
87+
bazel run //mayhem:run_test_calculator_package
8988
shell: bash
9089
env:
9190
MAYHEM_URL: ${{ env.MAYHEM_URL }}

.github/workflows/windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ jobs:
6868

6969
- name: Run bazel for Mayhem package
7070
run: |
71-
bazel build //mayhem:run_test_calculator_package
71+
bazel run //mayhem:run_test_calculator_package
7272
shell: cmd
7373
env:
7474
MAYHEM_URL: ${{ env.MAYHEM_URL }}

MODULE.bazel

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
bazel_dep(name = "googletest", version = "1.15.2")
2-
bazel_dep(name = "rules_pkg", version = "1.0.1")
3-
bazel_dep(name = "rules_fuzzing", version = "0.5.2")
4-
bazel_dep(name = "rules_mayhem", version = "0.8.3")
5-
bazel_dep(name = "rules_cc", version = "0.2.0")
1+
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
2+
bazel_dep(name = "rules_pkg", version = "1.2.0")
3+
bazel_dep(name = "rules_fuzzing", version = "0.6.0")
4+
bazel_dep(name = "rules_mayhem", version = "0.8.4")
5+
bazel_dep(name = "rules_cc", version = "0.2.16")
6+
7+
# Note: This is a temporary workaround to avoid pulling in v2.7.2, as this includes support for
8+
# the incompatible 'local_config_platform' (see https://github.com/bazelbuild/bazel/issues/22080)
9+
bazel_dep(name = "aspect_bazel_lib", version = "2.22.5")
610

711
rules_mayhem_extension = use_extension("@rules_mayhem//mayhem:extensions.bzl", "rules_mayhem_extension")
812
use_repo(rules_mayhem_extension, "bazel_skylib", "mayhem_cli_linux", "mayhem_cli_windows", "platforms", "yq_cli_linux", "yq_cli_windows")
913

1014
# to-do: fuzztest - see https://github.com/google/fuzztest/issues/950
11-
bazel_dep(name = "rules_oci", version = "1.8.0")
15+
bazel_dep(name = "rules_oci", version = "2.2.7")
1216

1317
oci = use_extension("@rules_oci//oci:extensions.bzl", "oci")
1418

@@ -21,4 +25,4 @@ oci.pull(
2125
)
2226

2327
# For each oci.pull call, repeat the "name" here to expose them as dependencies.
24-
use_repo(oci, "ubuntu")
28+
use_repo(oci, "ubuntu", "ubuntu_linux_amd64")

MODULE.bazel.lock

Lines changed: 516 additions & 3327 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ bazel build //mayhem:package_calculator
5151
## To run calculator target
5252

5353
```bash
54-
bazel build //mayhem:run_package_calculator
54+
bazel run //mayhem:run_package_calculator
5555
```
5656

5757
The above works with the test target `//test:test_calculator` as well.
@@ -85,15 +85,15 @@ bazel run --config=libfuzzer //mayhem:push_fuzz_calculator_image
8585
## To run Mayhem against docker image for libfuzzer target
8686

8787
```bash
88-
bazel build --config=libfuzzer //mayhem:run_fuzz_calculator_image
88+
bazel run --config=libfuzzer //mayhem:run_fuzz_calculator_image
8989
```
9090

9191
# Regression Testing
9292

9393
## To run Mayhem on regression tests only, wait for the run to finish, and output a SARIF report
9494

9595
```bash
96-
bazel build --config=libfuzzer //mayhem:run_test_calculator_package
96+
bazel run --config=libfuzzer //mayhem:run_test_calculator_package
9797
```
9898

9999

@@ -193,7 +193,7 @@ Under the `test` directory, there are a couple of examples of how to integrate G
193193
You can run this on Mayhem with:
194194

195195
```bash
196-
bazel build //mayhem:run_test_calculator_package
196+
bazel run //mayhem:run_test_calculator_package
197197
```
198198

199199
- `harness_utils_test_calculator` is an example inlining harness functionality via a HARNESS macro. The test functions are designed to take a buffer and size, and the HARNESS macro automatically calls the test function with the generated inputs.

harness_utils/fuzzing_utils

mayhem/BUILD

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("@rules_pkg//:pkg.bzl", "pkg_tar")
2-
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_tarball")
2+
load("@rules_oci//oci:defs.bzl", "oci_image", "oci_push", "oci_load")
33
load("@rules_mayhem//mayhem:mayhem.bzl", "mayhem_run", "mayhem_package", "mayhem_download")
44

55
package(default_visibility = ["//visibility:public"])
@@ -10,6 +10,7 @@ pkg_tar(
1010
name = "fuzz_calculator_tar",
1111
srcs = ["//fuzz:fuzz_calculator_bin"],
1212
mode = "0755",
13+
extension = "tar.gz",
1314
testonly = True,
1415
)
1516

@@ -23,8 +24,8 @@ oci_image(
2324
workdir = "/",
2425
)
2526

26-
oci_tarball(
27-
name = "fuzz_calculator_tarball",
27+
oci_load(
28+
name = "fuzz_calculator_load",
2829
image = ":fuzz_calculator_image",
2930
repo_tags = ["mayhem-bazel-example:latest"],
3031
testonly = True,
@@ -49,6 +50,8 @@ mayhem_run(
4950
sanitizer = "true",
5051
libfuzzer = "false",
5152
image = "ghcr.io/forallsecure/mayhem-bazel-example:latest",
53+
image_dependency = ":push_fuzz_calculator_image",
54+
testonly = True,
5255
)
5356

5457
# Calculator Standalone binary example

test/fuzzing_utils_test_calculator.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ TEST(CalculatorTest, TestAdd) {
3434
}
3535

3636
FUZZ_TEST(CalculatorTest, FuzzTestAdd) {
37+
INIT_FUZZ_TEST
3738
int x = provider.ConsumeIntegral<int>();
3839
int y = provider.ConsumeIntegral<int>();
3940
test_add(x, y);
@@ -44,6 +45,7 @@ TEST(CalculatorTest, TestSubtract) {
4445
}
4546

4647
FUZZ_TEST(CalculatorTest, FuzzTestSubtract) {
48+
INIT_FUZZ_TEST
4749
int x = provider.ConsumeIntegral<int>();
4850
int y = provider.ConsumeIntegral<int>();
4951
test_subtract(x, y);
@@ -54,6 +56,7 @@ TEST(CalculatorTest, TestMultiply) {
5456
}
5557

5658
FUZZ_TEST(CalculatorTest, FuzzTestMultiply) {
59+
INIT_FUZZ_TEST
5760
int x = provider.ConsumeIntegral<int>();
5861
int y = provider.ConsumeIntegral<int>();
5962
test_multiply(x, y);
@@ -64,6 +67,7 @@ TEST(CalculatorTest, TestDivide) {
6467
}
6568

6669
FUZZ_TEST(CalculatorTest, FuzzTestDivide) {
70+
INIT_FUZZ_TEST
6771
int x = provider.ConsumeIntegral<int>();
6872
int y = provider.ConsumeIntegral<int>();
6973
if (y == 0) {
@@ -77,6 +81,7 @@ TEST(CalculatorTest, TestFactorGame) {
7781
}
7882

7983
FUZZ_TEST(CalculatorTest, FuzzTestFactorGame) {
84+
INIT_FUZZ_TEST
8085
int x = provider.ConsumeIntegral<int>();
8186
int y = provider.ConsumeIntegral<int>();
8287
test_factor_game(x, y);

0 commit comments

Comments
 (0)