[llvm] [cmake] Add possibility to use ChooseMSVCCRT.cmake when include LLVM library
[llvm-core.git] / tools / llvm-reduce / TestRunner.cpp
blobd0e195d5697c96c34c91b0a6c41b1ec24f287d31
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 //===----------------------------------------------------------------------===//
9 #include "TestRunner.h"
11 using namespace llvm;
13 TestRunner::TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs)
14 : TestName(TestName), TestArgs(TestArgs) {
17 /// Runs the interestingness test, passes file to be tested as first argument
18 /// and other specified test arguments after that.
19 int TestRunner::run(StringRef Filename) {
20 std::vector<StringRef> ProgramArgs;
21 ProgramArgs.push_back(TestName);
23 for (const auto &Arg : TestArgs)
24 ProgramArgs.push_back(Arg);
26 ProgramArgs.push_back(Filename);
28 std::string ErrMsg;
29 int Result = sys::ExecuteAndWait(
30 TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None,
31 /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
33 if (Result < 0) {
34 Error E = make_error<StringError>("Error running interesting-ness test: " +
35 ErrMsg,
36 inconvertibleErrorCode());
37 errs() << toString(std::move(E));
38 exit(1);
41 return !Result;