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 | // Tests whether scaling the Entropic scheduling weight based on input execution |
6 | // time is effective or not. Inputs of size 10 will take at least 100 |
7 | // microseconds more than any input of size 1-9. The input of size 2 in the |
8 | // corpus should be favored by the exec-time-scaled Entropic scheduling policy |
9 | // than the input of size 10 in the corpus, eventually finding the crashing |
10 | // input {0xab, 0xcd} with less executions. |
11 | #include <chrono> |
12 | #include <cstdint> |
13 | #include <thread> |
14 | |
15 | static volatile int Sink; |
16 | static volatile int *Nil = nullptr; |
17 | |
18 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { |
19 | if (Size > 10) |
20 | return 0; // To make the test quicker. |
21 | |
22 | if (Size != 2) { |
23 | // execute a lot slower than the crashing input below. |
24 | size_t ExecTimeUSec = 100; |
25 | std::this_thread::sleep_for(std::chrono::microseconds(ExecTimeUSec)); |
26 | if (Size > 0 && Data[0] == 0xaa && Size > 1 && Data[1] == 0xbb && |
27 | Size > 2 && Data[2] == 0xcc && Size > 3 && Data[3] == 0xdd && |
28 | Size > 4 && Data[4] == 0xee && Size > 5 && Data[5] == 0xff) |
29 | Sink += 7; |
30 | } |
31 | |
32 | if (Size == 2 && Data[0] == 0xab && Data[1] == 0xcd) |
33 | *Nil = 42; // crash. |
34 | |
35 | return 0; |
36 | } |
37 | |