[{"id":2800,"web_url":"https://patchwork.libcamera.org/comment/2800/","msgid":"<20191006182821.wte3ilgxofog2mj6@uno.localdomain>","date":"2019-10-06T18:28:21","subject":"Re: [libcamera-devel] [PATCH 4/9] test: timer: Test that a timer\n\tcan be restarted before it expires","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Sun, Oct 06, 2019 at 08:32:21AM +0300, Laurent Pinchart wrote:\n> The Timer API allows restarting a timer before it expires. Add a\n> corresponding test. The test fails as the Timer class doesn't comply\n> with its API documentation.\n>\n[5/9] has subject:\nlibcamera: timer: Allow restarting a timer before expiration\n\nShouldn't this be moved before this test?\n\nThanks\n  j\n\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  test/timer.cpp | 28 ++++++++++++++++++++++++----\n>  1 file changed, 24 insertions(+), 4 deletions(-)\n>\n> diff --git a/test/timer.cpp b/test/timer.cpp\n> index d4f16a9bdd97..5ff94dbbdeb0 100644\n> --- a/test/timer.cpp\n> +++ b/test/timer.cpp\n> @@ -21,13 +21,14 @@ class ManagedTimer : public Timer\n>  {\n>  public:\n>  \tManagedTimer()\n> -\t\t: Timer()\n> +\t\t: Timer(), count_(0)\n>  \t{\n>  \t\ttimeout.connect(this, &ManagedTimer::timeoutHandler);\n>  \t}\n>\n>  \tvoid start(int msec)\n>  \t{\n> +\t\tcount_ = 0;\n>  \t\tstart_ = std::chrono::steady_clock::now();\n>  \t\texpiration_ = std::chrono::steady_clock::time_point();\n>\n> @@ -40,12 +41,19 @@ public:\n>  \t\treturn abs(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());\n>  \t}\n>\n> +\tbool hasFailed()\n> +\t{\n> +\t\treturn isRunning() || count_ != 1 || jitter() > 50;\n> +\t}\n> +\n>  private:\n>  \tvoid timeoutHandler(Timer *timer)\n>  \t{\n>  \t\texpiration_ = std::chrono::steady_clock::now();\n> +\t\tcount_++;\n>  \t}\n>\n> +\tunsigned int count_;\n>  \tstd::chrono::steady_clock::time_point start_;\n>  \tstd::chrono::steady_clock::time_point expiration_;\n>  };\n> @@ -74,7 +82,7 @@ protected:\n>\n>  \t\tdispatcher->processEvents();\n>\n> -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> +\t\tif (timer.hasFailed()) {\n>  \t\t\tcout << \"Timer expiration test failed\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -87,7 +95,7 @@ protected:\n>  \t\ttimer.start(4295);\n>  \t\tdispatcher->processEvents();\n>\n> -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> +\t\tif (timer.hasFailed()) {\n>  \t\t\tcout << \"Timer expiration test failed\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n> @@ -102,11 +110,23 @@ protected:\n>\n>  \t\tdispatcher->processEvents();\n>\n> -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> +\t\tif (timer.hasFailed()) {\n>  \t\t\tcout << \"Timer restart test failed\" << endl;\n>  \t\t\treturn TestFail;\n>  \t\t}\n>\n> +\t\t/* Timer restart before expiration. */\n> +\t\ttimer.start(50);\n> +\t\ttimer.start(100);\n> +\t\ttimer.start(150);\n> +\n> +\t\tdispatcher->processEvents();\n> +\n> +\t\tif (timer.hasFailed()) {\n> +\t\t\tcout << \"Timer restart before expiration test failed\" << endl;\n> +\t\t\treturn TestFail;\n> +\t\t}\n> +\n>  \t\t/* Two timers. */\n>  \t\ttimer.start(1000);\n>  \t\ttimer2.start(300);\n> --\n> Regards,\n>\n> Laurent Pinchart\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<jacopo@jmondi.org>","Received":["from relay12.mail.gandi.net (relay12.mail.gandi.net\n\t[217.70.178.232])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id ADE4E60E1E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun,  6 Oct 2019 20:26:36 +0200 (CEST)","from uno.localdomain (2-224-242-101.ip172.fastwebnet.it\n\t[2.224.242.101]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay12.mail.gandi.net (Postfix) with ESMTPSA id 38FE5200003;\n\tSun,  6 Oct 2019 18:26:36 +0000 (UTC)"],"Date":"Sun, 6 Oct 2019 20:28:21 +0200","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191006182821.wte3ilgxofog2mj6@uno.localdomain>","References":"<20191006053226.8976-1-laurent.pinchart@ideasonboard.com>\n\t<20191006053226.8976-5-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"multipart/signed; micalg=pgp-sha256;\n\tprotocol=\"application/pgp-signature\"; boundary=\"lhowhcp6ksh2o6zr\"","Content-Disposition":"inline","In-Reply-To":"<20191006053226.8976-5-laurent.pinchart@ideasonboard.com>","User-Agent":"NeoMutt/20180716","Subject":"Re: [libcamera-devel] [PATCH 4/9] test: timer: Test that a timer\n\tcan be restarted before it expires","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Sun, 06 Oct 2019 18:26:36 -0000"}},{"id":2810,"web_url":"https://patchwork.libcamera.org/comment/2810/","msgid":"<20191007025957.GH4740@pendragon.ideasonboard.com>","date":"2019-10-07T02:59:57","subject":"Re: [libcamera-devel] [PATCH 4/9] test: timer: Test that a timer\n\tcan be restarted before it expires","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Sun, Oct 06, 2019 at 08:28:21PM +0200, Jacopo Mondi wrote:\n> On Sun, Oct 06, 2019 at 08:32:21AM +0300, Laurent Pinchart wrote:\n> > The Timer API allows restarting a timer before it expires. Add a\n> > corresponding test. The test fails as the Timer class doesn't comply\n> > with its API documentation.\n> >\n> [5/9] has subject:\n> libcamera: timer: Allow restarting a timer before expiration\n> \n> Shouldn't this be moved before this test?\n\nWhen fixing a broken behaviour, I like to first have a test that fails\nto exhibit the problem, and a fix on top. This allows proving that the\nbehaviour was broken (the test fails) and that the fix fixes it (the\ntest then succeeds).\n\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  test/timer.cpp | 28 ++++++++++++++++++++++++----\n> >  1 file changed, 24 insertions(+), 4 deletions(-)\n> >\n> > diff --git a/test/timer.cpp b/test/timer.cpp\n> > index d4f16a9bdd97..5ff94dbbdeb0 100644\n> > --- a/test/timer.cpp\n> > +++ b/test/timer.cpp\n> > @@ -21,13 +21,14 @@ class ManagedTimer : public Timer\n> >  {\n> >  public:\n> >  \tManagedTimer()\n> > -\t\t: Timer()\n> > +\t\t: Timer(), count_(0)\n> >  \t{\n> >  \t\ttimeout.connect(this, &ManagedTimer::timeoutHandler);\n> >  \t}\n> >\n> >  \tvoid start(int msec)\n> >  \t{\n> > +\t\tcount_ = 0;\n> >  \t\tstart_ = std::chrono::steady_clock::now();\n> >  \t\texpiration_ = std::chrono::steady_clock::time_point();\n> >\n> > @@ -40,12 +41,19 @@ public:\n> >  \t\treturn abs(std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());\n> >  \t}\n> >\n> > +\tbool hasFailed()\n> > +\t{\n> > +\t\treturn isRunning() || count_ != 1 || jitter() > 50;\n> > +\t}\n> > +\n> >  private:\n> >  \tvoid timeoutHandler(Timer *timer)\n> >  \t{\n> >  \t\texpiration_ = std::chrono::steady_clock::now();\n> > +\t\tcount_++;\n> >  \t}\n> >\n> > +\tunsigned int count_;\n> >  \tstd::chrono::steady_clock::time_point start_;\n> >  \tstd::chrono::steady_clock::time_point expiration_;\n> >  };\n> > @@ -74,7 +82,7 @@ protected:\n> >\n> >  \t\tdispatcher->processEvents();\n> >\n> > -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> > +\t\tif (timer.hasFailed()) {\n> >  \t\t\tcout << \"Timer expiration test failed\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -87,7 +95,7 @@ protected:\n> >  \t\ttimer.start(4295);\n> >  \t\tdispatcher->processEvents();\n> >\n> > -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> > +\t\tif (timer.hasFailed()) {\n> >  \t\t\tcout << \"Timer expiration test failed\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> > @@ -102,11 +110,23 @@ protected:\n> >\n> >  \t\tdispatcher->processEvents();\n> >\n> > -\t\tif (timer.isRunning() || timer.jitter() > 50) {\n> > +\t\tif (timer.hasFailed()) {\n> >  \t\t\tcout << \"Timer restart test failed\" << endl;\n> >  \t\t\treturn TestFail;\n> >  \t\t}\n> >\n> > +\t\t/* Timer restart before expiration. */\n> > +\t\ttimer.start(50);\n> > +\t\ttimer.start(100);\n> > +\t\ttimer.start(150);\n> > +\n> > +\t\tdispatcher->processEvents();\n> > +\n> > +\t\tif (timer.hasFailed()) {\n> > +\t\t\tcout << \"Timer restart before expiration test failed\" << endl;\n> > +\t\t\treturn TestFail;\n> > +\t\t}\n> > +\n> >  \t\t/* Two timers. */\n> >  \t\ttimer.start(1000);\n> >  \t\ttimer2.start(300);","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 1E4DB6157C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Oct 2019 05:00:02 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(modemcable151.96-160-184.mc.videotron.ca [184.160.96.151])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E2294DD;\n\tMon,  7 Oct 2019 05:00:00 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1570417201;\n\tbh=fkL1wsWf9U8Uh8mp2C6A8DNJ91ZQ92HqMOp1xZUeMLU=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=IjcGYKAJ0EPRLCzLAdegvK/fzjhuuHH3oTPegMa8wfxHernZYqSNdguVraUoe200s\n\t6UFepZTcMjEVu+ZFtfDcuh6fO2cZZQFXNrn5ID82VrEgyAwD256xx4q6QDz4p1t+LH\n\tE7QTbvgHzFKe7M16mzI2Xzja12dDdeAtp8YF93Go=","Date":"Mon, 7 Oct 2019 05:59:57 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191007025957.GH4740@pendragon.ideasonboard.com>","References":"<20191006053226.8976-1-laurent.pinchart@ideasonboard.com>\n\t<20191006053226.8976-5-laurent.pinchart@ideasonboard.com>\n\t<20191006182821.wte3ilgxofog2mj6@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20191006182821.wte3ilgxofog2mj6@uno.localdomain>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/9] test: timer: Test that a timer\n\tcan be restarted before it expires","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Mon, 07 Oct 2019 03:00:02 -0000"}}]