From 5646b9ef2068f1577569226326f62d90e2de5f09 Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Thu, 9 Nov 2017 20:30:19 +0000 Subject: [libFuzzer] handle SIGUSR1/SIGUSR2 and try to exit grafully on these signals git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@317829 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/fuzzer/SleepOneSecondTest.cpp | 13 +++++++++++++ test/fuzzer/sigusr.test | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/fuzzer/SleepOneSecondTest.cpp create mode 100644 test/fuzzer/sigusr.test (limited to 'test/fuzzer') diff --git a/test/fuzzer/SleepOneSecondTest.cpp b/test/fuzzer/SleepOneSecondTest.cpp new file mode 100644 index 000000000..27de2f4f7 --- /dev/null +++ b/test/fuzzer/SleepOneSecondTest.cpp @@ -0,0 +1,13 @@ +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. + +// Simple test for a fuzzer: it simply sleeps for 1 second. +#include +#include +#include + +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { + std::this_thread::sleep_for(std::chrono::seconds(1)); + return 0; +} + diff --git a/test/fuzzer/sigusr.test b/test/fuzzer/sigusr.test new file mode 100644 index 000000000..fce244fa5 --- /dev/null +++ b/test/fuzzer/sigusr.test @@ -0,0 +1,29 @@ +# Check that libFuzzer honors SIGUSR1/SIGUSR2 +RUN: rm -rf %t +RUN: mkdir -p %t +RUN: %cpp_compiler %S/SleepOneSecondTest.cpp -o %t/LFSIGUSR + +RUN: %t/LFSIGUSR 2> %t/log & export PID=$! +RUN: sleep 2 +RUN: kill -SIGUSR1 $PID +RUN: cat %t/log | FileCheck %s + +RUN: mkdir -p %t/C1 %t/C2 +RUN: echo a > %t/C2/a +RUN: echo b > %t/C2/b +RUN: echo c > %t/C2/c +RUN: echo d > %t/C2/d +RUN: echo e > %t/C2/e +RUN: echo f > %t/C2/f +RUN: echo g > %t/C2/g + +RUN: %t/LFSIGUSR -merge=1 -merge_control_file=%t/MCF %t/C1 %t/C2 2> %t/log & export PID=$! +RUN: sleep 3 +RUN: killall -SIGUSR2 %t/LFSIGUSR +RUN: cat %t/log | FileCheck %s +RUN: grep C2/g %t/MCF +RUN: grep STARTED %t/MCF +RUN: grep DONE %t/MCF + +CHECK: INFO: signal received, trying to exit gracefully +CHECK: INFO: libFuzzer: exiting as requested -- cgit v1.2.3