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/ADT/SmallString.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/Error.h"
16 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/Program.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include <vector>
21 
22 namespace llvm {
23 
24 // This class contains all the info necessary for running the provided
25 // interesting-ness test, as well as the most reduced module and its
26 // respective filename.
27 class TestRunner {
28 public:
29   TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs,
30              std::unique_ptr<ReducerWorkItem> Program,
31              std::unique_ptr<TargetMachine> TM, StringRef ToolName,
32              StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
33 
34   /// Runs the interesting-ness test for the specified file
35   /// @returns 0 if test was successful, 1 if otherwise
36   int run(StringRef Filename) const;
37 
38   /// Returns the most reduced version of the original testcase
getProgram()39   ReducerWorkItem &getProgram() const { return *Program; }
40 
setProgram(std::unique_ptr<ReducerWorkItem> && P)41   void setProgram(std::unique_ptr<ReducerWorkItem> &&P) {
42     assert(P && "Setting null program?");
43     Program = std::move(P);
44   }
45 
getTargetMachine()46   const TargetMachine *getTargetMachine() const { return TM.get(); }
47 
getToolName()48   StringRef getToolName() const { return ToolName; }
49 
50   void writeOutput(StringRef Message);
51 
inputIsBitcode()52   bool inputIsBitcode() const {
53     return InputIsBitcode;
54   }
55 
56 private:
57   StringRef TestName;
58   StringRef ToolName;
59   const std::vector<std::string> &TestArgs;
60   std::unique_ptr<ReducerWorkItem> Program;
61   std::unique_ptr<TargetMachine> TM;
62   StringRef OutputFilename;
63   const bool InputIsBitcode;
64   bool EmitBitcode;
65 };
66 
67 } // namespace llvm
68 
69 #endif
70