[llvm-opt-fuzzer] NFC. Add sanity tests.

llvm-svn: 318293
diff --git a/llvm/test/tools/llvm-opt-fuzzer/command-line.ll b/llvm/test/tools/llvm-opt-fuzzer/command-line.ll
new file mode 100644
index 0000000..f747bba
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-fuzzer/command-line.ll
@@ -0,0 +1,20 @@
+; REQUIRES: x86-registered-target
+
+; Temporary bitcode file
+; RUN: opt -o %t %s
+
+; Don't start without target triple
+; RUN: not llvm-opt-fuzzer %t 2>&1 | FileCheck -check-prefix=TRIPLE %s
+; TRIPLE: -mtriple must be specified
+
+; Don't start without passes specified
+; RUN: not llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 2>&1 | FileCheck -check-prefix=PASSES %s
+; PASSES: at least one pass should be specified
+
+; Don't start with incorrect passes specified
+; RUN: not llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 -passes no-pass 2>&1 | FileCheck -check-prefix=PIPELINE %s
+; PIPELINE: can't parse pass pipeline
+
+; Correct command line
+; RUN: llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 -passes instcombine 2>&1 | FileCheck -check-prefix=CORRECT %s
+; CORRECT: Running
diff --git a/llvm/test/tools/llvm-opt-fuzzer/exec-options.ll b/llvm/test/tools/llvm-opt-fuzzer/exec-options.ll
new file mode 100644
index 0000000..9a42077
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-fuzzer/exec-options.ll
@@ -0,0 +1,23 @@
+; If the binary looks up libraries using an rpath, we can't test this
+; without copying the whole lib dir or polluting the build dir.
+; REQUIRES: static-libs
+
+; Temporary bitcode file
+; RUN: opt -o %t.input %s
+
+; RUN: cp llvm-opt-fuzzer %t.bin--
+; RUN: not %t.bin-- %t.input 2>&1 | FileCheck -check-prefix=EMPTY %s
+; EMPTY: -mtriple must be specified
+
+; RUN: cp llvm-opt-fuzzer %t.bin--x86_64
+; RUN: not %t.bin--x86_64 %t.input 2>&1 | FileCheck -check-prefix=PASSES %s
+; PASSES: at least one pass should be specified
+
+; RUN: cp llvm-opt-fuzzer %t.bin--x86_64-unknown
+; RUN: not %t.bin--x86_64-unknown %t.input 2>&1 | FileCheck -check-prefix=UNKNOWN %s
+; UNKNOWN: Unknown option: unknown
+
+; RUN: cp llvm-opt-fuzzer %t.bin--x86_64-instcombine
+; RUN: %t.bin--x86_64-instcombine %t.input 2>&1 | FileCheck -check-prefix=CORRECT %s
+; CORRECT: Injected args: -mtriple=x86_64 -passes=instcombine
+; CORRECT: Running
diff --git a/llvm/test/tools/llvm-opt-fuzzer/simple-fail.ll b/llvm/test/tools/llvm-opt-fuzzer/simple-fail.ll
new file mode 100644
index 0000000..2200474
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-fuzzer/simple-fail.ll
@@ -0,0 +1,7 @@
+; Check that fuzzer will fail on invalid input
+; REQUIRES: x86-registered-target
+
+; RUN: llvm-opt-fuzzer %s -ignore_remaining_args=1 -mtriple x86_64 -passes instcombine 2>&1 | FileCheck %s
+; CHECK: input module is broken
+
+invalid input
diff --git a/llvm/test/tools/llvm-opt-fuzzer/simple-run.ll b/llvm/test/tools/llvm-opt-fuzzer/simple-run.ll
new file mode 100644
index 0000000..8255d37
--- /dev/null
+++ b/llvm/test/tools/llvm-opt-fuzzer/simple-run.ll
@@ -0,0 +1,13 @@
+; Check that fuzzer will succeed on a trivial input
+; REQUIRES: x86-registered-target
+
+; Temporary bitcode file
+; RUN: opt -o %t %s
+
+; RUN: llvm-opt-fuzzer %t -ignore_remaining_args=1 -mtriple x86_64 -passes instcombine 2>&1 | FileCheck %s
+; CHECK: Running
+
+define i32 @test(i32 %n) {
+entry:
+  ret i32 0
+}