|
Boost Users : |
Subject: Re: [Boost-users] [test]
From: Stirling Westrup (swestrup_at_[hidden])
Date: 2011-03-23 16:19:28
On Wed, Mar 23, 2011 at 12:27 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
> 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.
>
Thanks! Your example is simple enough that I can see how to work it
into my unit tests. Luckily I'm benchmarking my code under Linux, so I
don't have to worry about other platforms when it comes to these
tests.
-- Stirling Westrup Programmer, Entrepreneur. https://www.linkedin.com/e/fpf/77228 http://www.linkedin.com/in/swestrup http://technaut.livejournal.com http://sourceforge.net/users/stirlingwestrup
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