[PATCH] test: Add unit test for mieq

Jeremy Huddleston jeremyhu at apple.com
Wed Oct 19 10:55:46 PDT 2011


On Oct 18, 2011, at 10:03 PM, Peter Hutterer wrote:

> 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.

Yeah, I thought about doing that, but it would require a redesign of mieq.c to expose internals, something I'm not keen on doing in a patch to add this test case.

If you really want to do that, we should do it in 2 separate commits, one to rework mieq.c to expose that functionality, and one to add that to this test.

> 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.

I agree, but can we do that separately due to the reasons above?



More information about the xorg-devel mailing list