Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports regression test in fuzzing_launcher #56

Merged
merged 7 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ build:clang --action_env=CXX=clang++
build:asan-libfuzzer --config=clang
build:asan-libfuzzer --linkopt=-fsanitize=fuzzer,address
build:asan-libfuzzer --copt=-fsanitize=fuzzer,address
build:asan-libfuzzer --//fuzzing:engine=libfuzzer

# Flags for Clang with MSAN and libfuzzer
build:msan-libfuzzer --config=clang
build:msan-libfuzzer --linkopt=-fsanitize=memory,fuzzer
build:msan-libfuzzer --copt=-fsanitize=memory,fuzzer
build:asan-libfuzzer --//fuzzing:engine=libfuzzer
tengpengli marked this conversation as resolved.
Show resolved Hide resolved
tengpengli marked this conversation as resolved.
Show resolved Hide resolved

# Flags for Clang with MSAN and libfuzzer, outputting detailed report
build:msan-libfuzzer-repro --config=msan-libfuzzer
build:msan-libfuzzer-repro --copt=-fsanitize-memory-track-origins=2
build:asan-libfuzzer --//fuzzing:engine=libfuzzer
tengpengli marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ workspace(name = "rules_fuzzing")
load("//fuzzing:repositories.bzl", "rules_fuzzing_dependencies")
rules_fuzzing_dependencies()

load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
bazel_skylib_workspace()

load("@rules_python//python:repositories.bzl", "py_repositories")
py_repositories()

Expand Down
12 changes: 12 additions & 0 deletions fuzzing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")

string_flag(
name = "engine",
build_setting_default = "default",
values = [
"default",
"libfuzzer",
],
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions fuzzing/cc_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def cc_fuzz_test(
name = name + "_run",
target = name,
corpus = name + "_corpus" if corpus else None,
is_regression = False,
# Since the script depends on the _fuzz_test above, which is a cc_test,
# this attribute must be set.
testonly = True,
Expand Down
17 changes: 15 additions & 2 deletions fuzzing/common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,23 @@

"""This file contains common rules for fuzzing test."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")

def _fuzzing_launcher_impl(ctx):
# Generate a script to launcher the fuzzing test.
script = ctx.actions.declare_file("%s" % ctx.label.name)

script_template = """#!/bin/sh
exec {launcher_path} {target_binary_path} --corpus_dir={corpus_dir} "$@"
"""
exec {launcher_path} {target_binary_path} --corpus_dir={corpus_dir} --engine={engine_type} "$@" """

script_content = script_template.format(
launcher_path = ctx.executable._launcher.short_path,
target_binary_path = ctx.executable.target.short_path,
corpus_dir = ctx.file.corpus.short_path if ctx.attr.corpus else "",
engine_type = ctx.attr._engine[BuildSettingInfo].value,
)
if ctx.attr.is_regression:
script_content += " --regression=True"
tengpengli marked this conversation as resolved.
Show resolved Hide resolved
ctx.actions.write(script, script_content, is_executable = True)

# Merge the dependencies.
Expand All @@ -50,6 +54,11 @@ Rule for creating a script to run the fuzzing test.
executable = True,
cfg = "host",
),
"_engine": attr.label(
tengpengli marked this conversation as resolved.
Show resolved Hide resolved
default = ":engine",
doc = "The engine type.",
providers = [BuildSettingInfo],
),
"target": attr.label(
executable = True,
doc = "The fuzzing test to run.",
Expand All @@ -60,6 +69,10 @@ Rule for creating a script to run the fuzzing test.
doc = "The target to create a directory containing corpus files.",
allow_single_file = True,
),
"is_regression": attr.bool(
doc = "If set true the target is for a regression test.",
default = True,
),
},
executable = True,
)
Expand Down
11 changes: 10 additions & 1 deletion fuzzing/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Contains the external dependencies
"""Contains the external dependencies."""

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

Expand All @@ -30,3 +30,12 @@ def rules_fuzzing_dependencies():
url = "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz",
sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a",
)

http_archive(
name = "bazel_skylib",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
],
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
)
15 changes: 13 additions & 2 deletions fuzzing/tools/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@
"If non-empty, a directory that will be used as a seed corpus for the fuzzer run."
)

flags.DEFINE_enum(
"engine", "default", ["default", "libfuzzer"],
"The type of the engine, the default is to run a gUnit test.")

flags.DEFINE_bool(
"regression", False,
"If set True, the script will trigger the target as a regression test.")


def main(argv):
if len(argv) != 2:
Expand All @@ -44,8 +52,11 @@ def main(argv):
"\n\tpython " + __file__ + " EXECUTABLE")

command_args = [argv[1]]
command_args.append("-max_total_time=" + str(FLAGS.timeout_secs))
command_args.append("-timeout=" + str(FLAGS.timeout_secs))
if FLAGS.engine == "libfuzzer":
command_args.append("-max_total_time=" + str(FLAGS.timeout_secs))
command_args.append("-timeout=" + str(FLAGS.timeout_secs))
if FLAGS.regression:
command_args.append("-runs=0")
if FLAGS.corpus_dir:
command_args.append(FLAGS.corpus_dir)
os.execv(argv[1], command_args)
Expand Down