#include <cerrno>
#include <cstdlib>
#include <exception>
#include <iostream>
#include <string>
#include <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include "boost/version.hpp"
#include "boost/filesystem/convenience.hpp"
#include "FWCore/Utilities/interface/EDMException.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/RegexMatch.h"
#include "FWCore/Utilities/interface/TestHelper.h"
Go to the source code of this file.
|
int | do_work (int argc, char *argv[], char **env) |
|
int | ptomaine (int argc, char *argv[], char **env) |
|
int | run_script (std::string const &shell, std::string const &script) |
|
int do_work |
( |
int |
argc, |
|
|
char * |
argv[], |
|
|
char ** |
env |
|
) |
| |
Definition at line 57 of file TestHelper.cc.
References edmStreamStallGrapher::argc, ecal_dqm_sourceclient-live_cfg::cerr, gather_cfg::cout, alignCSCRings::e, i, fed_dqm_sourceclient-live_cfg::path, run_script(), checkforupdate::scriptname, AlCaHLTBitMon_QueryRunRegistry::string, and edm::untaintString().
Referenced by ptomaine().
58 bf::path currentPath(bf::initial_path().
string());
61 std::cout <<
"Usage: " <<
argv[0] <<
" shell subdir script1 script2 ... scriptN\n\n"
62 <<
"where shell is the path+shell (e.g., /bin/bash) intended to run the scripts\n"
63 <<
"and subdir is the subsystem/package/subdir in which the scripts are found\n"
64 <<
"(e.g., FWCore/Utilities/test)\n"
67 std::cout <<
"Current directory is: " << currentPath.string() <<
'\n';
76 char const* goodDirectory =
"[A-Za-z0-9/_.-]+";
83 std::cerr <<
"shell is: " << shell <<
'\n';
85 std::cout <<
"Current directory is: " << currentPath.string() <<
'\n';
88 char const* topdir = getenv(
"SCRAMRT_LOCALRT");
89 if(!topdir) topdir = getenv(
"LOCALRT");
92 std::cerr <<
"Invalid top directory '" << topdir <<
"'" << std::endl;
96 catch(std::runtime_error
const&
e) {
97 std::cerr <<
"Invalid top directory '" << topdir <<
"'" << std::endl;
102 char const* arch = getenv(
"SCRAM_ARCH");
107 #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 47
108 std::string maybe_arch = exepath.parent_path().filename().string();
110 std::string maybe_arch = exepath.branch_path().leaf();
112 if(setenv(
"SCRAM_ARCH", maybe_arch.c_str(), 1) != 0) {
113 std::cerr <<
"SCRAM_ARCH not set and attempt to set it failed\n";
116 arch = getenv(
"SCRAM_ARCH");
122 std::cerr <<
"Neither SCRAMRT_LOCALRT nor LOCALRT is defined" << std::endl;
128 std::cerr <<
"Invalid test directory '" <<
argv[2] <<
"'" << std::endl;
132 catch(std::runtime_error
const& e) {
133 std::cerr <<
"Invalid test directory '" <<
argv[2] <<
"'" << std::endl;
139 std::string tmpdir(topdir); tmpdir +=
"/tmp/"; tmpdir += arch;
140 std::string testbin(topdir); testbin +=
"/test/"; testbin += arch;
142 std::cout <<
"topdir is: " << topdir <<
'\n';
143 std::cout <<
"testdir is: " << testdir <<
'\n';
144 std::cout <<
"tmpdir is: " << tmpdir <<
'\n';
145 std::cout <<
"testbin is: " << testbin <<
'\n';
147 if(setenv(
"LOCAL_TEST_DIR", testdir.c_str(),1) != 0) {
148 std::cerr <<
"Could not set LOCAL_TEST_DIR to " << testdir << std::endl;
151 if(setenv(
"LOCAL_TMP_DIR", tmpdir.c_str(),1) != 0) {
152 std::cerr <<
"Could not set LOCAL_TMP_DIR to " << tmpdir << std::endl;
155 if(setenv(
"LOCAL_TOP_DIR", topdir,1) != 0) {
156 std::cerr <<
"Could not set LOCAL_TOP_DIR to " << topdir << std::endl;
159 if(setenv(
"LOCAL_TEST_BIN", testbin.c_str(),1) != 0) {
160 std::cerr <<
"Could not set LOCAL_TEST_BIN to " << testbin << std::endl;
166 for(
int i = 3;
i < argc && rc == 0; ++
i) {
173 std::cout <<
"status = " << rc << std::endl;
174 return rc == 0 ? 0 : -1;
bool untaintString(char const *pattern, char const *regexp)
int run_script(std::string const &shell, std::string const &script)
int ptomaine |
( |
int |
argc, |
|
|
char * |
argv[], |
|
|
char ** |
env |
|
) |
| |
int run_script |
( |
std::string const & |
shell, |
|
|
std::string const & |
script |
|
) |
| |
Definition at line 23 of file TestHelper.cc.
References ecal_dqm_sourceclient-live_cfg::cerr, compareJSON::const, sysUtil::pid, and mps_update::status.
Referenced by do_work().
27 if((pid = fork()) < 0) {
28 std::cerr <<
"fork failed, to run " << script << std::endl;
33 execlp(shell.c_str(),
"sh",
"-c", script.c_str(),
static_cast<char const*
>(0));
34 std::cerr <<
"child failed becuase '" << strerror(errno) <<
"'\n";
37 while(waitpid(pid, &status, 0) < 0) {
39 std::cerr <<
"child process failed " << strerror(errno) <<
"\n";
43 if(WIFSIGNALED(status)) {
44 std::cerr <<
"child existed because of a signal " << WTERMSIG(status) <<
"\n";
48 if(WIFSIGNALED(status)) {
49 std::cerr <<
"child existed because of a signal " << WTERMSIG(status) <<
"\n";
51 if(WIFEXITED(status)) {