Skip to content

Commit 9f9fb62

Browse files
committed
Break SIGTRAP test cpp file out into separate file
1 parent a8d0dd0 commit 9f9fb62

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
2+
// See https://llvm.org/LICENSE.txt for license information.
3+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4+
5+
// Simple test for a fuzzer. The fuzzer must find the string "Hi!".
6+
#include <assert.h>
7+
#include <cstddef>
8+
#include <cstdint>
9+
#include <cstdlib>
10+
#include <iostream>
11+
#include <ostream>
12+
#include <signal.h>
13+
14+
static volatile int Sink;
15+
16+
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
17+
assert(Data);
18+
if (Size > 0 && Data[0] == 'H') {
19+
Sink = 1;
20+
if (Size > 1 && Data[1] == 'i') {
21+
Sink = 2;
22+
if (Size > 2 && Data[2] == '!') {
23+
std::cout << "BINGO; Found the target, exiting\n" << std::flush;
24+
raise(SIGTRAP);
25+
}
26+
}
27+
}
28+
return 0;
29+
}
30+

compiler-rt/test/fuzzer/SimpleTest.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#include <cstdlib>
1010
#include <iostream>
1111
#include <ostream>
12-
#ifdef SIGTRAP_TEST
13-
# include <signal.h>
14-
#endif
1512

1613
static volatile int Sink;
1714

@@ -23,11 +20,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
2320
Sink = 2;
2421
if (Size > 2 && Data[2] == '!') {
2522
std::cout << "BINGO; Found the target, exiting\n" << std::flush;
26-
#ifdef SIGTRAP_TEST
27-
raise(SIGTRAP);
28-
#else
2923
exit(0);
30-
#endif
3124
}
3225
}
3326
}

compiler-rt/test/fuzzer/sig-trap.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
RUN: %cpp_compiler %S/SimpleTest.cpp -DSIGTRAP_TEST -o %t-SigTrapTest
1+
RUN: %cpp_compiler %S/SigTrapTest.cpp -o %t
22

3-
RUN: not %run %t-SigTrapTest 2>&1 | FileCheck %s
3+
RUN: not %run %t 2>&1 | FileCheck %s
44
CHECK: BINGO
55
CHECK: ERROR: libFuzzer: deadly signal
66

7-
RUN: trap "%run %t-SigTrapTest -handle_trap=0" TRAP
7+
RUN: trap "%run %t -handle_trap=0" TRAP

0 commit comments

Comments
 (0)