| Dmytro Shteflyuk | 6041798 | 2026-03-14 02:12:29 -0400 | [diff] [blame^] | 1 | # |
| 2 | # Licensed to the Apache Software Foundation (ASF) under one |
| 3 | # or more contributor license agreements. See the NOTICE file |
| 4 | # distributed with this work for additional information |
| 5 | # regarding copyright ownership. The ASF licenses this file |
| 6 | # to you under the Apache License, Version 2.0 (the |
| 7 | # "License"); you may not use this file except in compliance |
| 8 | # with the License. You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, |
| 13 | # software distributed under the License is distributed on an |
| 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | # KIND, either express or implied. See the License for the |
| 16 | # specific language governing permissions and limitations |
| 17 | # under the License. |
| 18 | # |
| 19 | |
| 20 | THRIFT = $(top_builddir)/compiler/cpp/thrift |
| 21 | FUZZ_RB_ROOT = $(top_srcdir)/lib/rb |
| 22 | FUZZ_GEN_DIR = $(FUZZ_RB_ROOT)/test/fuzz |
| 23 | FUZZ_STUBS = \ |
| 24 | $(FUZZ_GEN_DIR)/gen-rb/fuzz_test_constants.rb \ |
| 25 | $(FUZZ_GEN_DIR)/gen-rb/fuzz_test_types.rb |
| 26 | |
| 27 | FUZZ_RUBY_FILES = \ |
| 28 | $(srcdir)/fuzz_tracer.rb \ |
| 29 | $(srcdir)/fuzz_common.rb \ |
| 30 | $(srcdir)/fuzz_parse_binary_protocol.rb \ |
| 31 | $(srcdir)/fuzz_parse_binary_protocol_harness.rb \ |
| 32 | $(srcdir)/fuzz_parse_binary_protocol_accelerated.rb \ |
| 33 | $(srcdir)/fuzz_parse_binary_protocol_accelerated_harness.rb \ |
| 34 | $(srcdir)/fuzz_parse_compact_protocol.rb \ |
| 35 | $(srcdir)/fuzz_parse_compact_protocol_harness.rb \ |
| 36 | $(srcdir)/fuzz_parse_json_protocol.rb \ |
| 37 | $(srcdir)/fuzz_parse_json_protocol_harness.rb \ |
| 38 | $(srcdir)/fuzz_roundtrip_binary_protocol.rb \ |
| 39 | $(srcdir)/fuzz_roundtrip_binary_protocol_harness.rb \ |
| 40 | $(srcdir)/fuzz_roundtrip_binary_protocol_accelerated.rb \ |
| 41 | $(srcdir)/fuzz_roundtrip_binary_protocol_accelerated_harness.rb \ |
| 42 | $(srcdir)/fuzz_roundtrip_compact_protocol.rb \ |
| 43 | $(srcdir)/fuzz_roundtrip_compact_protocol_harness.rb \ |
| 44 | $(srcdir)/fuzz_roundtrip_json_protocol.rb \ |
| 45 | $(srcdir)/fuzz_roundtrip_json_protocol_harness.rb |
| 46 | |
| 47 | FUZZ_ASAN_OPTIONS ?= allocator_may_return_null=1:detect_leaks=0:use_sigaltstack=0 |
| 48 | FUZZ_CC ?= clang |
| 49 | FUZZ_CXX ?= clang++ |
| 50 | FUZZ_LDSHARED ?= $(FUZZ_CC) -shared |
| 51 | FUZZ_LDSHAREDXX ?= $(FUZZ_CXX) -shared |
| 52 | FUZZ_CFLAGS ?= -fsanitize=address,fuzzer-no-link -fno-omit-frame-pointer -fno-common -fPIC -g |
| 53 | FUZZ_CXXFLAGS ?= -fsanitize=address,fuzzer-no-link -fno-omit-frame-pointer -fno-common -fPIC -g |
| 54 | FUZZ_MAKE ?= make |
| 55 | FUZZ_MAKEFLAGS ?= --environment-overrides V=1 |
| 56 | |
| 57 | check: fuzz-prepare |
| 58 | |
| 59 | fuzz-prepare: $(FUZZ_STUBS) |
| 60 | @for script in $(FUZZ_RUBY_FILES); do \ |
| 61 | $(RUBY) -c $$script; \ |
| 62 | done |
| 63 | cd $(FUZZ_RB_ROOT) && \ |
| 64 | RUBYLIB="lib:test/fuzz/gen-rb" $(RUBY) -e 'require "thrift"; require "fuzz_test_types"; abort("Fuzz::FuzzTest is missing") unless defined?(Fuzz::FuzzTest)' |
| 65 | |
| 66 | $(THRIFT): |
| 67 | $(MAKE) -C $(top_builddir)/compiler/cpp all |
| 68 | |
| 69 | $(FUZZ_STUBS): $(top_srcdir)/test/FuzzTest.thrift $(THRIFT) |
| 70 | $(MKDIR_P) $(FUZZ_GEN_DIR) |
| 71 | $(THRIFT) --gen rb -o $(FUZZ_GEN_DIR) $(top_srcdir)/test/FuzzTest.thrift |
| 72 | |
| 73 | fuzz-build-ext: |
| 74 | cd $(FUZZ_RB_ROOT)/ext && \ |
| 75 | env MAKE="$(FUZZ_MAKE) $(FUZZ_MAKEFLAGS)" \ |
| 76 | CC="$(FUZZ_CC)" \ |
| 77 | CXX="$(FUZZ_CXX)" \ |
| 78 | LDSHARED="$(FUZZ_LDSHARED)" \ |
| 79 | LDSHAREDXX="$(FUZZ_LDSHAREDXX)" \ |
| 80 | CFLAGS="$(FUZZ_CFLAGS)" \ |
| 81 | CXXFLAGS="$(FUZZ_CXXFLAGS)" \ |
| 82 | $(RUBY) extconf.rb && \ |
| 83 | env MAKE="$(FUZZ_MAKE) $(FUZZ_MAKEFLAGS)" \ |
| 84 | CC="$(FUZZ_CC)" \ |
| 85 | CXX="$(FUZZ_CXX)" \ |
| 86 | LDSHARED="$(FUZZ_LDSHARED)" \ |
| 87 | LDSHAREDXX="$(FUZZ_LDSHAREDXX)" \ |
| 88 | CFLAGS="$(FUZZ_CFLAGS)" \ |
| 89 | CXXFLAGS="$(FUZZ_CXXFLAGS)" \ |
| 90 | $(FUZZ_MAKE) $(FUZZ_MAKEFLAGS) clean all |
| 91 | |
| 92 | fuzz-run: fuzz-prepare |
| 93 | @test -n "$(TARGET)" || { echo 'Set TARGET=<fuzz script name>'; exit 1; } |
| 94 | cd $(FUZZ_RB_ROOT) && \ |
| 95 | ASAN_OPTIONS="$(FUZZ_ASAN_OPTIONS)" \ |
| 96 | LD_PRELOAD=$$($(RUBY) -e 'require "ruzzy"; print Ruzzy::ASAN_PATH') \ |
| 97 | $(RUBY) test/fuzz/$(TARGET) $(CORPUS) $(FUZZ_ARGS) |
| 98 | |
| 99 | fuzz-parse-binary: |
| 100 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_parse_binary_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 101 | |
| 102 | fuzz-parse-binary-accelerated: fuzz-build-ext |
| 103 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_parse_binary_protocol_accelerated.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 104 | |
| 105 | fuzz-parse-compact: |
| 106 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_parse_compact_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 107 | |
| 108 | fuzz-parse-json: |
| 109 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_parse_json_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 110 | |
| 111 | fuzz-roundtrip-binary: |
| 112 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_roundtrip_binary_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 113 | |
| 114 | fuzz-roundtrip-binary-accelerated: fuzz-build-ext |
| 115 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_roundtrip_binary_protocol_accelerated.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 116 | |
| 117 | fuzz-roundtrip-compact: |
| 118 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_roundtrip_compact_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 119 | |
| 120 | fuzz-roundtrip-json: |
| 121 | $(MAKE) $(AM_MAKEFLAGS) fuzz-run TARGET=fuzz_roundtrip_json_protocol.rb CORPUS="$(CORPUS)" FUZZ_ARGS="$(FUZZ_ARGS)" |
| 122 | |
| 123 | fuzz-smoke-parse-binary: |
| 124 | $(MAKE) $(AM_MAKEFLAGS) fuzz-parse-binary CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 125 | |
| 126 | fuzz-smoke-parse-binary-accelerated: |
| 127 | $(MAKE) $(AM_MAKEFLAGS) fuzz-parse-binary-accelerated CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 128 | |
| 129 | fuzz-smoke-parse-compact: |
| 130 | $(MAKE) $(AM_MAKEFLAGS) fuzz-parse-compact CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 131 | |
| 132 | fuzz-smoke-parse-json: |
| 133 | $(MAKE) $(AM_MAKEFLAGS) fuzz-parse-json CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 134 | |
| 135 | fuzz-smoke-roundtrip-binary: |
| 136 | $(MAKE) $(AM_MAKEFLAGS) fuzz-roundtrip-binary CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 137 | |
| 138 | fuzz-smoke-roundtrip-binary-accelerated: |
| 139 | $(MAKE) $(AM_MAKEFLAGS) fuzz-roundtrip-binary-accelerated CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 140 | |
| 141 | fuzz-smoke-roundtrip-compact: |
| 142 | $(MAKE) $(AM_MAKEFLAGS) fuzz-roundtrip-compact CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 143 | |
| 144 | fuzz-smoke-roundtrip-json: |
| 145 | $(MAKE) $(AM_MAKEFLAGS) fuzz-roundtrip-json CORPUS="$(CORPUS)" FUZZ_ARGS="-runs=100 $(FUZZ_ARGS)" |
| 146 | |
| 147 | clean-local: |
| 148 | -$(RM) -r $(FUZZ_GEN_DIR)/gen-rb |
| 149 | |
| 150 | distdir: |
| 151 | $(MAKE) $(AM_MAKEFLAGS) distdir-am |
| 152 | |
| 153 | EXTRA_DIST = \ |
| 154 | .gitignore \ |
| 155 | README.md \ |
| 156 | fuzz_common.rb \ |
| 157 | fuzz_tracer.rb \ |
| 158 | fuzz_parse_binary_protocol.rb \ |
| 159 | fuzz_parse_binary_protocol_harness.rb \ |
| 160 | fuzz_parse_binary_protocol_accelerated.rb \ |
| 161 | fuzz_parse_binary_protocol_accelerated_harness.rb \ |
| 162 | fuzz_parse_compact_protocol.rb \ |
| 163 | fuzz_parse_compact_protocol_harness.rb \ |
| 164 | fuzz_parse_json_protocol.rb \ |
| 165 | fuzz_parse_json_protocol_harness.rb \ |
| 166 | fuzz_roundtrip_binary_protocol.rb \ |
| 167 | fuzz_roundtrip_binary_protocol_harness.rb \ |
| 168 | fuzz_roundtrip_binary_protocol_accelerated.rb \ |
| 169 | fuzz_roundtrip_binary_protocol_accelerated_harness.rb \ |
| 170 | fuzz_roundtrip_compact_protocol.rb \ |
| 171 | fuzz_roundtrip_compact_protocol_harness.rb \ |
| 172 | fuzz_roundtrip_json_protocol.rb \ |
| 173 | fuzz_roundtrip_json_protocol_harness.rb |