Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
46 changes: 40 additions & 6 deletions .github/workflows/bazel_test_centipede.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
# TODO(xinhaoyuan): Bump to 24.04 after https://github.com/llvm/llvm-project/issues/102443
# is fixed.
runs-on: ubuntu-22.04
permissions:
contents: read
timeout-minutes: 60
strategy:
matrix:
Expand All @@ -39,13 +41,13 @@ jobs:
run: |
sudo sysctl -w kernel.core_pattern=""
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install dependencies
run: |
sudo apt-get update && sudo apt-get install -yq \
clang llvm libssl-dev
- name: Restore latest cache
uses: actions/cache/restore@v4
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-${{ matrix.config }}
Expand Down Expand Up @@ -84,19 +86,21 @@ jobs:
bazel test --no//fuzztest:use_riegeli --test_output=errors --linkopt=-fsanitize=address --copt=-fsanitize=address --test_env=ASAN_OPTIONS=detect_leaks=0 --platform_suffix=asan --test_timeout=600 centipede/puzzles:all
- name: Save new cache based on main
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-${{ matrix.config }}-${{ github.run_id }}
run_tests_mac:
name: Run Centipede tests (MacOS)
runs-on: macos-15
permissions:
contents: read
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v4
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Restore latest cache
uses: actions/cache/restore@v4
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-mac
Expand Down Expand Up @@ -127,7 +131,37 @@ jobs:
bazel --output_user_root="${HOME}/.cache/bazel" test --test_output=errors --no//fuzztest:use_riegeli --linkopt=-fsanitize=address --copt=-fsanitize=address --test_env=ASAN_OPTIONS=detect_leaks=0 --platform_suffix=asan --test_timeout=600 centipede/puzzles:all
- name: Save new cache based on main
if: github.ref == 'refs/heads/main'
uses: actions/cache/save@v4
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-mac-${{ github.run_id }}
run_tests_win:
name: Run Centipede tests (Windows)
runs-on: windows-latest
permissions:
contents: read
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Restore latest cache
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-win-${{ matrix.config }}
restore-keys: bazel-centipede-cache-win-${{ matrix.config }}-
- name: Set environment variable
run: echo "USE_BAZEL_VERSION=8.7.0" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Run unit tests
if: ${{ !cancelled() }}
run: |
<# Only supported libraries are tested here. #> `
bazelisk test --disk_cache=~/.cache/bazel --local_test_jobs=1 --test_output=errors --no//fuzztest:use_riegeli `
--extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl `
--extra_execution_platforms=//:x64_windows-clang-cl -- centipede:util_test
- name: Save new cache based on main
# if: github.ref == 'refs/heads/main'
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: "~/.cache/bazel"
key: bazel-centipede-cache-win-${{ github.run_id }}
8 changes: 8 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
platform(
name = "x64_windows-clang-cl",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
],
)
4 changes: 4 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ bazel_dep(
name = "rules_cc",
version = "0.2.17",
)

cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")

bazel_dep(
name = "rules_shell",
version = "0.6.1",
Expand Down
7 changes: 6 additions & 1 deletion centipede/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,12 @@ cc_test(
cc_test(
name = "util_test",
srcs = ["util_test.cc"],
copts = ["-fno-signed-char"],
copts = select({
"@platforms//os:windows": [
"/J",
],
"//conditions:default": ["-fno-signed-char"],
}),
deps = [
":feature",
":thread_pool",
Expand Down
1 change: 0 additions & 1 deletion centipede/puzzles/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ licenses(["notice"])

package(default_visibility = ["@com_google_fuzztest//centipede/puzzles:__subpackages__"])

# The puzzles use a simple configuration language, see run_puzzle.sh.
[puzzle(name = n) for n in [
"byte_cmp_4",
"callstack",
Expand Down
7 changes: 4 additions & 3 deletions centipede/puzzles/autodictionary_stress.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Centipede puzzle: stress test for --use_auto_dictionary=1.
// RUN: Run --use_auto_dictionary=1 --use_cmp_features=0 -j 5
// RUN: ExpectInLog "Input bytes.*: abcdxyzVeryLongStringKeyword"
// CASE main: ARG: --use_auto_dictionary=1
// CASE main: ARG: --use_cmp_features=0
// CASE main: ARG: --j=5
// CASE main: MATCH: Input bytes.*: abcdxyzVeryLongStringKeyword

// TODO(kcc): we currently use --use_cmp_features=0 because otherwise
// the corpus gets too large and the puzzle does not get solved quickly.
Expand Down
2 changes: 1 addition & 1 deletion centipede/puzzles/byte_cmp_4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// Centipede puzzle: sequence of 4 1-byte comparisons.
// RUN: Run && SolutionIs fuzZ
// CASE main: MATCH: Input bytes *: fuzZ
#include <cstddef>
#include <cstdint>
#include <cstdlib>
Expand Down
8 changes: 4 additions & 4 deletions centipede/puzzles/callstack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
// All functions but F0 also modify `g_result`.
// The puzzle can be solved if the call sequence is FA->FB->FC->FD->FE.

// clang-format off
// RUN: Run --callstack_level=10 --use_cmp_features=0 --use_dataflow_features=0 // NOLINT
// RUN: SolutionIs ABCDE
// clang-format on
// CASE main: ARG: --callstack_level=10
// CASE main: ARG: --use_cmp_features=0
// CASE main: ARG: --use_dataflow_features=0
// CASE main: MATCH: Input bytes *: ABCDE
#include <cstddef>
#include <cstdint>
#include <cstdlib>
Expand Down
10 changes: 5 additions & 5 deletions centipede/puzzles/deep_recursion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
// limitations under the License.

// Centipede puzzle: use callstack features to reach deep recursion
// clang-format off
// RUN: Run --callstack_level=10 --use_cmp_features=0 --max_len=10 --num_runs=10000000 # NOLINT
// RUN: SolutionIs ABCDEF
// clang-format on
#include <sys/resource.h>
// CASE main: ARG: --callstack_level=10
// CASE main: ARG: --use_cmp_features=0
// CASE main: ARG: --max_len=10
// CASE main: ARG: --num_runs=10000000
// CASE main: MATCH: Input bytes *: ABCDEF

#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion centipede/puzzles/independent_compares.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

// Centipede puzzle: 4 independent compares setting a mask.
// RUN: Run && SolutionIs FUZZ
// CASE main: MATCH: Input bytes *: FUZZ
#include <cstddef>
#include <cstdint>
#include <cstdlib>
Expand Down
7 changes: 4 additions & 3 deletions centipede/puzzles/memcmp_3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

// Centipede puzzle: one 3-byte memcmp. Check the output in the log.
// Disable use_auto_dictionary so that we test other functionality.
// RUN: Run --use_auto_dictionary=false && SolutionIs fUz
// RUN: ExpectInLog "TEXT IN STDOUT"
// RUN: ExpectInLog "TEXT IN STDERR"
// CASE main: ARG: --use_auto_dictionary=false
// CASE main: MATCH: Input bytes *: fUz
// CASE main: MATCH: TEXT IN STDOUT
// CASE main: MATCH: TEXT IN STDERR

#include <cstdint>
#include <cstdio>
Expand Down
4 changes: 3 additions & 1 deletion centipede/puzzles/memcmp_4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

// Centipede puzzle: one 4-byte memcmp.
// Disable use_auto_dictionary so that we test other functionality.
// RUN: Run --use_auto_dictionary=false --max_len=10 && SolutionIs fuZz
// CASE main: ARG: --use_auto_dictionary=false
// CASE main: ARG: --max_len=10
// CASE main: MATCH: Input bytes *: fuZz

#include <cstdint>
#include <cstdlib>
Expand Down
3 changes: 2 additions & 1 deletion centipede/puzzles/memcmp_4_may_inline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

// Centipede puzzle: one 4-byte memcmp, which may get inlined.
// Disable use_auto_dictionary so that we test other functionality.
// RUN: Run --use_auto_dictionary=false && SolutionIs FUZz
// CASE main: ARG: --use_auto_dictionary=false
// CASE main: MATCH: Input bytes *: FUZz

#include <cstdint>
#include <cstdlib>
Expand Down
4 changes: 3 additions & 1 deletion centipede/puzzles/oom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// limitations under the License.

// Centipede puzzle: easy-to-reach OOM.
// RUN: Run --rss_limit_mb=1000 && SolutionIs OOM && ExpectOOM
// CASE main: ARG: --rss_limit_mb=1000
// CASE main: MATCH: Input bytes *: OOM
// CASE main: MATCH: Failure.*: rss-limit-exceeded
#include <cstddef>
#include <cstdint>
#include <cstdio>
Expand Down
6 changes: 4 additions & 2 deletions centipede/puzzles/paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
// We disable use_dataflow_features because on this puzzle
// it is also effective.

// RUN: Run --use_dataflow_features=0 --use_cmp_features=0 --path_level=10
// RUN: ExpectInLog "Input bytes.*: .x1.x2.x3"
// CASE main: ARG: --use_dataflow_features=0
// CASE main: ARG: --use_cmp_features=0
// CASE main: ARG: --path_level=10
// CASE main: MATCH: Input bytes.*: .x1.x2.x3

// This puzzle aborts on input "\x1\x2\x3"
// The code here has very little control flow, but an exponential number of
Expand Down
8 changes: 4 additions & 4 deletions centipede/puzzles/per_batch_timeout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.

// Centipede puzzle: easy-to-reach per-batch timeout.
// clang-format off
// NOLINTNEXTLINE
// RUN: Run --batch_size=10 --timeout_per_input=2 --timeout_per_batch=7 && ExpectPerBatchTimeout
// clang-format on
// CASE main: ARG: --batch_size=10
// CASE main: ARG: --timeout_per_input=2
// CASE main: ARG: --timeout_per_batch=7
// CASE main: MATCH: Failure.*: per-batch-timeout-exceeded

#include <unistd.h>

Expand Down
5 changes: 3 additions & 2 deletions centipede/puzzles/per_input_timeout.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Centipede puzzle: easy-to-reach per-input timeout.
// RUN: Run --timeout_per_input=2 && SolutionIs SLO && ExpectPerInputTimeout
// CASE main: ARG: --timeout_per_input=2
// CASE main: MATCH: Input bytes *: SLO
// CASE main: MATCH: Failure.*: per-input-timeout-exceeded

#include <unistd.h>

Expand Down
9 changes: 5 additions & 4 deletions centipede/puzzles/pthread_exit_uint32_cmp_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// Centipede puzzle: one 4-byte cmp, in a separate thread using pthread
// interface. We should be able to solve it w/o cmp features *or* w/o auto
// dictionary.
//
// RUN: Run && SolutionIs Fuzz
// RUN: Run --use_auto_dictionary=0 && SolutionIs Fuzz
// RUN: Run --use_cmp_features=0 && SolutionIs Fuzz
// CASE main: MATCH: Input bytes *: Fuzz
// CASE no_cmp: ARG: --use_cmp_features=0
// CASE no_cmp: MATCH: Input bytes *: Fuzz
// CASE no_autodict: ARG: --use_auto_dictionary=0
// CASE no_autodict: MATCH: Input bytes *: Fuzz

#include <pthread.h>

Expand Down
18 changes: 14 additions & 4 deletions centipede/puzzles/puzzle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""BUILD rule for Centipede puzzles"""

load("@rules_shell//shell:sh_test.bzl", "sh_test")
load("@rules_cc//cc:cc_test.bzl", "cc_test")
load("@com_google_fuzztest//centipede/testing:build_defs.bzl", "centipede_fuzz_target")

def puzzle(name):
Expand All @@ -36,13 +36,23 @@ def puzzle(name):
# repeatability. Each sh_test performs a single run with a single seed, so
# that the log is minimal.
for seed in ["1", "2"]:
sh_test(
cc_test(
name = "run_" + seed + "_" + name,
srcs = ["run_puzzle.sh"],
srcs = ["run_puzzle.cc"],
args = ["--seed=" + seed, "--puzzle=" + name],
data = [
":" + name,
name + ".cc",
"@com_google_fuzztest//centipede:centipede_uninstrumented",
"@com_google_fuzztest//centipede:test_util_sh",
],
deps = [
"@googletest//:gtest",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
"@abseil-cpp//absl/strings",
"@abseil-cpp//absl/time",
"@com_google_fuzztest//centipede:command",
"@com_google_fuzztest//common:logging",
"@com_google_fuzztest//common:test_util",
],
)
Loading
Loading