Skip to content

Initial port of UnitTest++ to VxWorks 5.5. #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.a
*.lo
*.la
*.out

# Visual Studio temp/user files
*.user
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ UnitTest++ is a lightweight unit testing framework for C++. It was designed to d
* Windows
* Linux
* Mac OS X
* VxWorks 5.5

Documentation
--------------
Expand Down
4 changes: 4 additions & 0 deletions UnitTest++/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#define UNITTEST_POSIX
#endif

#if defined (_WRS_VXWORKS_5_X)
#define UNITTEST_VXWORKS
#endif

#if defined(__MINGW32__)
#define UNITTEST_MINGW
#endif
Expand Down
6 changes: 5 additions & 1 deletion UnitTest++/TimeHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
#if defined UNITTEST_POSIX
#include "Posix/TimeHelpers.h"
#else
#include "Win32/TimeHelpers.h"
#if defined UNITTEST_VXWORKS
#include "VxWorks/TimeHelpers.h"
#else
#include "Win32/TimeHelpers.h"
#endif
#endif
36 changes: 36 additions & 0 deletions UnitTest++/VxWorks/TimeHelpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "TimeHelpers.h"

namespace UnitTest {

Timer::Timer()
{
m_startTime.tv_sec = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer initializing members in the constructor initializer list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that can be done but I just implemented it in the same way as done in the Posix version of TimeHelpers.cpp.

m_startTime.tv_nsec = 0;
}

void Timer::Start()
{
clock_gettime(CLOCK_REALTIME, &m_startTime);
}

double Timer::GetTimeInMs() const
{
struct timespec currentTime;
clock_gettime(CLOCK_REALTIME, &currentTime);

double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
double const dns = currentTime.tv_nsec - m_startTime.tv_nsec;

return (dsecs * 1000.0) + (dns / 1000000.0);
}

void TimeHelpers::SleepMs(int ms)
{
struct timespec sleepTime;
sleepTime.tv_sec = 0;
sleepTime.tv_nsec = ms * 1000000;

nanosleep(&sleepTime, NULL);
}

}
28 changes: 28 additions & 0 deletions UnitTest++/VxWorks/TimeHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef UNITTEST_TIMEHELPERS_H
#define UNITTEST_TIMEHELPERS_H

#include <timers.h>

namespace UnitTest {

class Timer
{
public:
Timer();
void Start();
double GetTimeInMs() const;

private:
struct timespec m_startTime;
};


namespace TimeHelpers
{
void SleepMs(int ms);
}


}

#endif
12 changes: 6 additions & 6 deletions tests/TestDeferredTestReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace UnitTest
{
reporter.ReportTestStart(details);

DeferredTestResult const& result = reporter.GetResults().at(0);
DeferredTestResult const& result = reporter.GetResults()[0];
Copy link
Member

@pjohnmeyer pjohnmeyer Aug 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to lose the bounds-checking behavior of .at in these tests. If this is truly necessary, then we may need another way.

Copy link
Author

@sulemankm sulemankm Aug 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The STL version in VxWorks doesn't implement the .at() method. That's why I had to modify the this test file. You may suggest a better way of handling this problem, if possible.

CHECK_EQUAL(testName.c_str(), result.testName.c_str());
CHECK_EQUAL(testSuite.c_str(), result.suiteName.c_str());
}
Expand All @@ -65,7 +65,7 @@ namespace UnitTest
reporter.ReportTestStart(details);
reporter.ReportTestFinish(details, elapsed);

DeferredTestResult const& result = reporter.GetResults().at(0);
DeferredTestResult const& result = reporter.GetResults()[0];
CHECK_CLOSE(elapsed, result.timeElapsed, 0.0001f);
}

Expand All @@ -76,7 +76,7 @@ namespace UnitTest
reporter.ReportTestStart(details);
reporter.ReportFailure(details, failure);

DeferredTestResult const& result = reporter.GetResults().at(0);
DeferredTestResult const& result = reporter.GetResults()[0];
CHECK(result.failed == true);
CHECK_EQUAL(fileName.c_str(), result.failureFile.c_str());
}
Expand All @@ -90,7 +90,7 @@ namespace UnitTest
reporter.ReportFailure(details, failure1);
reporter.ReportFailure(details, failure2);

DeferredTestResult const& result = reporter.GetResults().at(0);
DeferredTestResult const& result = reporter.GetResults()[0];
CHECK_EQUAL(2, (int)result.failures.size());
CHECK_EQUAL(failure1, result.failures[0].failureStr);
CHECK_EQUAL(failure2, result.failures[1].failureStr);
Expand All @@ -110,8 +110,8 @@ namespace UnitTest
reporter.ReportFailure(details, failureMessage);
strcpy(failureMessage, badStr);

DeferredTestResult const& result = reporter.GetResults().at(0);
DeferredTestFailure const& failure = result.failures.at(0);
DeferredTestResult const& result = reporter.GetResults()[0];
DeferredTestFailure const& failure = result.failures[0];
CHECK_EQUAL(goodStr, failure.failureStr);
}

Expand Down
15 changes: 15 additions & 0 deletions vxworks/utppvxw.wsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Document file - DO NOT EDIT

<BEGIN> CORE_INFO_TYPE
Workspace
<END>

<BEGIN> CORE_INFO_VERSION
2.2
<END>

<BEGIN> projectList
$(PRJ_DIR)/utppvxwlib/utppvxwlib.wpj \
$(PRJ_DIR)/utppvxwtests/utppvxwtests.wpj
<END>

21 changes: 21 additions & 0 deletions vxworks/utppvxwlib/prjObjs.lst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
AssertException.o
Checks.o
CompositeTestReporter.o
CurrentTest.o
DeferredTestResult.o
MemoryOutStream.o
ReportAssert.o
RequiredCheckException.o
RequiredCheckTestReporter.o
Test.o
TestDetails.o
TestList.o
TestReporter.o
TestReporterStdout.o
TestResults.o
TestRunner.o
ThrowingTestReporter.o
TimeConstraint.o
XmlTestReporter.o
TimeHelpers.o
DeferredTestReporter.o
Loading