From 408796c672ab95e9fbe697d48f6b1311a60218cd Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Wed, 28 Jan 2015 22:49:25 +0000 Subject: [PATCH] Add lit-style tests for the Fuzzer library Summary: Add test targets and the lit-style runner. Test Plan: Run the tests on bot. Reviewers: samsonov Reviewed By: samsonov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D7217 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@227389 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Fuzzer/CMakeLists.txt | 4 ++++ lib/Fuzzer/FuzzerLoop.cpp | 4 ++-- lib/Fuzzer/test/CMakeLists.txt | 37 +++++++++++++++++++++++++++++++++ lib/Fuzzer/test/fuzzer.test | 13 ++++++++++++ lib/Fuzzer/test/lit.cfg | 6 ++++++ lib/Fuzzer/test/lit.site.cfg.in | 2 ++ 6 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 lib/Fuzzer/test/CMakeLists.txt create mode 100644 lib/Fuzzer/test/fuzzer.test create mode 100644 lib/Fuzzer/test/lit.cfg create mode 100644 lib/Fuzzer/test/lit.site.cfg.in diff --git a/lib/Fuzzer/CMakeLists.txt b/lib/Fuzzer/CMakeLists.txt index 62207abb7d6..e1ff65848cc 100644 --- a/lib/Fuzzer/CMakeLists.txt +++ b/lib/Fuzzer/CMakeLists.txt @@ -7,3 +7,7 @@ add_library(LLVMFuzzer STATIC FuzzerMutate.cpp FuzzerUtil.cpp ) + +if( LLVM_INCLUDE_TESTS ) + add_subdirectory(test) +endif() diff --git a/lib/Fuzzer/FuzzerLoop.cpp b/lib/Fuzzer/FuzzerLoop.cpp index 9ad2bd729aa..b0bfce73ffd 100644 --- a/lib/Fuzzer/FuzzerLoop.cpp +++ b/lib/Fuzzer/FuzzerLoop.cpp @@ -41,12 +41,12 @@ void Fuzzer::AlarmCallback() { duration_cast(system_clock::now() - UnitStartTime).count(); std::cerr << "ALARM: working on the last Unit for " << Seconds << " seconds" << std::endl; - if (Seconds > 60) { + if (Seconds >= 3) { Print(CurrentUnit, "\n"); PrintASCII(CurrentUnit, "\n"); WriteToCrash(CurrentUnit, "timeout-"); } - abort(); + exit(1); } void Fuzzer::ShuffleAndMinimize() { diff --git a/lib/Fuzzer/test/CMakeLists.txt b/lib/Fuzzer/test/CMakeLists.txt new file mode 100644 index 00000000000..0c2118f31b0 --- /dev/null +++ b/lib/Fuzzer/test/CMakeLists.txt @@ -0,0 +1,37 @@ +set(Tests + ExactTest + InfiniteTest + NullDerefTest + SimpleTest + TimeoutTest + ) + +set(TestBinaries) + +foreach(Test ${Tests}) + add_executable(LLVMFuzzer-${Test} + EXCLUDE_FROM_ALL + ${Test}.cpp + ) + target_link_libraries(LLVMFuzzer-${Test} + LLVMFuzzer + ) + set(TestBinaries ${TestBinaries} LLVMFuzzer-${Test}) +endforeach() + +set_target_properties(${TestBinaries} + PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) + +set(EXCLUDE_FROM_ALL TRUE) +add_lit_testsuite(check-fuzzer "Running Fuzzer tests" + ${CMAKE_CURRENT_BINARY_DIR} + DEPENDS ${TestBinaries} + ) +set(EXCLUDE_FROM_ALL FALSE) + +configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg + ) + diff --git a/lib/Fuzzer/test/fuzzer.test b/lib/Fuzzer/test/fuzzer.test new file mode 100644 index 00000000000..5f013109f62 --- /dev/null +++ b/lib/Fuzzer/test/fuzzer.test @@ -0,0 +1,13 @@ +RUN: ./LLVMFuzzer-SimpleTest 2>&1 | FileCheck %s --check-prefix=SimpleTest +SimpleTest: Found the target, exiting + +RUN: not ./LLVMFuzzer-InfiniteTest -timeout=2 2>&1 | FileCheck %s --check-prefix=InfiniteTest +InfiniteTest: ALARM: working on the last Unit for +InfiniteTest-NOT: CRASHED; file written to timeout + +RUN: not ./LLVMFuzzer-TimeoutTest -timeout=5 2>&1 | FileCheck %s --check-prefix=TimeoutTest +TimeoutTest: ALARM: working on the last Unit for +TimeoutTest: CRASHED; file written to timeout + +RUN: not ./LLVMFuzzer-NullDerefTest 2>&1 | FileCheck %s --check-prefix=NullDerefTest +NullDerefTest: CRASHED; file written to crash- diff --git a/lib/Fuzzer/test/lit.cfg b/lib/Fuzzer/test/lit.cfg new file mode 100644 index 00000000000..d1c85051b47 --- /dev/null +++ b/lib/Fuzzer/test/lit.cfg @@ -0,0 +1,6 @@ +import lit.formats + +config.name = "LLVMFuzzer" +config.test_format = lit.formats.ShTest(True) +config.suffixes = ['.test'] +config.test_source_root = os.path.dirname(__file__) diff --git a/lib/Fuzzer/test/lit.site.cfg.in b/lib/Fuzzer/test/lit.site.cfg.in new file mode 100644 index 00000000000..5fedc1dff6f --- /dev/null +++ b/lib/Fuzzer/test/lit.site.cfg.in @@ -0,0 +1,2 @@ +config.test_exec_root = "@CMAKE_CURRENT_BINARY_DIR@" +lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg") -- 2.34.1