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 #include "ReducerWorkItem.h"
11 #include "llvm/CodeGen/MachineFunction.h"
12
13 using namespace llvm;
14
TestRunner(StringRef TestName,const std::vector<std::string> & TestArgs,std::unique_ptr<ReducerWorkItem> Program,std::unique_ptr<TargetMachine> TM,const char * ToolName)15 TestRunner::TestRunner(StringRef TestName,
16 const std::vector<std::string> &TestArgs,
17 std::unique_ptr<ReducerWorkItem> Program,
18 std::unique_ptr<TargetMachine> TM, const char *ToolName)
19 : TestName(TestName), ToolName(ToolName), TestArgs(TestArgs),
20 Program(std::move(Program)), TM(std::move(TM)) {
21 assert(this->Program && "Initialized with null program?");
22 }
23
24 /// Runs the interestingness test, passes file to be tested as first argument
25 /// and other specified test arguments after that.
run(StringRef Filename)26 int TestRunner::run(StringRef Filename) {
27 std::vector<StringRef> ProgramArgs;
28 ProgramArgs.push_back(TestName);
29
30 for (const auto &Arg : TestArgs)
31 ProgramArgs.push_back(Arg);
32
33 ProgramArgs.push_back(Filename);
34
35 std::string ErrMsg;
36 int Result = sys::ExecuteAndWait(
37 TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None,
38 /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
39
40 if (Result < 0) {
41 Error E = make_error<StringError>("Error running interesting-ness test: " +
42 ErrMsg,
43 inconvertibleErrorCode());
44 errs() << toString(std::move(E));
45 exit(1);
46 }
47
48 return !Result;
49 }
50
setProgram(std::unique_ptr<ReducerWorkItem> P)51 void TestRunner::setProgram(std::unique_ptr<ReducerWorkItem> P) {
52 assert(P && "Setting null program?");
53 Program = std::move(P);
54 }
55