llvm.org GIT mirror llvm / fc2271f
Require a remote command to exit with the exit status of the test program or with 255 if an error occurred. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76323 91177308-0d34-0410-b5e6-96231b3b80d8 Viktor Kutuzov 11 years ago
2 changed file(s) with 70 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
4545
4646 ToolExecutionError::~ToolExecutionError() throw() { }
4747
48 /// RunProgramWithTimeout - This function provides an alternate interface to the
49 /// sys::Program::ExecuteAndWait interface.
48 /// RunProgramWithTimeout - This function provides an alternate interface
49 /// to the sys::Program::ExecuteAndWait interface.
5050 /// @see sys:Program::ExecuteAndWait
5151 static int RunProgramWithTimeout(const sys::Path &ProgramPath,
5252 const char **Args,
5959 redirects[0] = &StdInFile;
6060 redirects[1] = &StdOutFile;
6161 redirects[2] = &StdErrFile;
62
63 if (0) {
62
63 #if 0 // For debug purposes
64 {
6465 errs() << "RUN:";
6566 for (unsigned i = 0; Args[i]; ++i)
6667 errs() << " " << Args[i];
6768 errs() << "\n";
6869 }
70 #endif
6971
7072 return
7173 sys::Program::ExecuteAndWait(ProgramPath, Args, 0, redirects,
7274 NumSeconds, MemoryLimit);
7375 }
7476
75
77 /// RunProgramRemotelyWithTimeout - This function runs the given program
78 /// remotely using the given remote client and the sys::Program::ExecuteAndWait.
79 /// Returns the remote program exit code or reports a remote client error if it
80 /// fails. Remote client is required to return 255 if it failed or program exit
81 /// code otherwise.
82 /// @see sys:Program::ExecuteAndWait
83 static int RunProgramRemotelyWithTimeout(const sys::Path &RemoteClientPath,
84 const char **Args,
85 const sys::Path &StdInFile,
86 const sys::Path &StdOutFile,
87 const sys::Path &StdErrFile,
88 unsigned NumSeconds = 0,
89 unsigned MemoryLimit = 0) {
90 const sys::Path* redirects[3];
91 redirects[0] = &StdInFile;
92 redirects[1] = &StdOutFile;
93 redirects[2] = &StdErrFile;
94
95 #if 0 // For debug purposes
96 {
97 errs() << "RUN:";
98 for (unsigned i = 0; Args[i]; ++i)
99 errs() << " " << Args[i];
100 errs() << "\n";
101 }
102 #endif
103
104 // Run the program remotely with the remote client
105 int ReturnCode = sys::Program::ExecuteAndWait(RemoteClientPath, Args,
106 0, redirects, NumSeconds, MemoryLimit);
107
108 // Has the remote client fail?
109 if (255 == ReturnCode) {
110 std::ostringstream OS;
111 OS << "\nError running remote client:\n ";
112 for (const char **Arg = Args; *Arg; ++Arg)
113 OS << " " << *Arg;
114 OS << "\n";
115
116 // The error message is in the output file, let's print it out from there.
117 std::ifstream ErrorFile(StdOutFile.c_str());
118 if (ErrorFile) {
119 std::copy(std::istreambuf_iterator(ErrorFile),
120 std::istreambuf_iterator(),
121 std::ostreambuf_iterator(OS));
122 ErrorFile.close();
123 }
124
125 throw ToolExecutionError(OS.str());
126 }
127
128 return ReturnCode;
129 }
76130
77131 static void ProcessFailure(sys::Path ProgPath, const char** Args) {
78132 std::ostringstream OS;
679733 Timeout, MemoryLimit);
680734 } else {
681735 outs() << ""; outs().flush();
682 int RemoteClientStatus = RunProgramWithTimeout(sys::Path(RemoteClientPath),
736 return RunProgramRemotelyWithTimeout(sys::Path(RemoteClientPath),
683737 &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
684738 sys::Path(OutputFile), Timeout, MemoryLimit);
685 if (RemoteClientStatus != 0) {
686 errs() << "Remote Client failed with an error: " <<
687 RemoteClientStatus << ".\n";
688 }
689 }
690
691 return 0;
739 }
692740 }
693741
694742 int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
11 #
22 # Program: RemoteRunSafely.sh
33 #
4 # Synopsis: This script simply runs another program remotely using rsh.
5 # It always returns the another program exit code.
6 #
7 # (?) only exit statuses that indicates that the program could not be executed
8 # normally is considered to indicate a test failure.
4 # Synopsis: This script simply runs another program remotely using ssh.
5 # It always returns the another program exit code or exit with
6 # code 255 which indicates that the program could not be executed.
97 #
108 # Syntax:
119 #
2422 {
2523 echo "Usage:"
2624 echo "./RemoteRunSafely.sh [-l ] [-p ] " \
27 "[cd ] "
28 exit 1
25 " "
26 exit 255
2927 }
3028
3129 moreArgsExpected()
8785 local_program=$WORKING_DIR"/"$PROGRAM
8886 if [ ! -x "$local_program" ]; then
8987 echo "File "$local_program" does not exist or is not an executable.."
90 exit 2
88 exit 255
9189 fi
9290
9391 connection=$RUSER'@'$RHOST
9795 $RCLIENT $connection $RPORT \
9896 'rm -f '$remote' ; ' \
9997 'cat > '$remote' ; chmod +x '$remote' ; '$remote' '$*' ; ' \
100 'echo exit $? ; ' \
101 'rm -f '$remote
98 'err=$? ; rm -f '$remote' ; exit $err'
10299 )
100 err=$?
103101
104 #DEBUG: err=$?
105102 #DEBUG: echo script exit $err
106 #DEBUG: exit $err
103 exit $err
107104