Skip to content

Commit

Permalink
css2/test: Set up fuzz testing for the tokenizer
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlinden committed Oct 8, 2024
1 parent 9f9abab commit 2ea6d67
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
18 changes: 16 additions & 2 deletions css2/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//bzl:copts.bzl", "HASTUR_COPTS")
load("@rules_fuzzing//fuzzing:cc_defs.bzl", "cc_fuzz_test")
load("//bzl:copts.bzl", "HASTUR_COPTS", "HASTUR_FUZZ_PLATFORMS")

cc_library(
name = "css2",
Expand All @@ -26,4 +27,17 @@ cc_library(
":css2",
"//etest",
],
) for src in glob(["*_test.cpp"])]
) for src in glob(
include = ["*_test.cpp"],
exclude = ["*_fuzz_test.cpp"],
)]

[cc_fuzz_test(
name = src[:-4],
size = "small",
testonly = True,
srcs = [src],
copts = HASTUR_COPTS,
target_compatible_with = HASTUR_FUZZ_PLATFORMS,
deps = [":css2"],
) for src in glob(["*_fuzz_test.cpp"])]
21 changes: 21 additions & 0 deletions css2/tokenizer_fuzz_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-FileCopyrightText: 2024 Robin Lindén <[email protected]>
//
// SPDX-License-Identifier: BSD-2-Clause

#include "css2/tokenizer.h"

#include <cstddef>
#include <cstdint>
#include <string_view>

extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *data, std::size_t size);

extern "C" int LLVMFuzzerTestOneInput(std::uint8_t const *data, std::size_t size) {
auto input = std::string_view{reinterpret_cast<char const *>(data), size};
css2::Tokenizer{input,
[](auto &&) {},
[](auto) {
}}
.run();
return 0;
}

0 comments on commit 2ea6d67

Please sign in to comment.