Try to fix fuzztest issue on Windows.
The buffer length was a bit small so most of the corpus
messages wouldn't fit in it, causing pipe write to hang
until the process exited.
diff --git a/tests/fuzztest/SConscript b/tests/fuzztest/SConscript
index e7eb4e2..a80a902 100644
--- a/tests/fuzztest/SConscript
+++ b/tests/fuzztest/SConscript
@@ -94,9 +94,12 @@
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate(input = corpus.read(filename))
result = process.wait()
- except Exception as e:
- print('Exception when fuzzing against ' + filename + ": " + str(e))
- raise
+ except OSError as e:
+ if e.errno == 22:
+ print("Warning: OSError 22 when running with input " + filename)
+ result = process.wait()
+ else:
+ raise
if result != 0:
stdout += stderr
diff --git a/tests/fuzztest/fuzztest.c b/tests/fuzztest/fuzztest.c
index ab7824c..4de793d 100644
--- a/tests/fuzztest/fuzztest.c
+++ b/tests/fuzztest/fuzztest.c
@@ -25,13 +25,13 @@
#include "alltypes_proto3_pointer.pb.h"
/* Longer buffer size allows hitting more branches, but lowers performance. */
-#if defined(LLVMFUZZER)
-static size_t g_bufsize = 256*1024;
-#elif defined(__AVR__)
-static size_t g_bufsize = 2048;
-#else
-static size_t g_bufsize = 4096;
+#ifndef FUZZTEST_BUFSIZE
+#define FUZZTEST_BUFSIZE 256*1024
#endif
+#ifndef FUZZTEST_MAX_STANDALONE_BUFSIZE
+#define FUZZTEST_MAX_STANDALONE_BUFSIZE 16384
+#endif
+static size_t g_bufsize = FUZZTEST_BUFSIZE;
static uint32_t xor32_checksum(const void *data, size_t len)
{
@@ -393,6 +393,9 @@
if (argc >= 2)
{
/* Run in stand-alone mode */
+ if (g_bufsize > FUZZTEST_MAX_STANDALONE_BUFSIZE)
+ g_bufsize = FUZZTEST_MAX_STANDALONE_BUFSIZE;
+
random_set_seed(strtoul(argv[1], NULL, 0));
iterations = (argc >= 3) ? atol(argv[2]) : 10000;
@@ -411,9 +414,17 @@
buffer = malloc_with_check(g_bufsize);
SET_BINARY_MODE(stdin);
- msglen = fread(buffer, 1, g_bufsize, stdin);
+ msglen = fread(buffer, 1, g_bufsize/2, stdin);
LLVMFuzzerTestOneInput(buffer, msglen);
+ while (!feof(stdin))
+ {
+ /* Read any leftover input data if our buffer is smaller than
+ * message size. */
+ fprintf(stderr, "Warning: input message too long\n");
+ fread(buffer, 1, g_bufsize, stdin);
+ }
+
free_with_check(buffer);
}
diff --git a/tests/site_scons/platforms/avr/avr.py b/tests/site_scons/platforms/avr/avr.py
index 64c608a..87608f4 100644
--- a/tests/site_scons/platforms/avr/avr.py
+++ b/tests/site_scons/platforms/avr/avr.py
@@ -12,7 +12,8 @@
env.Append(CFLAGS = "-mmcu=atmega1284 -Dmain=app_main -Os")
env.Append(CXXFLAGS = "-mmcu=atmega1284 -Dmain=app_main -Os -Wno-type-limits")
env.Append(CPPDEFINES = {'PB_CONVERT_DOUBLE_FLOAT': 1, 'UNITTESTS_SHORT_MSGS': 1,
- '__ASSERT_USE_STDERR': 1, 'MAX_REALLOC_SIZE': '4096'})
+ '__ASSERT_USE_STDERR': 1, 'MAX_REALLOC_SIZE': '4096',
+ 'FUZZTEST_BUFSIZE': 2048})
env.Append(LINKFLAGS = "-mmcu=atmega1284")
env.Append(LINKFLAGS = "build/avr_io.o -Wl,-Map,avr.map")
avr_io = env.Object("build/avr_io.o", "site_scons/platforms/avr/avr_io.c")
diff --git a/tests/site_scons/platforms/stm32/stm32.py b/tests/site_scons/platforms/stm32/stm32.py
index 48bba2e..5e68dc2 100644
--- a/tests/site_scons/platforms/stm32/stm32.py
+++ b/tests/site_scons/platforms/stm32/stm32.py
@@ -8,6 +8,7 @@
env.Replace(CC = "arm-none-eabi-gcc",
CXX = "arm-none-eabi-g++")
env.Replace(TEST_RUNNER = "site_scons/platforms/stm32/run_test.sh")
+ env.Append(CPPDEFINES = {'FUZZTEST_BUFSIZE': 4096})
env.Append(CFLAGS = "-mcpu=cortex-m3 -mthumb -Os")
env.Append(CXXFLAGS = "-mcpu=cortex-m3 -mthumb -Os")
env.Append(LINKFLAGS = "-mcpu=cortex-m3 -mthumb")