[libcamera-devel,9/9] test: timer: Test start() with absolute deadline

Message ID 20191006053226.8976-10-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Timer fixes and enhancements
Related show

Commit Message

Laurent Pinchart Oct. 6, 2019, 5:32 a.m. UTC
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 test/timer.cpp | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Jacopo Mondi Oct. 6, 2019, 7:37 p.m. UTC | #1
Hi Laurent,

On Sun, Oct 06, 2019 at 08:32:26AM +0300, Laurent Pinchart wrote:
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
>  test/timer.cpp | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
>
> diff --git a/test/timer.cpp b/test/timer.cpp
> index 5ff94dbbdeb0..93ce26a0a9a3 100644
> --- a/test/timer.cpp
> +++ b/test/timer.cpp
> @@ -35,6 +35,15 @@ public:
>  		Timer::start(msec);
>  	}
>
> +	void start(std::chrono::steady_clock::time_point deadline)
> +	{
> +		count_ = 0;
> +		start_ = std::chrono::steady_clock::now();
> +		expiration_ = std::chrono::steady_clock::time_point();
> +
> +		Timer::start(deadline);
> +	}
> +
>  	int jitter()
>  	{
>  		std::chrono::steady_clock::duration duration = expiration_ - deadline();
> @@ -127,6 +136,16 @@ protected:
>  			return TestFail;
>  		}
>
> +		/* Timer with absolute deadline. */
> +		timer.start(std::chrono::steady_clock::now() + std::chrono::milliseconds(200));
> +
> +		dispatcher->processEvents();
> +
> +		if (timer.isRunning() || timer.jitter() > 50) {
> +			cout << "Absolute timer test failed" << endl;

"Absolute timer" sounds funny.

Otherwise
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>

Thanks
  j

> +			return TestFail;
> +		}
> +
>  		/* Two timers. */
>  		timer.start(1000);
>  		timer2.start(300);
> --
> Regards,
>
> Laurent Pinchart
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
Laurent Pinchart Oct. 7, 2019, 3:20 a.m. UTC | #2
Hi Jacopo,

On Sun, Oct 06, 2019 at 09:37:28PM +0200, Jacopo Mondi wrote:
> On Sun, Oct 06, 2019 at 08:32:26AM +0300, Laurent Pinchart wrote:
> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> > ---
> >  test/timer.cpp | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> >
> > diff --git a/test/timer.cpp b/test/timer.cpp
> > index 5ff94dbbdeb0..93ce26a0a9a3 100644
> > --- a/test/timer.cpp
> > +++ b/test/timer.cpp
> > @@ -35,6 +35,15 @@ public:
> >  		Timer::start(msec);
> >  	}
> >
> > +	void start(std::chrono::steady_clock::time_point deadline)
> > +	{
> > +		count_ = 0;
> > +		start_ = std::chrono::steady_clock::now();
> > +		expiration_ = std::chrono::steady_clock::time_point();
> > +
> > +		Timer::start(deadline);
> > +	}
> > +
> >  	int jitter()
> >  	{
> >  		std::chrono::steady_clock::duration duration = expiration_ - deadline();
> > @@ -127,6 +136,16 @@ protected:
> >  			return TestFail;
> >  		}
> >
> > +		/* Timer with absolute deadline. */
> > +		timer.start(std::chrono::steady_clock::now() + std::chrono::milliseconds(200));
> > +
> > +		dispatcher->processEvents();
> > +
> > +		if (timer.isRunning() || timer.jitter() > 50) {
> > +			cout << "Absolute timer test failed" << endl;
> 
> "Absolute timer" sounds funny.

I'll rename that to "Absolute deadline".

> Otherwise
> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
> 
> > +			return TestFail;
> > +		}
> > +
> >  		/* Two timers. */
> >  		timer.start(1000);
> >  		timer2.start(300);

Patch

diff --git a/test/timer.cpp b/test/timer.cpp
index 5ff94dbbdeb0..93ce26a0a9a3 100644
--- a/test/timer.cpp
+++ b/test/timer.cpp
@@ -35,6 +35,15 @@  public:
 		Timer::start(msec);
 	}
 
+	void start(std::chrono::steady_clock::time_point deadline)
+	{
+		count_ = 0;
+		start_ = std::chrono::steady_clock::now();
+		expiration_ = std::chrono::steady_clock::time_point();
+
+		Timer::start(deadline);
+	}
+
 	int jitter()
 	{
 		std::chrono::steady_clock::duration duration = expiration_ - deadline();
@@ -127,6 +136,16 @@  protected:
 			return TestFail;
 		}
 
+		/* Timer with absolute deadline. */
+		timer.start(std::chrono::steady_clock::now() + std::chrono::milliseconds(200));
+
+		dispatcher->processEvents();
+
+		if (timer.isRunning() || timer.jitter() > 50) {
+			cout << "Absolute timer test failed" << endl;
+			return TestFail;
+		}
+
 		/* Two timers. */
 		timer.start(1000);
 		timer2.start(300);