TestRunner.h 2.1 KB

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