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 seeds the random | |
| 13 // number generator each time bitcode is fuzzed. As a result, this | |
| 14 // code is not thread safe. | |
| 15 | |
| 16 #ifndef LLVM_BITCODE_NACL_NACLFUZZ_H | |
| 17 #define LLVM_BITCODE_NACL_NACLFUZZ_H | |
| 18 | |
| 19 #include "llvm/ADT/SmallVector.h" | |
| 20 #include "llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h" | |
| 21 | |
| 22 namespace naclfuzz { | |
| 23 | |
| 24 using namespace llvm; | |
| 25 | |
| 26 /// \brief Fuzzes a list of editable bitcode records. | |
| 27 class RecordFuzzer { | |
| 28 RecordFuzzer(const RecordFuzzer&) = delete; | |
| 29 void operator=(const RecordFuzzer&) = delete; | |
| 30 public: | |
| 31 | |
| 32 typedef NaClMungedBitcode::iterator iterator; | |
| 33 /// \brief The set of possible fuzzing actions. | |
| 34 enum EditAction { | |
| 35 /// \brief Inserts a new record into the list of bitcode records. | |
| 36 InsertRecord, | |
| 37 /// \brief Mutate contents of an existing bitcode record. | |
| 38 MutateRecord, | |
| 39 /// \brief Removes an existing record from the list of bitcode | |
| 40 /// records. | |
| 41 RemoveRecord, | |
| 42 /// \brief Replaces an existing record with a new bitcode record. | |
| 43 ReplaceRecord, | |
| 44 /// \brief Swaps two records in the bitcode record list. | |
| 45 SwapRecord | |
| 46 }; | |
| 47 | |
| 48 virtual ~RecordFuzzer(); | |
| 49 | |
| 50 /// \brief Sets the random number generator seed to the given value. | |
| 51 /// Value of 1 implies reset to default for random number generator. | |
| 52 virtual void setRandomGeneratorSeed(uint64_t NewValue = 1) = 0; | |
| 53 | |
| 54 /// \brief Generates a new fuzzing of the bitcode, using the a random | |
|
kcc2
2015/05/26 20:38:32
Do you mean "generates a random mutation"?
Karl
2015/05/29 20:59:34
Done.
| |
| 55 /// number generator. Percentage (a value between 0 and 1) is used to | |
| 56 /// define the number of fuzzing actions applied to the bitcode. | |
| 57 /// Returns true if fuzzing succeeded. | |
| 58 /// | |
| 59 /// Many be called an arbitrary number of times. Results are left in | |
| 60 /// the munged bitcode records passed into static method | |
| 61 /// createSimpleRecordFuzzer. | |
| 62 virtual bool fuzz(float MinPercentage) = 0; | |
|
kcc2
2015/05/26 20:38:32
float?
mmmm. I don't like floats except for when
Karl
2015/05/29 20:59:34
Changed to pass in Count/Base (integer) values to
| |
| 63 | |
| 64 /// \brief Shows how many times each record was edited in the | |
| 65 /// corresponding (input) bitcode, over all calls to fuzz. | |
| 66 virtual void showRecordDistribution(raw_ostream &Out) const = 0; | |
| 67 | |
| 68 /// \brief Shows how many times each type of edit action was applied | |
| 69 /// to the corresponding bitcode, over all calls to fuzz. | |
| 70 virtual void showEditDistribution(raw_ostream &Out) const = 0; | |
| 71 | |
| 72 // Creates an instance of a fuzzer for the given bitcode. | |
| 73 static RecordFuzzer *createSimpleRecordFuzzer(NaClMungedBitcode &Bitcode); | |
| 74 | |
| 75 /// Returns printable name for the edit action. | |
| 76 static const char *actionName(EditAction Action); | |
| 77 | |
| 78 protected: | |
| 79 explicit RecordFuzzer(NaClMungedBitcode &Bitcode); | |
| 80 | |
| 81 // Holds the bitcode being munged. | |
| 82 NaClMungedBitcode &Bitcode; | |
| 83 | |
| 84 // Erases the last fuzzing result from the munged bitcode records | |
| 85 // in Bitcode. | |
| 86 virtual void clear(); | |
| 87 }; | |
| 88 | |
| 89 } // end of namespace naclfuzz | |
| 90 | |
| 91 #endif // LLVM_BITCODE_NACL_NACLFUZZ_H | |
| OLD | NEW |