1.1 --- a/src/common/pcap-file-test-suite.cc Wed Nov 04 21:08:32 2009 -0800
1.2 +++ b/src/common/pcap-file-test-suite.cc Thu Nov 05 19:14:37 2009 -0800
1.3 @@ -107,7 +107,7 @@
1.4 std::stringstream filename;
1.5 uint32_t n = rand ();
1.6 filename << n;
1.7 - m_testFilename = "/tmp/" + filename.str () + ".pcap";
1.8 + m_testFilename = GetTempDir () + filename.str () + ".pcap";
1.9 }
1.10
1.11 void
1.12 @@ -218,7 +218,7 @@
1.13 std::stringstream filename;
1.14 uint32_t n = rand ();
1.15 filename << n;
1.16 - m_testFilename = "/tmp/" + filename.str () + ".pcap";
1.17 + m_testFilename = GetTempDir () + filename.str () + ".pcap";
1.18 }
1.19
1.20 void
1.21 @@ -317,7 +317,7 @@
1.22 std::stringstream filename;
1.23 uint32_t n = rand ();
1.24 filename << n;
1.25 - m_testFilename = "/tmp/" + filename.str () + ".pcap";
1.26 + m_testFilename = GetTempDir () + filename.str () + ".pcap";
1.27 }
1.28
1.29 void
1.30 @@ -416,7 +416,7 @@
1.31 std::stringstream filename;
1.32 uint32_t n = rand ();
1.33 filename << n;
1.34 - m_testFilename = "/tmp/" + filename.str () + ".pcap";
1.35 + m_testFilename = GetTempDir () + filename.str () + ".pcap";
1.36 }
1.37
1.38 void
1.39 @@ -607,7 +607,7 @@
1.40 std::stringstream filename;
1.41 uint32_t n = rand ();
1.42 filename << n;
1.43 - m_testFilename = "/tmp/" + filename.str () + ".pcap";
1.44 + m_testFilename = GetTempDir () + filename.str () + ".pcap";
1.45 }
1.46
1.47 void
2.1 --- a/src/core/test.cc Wed Nov 04 21:08:32 2009 -0800
2.2 +++ b/src/core/test.cc Thu Nov 05 19:14:37 2009 -0800
2.3 @@ -87,6 +87,7 @@
2.4 m_continueOnFailure (false),
2.5 m_detailsReported (false),
2.6 m_basedir ("invalid"),
2.7 + m_tempdir ("invalid"),
2.8 m_ofs (0),
2.9 m_error (false)
2.10 {
2.11 @@ -203,7 +204,14 @@
2.12 void
2.13 TestCase::SetBaseDir (std::string basedir)
2.14 {
2.15 - m_basedir = basedir;
2.16 + if (basedir[basedir.length () - 1] != '/')
2.17 + {
2.18 + m_basedir = basedir + "/";
2.19 + }
2.20 + else
2.21 + {
2.22 + m_basedir = basedir;
2.23 + }
2.24 }
2.25
2.26 std::string
2.27 @@ -212,13 +220,32 @@
2.28 return m_basedir;
2.29 }
2.30
2.31 +void
2.32 +TestCase::SetTempDir (std::string tempdir)
2.33 +{
2.34 + if (tempdir[tempdir.length () - 1] != '/')
2.35 + {
2.36 + m_tempdir = tempdir + "/";
2.37 + }
2.38 + else
2.39 + {
2.40 + m_tempdir = tempdir;
2.41 + }
2.42 +}
2.43 +
2.44 +std::string
2.45 +TestCase::GetTempDir (void)
2.46 +{
2.47 + return m_tempdir;
2.48 +}
2.49 +
2.50 std::string
2.51 TestCase::GetSourceDir (std::string file)
2.52 {
2.53 std::string::size_type relPathBegin = file.find_first_of ("/");
2.54 - NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
2.55 + NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
2.56 std::string::size_type relPathEnd = file.find_last_of ("/");
2.57 - NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
2.58 + NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
2.59
2.60 return GetBaseDir () + file.substr (relPathBegin, relPathEnd + 1 - relPathBegin);
2.61 }
2.62 @@ -353,6 +380,7 @@
2.63 : m_name (name),
2.64 m_verbose (false),
2.65 m_basedir ("invalid"),
2.66 + m_tempdir ("invalid"),
2.67 m_ofs (0),
2.68 m_error (false),
2.69 m_type (type)
2.70 @@ -476,7 +504,14 @@
2.71 void
2.72 TestSuite::SetBaseDir (std::string basedir)
2.73 {
2.74 - m_basedir = basedir;
2.75 + if (basedir[basedir.length () - 1] != '/')
2.76 + {
2.77 + m_basedir = basedir + "/";
2.78 + }
2.79 + else
2.80 + {
2.81 + m_basedir = basedir;
2.82 + }
2.83 }
2.84
2.85 std::string
2.86 @@ -486,6 +521,25 @@
2.87 }
2.88
2.89 void
2.90 +TestSuite::SetTempDir (std::string tempdir)
2.91 +{
2.92 + if (tempdir[tempdir.length () - 1] != '/')
2.93 + {
2.94 + m_tempdir = tempdir + "/";
2.95 + }
2.96 + else
2.97 + {
2.98 + m_tempdir = tempdir;
2.99 + }
2.100 +}
2.101 +
2.102 +std::string
2.103 +TestSuite::GetTempDir (void)
2.104 +{
2.105 + return m_tempdir;
2.106 +}
2.107 +
2.108 +void
2.109 TestSuite::SetStream (std::ofstream *ofs)
2.110 {
2.111 m_ofs = ofs;
2.112 @@ -589,6 +643,7 @@
2.113 (*i)->SetVerbose (m_verbose);
2.114 (*i)->SetContinueOnFailure (m_continueOnFailure);
2.115 (*i)->SetBaseDir (m_basedir);
2.116 + (*i)->SetTempDir (m_tempdir);
2.117 (*i)->SetStream (m_ofs);
2.118
2.119 //
3.1 --- a/src/core/test.h Wed Nov 04 21:08:32 2009 -0800
3.2 +++ b/src/core/test.h Thu Nov 05 19:14:37 2009 -0800
3.3 @@ -662,6 +662,16 @@
3.4 */
3.5 std::string GetBaseDir (void);
3.6
3.7 + /**
3.8 + * \brief Set the temporary file directory (where to write temporary files).
3.9 + */
3.10 + void SetTempDir (std::string dir);
3.11 +
3.12 + /**
3.13 + * \brief Get the temporary file directory .
3.14 + */
3.15 + std::string GetTempDir (void);
3.16 +
3.17 /**
3.18 * \brief Get the source directory of the current source file.
3.19 *
3.20 @@ -830,6 +840,7 @@
3.21 bool m_continueOnFailure;
3.22 bool m_detailsReported;
3.23 std::string m_basedir;
3.24 + std::string m_tempdir;
3.25 std::ofstream *m_ofs;
3.26 bool m_error;
3.27 };
3.28 @@ -945,6 +956,16 @@
3.29 std::string GetBaseDir (void);
3.30
3.31 /**
3.32 + * \brief Set the temporary file directory (where to write temporary files).
3.33 + */
3.34 + void SetTempDir (std::string dir);
3.35 +
3.36 + /**
3.37 + * \brief Get the temporary file directory.
3.38 + */
3.39 + std::string GetTempDir (void);
3.40 +
3.41 + /**
3.42 * \brief Set the stream to which status and result messages will be written.
3.43 *
3.44 * We really don't want to have to pass an ofstream around to every function
3.45 @@ -1064,6 +1085,7 @@
3.46 bool m_verbose;
3.47 bool m_continueOnFailure;
3.48 std::string m_basedir;
3.49 + std::string m_tempdir;
3.50 std::ofstream *m_ofs;
3.51 bool m_error;
3.52 TestType m_type;
4.1 --- a/test.py Wed Nov 04 21:08:32 2009 -0800
4.2 +++ b/test.py Thu Nov 05 19:14:37 2009 -0800
4.3 @@ -616,6 +616,7 @@
4.4 self.shell_command = ""
4.5 self.display_name = ""
4.6 self.basedir = ""
4.7 + self.tempdir = ""
4.8 self.cwd = ""
4.9 self.tmp_file_name = ""
4.10 self.returncode = False
4.11 @@ -674,6 +675,13 @@
4.12 self.basedir = basedir
4.13
4.14 #
4.15 + # This is the directory to which a running test suite should write any
4.16 + # temporary files.
4.17 + #
4.18 + def set_tempdir(self, tempdir):
4.19 + self.tempdir = tempdir
4.20 +
4.21 + #
4.22 # This is the current working directory that will be given to an executing
4.23 # test as it is being run. It will be used for examples to tell them where
4.24 # to write all of the pcap files that we will be carefully ignoring. For
4.25 @@ -766,7 +774,8 @@
4.26 # file name
4.27 #
4.28 (job.returncode, standard_out, standard_err, et) = run_job_synchronously(job.shell_command +
4.29 - " --basedir=%s --out=%s" % (job.basedir, job.tmp_file_name), job.cwd, options.valgrind)
4.30 + " --basedir=%s --tempdir=%s --out=%s" % (job.basedir, job.tempdir, job.tmp_file_name),
4.31 + job.cwd, options.valgrind)
4.32
4.33 job.set_elapsed_time(et)
4.34
4.35 @@ -1004,6 +1013,7 @@
4.36 job.set_tmp_file_name(os.path.join(testpy_output_dir, "%s.xml" % test))
4.37 job.set_cwd(os.getcwd())
4.38 job.set_basedir(os.getcwd())
4.39 + job.set_tempdir(testpy_output_dir)
4.40 if (options.multiple):
4.41 multiple = " --multiple"
4.42 else:
4.43 @@ -1074,6 +1084,7 @@
4.44 job.set_tmp_file_name("")
4.45 job.set_cwd(testpy_output_dir)
4.46 job.set_basedir(os.getcwd())
4.47 + job.set_tempdir(testpy_output_dir)
4.48 job.set_shell_command("examples/%s" % test)
4.49
4.50 if options.valgrind and not eval(do_valgrind_run):
4.51 @@ -1097,6 +1108,7 @@
4.52 job.set_tmp_file_name("")
4.53 job.set_cwd(testpy_output_dir)
4.54 job.set_basedir(os.getcwd())
4.55 + job.set_tempdir(testpy_output_dir)
4.56 job.set_shell_command("examples/%s" % options.example)
4.57
4.58 if options.verbose:
5.1 --- a/utils/test-runner.cc Wed Nov 04 21:08:32 2009 -0800
5.2 +++ b/utils/test-runner.cc Thu Nov 05 19:14:37 2009 -0800
5.3 @@ -40,11 +40,13 @@
5.4 bool doKinds = false;
5.5
5.6 bool haveBasedir = false;
5.7 + bool haveTempdir = false;
5.8 bool haveOutfile = false;
5.9 bool haveType = false;
5.10
5.11 std::string suiteName;
5.12 std::string basedir;
5.13 + std::string tempdir;
5.14 std::string outfileName;
5.15 std::string typeName;
5.16
5.17 @@ -96,6 +98,12 @@
5.18 doSuite = true;
5.19 }
5.20
5.21 + if (arg.find ("--tempdir=") != std::string::npos)
5.22 + {
5.23 + tempdir = arg.substr (arg.find_first_of ("=") + 1, 9999);
5.24 + haveTempdir = true;
5.25 + }
5.26 +
5.27 if (arg.compare ("--verbose") == 0)
5.28 {
5.29 doVerbose = true;
5.30 @@ -247,6 +255,7 @@
5.31 if (doSuite == false || (doSuite == true && suiteName == testSuite->GetName ()))
5.32 {
5.33 testSuite->SetBaseDir (basedir);
5.34 + testSuite->SetTempDir (tempdir);
5.35 testSuite->SetStream (pofs);
5.36 testSuite->SetVerbose (doVerbose);
5.37 testSuite->SetContinueOnFailure (doMultiple);