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, const char *ToolName);
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);
36 
37   /// Returns the most reduced version of the original testcase
getProgram()38   ReducerWorkItem &getProgram() const { return *Program; }
39 
40   void setProgram(std::unique_ptr<ReducerWorkItem> P);
41 
getTargetMachine()42   const TargetMachine *getTargetMachine() const { return TM.get(); }
43 
getToolName()44   const char *getToolName() const { return ToolName; }
45 
46 private:
47   StringRef TestName;
48   const char *ToolName;
49   const std::vector<std::string> &TestArgs;
50   std::unique_ptr<ReducerWorkItem> Program;
51   std::unique_ptr<TargetMachine> TM;
52 };
53 
54 } // namespace llvm
55 
56 #endif
57