blob: 0cab7b7035f95544ab0804e77f03a55620043e85 [file] [log] [blame]
Chris Wailese3116c42021-07-13 14:40:48 -07001// 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
15static volatile int Sink;
16static volatile int *Nil = nullptr;
17
18extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
19 if (Size > 10)
20 return 0; // To make the test quicker.
21
Chris Wailesbcf972c2021-10-21 11:03:28 -070022 if (Size != 2) {
23 // execute a lot slower than the crashing input below.
Chris Wailese3116c42021-07-13 14:40:48 -070024 size_t ExecTimeUSec = 100;
25 std::this_thread::sleep_for(std::chrono::microseconds(ExecTimeUSec));
Chris Wailesbcf972c2021-10-21 11:03:28 -070026 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;
Chris Wailese3116c42021-07-13 14:40:48 -070030 }
31
32 if (Size == 2 && Data[0] == 0xab && Data[1] == 0xcd)
33 *Nil = 42; // crash.
34
35 return 0;
36}