1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2022 Google, Inc.
4 * Written by Andrew Scull <ascull@google.com>
10 #include <fuzzing_engine.h>
11 #include <test/fuzz.h>
13 static struct fuzz_test *find_fuzz_test(const char *name)
15 struct fuzz_test *fuzzer = FUZZ_TEST_START();
16 size_t count = FUZZ_TEST_COUNT();
19 for (i = 0; i < count; ++i) {
20 if (strcmp(name, fuzzer->name) == 0)
28 static struct udevice *find_fuzzing_engine(void)
32 if (uclass_first_device_err(UCLASS_FUZZING_ENGINE, &dev))
38 static int do_fuzz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
40 struct fuzz_test *fuzzer;
46 fuzzer = find_fuzz_test(argv[1]);
48 printf("Could not find fuzzer: %s\n", argv[1]);
52 dev = find_fuzzing_engine();
54 puts("No fuzzing engine available\n");
62 if (dm_fuzzing_engine_get_input(dev, &data, &size)) {
63 puts("Fuzzing engine failed\n");
67 fuzzer->func(data, size);
73 #ifdef CONFIG_SYS_LONGHELP
74 static char fuzz_help_text[] =
75 "[fuzz-test-name] - execute the named fuzz test\n"
77 #endif /* CONFIG_SYS_LONGHELP */
80 fuzz, CONFIG_SYS_MAXARGS, 1, do_fuzz,
81 "fuzz tests", fuzz_help_text