Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp

Issue 1156103003: Initial implementation of a record-level bitcode fuzzer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@fuzz
Patch Set: Fix issues in last patch. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/CMakeLists.txt ('k') | lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp
diff --git a/lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp b/lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0673736277aed289b757805c01e4f452bfa1bcaf
--- /dev/null
+++ b/lib/Bitcode/NaCl/TestUtils/NaClFuzz.cpp
@@ -0,0 +1,53 @@
+//===- NaClFuzz.cpp - Fuzz PNaCl bitcode records --------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements a basic fuzzer for a list of PNaCl bitcode records.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/Bitcode/NaCl/NaClFuzz.h"
+
+using namespace llvm;
+
+namespace {
+
+// Names for edit actions.
+const char *ActionNameArray[] = {
+ "Insert",
+ "Mutate",
+ "Remove",
+ "Replace",
+ "Swap"
+};
+
+} // end of anonymous namespace
+
+namespace naclfuzz {
+
+const char *RecordFuzzer::actionName(EditAction Action) {
+ return Action < array_lengthof(ActionNameArray)
+ ? ActionNameArray[Action] : "???";
+}
+
+RecordFuzzer::RecordFuzzer(NaClMungedBitcode &Bitcode,
+ RandomNumberGenerator &Generator)
+ : Bitcode(Bitcode), Generator(Generator) {
+ if (Bitcode.getBaseRecords().empty())
+ report_fatal_error(
+ "Sorry, the fuzzer doesn't know how to fuzz an empty record list");
+}
+
+RecordFuzzer::~RecordFuzzer() {}
+
+void RecordFuzzer::clear() {
+ Bitcode.removeEdits();
+}
+
+} // end of namespace naclfuzz
« no previous file with comments | « lib/Bitcode/NaCl/TestUtils/CMakeLists.txt ('k') | lib/Bitcode/NaCl/TestUtils/NaClRandNumGen.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698