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 9 #include "TestRunner.h" 10 11 using namespace llvm; 12 13 TestRunner::TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs) 14 : TestName(TestName), TestArgs(TestArgs) { 15 } 16 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); 22 23 for (const auto &Arg : TestArgs) 24 ProgramArgs.push_back(Arg); 25 26 ProgramArgs.push_back(Filename); 27 28 std::string ErrMsg; 29 int Result = sys::ExecuteAndWait( 30 TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None, 31 /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg); 32 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); 39 } 40 41 return !Result; 42 } 43