diff mbox

[i-g-t,v3] tests/kms_flip: Adjust tolerance when counting frames

Message ID 1463139909-12826-1-git-send-email-gabriel.feceoru@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Feceoru, Gabriel May 13, 2016, 11:45 a.m. UTC
basic-flip-vs-wf_vblank subtest sometimes fails asserting counted frames to
be aproximately equal with the estimated number.

This is a false negative, one of the reasons being the precision lost when
truncating a fractional number.

Fixed this by using floating point arithmetic.

Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Gabriel Feceoru <gabriel.feceoru@intel.com>
---
 tests/kms_flip.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Chris Wilson May 13, 2016, noon UTC | #1
On Fri, May 13, 2016 at 02:45:09PM +0300, Gabriel Feceoru wrote:
> basic-flip-vs-wf_vblank subtest sometimes fails asserting counted frames to
> be aproximately equal with the estimated number.
> 
> This is a false negative, one of the reasons being the precision lost when
> truncating a fractional number.
> 
> Fixed this by using floating point arithmetic.
> 
> Cc: Jani Nikula <jani.nikula@intel.com>
> Cc: Daniel Vetter <daniel.vetter@intel.com>
> Signed-off-by: Gabriel Feceoru <gabriel.feceoru@intel.com>
> ---
>  tests/kms_flip.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> index eda2fcc..6ec97d0 100644
> --- a/tests/kms_flip.c
> +++ b/tests/kms_flip.c
> @@ -1182,13 +1182,13 @@ static void check_final_state(struct test_output *o, struct event_state *es,
>  	/* Verify we drop no frames, but only if it's not a TV encoder, since
>  	 * those use some funny fake timings behind userspace's back. */
>  	if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
> -		int expected;
> +		double expected;
>  		int count = es->count;
>  
>  		count *= o->seq_step;
> -		expected = elapsed / frame_time(o);

int expected = count * frame_time(o);
igt_assert_f(100 * expected >= elasped * 99 && 100 * count <= expected * 101,
	     "dropped frames, expected %d, counted %d, encoder type %d\n",
	     elapsed / frame_time(o), count, o->kencoder[0]->encoder_type);

if I understood your concern correctly, as the only loss of precison
there would be from calculating 'expected'.
-Chris
Chris Wilson May 13, 2016, 12:04 p.m. UTC | #2
On Fri, May 13, 2016 at 01:00:33PM +0100, Chris Wilson wrote:
> On Fri, May 13, 2016 at 02:45:09PM +0300, Gabriel Feceoru wrote:
> > basic-flip-vs-wf_vblank subtest sometimes fails asserting counted frames to
> > be aproximately equal with the estimated number.
> > 
> > This is a false negative, one of the reasons being the precision lost when
> > truncating a fractional number.
> > 
> > Fixed this by using floating point arithmetic.
> > 
> > Cc: Jani Nikula <jani.nikula@intel.com>
> > Cc: Daniel Vetter <daniel.vetter@intel.com>
> > Signed-off-by: Gabriel Feceoru <gabriel.feceoru@intel.com>
> > ---
> >  tests/kms_flip.c | 8 ++++----
> >  1 file changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/tests/kms_flip.c b/tests/kms_flip.c
> > index eda2fcc..6ec97d0 100644
> > --- a/tests/kms_flip.c
> > +++ b/tests/kms_flip.c
> > @@ -1182,13 +1182,13 @@ static void check_final_state(struct test_output *o, struct event_state *es,
> >  	/* Verify we drop no frames, but only if it's not a TV encoder, since
> >  	 * those use some funny fake timings behind userspace's back. */
> >  	if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
> > -		int expected;
> > +		double expected;
> >  		int count = es->count;
> >  
> >  		count *= o->seq_step;
> > -		expected = elapsed / frame_time(o);
> 
> int expected = count * frame_time(o);
> igt_assert_f(100 * expected >= elasped * 99 && 100 * count <= expected * 101,

igt_assert_f(100 * expected >= elasped * 99 && 100 * expected <= elasped * 101,
-Chris
Feceoru, Gabriel May 13, 2016, 12:54 p.m. UTC | #3
On 13.05.2016 15:00, Chris Wilson wrote:
> On Fri, May 13, 2016 at 02:45:09PM +0300, Gabriel Feceoru wrote:
>> basic-flip-vs-wf_vblank subtest sometimes fails asserting counted frames to
>> be aproximately equal with the estimated number.
>>
>> This is a false negative, one of the reasons being the precision lost when
>> truncating a fractional number.
>>
>> Fixed this by using floating point arithmetic.
>>
>> Cc: Jani Nikula <jani.nikula@intel.com>
>> Cc: Daniel Vetter <daniel.vetter@intel.com>
>> Signed-off-by: Gabriel Feceoru <gabriel.feceoru@intel.com>
>> ---
>>   tests/kms_flip.c | 8 ++++----
>>   1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/tests/kms_flip.c b/tests/kms_flip.c
>> index eda2fcc..6ec97d0 100644
>> --- a/tests/kms_flip.c
>> +++ b/tests/kms_flip.c
>> @@ -1182,13 +1182,13 @@ static void check_final_state(struct test_output *o, struct event_state *es,
>>   	/* Verify we drop no frames, but only if it's not a TV encoder, since
>>   	 * those use some funny fake timings behind userspace's back. */
>>   	if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
>> -		int expected;
>> +		double expected;
>>   		int count = es->count;
>>
>>   		count *= o->seq_step;
>> -		expected = elapsed / frame_time(o);
>
> int expected = count * frame_time(o);
> igt_assert_f(100 * expected >= elasped * 99 && 100 * count <= expected * 101,
> 	     "dropped frames, expected %d, counted %d, encoder type %d\n",
> 	     elapsed / frame_time(o), count, o->kencoder[0]->encoder_type);
>
> if I understood your concern correctly, as the only loss of precison
> there would be from calculating 'expected'.

That would also do it, but with care where to use the cast:

int expected =  (int)((double)count * frame_time(o));
vs
int expected = count * (int)frame_time(o);

Gabriel.

> -Chris
>
diff mbox

Patch

diff --git a/tests/kms_flip.c b/tests/kms_flip.c
index eda2fcc..6ec97d0 100644
--- a/tests/kms_flip.c
+++ b/tests/kms_flip.c
@@ -1182,13 +1182,13 @@  static void check_final_state(struct test_output *o, struct event_state *es,
 	/* Verify we drop no frames, but only if it's not a TV encoder, since
 	 * those use some funny fake timings behind userspace's back. */
 	if (o->flags & TEST_CHECK_TS && !analog_tv_connector(o)) {
-		int expected;
+		double expected;
 		int count = es->count;
 
 		count *= o->seq_step;
-		expected = elapsed / frame_time(o);
-		igt_assert_f(count >= expected * 99/100 && count <= expected * 101/100,
-			     "dropped frames, expected %d, counted %d, encoder type %d\n",
+		expected = (double)elapsed / frame_time(o);
+		igt_assert_f(fabs((double)count - expected)/expected <= 0.01,
+			     "dropped frames, expected %f, counted %d, encoder type %d\n",
 			     expected, count, o->kencoder[0]->encoder_type);
 	}
 }