forked from OSchip/llvm-project
Require a remote command to exit with the exit status of the test program or with 255 if an error occurred.
llvm-svn: 76323
This commit is contained in:
parent
4105f3eaf9
commit
858702541d
|
@ -46,8 +46,8 @@ namespace {
|
||||||
|
|
||||||
ToolExecutionError::~ToolExecutionError() throw() { }
|
ToolExecutionError::~ToolExecutionError() throw() { }
|
||||||
|
|
||||||
/// RunProgramWithTimeout - This function provides an alternate interface to the
|
/// RunProgramWithTimeout - This function provides an alternate interface
|
||||||
/// sys::Program::ExecuteAndWait interface.
|
/// to the sys::Program::ExecuteAndWait interface.
|
||||||
/// @see sys:Program::ExecuteAndWait
|
/// @see sys:Program::ExecuteAndWait
|
||||||
static int RunProgramWithTimeout(const sys::Path &ProgramPath,
|
static int RunProgramWithTimeout(const sys::Path &ProgramPath,
|
||||||
const char **Args,
|
const char **Args,
|
||||||
|
@ -61,19 +61,73 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath,
|
||||||
redirects[1] = &StdOutFile;
|
redirects[1] = &StdOutFile;
|
||||||
redirects[2] = &StdErrFile;
|
redirects[2] = &StdErrFile;
|
||||||
|
|
||||||
if (0) {
|
#if 0 // For debug purposes
|
||||||
|
{
|
||||||
errs() << "RUN:";
|
errs() << "RUN:";
|
||||||
for (unsigned i = 0; Args[i]; ++i)
|
for (unsigned i = 0; Args[i]; ++i)
|
||||||
errs() << " " << Args[i];
|
errs() << " " << Args[i];
|
||||||
errs() << "\n";
|
errs() << "\n";
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return
|
return
|
||||||
sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects,
|
sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects,
|
||||||
NumSeconds, MemoryLimit);
|
NumSeconds, MemoryLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// RunProgramRemotelyWithTimeout - This function runs the given program
|
||||||
|
/// remotely using the given remote client and the sys::Program::ExecuteAndWait.
|
||||||
|
/// Returns the remote program exit code or reports a remote client error if it
|
||||||
|
/// fails. Remote client is required to return 255 if it failed or program exit
|
||||||
|
/// code otherwise.
|
||||||
|
/// @see sys:Program::ExecuteAndWait
|
||||||
|
static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
|
||||||
|
const char **Args,
|
||||||
|
const sys::Path &StdInFile,
|
||||||
|
const sys::Path &StdOutFile,
|
||||||
|
const sys::Path &StdErrFile,
|
||||||
|
unsigned NumSeconds = 0,
|
||||||
|
unsigned MemoryLimit = 0) {
|
||||||
|
const sys::Path* redirects[3];
|
||||||
|
redirects[0] = &StdInFile;
|
||||||
|
redirects[1] = &StdOutFile;
|
||||||
|
redirects[2] = &StdErrFile;
|
||||||
|
|
||||||
|
#if 0 // For debug purposes
|
||||||
|
{
|
||||||
|
errs() << "RUN:";
|
||||||
|
for (unsigned i = 0; Args[i]; ++i)
|
||||||
|
errs() << " " << Args[i];
|
||||||
|
errs() << "\n";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Run the program remotely with the remote client
|
||||||
|
int ReturnCode = sys::Program::ExecuteAndWait(RemoteClientPath, Args,
|
||||||
|
0, redirects, NumSeconds, MemoryLimit);
|
||||||
|
|
||||||
|
// Has the remote client fail?
|
||||||
|
if (255 == ReturnCode) {
|
||||||
|
std::ostringstream OS;
|
||||||
|
OS << "\nError running remote client:\n ";
|
||||||
|
for (const char **Arg = Args; *Arg; ++Arg)
|
||||||
|
OS << " " << *Arg;
|
||||||
|
OS << "\n";
|
||||||
|
|
||||||
|
// The error message is in the output file, let's print it out from there.
|
||||||
|
std::ifstream ErrorFile(StdOutFile.c_str());
|
||||||
|
if (ErrorFile) {
|
||||||
|
std::copy(std::istreambuf_iterator<char>(ErrorFile),
|
||||||
|
std::istreambuf_iterator<char>(),
|
||||||
|
std::ostreambuf_iterator<char>(OS));
|
||||||
|
ErrorFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw ToolExecutionError(OS.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReturnCode;
|
||||||
|
}
|
||||||
|
|
||||||
static void ProcessFailure(sys::Path ProgPath, const char** Args) {
|
static void ProcessFailure(sys::Path ProgPath, const char** Args) {
|
||||||
std::ostringstream OS;
|
std::ostringstream OS;
|
||||||
|
@ -680,18 +734,12 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
|
||||||
Timeout, MemoryLimit);
|
Timeout, MemoryLimit);
|
||||||
} else {
|
} else {
|
||||||
outs() << "<run remotely>"; outs().flush();
|
outs() << "<run remotely>"; outs().flush();
|
||||||
int RemoteClientStatus = RunProgramWithTimeout(sys::Path(RemoteClientPath),
|
return RunProgramRemotelyWithTimeout(sys::Path(RemoteClientPath),
|
||||||
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
|
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
|
||||||
sys::Path(OutputFile), Timeout, MemoryLimit);
|
sys::Path(OutputFile), Timeout, MemoryLimit);
|
||||||
if (RemoteClientStatus != 0) {
|
|
||||||
errs() << "Remote Client failed with an error: " <<
|
|
||||||
RemoteClientStatus << ".\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
|
||||||
std::string &OutputFile,
|
std::string &OutputFile,
|
||||||
const std::vector<std::string> &ArgsForGCC) {
|
const std::vector<std::string> &ArgsForGCC) {
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
#
|
#
|
||||||
# Program: RemoteRunSafely.sh
|
# Program: RemoteRunSafely.sh
|
||||||
#
|
#
|
||||||
# Synopsis: This script simply runs another program remotely using rsh.
|
# Synopsis: This script simply runs another program remotely using ssh.
|
||||||
# It always returns the another program exit code.
|
# It always returns the another program exit code or exit with
|
||||||
#
|
# code 255 which indicates that the program could not be executed.
|
||||||
# (?) only exit statuses that indicates that the program could not be executed
|
|
||||||
# normally is considered to indicate a test failure.
|
|
||||||
#
|
#
|
||||||
# Syntax:
|
# Syntax:
|
||||||
#
|
#
|
||||||
|
@ -25,8 +23,8 @@ printUsageAndExit()
|
||||||
{
|
{
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo "./RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>] " \
|
echo "./RemoteRunSafely.sh <hostname> [-l <login_name>] [-p <port>] " \
|
||||||
"[cd <working_dir>] <program> <args...>"
|
"<program> <args...>"
|
||||||
exit 1
|
exit 255
|
||||||
}
|
}
|
||||||
|
|
||||||
moreArgsExpected()
|
moreArgsExpected()
|
||||||
|
@ -88,7 +86,7 @@ fi
|
||||||
local_program=$WORKING_DIR"/"$PROGRAM
|
local_program=$WORKING_DIR"/"$PROGRAM
|
||||||
if [ ! -x "$local_program" ]; then
|
if [ ! -x "$local_program" ]; then
|
||||||
echo "File "$local_program" does not exist or is not an executable.."
|
echo "File "$local_program" does not exist or is not an executable.."
|
||||||
exit 2
|
exit 255
|
||||||
fi
|
fi
|
||||||
|
|
||||||
connection=$RUSER'@'$RHOST
|
connection=$RUSER'@'$RHOST
|
||||||
|
@ -98,11 +96,10 @@ remote="./"$PROGRAM
|
||||||
$RCLIENT $connection $RPORT \
|
$RCLIENT $connection $RPORT \
|
||||||
'rm -f '$remote' ; ' \
|
'rm -f '$remote' ; ' \
|
||||||
'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \
|
'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \
|
||||||
'echo exit $? ; ' \
|
'err=$? ; rm -f '$remote' ; exit $err'
|
||||||
'rm -f '$remote
|
|
||||||
)
|
)
|
||||||
|
err=$?
|
||||||
|
|
||||||
#DEBUG: err=$?
|
|
||||||
#DEBUG: echo script exit $err
|
#DEBUG: echo script exit $err
|
||||||
#DEBUG: exit $err
|
exit $err
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue