TestRunner.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===-- TestRunner.cpp ----------------------------------------------------===//
  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. #include "TestRunner.h"
  9. using namespace llvm;
  10. TestRunner::TestRunner(StringRef TestName,
  11. const std::vector<std::string> &TestArgs,
  12. std::unique_ptr<ReducerWorkItem> Program)
  13. : TestName(TestName), TestArgs(TestArgs), Program(std::move(Program)) {
  14. assert(this->Program && "Initialized with null program?");
  15. }
  16. /// Runs the interestingness test, passes file to be tested as first argument
  17. /// and other specified test arguments after that.
  18. int TestRunner::run(StringRef Filename) {
  19. std::vector<StringRef> ProgramArgs;
  20. ProgramArgs.push_back(TestName);
  21. for (const auto &Arg : TestArgs)
  22. ProgramArgs.push_back(Arg);
  23. ProgramArgs.push_back(Filename);
  24. std::string ErrMsg;
  25. int Result = sys::ExecuteAndWait(
  26. TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None,
  27. /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
  28. if (Result < 0) {
  29. Error E = make_error<StringError>("Error running interesting-ness test: " +
  30. ErrMsg,
  31. inconvertibleErrorCode());
  32. errs() << toString(std::move(E));
  33. exit(1);
  34. }
  35. return !Result;
  36. }