summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-05 16:01:50 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-06 09:32:18 +0100
commitc1c9510c9bb6922bdb315d39b1961e75ebdbbd69 (patch)
tree749be2a47e7a50a43f5054254ecb2f5c0ab41f6c /src/fuzz
parent8df3f44c90a3e479b717e8cc4bb26c95ebbc5cb0 (diff)
downloadsystemd-c1c9510c9bb6922bdb315d39b1961e75ebdbbd69.tar.gz
fuzz-main: allow the number of runs to be overridden
This is useful when debugging.
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-main.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/fuzz/fuzz-main.c b/src/fuzz/fuzz-main.c
index c39db5d59d..cf70424c16 100644
--- a/src/fuzz/fuzz-main.c
+++ b/src/fuzz/fuzz-main.c
@@ -1,9 +1,11 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include "alloc-util.h"
-#include "log.h"
#include "fileio.h"
#include "fuzz.h"
+#include "log.h"
+#include "parse-util.h"
+#include "string-util.h"
#include "tests.h"
/* This is a test driver for the systemd fuzzers that provides main function
@@ -15,13 +17,22 @@
/* This one was borrowed from
* https://github.com/google/oss-fuzz/blob/646fca1b506b056db3a60d32c4a1a7398f171c94/infra/base-images/base-runner/bad_build_check#L19
*/
-#define MIN_NUMBER_OF_RUNS 4
+#define NUMBER_OF_RUNS 4
int main(int argc, char **argv) {
int r;
test_setup_logging(LOG_DEBUG);
+ unsigned number_of_runs = NUMBER_OF_RUNS;
+
+ const char *v = getenv("SYSTEMD_FUZZ_RUNS");
+ if (!isempty(v)) {
+ r = safe_atou(v, &number_of_runs);
+ if (r < 0)
+ return log_error_errno(r, "Failed to parse SYSTEMD_FUZZ_RUNS=%s: %m", v);
+ }
+
for (int i = 1; i < argc; i++) {
_cleanup_free_ char *buf = NULL;
size_t size;
@@ -35,7 +46,7 @@ int main(int argc, char **argv) {
}
printf("%s... ", name);
fflush(stdout);
- for (int j = 0; j < MIN_NUMBER_OF_RUNS; j++)
+ for (unsigned j = 0; j < number_of_runs; j++)
if (LLVMFuzzerTestOneInput((uint8_t*)buf, size) == EXIT_TEST_SKIP)
return EXIT_TEST_SKIP;
printf("ok\n");