xref: /llvm-project/llvm/tools/llvm-reduce/TestRunner.h (revision 3e0d37fd79faeb60a47ed8aace1c594ff7f637f2)
1 //===-- tools/llvm-reduce/TestRunner.h ---------------------------*- C++ -*-===/
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
10 #define LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
11 
12 #include "ReducerWorkItem.h"
13 #include "llvm/IR/Module.h"
14 #include "llvm/Support/Error.h"
15 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/Path.h"
17 #include "llvm/Support/Program.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include <vector>
20 
21 namespace llvm {
22 
23 // This class contains all the info necessary for running the provided
24 // interesting-ness test, as well as the most reduced module and its
25 // respective filename.
26 class TestRunner {
27 public:
28   TestRunner(StringRef TestName, ArrayRef<std::string> TestArgs,
29              std::unique_ptr<ReducerWorkItem> Program,
30              std::unique_ptr<TargetMachine> TM, StringRef ToolName,
31              StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
32 
33   /// Runs the interesting-ness test for the specified file
34   /// @returns 0 if test was successful, 1 if otherwise
35   int run(StringRef Filename) const;
36 
37   /// Returns the most reduced version of the original testcase
38   ReducerWorkItem &getProgram() const { return *Program; }
39 
40   void setProgram(std::unique_ptr<ReducerWorkItem> &&P) {
41     assert(P && "Setting null program?");
42     Program = std::move(P);
43   }
44 
45   const TargetMachine *getTargetMachine() const { return TM.get(); }
46 
47   StringRef getToolName() const { return ToolName; }
48 
49   void writeOutput(StringRef Message);
50 
51   bool inputIsBitcode() const {
52     return InputIsBitcode;
53   }
54 
55 private:
56   StringRef TestName;
57   StringRef ToolName;
58   SmallVector<StringRef> TestArgs;
59   std::unique_ptr<ReducerWorkItem> Program;
60   std::unique_ptr<TargetMachine> TM;
61   StringRef OutputFilename;
62   const bool InputIsBitcode;
63   bool EmitBitcode;
64 };
65 
66 } // namespace llvm
67 
68 #endif
69