[PATCH] test: Add unit test for mieq

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 18 22:03:20 PDT 2011


On Mon, Oct 17, 2011 at 11:59:38PM -0700, Jeremy Huddleston wrote:
> 
> Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
> ---
> 
> The comments only really make sense wrt the mieq changes that I have pending, but the test should work regardless.
> 
>  test/input.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 69 insertions(+), 0 deletions(-)
> 
> diff --git a/test/input.c b/test/input.c
> index a483957..5125dd7 100644
> --- a/test/input.c
> +++ b/test/input.c
> @@ -40,6 +40,7 @@
>  #include "dixgrabs.h"
>  #include "eventstr.h"
>  #include "inpututils.h"
> +#include "mi.h"
>  #include "assert.h"
>  
>  /**
> @@ -1592,6 +1593,73 @@ dix_double_fp_conversion(void)
>      }
>  }
>  
> +/* The mieq test verifies that events added to the queue come out in the same
> + * order that they went in.
> + */
> +static uint32_t mieq_test_event_last_processed;
> +
> +static void
> +mieq_test_event_handler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) {
> +    RawDeviceEvent *e = (RawDeviceEvent *)ie;
> +
> +    assert(e->type == ET_RawMotion);
> +    assert(e->flags > mieq_test_event_last_processed);
> +    mieq_test_event_last_processed = e->flags;
> +}
> +
> +static void _mieq_test_generate_events(uint32_t start, uint32_t count) {
> +    count += start;
> +    while (start < count) {
> +        RawDeviceEvent e = {0};
> +        e.header = ET_Internal;
> +        e.type = ET_RawMotion;
> +        e.length = sizeof(e);
> +        e.time = GetTimeInMillis();
> +        e.flags = start;
> +
> +        mieqEnqueue(NULL, (InternalEvent*)&e);
> +
> +        start++;
> +    }
> +}
> +
> +#define mieq_test_generate_events(c) { _mieq_test_generate_events(next, c); next += c; }
> +
> +static void
> +mieq_test(void) {
> +    uint32_t next = 1;
> +
> +    mieq_test_event_last_processed = 0;
> +    mieqInit();
> +    mieqSetHandler(ET_RawMotion, mieq_test_event_handler);
> +
> +    /* Enough to fit the buffer but trigger a grow */
> +    mieq_test_generate_events(180);
> +
> +    /* We should resize to 512 now */
> +    mieqProcessInputEvents();

"should" could be tested against with an assert. a simple
assert(miEventQueue->nevents == 512) would do here.
likewise, you can test for the right number of dropped events.
other than that, the output looks correct.

I'd like to see an extra test that just tests mieqGrowQueue and makes sure
it is sane. it's too easy to mix up the argument and the global
mieqEventQueue because chances are they're the same in virtually all cases.
A simple test that doesn't sue mieqEventQueue as argument would help there.

Cheers,
  Peter

> +
> +    /* Some should now get dropped */
> +    mieq_test_generate_events(500);
> +
> +    /* Tell us how many got dropped, 1024 now */
> +    mieqProcessInputEvents();
> +
> +    /* Now make it 2048 */
> +    mieq_test_generate_events(900);
> +    mieqProcessInputEvents();
> +
> +    /* Now make it 4096 (max) */
> +    mieq_test_generate_events(1950);
> +    mieqProcessInputEvents();
> +
> +    /* Now overflow one last time with the maximal queue and reach the verbosity limit */
> +    mieq_test_generate_events(10000);
> +    mieqProcessInputEvents();
> +
> +    mieqFini();
> +}
> +
>  int main(int argc, char** argv)
>  {
>      dix_double_fp_conversion();
> @@ -1610,6 +1678,7 @@ int main(int argc, char** argv)
>      dix_valuator_alloc();
>      dix_get_master();
>      input_option_test();
> +    mieq_test();
>  
>      return 0;
>  }
> -- 
> 1.7.5.4
> 


More information about the xorg-devel mailing list