pass explicit temp directory to test suites
This commit is contained in:
@@ -107,7 +107,7 @@ WriteModeCreateTestCase::DoSetup (void)
|
||||
std::stringstream filename;
|
||||
uint32_t n = rand ();
|
||||
filename << n;
|
||||
m_testFilename = "/tmp/" + filename.str () + ".pcap";
|
||||
m_testFilename = GetTempDir () + filename.str () + ".pcap";
|
||||
}
|
||||
|
||||
void
|
||||
@@ -218,7 +218,7 @@ ReadModeCreateTestCase::DoSetup (void)
|
||||
std::stringstream filename;
|
||||
uint32_t n = rand ();
|
||||
filename << n;
|
||||
m_testFilename = "/tmp/" + filename.str () + ".pcap";
|
||||
m_testFilename = GetTempDir () + filename.str () + ".pcap";
|
||||
}
|
||||
|
||||
void
|
||||
@@ -317,7 +317,7 @@ AppendModeCreateTestCase::DoSetup (void)
|
||||
std::stringstream filename;
|
||||
uint32_t n = rand ();
|
||||
filename << n;
|
||||
m_testFilename = "/tmp/" + filename.str () + ".pcap";
|
||||
m_testFilename = GetTempDir () + filename.str () + ".pcap";
|
||||
}
|
||||
|
||||
void
|
||||
@@ -416,7 +416,7 @@ FileHeaderTestCase::DoSetup (void)
|
||||
std::stringstream filename;
|
||||
uint32_t n = rand ();
|
||||
filename << n;
|
||||
m_testFilename = "/tmp/" + filename.str () + ".pcap";
|
||||
m_testFilename = GetTempDir () + filename.str () + ".pcap";
|
||||
}
|
||||
|
||||
void
|
||||
@@ -607,7 +607,7 @@ RecordHeaderTestCase::DoSetup (void)
|
||||
std::stringstream filename;
|
||||
uint32_t n = rand ();
|
||||
filename << n;
|
||||
m_testFilename = "/tmp/" + filename.str () + ".pcap";
|
||||
m_testFilename = GetTempDir () + filename.str () + ".pcap";
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -87,6 +87,7 @@ TestCase::TestCase (std::string name)
|
||||
m_continueOnFailure (false),
|
||||
m_detailsReported (false),
|
||||
m_basedir ("invalid"),
|
||||
m_tempdir ("invalid"),
|
||||
m_ofs (0),
|
||||
m_error (false)
|
||||
{
|
||||
@@ -203,7 +204,14 @@ TestCase::GetName (void)
|
||||
void
|
||||
TestCase::SetBaseDir (std::string basedir)
|
||||
{
|
||||
if (basedir[basedir.length () - 1] != '/')
|
||||
{
|
||||
m_basedir = basedir + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_basedir = basedir;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
@@ -212,13 +220,32 @@ TestCase::GetBaseDir (void)
|
||||
return m_basedir;
|
||||
}
|
||||
|
||||
void
|
||||
TestCase::SetTempDir (std::string tempdir)
|
||||
{
|
||||
if (tempdir[tempdir.length () - 1] != '/')
|
||||
{
|
||||
m_tempdir = tempdir + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tempdir = tempdir;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
TestCase::GetTempDir (void)
|
||||
{
|
||||
return m_tempdir;
|
||||
}
|
||||
|
||||
std::string
|
||||
TestCase::GetSourceDir (std::string file)
|
||||
{
|
||||
std::string::size_type relPathBegin = file.find_first_of ("/");
|
||||
NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
|
||||
NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
|
||||
std::string::size_type relPathEnd = file.find_last_of ("/");
|
||||
NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
|
||||
NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
|
||||
|
||||
return GetBaseDir () + file.substr (relPathBegin, relPathEnd + 1 - relPathBegin);
|
||||
}
|
||||
@@ -353,6 +380,7 @@ TestSuite::TestSuite (std::string name, TestType type)
|
||||
: m_name (name),
|
||||
m_verbose (false),
|
||||
m_basedir ("invalid"),
|
||||
m_tempdir ("invalid"),
|
||||
m_ofs (0),
|
||||
m_error (false),
|
||||
m_type (type)
|
||||
@@ -476,7 +504,14 @@ TestSuite::GetName (void)
|
||||
void
|
||||
TestSuite::SetBaseDir (std::string basedir)
|
||||
{
|
||||
if (basedir[basedir.length () - 1] != '/')
|
||||
{
|
||||
m_basedir = basedir + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_basedir = basedir;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
@@ -485,6 +520,25 @@ TestSuite::GetBaseDir (void)
|
||||
return m_basedir;
|
||||
}
|
||||
|
||||
void
|
||||
TestSuite::SetTempDir (std::string tempdir)
|
||||
{
|
||||
if (tempdir[tempdir.length () - 1] != '/')
|
||||
{
|
||||
m_tempdir = tempdir + "/";
|
||||
}
|
||||
else
|
||||
{
|
||||
m_tempdir = tempdir;
|
||||
}
|
||||
}
|
||||
|
||||
std::string
|
||||
TestSuite::GetTempDir (void)
|
||||
{
|
||||
return m_tempdir;
|
||||
}
|
||||
|
||||
void
|
||||
TestSuite::SetStream (std::ofstream *ofs)
|
||||
{
|
||||
@@ -589,6 +643,7 @@ TestSuite::DoRun (void)
|
||||
(*i)->SetVerbose (m_verbose);
|
||||
(*i)->SetContinueOnFailure (m_continueOnFailure);
|
||||
(*i)->SetBaseDir (m_basedir);
|
||||
(*i)->SetTempDir (m_tempdir);
|
||||
(*i)->SetStream (m_ofs);
|
||||
|
||||
//
|
||||
|
||||
@@ -662,6 +662,16 @@ public:
|
||||
*/
|
||||
std::string GetBaseDir (void);
|
||||
|
||||
/**
|
||||
* \brief Set the temporary file directory (where to write temporary files).
|
||||
*/
|
||||
void SetTempDir (std::string dir);
|
||||
|
||||
/**
|
||||
* \brief Get the temporary file directory .
|
||||
*/
|
||||
std::string GetTempDir (void);
|
||||
|
||||
/**
|
||||
* \brief Get the source directory of the current source file.
|
||||
*
|
||||
@@ -830,6 +840,7 @@ private:
|
||||
bool m_continueOnFailure;
|
||||
bool m_detailsReported;
|
||||
std::string m_basedir;
|
||||
std::string m_tempdir;
|
||||
std::ofstream *m_ofs;
|
||||
bool m_error;
|
||||
};
|
||||
@@ -944,6 +955,16 @@ public:
|
||||
*/
|
||||
std::string GetBaseDir (void);
|
||||
|
||||
/**
|
||||
* \brief Set the temporary file directory (where to write temporary files).
|
||||
*/
|
||||
void SetTempDir (std::string dir);
|
||||
|
||||
/**
|
||||
* \brief Get the temporary file directory.
|
||||
*/
|
||||
std::string GetTempDir (void);
|
||||
|
||||
/**
|
||||
* \brief Set the stream to which status and result messages will be written.
|
||||
*
|
||||
@@ -1064,6 +1085,7 @@ private:
|
||||
bool m_verbose;
|
||||
bool m_continueOnFailure;
|
||||
std::string m_basedir;
|
||||
std::string m_tempdir;
|
||||
std::ofstream *m_ofs;
|
||||
bool m_error;
|
||||
TestType m_type;
|
||||
|
||||
14
test.py
14
test.py
@@ -616,6 +616,7 @@ class Job:
|
||||
self.shell_command = ""
|
||||
self.display_name = ""
|
||||
self.basedir = ""
|
||||
self.tempdir = ""
|
||||
self.cwd = ""
|
||||
self.tmp_file_name = ""
|
||||
self.returncode = False
|
||||
@@ -673,6 +674,13 @@ class Job:
|
||||
def set_basedir(self, basedir):
|
||||
self.basedir = basedir
|
||||
|
||||
#
|
||||
# This is the directory to which a running test suite should write any
|
||||
# temporary files.
|
||||
#
|
||||
def set_tempdir(self, tempdir):
|
||||
self.tempdir = tempdir
|
||||
|
||||
#
|
||||
# This is the current working directory that will be given to an executing
|
||||
# test as it is being run. It will be used for examples to tell them where
|
||||
@@ -766,7 +774,8 @@ class worker_thread(threading.Thread):
|
||||
# file name
|
||||
#
|
||||
(job.returncode, standard_out, standard_err, et) = run_job_synchronously(job.shell_command +
|
||||
" --basedir=%s --out=%s" % (job.basedir, job.tmp_file_name), job.cwd, options.valgrind)
|
||||
" --basedir=%s --tempdir=%s --out=%s" % (job.basedir, job.tempdir, job.tmp_file_name),
|
||||
job.cwd, options.valgrind)
|
||||
|
||||
job.set_elapsed_time(et)
|
||||
|
||||
@@ -1004,6 +1013,7 @@ def run_tests():
|
||||
job.set_tmp_file_name(os.path.join(testpy_output_dir, "%s.xml" % test))
|
||||
job.set_cwd(os.getcwd())
|
||||
job.set_basedir(os.getcwd())
|
||||
job.set_tempdir(testpy_output_dir)
|
||||
if (options.multiple):
|
||||
multiple = " --multiple"
|
||||
else:
|
||||
@@ -1074,6 +1084,7 @@ def run_tests():
|
||||
job.set_tmp_file_name("")
|
||||
job.set_cwd(testpy_output_dir)
|
||||
job.set_basedir(os.getcwd())
|
||||
job.set_tempdir(testpy_output_dir)
|
||||
job.set_shell_command("examples/%s" % test)
|
||||
|
||||
if options.valgrind and not eval(do_valgrind_run):
|
||||
@@ -1097,6 +1108,7 @@ def run_tests():
|
||||
job.set_tmp_file_name("")
|
||||
job.set_cwd(testpy_output_dir)
|
||||
job.set_basedir(os.getcwd())
|
||||
job.set_tempdir(testpy_output_dir)
|
||||
job.set_shell_command("examples/%s" % options.example)
|
||||
|
||||
if options.verbose:
|
||||
|
||||
@@ -40,11 +40,13 @@ main (int argc, char *argv[])
|
||||
bool doKinds = false;
|
||||
|
||||
bool haveBasedir = false;
|
||||
bool haveTempdir = false;
|
||||
bool haveOutfile = false;
|
||||
bool haveType = false;
|
||||
|
||||
std::string suiteName;
|
||||
std::string basedir;
|
||||
std::string tempdir;
|
||||
std::string outfileName;
|
||||
std::string typeName;
|
||||
|
||||
@@ -96,6 +98,12 @@ main (int argc, char *argv[])
|
||||
doSuite = true;
|
||||
}
|
||||
|
||||
if (arg.find ("--tempdir=") != std::string::npos)
|
||||
{
|
||||
tempdir = arg.substr (arg.find_first_of ("=") + 1, 9999);
|
||||
haveTempdir = true;
|
||||
}
|
||||
|
||||
if (arg.compare ("--verbose") == 0)
|
||||
{
|
||||
doVerbose = true;
|
||||
@@ -247,6 +255,7 @@ main (int argc, char *argv[])
|
||||
if (doSuite == false || (doSuite == true && suiteName == testSuite->GetName ()))
|
||||
{
|
||||
testSuite->SetBaseDir (basedir);
|
||||
testSuite->SetTempDir (tempdir);
|
||||
testSuite->SetStream (pofs);
|
||||
testSuite->SetVerbose (doVerbose);
|
||||
testSuite->SetContinueOnFailure (doMultiple);
|
||||
|
||||
Reference in New Issue
Block a user