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 LLVMFuzzerTestOneInput(const uint8_t * Data,size_t Size)18extern "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 == 10) { 23 size_t ExecTimeUSec = 100; 24 std::this_thread::sleep_for(std::chrono::microseconds(ExecTimeUSec)); 25 26 Sink = 0; // execute a lot slower than the crashing input below. 27 } 28 29 if (Size == 2 && Data[0] == 0xab && Data[1] == 0xcd) 30 *Nil = 42; // crash. 31 32 return 0; 33 } 34