Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- NaClFuzz.h - Fuzz PNaCl bitcode records ------------------*- C++ -*-===// | |
| 2 // | |
| 3 // The LLVM Compiler Infrastructure | |
| 4 // | |
| 5 // This file is distributed under the University of Illinois Open Source | |
| 6 // License. See LICENSE.TXT for details. | |
| 7 // | |
| 8 //===----------------------------------------------------------------------===// | |
| 9 // | |
| 10 // This file defines a basic fuzzer for a list of PNaCl bitcode records. | |
| 11 // | |
| 12 // *** WARNING *** The implementation of the fuzzer uses a random | |
| 13 // number generator. As a result, this code is not thread safe. | |
|
jvoung (off chromium)
2015/06/01 17:26:35
Close the header description with another line of
Karl
2015/06/01 22:40:54
Done.
| |
| 14 | |
| 15 #ifndef LLVM_BITCODE_NACL_NACLFUZZ_H | |
| 16 #define LLVM_BITCODE_NACL_NACLFUZZ_H | |
| 17 | |
| 18 #include "llvm/ADT/SmallVector.h" | |
| 19 #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" | |
| 20 #include "llvm/Bitcode/NaCl/NaClRandNumGen.h" | |
| 21 | |
| 22 #include <random> | |
| 23 | |
| 24 namespace naclfuzz { | |
| 25 | |
| 26 using namespace llvm; | |
| 27 | |
| 28 /// \brief Fuzzes a list of editable bitcode records. | |
| 29 class RecordFuzzer { | |
| 30 RecordFuzzer(const RecordFuzzer&) = delete; | |
| 31 void operator=(const RecordFuzzer&) = delete; | |
| 32 public: | |
| 33 typedef NaClMungedBitcode::iterator iterator; | |
| 34 | |
| 35 /// \brief The set of possible fuzzing actions. | |
| 36 enum EditAction { | |
| 37 /// \brief Inserts a new record into the list of bitcode records. | |
| 38 InsertRecord, | |
| 39 /// \brief Mutate contents of an existing bitcode record. | |
| 40 MutateRecord, | |
| 41 /// \brief Removes an existing record from the list of bitcode | |
| 42 /// records. | |
| 43 RemoveRecord, | |
| 44 /// \brief Replaces an existing record with a new bitcode record. | |
| 45 ReplaceRecord, | |
| 46 /// \brief Swaps two records in the bitcode record list. | |
| 47 SwapRecord | |
| 48 }; | |
| 49 | |
| 50 virtual ~RecordFuzzer(); | |
| 51 | |
| 52 /// \brief Generates a random mutation of the bitcode, using the | |
| 53 /// provided random number generator. Percentage (a value between 0 | |
| 54 /// and 1 defined by Count/Base) is used to define the number of | |
| 55 /// fuzzing actions applied to the bitcode. Returns true if fuzzing | |
| 56 /// succeeded. | |
| 57 /// | |
| 58 /// Many be called an arbitrary number of times. Results are left in | |
|
jvoung (off chromium)
2015/06/01 17:26:34
Many be -> May be
Karl
2015/06/01 22:40:54
Done.
| |
| 59 /// the munged bitcode records passed into static method | |
| 60 /// createSimpleRecordFuzzer. | |
| 61 virtual bool fuzz(unsigned Count, unsigned Base=100) = 0; | |
| 62 | |
| 63 /// \brief Shows how many times each record was edited in the | |
| 64 /// corresponding (input) bitcode, over all calls to fuzz. | |
| 65 virtual void showRecordDistribution(raw_ostream &Out) const = 0; | |
| 66 | |
| 67 /// \brief Shows how many times each type of edit action was applied | |
| 68 /// to the corresponding bitcode, over all calls to fuzz. | |
| 69 virtual void showEditDistribution(raw_ostream &Out) const = 0; | |
| 70 | |
| 71 // Creates an instance of a fuzzer for the given bitcode. | |
| 72 static RecordFuzzer | |
| 73 *createSimpleRecordFuzzer(NaClMungedBitcode &Bitcode, | |
| 74 RandomNumberGenerator &RandGenerator); | |
| 75 | |
| 76 /// Returns printable name for the edit action. | |
| 77 static const char *actionName(EditAction Action); | |
| 78 | |
| 79 protected: | |
| 80 explicit RecordFuzzer(NaClMungedBitcode &Bitcode, | |
|
jvoung (off chromium)
2015/06/01 17:26:34
No longer need explicit w/ two params.
Karl
2015/06/01 22:40:54
Done.
| |
| 81 RandomNumberGenerator &Generator); | |
| 82 | |
| 83 // Holds the bitcode being munged. | |
| 84 NaClMungedBitcode &Bitcode; | |
| 85 | |
| 86 // Hold the random number generator. | |
| 87 RandomNumberGenerator &Generator; | |
| 88 | |
| 89 // Erases the last fuzzing result from the munged bitcode records | |
| 90 // in Bitcode. | |
| 91 virtual void clear(); | |
| 92 }; | |
| 93 | |
| 94 } // end of namespace naclfuzz | |
| 95 | |
| 96 #endif // LLVM_BITCODE_NACL_NACLFUZZ_H | |
| OLD | NEW |