Make tests work with MinGW (make win32-system-wall-clock-ms work)
This commit is contained in:
@@ -25,6 +25,9 @@ namespace ns3 {
|
||||
|
||||
/**
|
||||
* \brief measure wall-clock time in milliseconds
|
||||
|
||||
* \todo This class exists also in non-unix systems but is not
|
||||
* implemented and always return zero as measurd time.
|
||||
*/
|
||||
class SystemWallClockMs {
|
||||
public:
|
||||
@@ -36,13 +39,31 @@ public:
|
||||
*/
|
||||
void Start (void);
|
||||
/**
|
||||
* \returns the measured elapsed wall clock time since
|
||||
* ns3::SystemWallClockMs::start was invoked.
|
||||
* \brief Stop measuring the time since Start() was called.
|
||||
* \returns the measured elapsed wall clock time (in milliseconds) since
|
||||
* ns3::SystemWallClockMs::Start was invoked.
|
||||
*
|
||||
* It is possible to start a new measurement with ns3::SystemWallClockMs::start
|
||||
* It is possible to start a new measurement with ns3::SystemWallClockMs::Start
|
||||
* after this method returns.
|
||||
*/
|
||||
unsigned long long End (void);
|
||||
|
||||
/**
|
||||
* \returns the measured elapsed wall clock time (in milliseconds) since
|
||||
* ns3::SystemWallClockMs::Start was invoked.
|
||||
*/
|
||||
double GetElapsedReal (void) const;
|
||||
/**
|
||||
* \returns the measured elapsed 'user' wall clock time (in milliseconds) since
|
||||
* ns3::SystemWallClockMs::Start was invoked.
|
||||
*/
|
||||
double GetElapsedUser (void) const;
|
||||
/**
|
||||
* \returns the measured elapsed 'system' wall clock time (in milliseconds) since
|
||||
* ns3::SystemWallClockMs::Start was invoked.
|
||||
*/
|
||||
double GetElapsedSystem (void) const;
|
||||
|
||||
private:
|
||||
class SystemWallClockMsPrivate *m_priv;
|
||||
};
|
||||
|
||||
@@ -262,7 +262,7 @@ TestCase::ContinueOnFailure (void)
|
||||
void
|
||||
TestCase::DoReportStart (void)
|
||||
{
|
||||
m_startTime = times (&m_startTimes);
|
||||
m_clock.Start ();
|
||||
|
||||
if (m_ofs == 0)
|
||||
{
|
||||
@@ -319,26 +319,18 @@ TestCase::DoReportTestFailure (
|
||||
void
|
||||
TestCase::DoReportEnd (void)
|
||||
{
|
||||
static long ticksPerSecond = sysconf (_SC_CLK_TCK);
|
||||
|
||||
m_clock.End ();
|
||||
if (m_ofs == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct tms endTimes;
|
||||
clock_t endTime = times (&endTimes);
|
||||
|
||||
clock_t elapsed = endTime - m_startTime;
|
||||
clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
|
||||
clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
|
||||
|
||||
(*m_ofs).precision (2);
|
||||
*m_ofs << std::fixed;
|
||||
|
||||
*m_ofs << " <CaseTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
|
||||
<< " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
|
||||
<< " system " << static_cast<double> (elapsedSys) / ticksPerSecond
|
||||
*m_ofs << " <CaseTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
|
||||
<< " user " << m_clock.GetElapsedUser () * 1e-3
|
||||
<< " system " << m_clock.GetElapsedSystem () * 1e-3
|
||||
<< "</CaseTime>" << std::endl;
|
||||
|
||||
*m_ofs << " </TestCase>" << std::endl;
|
||||
@@ -523,8 +515,8 @@ TestSuite::ContinueOnFailure (void)
|
||||
void
|
||||
TestSuite::DoReportStart (void)
|
||||
{
|
||||
m_startTime = times (&m_startTimes);
|
||||
|
||||
m_clock.Start ();
|
||||
|
||||
if (m_ofs == 0)
|
||||
{
|
||||
return;
|
||||
@@ -556,25 +548,19 @@ TestSuite::DoReportSuccess (void)
|
||||
void
|
||||
TestSuite::DoReportEnd (void)
|
||||
{
|
||||
static long ticksPerSecond = sysconf (_SC_CLK_TCK);
|
||||
|
||||
m_clock.End ();
|
||||
|
||||
if (m_ofs == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
struct tms endTimes;
|
||||
clock_t endTime = times (&endTimes);
|
||||
|
||||
clock_t elapsed = endTime - m_startTime;
|
||||
clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
|
||||
clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
|
||||
|
||||
(*m_ofs).precision (2);
|
||||
*m_ofs << std::fixed;
|
||||
|
||||
*m_ofs << " <SuiteTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
|
||||
<< " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
|
||||
<< " system " << static_cast<double> (elapsedSys) / ticksPerSecond
|
||||
*m_ofs << " <SuiteTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
|
||||
<< " user " << m_clock.GetElapsedUser () * 1e-3
|
||||
<< " system " << m_clock.GetElapsedSystem () * 1e-3
|
||||
<< "</SuiteTime>" << std::endl;
|
||||
|
||||
*m_ofs << "</TestSuite>" << std::endl;
|
||||
|
||||
@@ -27,7 +27,10 @@
|
||||
#include <list>
|
||||
#include <limits>
|
||||
#include <stdint.h>
|
||||
#include <sys/times.h>
|
||||
|
||||
#include "ns3/system-wall-clock-ms.h"
|
||||
|
||||
|
||||
//
|
||||
// Note on below macros:
|
||||
//
|
||||
@@ -821,6 +824,7 @@ private:
|
||||
TestCase (TestCase& tc);
|
||||
TestCase& operator= (TestCase& tc);
|
||||
|
||||
SystemWallClockMs m_clock;
|
||||
std::string m_name;
|
||||
bool m_verbose;
|
||||
bool m_continueOnFailure;
|
||||
@@ -828,8 +832,6 @@ private:
|
||||
std::string m_basedir;
|
||||
std::ofstream *m_ofs;
|
||||
bool m_error;
|
||||
clock_t m_startTime;
|
||||
struct tms m_startTimes;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1057,6 +1059,7 @@ private:
|
||||
TestSuite (TestSuite& ts);
|
||||
TestSuite& operator= (TestSuite& ts);
|
||||
|
||||
SystemWallClockMs m_clock;
|
||||
std::string m_name;
|
||||
bool m_verbose;
|
||||
bool m_continueOnFailure;
|
||||
@@ -1064,10 +1067,7 @@ private:
|
||||
std::ofstream *m_ofs;
|
||||
bool m_error;
|
||||
TestType m_type;
|
||||
|
||||
clock_t m_startTime;
|
||||
struct tms m_startTimes;
|
||||
|
||||
|
||||
typedef std::vector<TestCase *> TestCaseVector_t;
|
||||
TestCaseVector_t m_tests;
|
||||
};
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
*/
|
||||
|
||||
#include "system-wall-clock-ms.h"
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -27,28 +29,57 @@ class SystemWallClockMsPrivate {
|
||||
public:
|
||||
void Start (void);
|
||||
unsigned long long End (void);
|
||||
double GetElapsedReal (void) const;
|
||||
double GetElapsedUser (void) const;
|
||||
double GetElapsedSystem (void) const;
|
||||
|
||||
private:
|
||||
struct timeval m_startTv;
|
||||
struct timeval m_endTv;
|
||||
struct tms m_startTimes;
|
||||
clock_t m_startTime;
|
||||
double m_elapsedReal;
|
||||
double m_elapsedUser;
|
||||
double m_elapsedSystem;
|
||||
};
|
||||
|
||||
void
|
||||
SystemWallClockMsPrivate::Start (void)
|
||||
{
|
||||
struct timezone tz;
|
||||
gettimeofday (&m_startTv, &tz);
|
||||
m_startTime = times (&m_startTimes);
|
||||
}
|
||||
|
||||
unsigned long long
|
||||
SystemWallClockMsPrivate::End (void)
|
||||
{
|
||||
struct timezone tz;
|
||||
gettimeofday (&m_endTv, &tz);
|
||||
unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
|
||||
unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
|
||||
return end - start;
|
||||
static long ticksPerSecond = sysconf (_SC_CLK_TCK);
|
||||
|
||||
struct tms endTimes;
|
||||
clock_t endTime = times (&endTimes);
|
||||
|
||||
m_elapsedReal = 1e3 * static_cast<double> (endTime - m_startTime) / ticksPerSecond;
|
||||
m_elapsedUser = 1e3 * static_cast<double> (endTimes.tms_utime - m_startTimes.tms_utime) / ticksPerSecond;
|
||||
m_elapsedSystem = 1e3 * static_cast<double> (endTimes.tms_stime - m_startTimes.tms_stime) / ticksPerSecond;
|
||||
|
||||
return m_elapsedReal;
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMsPrivate::GetElapsedReal (void) const
|
||||
{
|
||||
return m_elapsedReal;
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMsPrivate::GetElapsedUser (void) const
|
||||
{
|
||||
return m_elapsedUser;
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMsPrivate::GetElapsedSystem (void) const
|
||||
{
|
||||
return m_elapsedSystem;
|
||||
}
|
||||
|
||||
SystemWallClockMs::SystemWallClockMs ()
|
||||
: m_priv (new SystemWallClockMsPrivate ())
|
||||
{}
|
||||
@@ -70,4 +101,22 @@ SystemWallClockMs::End (void)
|
||||
return m_priv->End ();
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedReal (void) const
|
||||
{
|
||||
return m_priv->GetElapsedReal ();
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedUser (void) const
|
||||
{
|
||||
return m_priv->GetElapsedUser ();
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedSystem (void) const
|
||||
{
|
||||
return m_priv->GetElapsedSystem ();
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -61,4 +61,22 @@ SystemWallClockMs::End (void)
|
||||
return m_priv->End ();
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedReal (void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedUser (void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
double
|
||||
SystemWallClockMs::GetElapsedSystem (void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user