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