diff --git a/tests-fuzz/.gitignore b/tests-fuzz/.gitignore
index 6ac8bb7422b5301f63d047b6d847582cc3e1480e..c8a7a2024c23271096c4a2efecd8de4fab5f7567 100644
--- a/tests-fuzz/.gitignore
+++ b/tests-fuzz/.gitignore
@@ -4,3 +4,4 @@
 /knotd_stdio
 /packet
 /packet_libfuzzer
+/wrap/main.c
diff --git a/tests-fuzz/Makefile.am b/tests-fuzz/Makefile.am
index b6eb1a30f37eba94da8b90a775e9d122aaa0fb65..145eaba3221c7c6b7ef1b5a4a0348f2908e1cc6d 100644
--- a/tests-fuzz/Makefile.am
+++ b/tests-fuzz/Makefile.am
@@ -1,7 +1,10 @@
 AM_CPPFLAGS = \
-	-include $(top_builddir)/src/config.h \
-	-I$(top_srcdir)/src \
-	-I$(top_srcdir)/src/dnssec/lib
+	-include $(top_builddir)/src/config.h	\
+	-I$(top_srcdir)/src			\
+	-I$(top_srcdir)/src/dnssec/lib		\
+        -DCONFIG_DIR='"${config_dir}"'          \
+        -DSTORAGE_DIR='"${storage_dir}"'        \
+        -DRUN_DIR='"${run_dir}"'
 
 LDADD = \
 	$(top_builddir)/src/libknot.la
@@ -15,11 +18,17 @@ check_PROGRAMS += packet_libfuzzer
 packet_libfuzzer_LDADD = $(LDADD) $(libfuzzer_LIBS) -lstdc++
 endif
 
-knotd_stdio_SOURCES = wrap/server.c wrap/tcp-handler.c wrap/udp-handler.c
+packet_SOURCES = packet.c afl-loop.h
+knotd_stdio_SOURCES = wrap/server.c wrap/tcp-handler.c wrap/udp-handler.c afl-loop.h
+nodist_knotd_stdio_SOURCES = wrap/main.c
 knotd_stdio_CPPFLAGS = $(AM_CPPFLAGS) $(liburcu_CFLAGS)
 knotd_stdio_LDADD = \
-	$(top_builddir)/src/utils/knotd/knotd-main.o \
 	$(top_builddir)/src/libknotd.la $(top_builddir)/src/libcontrib.la \
 	$(liburcu_LIBS)
+BUILT_SOURCES = wrap/main.c
+CLEANFILES = wrap/main.c
+wrap/main.c: Makefile $(top_builddir)/src/utils/knotd/main.c
+	echo '#include "afl-loop.h"' > $@
+	sed -e 's/for (;;)/while (__AFL_LOOP(1000))/' $(top_builddir)/src/utils/knotd/main.c >>$@
 
 check-compile: $(check_PROGRAMS)
diff --git a/tests-fuzz/afl-loop.h b/tests-fuzz/afl-loop.h
new file mode 100644
index 0000000000000000000000000000000000000000..8a8941b77aa0f37189e1a230e351ad25f021d7ae
--- /dev/null
+++ b/tests-fuzz/afl-loop.h
@@ -0,0 +1,3 @@
+#ifndef __AFL_COMPILER
+#define __AFL_LOOP(x) (0)
+#endif
diff --git a/tests-fuzz/packet.c b/tests-fuzz/packet.c
index bc6fc7ec74ad651ed2a4f8a94b9c9da8184497a2..feb381ec2bd51298de1232a7c06a294dee5c53a1 100644
--- a/tests-fuzz/packet.c
+++ b/tests-fuzz/packet.c
@@ -20,10 +20,11 @@
 #include <signal.h>
 
 #include "libknot/libknot.h"
+#include "afl-loop.h"
 
 int main(void)
 {
-	for(;;) {
+	while (__AFL_LOOP(1000)) {
 		uint8_t buffer[UINT16_MAX + 1] = { 0 };
 		size_t len = fread(buffer, 1, sizeof(buffer), stdin);
 
@@ -32,10 +33,6 @@ int main(void)
 		int r = knot_pkt_parse(pkt, 0);
 		knot_pkt_free(&pkt);
 
-		if (getenv("AFL_PERSISTENT")) {
-			raise(SIGSTOP);
-		} else {
-			return (r == KNOT_EOK ? 0 : 1);
-		}
+		return (r == KNOT_EOK ? 0 : 1);
 	}
 }