Boost logo

Boost Users :

Subject: Re: [Boost-users] [test]
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-03-23 12:27:29


AMDG

On 03/22/2011 11:52 PM, Stirling Westrup wrote:
> I have been using Boost.test to run some simple unit tests as I build
> my code. I've come across a case where I need to test if my code runs
> within an acceptable time limit. I know that the execution monitor has
> a timeout system for testing that sort of thing, but I can't figure
> out how it is supposed to be integrated into the unit test framework.

Well, you can just use boost::execution_monitor.
There's nothing incompatible between it and the
Unit Test Framework.

Unfortunately, as the documentation notes:

unit_test::readwrite_property<int> p_timeout; //
        Specifies the seconds that elapse before a timer_error occurs.
May be ignored on some platforms.

I tried the following on both Linux and Windows,
and it didn't work on Windows.

#include <boost/test/included/execution_monitor.hpp>

#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>

int f()
{
     for(;;);
}

BOOST_AUTO_TEST_CASE(test_timeout) {
     boost::execution_monitor monitor;
     monitor.p_timeout.set(5);
     monitor.execute(&f);
}

> Ideally, I'd love to just have a BOOST_CHECK_TIMED( f(), timeout) that
> I could invoke to ensure that the code returns true, and returns
> within the specified timeout interval.

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net