summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2017-11-09 20:30:19 +0000
committerKostya Serebryany <kcc@google.com>2017-11-09 20:30:19 +0000
commit5646b9ef2068f1577569226326f62d90e2de5f09 (patch)
tree2e561ae7a8c60e83555ca99bdd1589813f8b8ee2 /test
parentc483d54d4a6d703121c3054a522f1eeb745287d2 (diff)
[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
Diffstat (limited to 'test')
-rw-r--r--test/fuzzer/SleepOneSecondTest.cpp13
-rw-r--r--test/fuzzer/sigusr.test29
2 files changed, 42 insertions, 0 deletions
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 <cstddef>
+#include <cstdint>
+#include <thread>
+
+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