Skip to content
Merged
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
4 changes: 2 additions & 2 deletions scripts/fuzz.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ with the -b option.

Simple wrapper around a libfuzzer test run, as much for
documentation as direct use. The idea here is really simple: build
for the Zephyr "native_posix" board (which is a just a x86
for the Zephyr "native_sim" board (which is a just a x86
executable for the build host, not an emulated device) and run the
resulting zephyr.exe file. This specifies a "fuzz_corpus" directory
to save the seeds that produce useful coverage output for use in
Expand Down Expand Up @@ -124,7 +124,7 @@ main()
(set -x
# When passing conflicting -DVAR='VAL UE1' -DVAR='VAL UE2' to CMake,
# the last 'VAL UE2' wins. Previous ones are silently ignored.
west build -d build-fuzz -b native_posix "$SOF_TOP"/app/ -- \
west build -d build-fuzz -b native_sim "$SOF_TOP"/app/ -- \
"${fuzz_configs[@]}" "$@"
)

Expand Down
11 changes: 5 additions & 6 deletions src/platform/posix/fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

#include <irq_ctrl.h>
#include <zephyr/sys/time_units.h>

/* Zephyr arch APIs, not in a header (native_sim has them though) */
void posix_init(int argc, char *argv[]);
void posix_exec_for(uint64_t us);
#include <nsi_cpu_if.h>
#include <nsi_main_semipublic.h>

const uint8_t *posix_fuzz_buf;
size_t posix_fuzz_sz;
Expand All @@ -23,12 +21,13 @@ size_t posix_fuzz_sz;
* "long enough" to handle the event and reach a quiescent state
* again)
*/
NATIVE_SIMULATOR_IF
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz)
{
static bool runner_initialized;

if (!runner_initialized) {
posix_init(0, NULL);
nsi_init(0, NULL);
runner_initialized = true;
}

Expand All @@ -42,6 +41,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t sz)
/* Give the OS time to process whatever happened in that
* interrupt and reach an idle state.
*/
posix_exec_for(k_ticks_to_us_ceil64(CONFIG_ZEPHYR_POSIX_FUZZ_TICKS));
nsi_exec_for(k_ticks_to_us_ceil64(CONFIG_ZEPHYR_POSIX_FUZZ_TICKS));
return 0;
}