mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-27 05:55:02 +03:00
ee5174de58
The accuracy of getrusage() is limited by the resolution of software clock as described in http://www.kernel.org/doc/man-pages/online/pages/man7/time.7.html The assertions required a timer with microsecond accuracy. However, we don't necessarily want the timer, and we don't want to add some time-consuming processes to the test code because we normally build programs again and again, which means we want to run unit tests as quickly as possible.
28 lines
785 B
C++
28 lines
785 B
C++
#include "Timer.h"
|
|
|
|
#define BOOST_TEST_MODULE TimerTest
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <string>
|
|
#include <unistd.h>
|
|
|
|
BOOST_AUTO_TEST_CASE(timer_basic_test) {
|
|
Timer timer;
|
|
const int sleep_time_microsec = 40; // ad-hoc microseconds to pass unit tests.
|
|
|
|
timer.start();
|
|
BOOST_REQUIRE(timer.is_running());
|
|
BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
|
|
BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
|
|
BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
|
|
|
|
timer.restart();
|
|
BOOST_REQUIRE(timer.is_running());
|
|
BOOST_REQUIRE(usleep(sleep_time_microsec) == 0);
|
|
BOOST_CHECK(timer.get_elapsed_wall_time() > 0.0);
|
|
BOOST_CHECK(timer.get_elapsed_wall_time_microseconds() > 0);
|
|
|
|
const std::string s = timer.ToString();
|
|
BOOST_CHECK(!s.empty());
|
|
}
|