[sanitizer] Improve FreeBSD ASLR detection
[llvm-project.git] / llvm / tools / llvm-reduce / TestRunner.cpp
blobe8c12138936fa1ec97cfcdc6e9fc56b22af7791e
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,
14 const std::vector<std::string> &TestArgs,
15 std::unique_ptr<ReducerWorkItem> Program)
16 : TestName(TestName), TestArgs(TestArgs), Program(std::move(Program)) {
17 assert(this->Program && "Initialized with null program?");
20 /// Runs the interestingness test, passes file to be tested as first argument
21 /// and other specified test arguments after that.
22 int TestRunner::run(StringRef Filename) {
23 std::vector<StringRef> ProgramArgs;
24 ProgramArgs.push_back(TestName);
26 for (const auto &Arg : TestArgs)
27 ProgramArgs.push_back(Arg);
29 ProgramArgs.push_back(Filename);
31 std::string ErrMsg;
32 int Result = sys::ExecuteAndWait(
33 TestName, ProgramArgs, /*Env=*/None, /*Redirects=*/None,
34 /*SecondsToWait=*/0, /*MemoryLimit=*/0, &ErrMsg);
36 if (Result < 0) {
37 Error E = make_error<StringError>("Error running interesting-ness test: " +
38 ErrMsg,
39 inconvertibleErrorCode());
40 errs() << toString(std::move(E));
41 exit(1);
44 return !Result;