1.1 --- a/src/common/pcap-file-test-suite.cc Fri Nov 06 11:27:04 2009 +0100
1.2 +++ b/src/common/pcap-file-test-suite.cc Fri Nov 06 11:27:17 2009 +0100
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 Fri Nov 06 11:27:04 2009 +0100
2.2 +++ b/src/core/test.cc Fri Nov 06 11:27:17 2009 +0100
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,18 @@
2.12 void
2.13 TestCase::SetBaseDir (std::string basedir)
2.14 {
2.15 - m_basedir = basedir;
2.16 + //
2.17 + // C and C++ allow one to use forward slashes even on systems where the
2.18 + // separator is actually a backslash.
2.19 + //
2.20 + if (basedir[basedir.length () - 1] != '/')
2.21 + {
2.22 + m_basedir = basedir + "/";
2.23 + }
2.24 + else
2.25 + {
2.26 + m_basedir = basedir;
2.27 + }
2.28 }
2.29
2.30 std::string
2.31 @@ -212,13 +224,52 @@
2.32 return m_basedir;
2.33 }
2.34
2.35 +void
2.36 +TestCase::SetTempDir (std::string tempdir)
2.37 +{
2.38 + //
2.39 + // C and C++ allow one to use forward slashes even on systems where the
2.40 + // separator is actually a backslash.
2.41 + //
2.42 + if (tempdir[tempdir.length () - 1] != '/')
2.43 + {
2.44 + m_tempdir = tempdir + "/";
2.45 + }
2.46 + else
2.47 + {
2.48 + m_tempdir = tempdir;
2.49 + }
2.50 +}
2.51 +
2.52 +std::string
2.53 +TestCase::GetTempDir (void)
2.54 +{
2.55 + return m_tempdir;
2.56 +}
2.57 +
2.58 std::string
2.59 TestCase::GetSourceDir (std::string file)
2.60 {
2.61 + //
2.62 + // The <file> parameter is actually going to be __FILE__ which may have
2.63 + // backslashes in it on win32 systems. For example,
2.64 + //
2.65 + // ..\src\common\pcap-file-test-suite.cc (win32)
2.66 + //
2.67 + // or
2.68 + //
2.69 + // ../src/common/pcap-file-test-suite.cc (grown-up systems)
2.70 + //
2.71 +#ifdef WIN32
2.72 + std::string::size_type relPathBegin = file.find_first_of ("\\");
2.73 + std::string::size_type relPathEnd = file.find_last_of ("\\");
2.74 +#else
2.75 std::string::size_type relPathBegin = file.find_first_of ("/");
2.76 - NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
2.77 std::string::size_type relPathEnd = file.find_last_of ("/");
2.78 - NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSrouceDir(): Internal Error");
2.79 +#endif
2.80 +
2.81 + NS_ABORT_MSG_IF (relPathBegin == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
2.82 + NS_ABORT_MSG_IF (relPathEnd == std::string::npos, "TestCase::GetSourceDir(): Internal Error");
2.83
2.84 return GetBaseDir () + file.substr (relPathBegin, relPathEnd + 1 - relPathBegin);
2.85 }
2.86 @@ -353,6 +404,7 @@
2.87 : m_name (name),
2.88 m_verbose (false),
2.89 m_basedir ("invalid"),
2.90 + m_tempdir ("invalid"),
2.91 m_ofs (0),
2.92 m_error (false),
2.93 m_type (type)
2.94 @@ -476,7 +528,18 @@
2.95 void
2.96 TestSuite::SetBaseDir (std::string basedir)
2.97 {
2.98 - m_basedir = basedir;
2.99 + //
2.100 + // C and C++ allow one to use forward slashes even on systems where the
2.101 + // separator is actually a backslash.
2.102 + //
2.103 + if (basedir[basedir.length () - 1] != '/')
2.104 + {
2.105 + m_basedir = basedir + "/";
2.106 + }
2.107 + else
2.108 + {
2.109 + m_basedir = basedir;
2.110 + }
2.111 }
2.112
2.113 std::string
2.114 @@ -486,6 +549,29 @@
2.115 }
2.116
2.117 void
2.118 +TestSuite::SetTempDir (std::string tempdir)
2.119 +{
2.120 + //
2.121 + // C and C++ allow one to use forward slashes even on systems where the
2.122 + // separator is actually a backslash.
2.123 + //
2.124 + if (tempdir[tempdir.length () - 1] != '/')
2.125 + {
2.126 + m_tempdir = tempdir + "/";
2.127 + }
2.128 + else
2.129 + {
2.130 + m_tempdir = tempdir;
2.131 + }
2.132 +}
2.133 +
2.134 +std::string
2.135 +TestSuite::GetTempDir (void)
2.136 +{
2.137 + return m_tempdir;
2.138 +}
2.139 +
2.140 +void
2.141 TestSuite::SetStream (std::ofstream *ofs)
2.142 {
2.143 m_ofs = ofs;
2.144 @@ -589,6 +675,7 @@
2.145 (*i)->SetVerbose (m_verbose);
2.146 (*i)->SetContinueOnFailure (m_continueOnFailure);
2.147 (*i)->SetBaseDir (m_basedir);
2.148 + (*i)->SetTempDir (m_tempdir);
2.149 (*i)->SetStream (m_ofs);
2.150
2.151 //
3.1 --- a/src/core/test.h Fri Nov 06 11:27:04 2009 +0100
3.2 +++ b/src/core/test.h Fri Nov 06 11:27:17 2009 +0100
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 Fri Nov 06 11:27:04 2009 +0100
4.2 +++ b/test.py Fri Nov 06 11:27:17 2009 +0100
4.3 @@ -132,6 +132,7 @@
4.4 ("tutorial/second", "True", "True"),
4.5 ("tutorial/third", "True", "True"),
4.6 ("tutorial/fourth", "True", "True"),
4.7 + ("tutorial/fifth", "True", "True"),
4.8
4.9 ("udp/udp-echo", "True", "True"),
4.10
4.11 @@ -616,6 +617,7 @@
4.12 self.shell_command = ""
4.13 self.display_name = ""
4.14 self.basedir = ""
4.15 + self.tempdir = ""
4.16 self.cwd = ""
4.17 self.tmp_file_name = ""
4.18 self.returncode = False
4.19 @@ -674,6 +676,13 @@
4.20 self.basedir = basedir
4.21
4.22 #
4.23 + # This is the directory to which a running test suite should write any
4.24 + # temporary files.
4.25 + #
4.26 + def set_tempdir(self, tempdir):
4.27 + self.tempdir = tempdir
4.28 +
4.29 + #
4.30 # This is the current working directory that will be given to an executing
4.31 # test as it is being run. It will be used for examples to tell them where
4.32 # to write all of the pcap files that we will be carefully ignoring. For
4.33 @@ -766,7 +775,8 @@
4.34 # file name
4.35 #
4.36 (job.returncode, standard_out, standard_err, et) = run_job_synchronously(job.shell_command +
4.37 - " --basedir=%s --out=%s" % (job.basedir, job.tmp_file_name), job.cwd, options.valgrind)
4.38 + " --basedir=%s --tempdir=%s --out=%s" % (job.basedir, job.tempdir, job.tmp_file_name),
4.39 + job.cwd, options.valgrind)
4.40
4.41 job.set_elapsed_time(et)
4.42
4.43 @@ -1004,6 +1014,7 @@
4.44 job.set_tmp_file_name(os.path.join(testpy_output_dir, "%s.xml" % test))
4.45 job.set_cwd(os.getcwd())
4.46 job.set_basedir(os.getcwd())
4.47 + job.set_tempdir(testpy_output_dir)
4.48 if (options.multiple):
4.49 multiple = " --multiple"
4.50 else:
4.51 @@ -1074,6 +1085,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" % test)
4.57
4.58 if options.valgrind and not eval(do_valgrind_run):
4.59 @@ -1097,6 +1109,7 @@
4.60 job.set_tmp_file_name("")
4.61 job.set_cwd(testpy_output_dir)
4.62 job.set_basedir(os.getcwd())
4.63 + job.set_tempdir(testpy_output_dir)
4.64 job.set_shell_command("examples/%s" % options.example)
4.65
4.66 if options.verbose:
5.1 --- a/utils/test-runner.cc Fri Nov 06 11:27:04 2009 +0100
5.2 +++ b/utils/test-runner.cc Fri Nov 06 11:27:17 2009 +0100
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);