From ac512890b47032fcee167a702ab14da59137723c Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Mon, 3 May 2021 10:25:32 -0700 Subject: [PATCH] [libFuzzer] Deflake entropic exec-time test. --- compiler-rt/test/fuzzer/EntropicScalePerExecTimeTest.cpp | 9 ++++++--- compiler-rt/test/fuzzer/entropic-scale-per-exec-time.test | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler-rt/test/fuzzer/EntropicScalePerExecTimeTest.cpp b/compiler-rt/test/fuzzer/EntropicScalePerExecTimeTest.cpp index ec3a690..0cab7b7 100644 --- a/compiler-rt/test/fuzzer/EntropicScalePerExecTimeTest.cpp +++ b/compiler-rt/test/fuzzer/EntropicScalePerExecTimeTest.cpp @@ -19,11 +19,14 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { if (Size > 10) return 0; // To make the test quicker. - if (Size == 10) { + if (Size != 2) { + // execute a lot slower than the crashing input below. size_t ExecTimeUSec = 100; std::this_thread::sleep_for(std::chrono::microseconds(ExecTimeUSec)); - - Sink = 0; // execute a lot slower than the crashing input below. + if (Size > 0 && Data[0] == 0xaa && Size > 1 && Data[1] == 0xbb && + Size > 2 && Data[2] == 0xcc && Size > 3 && Data[3] == 0xdd && + Size > 4 && Data[4] == 0xee && Size > 5 && Data[5] == 0xff) + Sink += 7; } if (Size == 2 && Data[0] == 0xab && Data[1] == 0xcd) diff --git a/compiler-rt/test/fuzzer/entropic-scale-per-exec-time.test b/compiler-rt/test/fuzzer/entropic-scale-per-exec-time.test index d34550f..2b8fec9 100644 --- a/compiler-rt/test/fuzzer/entropic-scale-per-exec-time.test +++ b/compiler-rt/test/fuzzer/entropic-scale-per-exec-time.test @@ -1,8 +1,7 @@ REQUIRES: linux, x86_64 RUN: %cpp_compiler %S/EntropicScalePerExecTimeTest.cpp -o %t-EntropicScalePerExecTimeTest -RUN: not %run %t-EntropicScalePerExecTimeTest -entropic=1 -entropic_scale_per_exec_time=1 -seed=1 -runs=100000 -max_len=10 +RUN: not %run %t-EntropicScalePerExecTimeTest -entropic=1 -entropic_scale_per_exec_time=1 -seed=1 -runs=150000 -max_len=10 -# The following test is added as a comment here for reference, which should -# take more runs than with -entropic_scale_per_exec_time=1 to find the crash. -# (it takes 126,633 runs) -# RUN: not %run %t-EntropicScalePerExecTimeTest -entropic=1 -seed=1 -runs=200000 -max_len=10 +# Without -entropic_scale_per_exec_time=1, the crash takes longer to find since +# the slow path is explored first. +RUN: %run %t-EntropicScalePerExecTimeTest -entropic=1 -seed=1 -runs=150000 -max_len=10 -- 2.7.4