TestRunner.cpp 1.3 KB

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