Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset b093a62 in mainline


Ignore:
Timestamp:
2019-11-11T13:04:25Z (16 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
84876aa4
Parents:
da412547
git-author:
Jiri Svoboda <jiri@…> (2019-11-10 18:04:14)
git-committer:
Jiri Svoboda <jiri@…> (2019-11-11 13:04:25)
Message:

Fix event delivery test

There was an infinite supply of events which prevented proper shutdown

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/display/test/display.c

    rda412547 rb093a62  
    3131#include <display.h>
    3232#include <disp_srv.h>
     33#include <fibril_synch.h>
    3334#include <gfx/color.h>
    3435#include <gfx/context.h>
     
    7576        sysarg_t wnd_id;
    7677        display_wnd_ev_t event;
     78        display_wnd_ev_t revent;
     79        int event_cnt;
    7780        bool window_create_called;
    7881        bool window_destroy_called;
    7982        bool get_event_called;
    8083        bool set_color_called;
     84        bool kbd_event_called;
     85        fibril_condvar_t kbd_event_cv;
     86        fibril_mutex_t kbd_event_lock;
    8187        display_srv_t *srv;
    8288} test_response_t;
     
    325331
    326332/** Keyboard event can be delivered from server to client callback function */
    327 #include <stdio.h>
    328333PCUT_TEST(kbd_event_deliver)
    329334{
     
    351356        wnd = NULL;
    352357        resp.rc = EOK;
    353         rc = display_window_create(disp, &test_display_wnd_cb, NULL, &wnd);
     358        rc = display_window_create(disp, &test_display_wnd_cb, (void *) &resp,
     359            &wnd);
    354360        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    355361        PCUT_ASSERT_NOT_NULL(wnd);
    356362
    357         printf(" ** call display_window_get_gc\n");
    358363        gc = NULL;
    359364        rc = display_window_get_gc(wnd, &gc);
     
    361366        PCUT_ASSERT_NOT_NULL(gc);
    362367
    363         printf(" ** call display_srv_ev_pending\n");
     368        resp.event_cnt = 1;
     369        resp.event.kbd_event.type = KEY_PRESS;
     370        resp.event.kbd_event.key = KC_ENTER;
     371        resp.event.kbd_event.mods = 0;
     372        resp.event.kbd_event.c = L'\0';
     373        resp.wnd_id = wnd->id;
     374        resp.kbd_event_called = false;
     375        fibril_mutex_initialize(&resp.kbd_event_lock);
     376        fibril_condvar_initialize(&resp.kbd_event_cv);
    364377        display_srv_ev_pending(resp.srv);
    365378
    366         printf(" ** call display_window_destroy\n");
     379        /* Wait for the event handler to be called. */
     380        fibril_mutex_lock(&resp.kbd_event_lock);
     381        while (!resp.kbd_event_called) {
     382                fibril_condvar_wait(&resp.kbd_event_cv, &resp.kbd_event_lock);
     383        }
     384        fibril_mutex_unlock(&resp.kbd_event_lock);
     385
     386        /* Verify that the event was delivered correctly */
     387        PCUT_ASSERT_EQUALS(resp.event.kbd_event.type,
     388            resp.revent.kbd_event.type);
     389        PCUT_ASSERT_EQUALS(resp.event.kbd_event.key,
     390            resp.revent.kbd_event.key);
     391        PCUT_ASSERT_EQUALS(resp.event.kbd_event.mods,
     392            resp.revent.kbd_event.mods);
     393        PCUT_ASSERT_EQUALS(resp.event.kbd_event.c,
     394            resp.revent.kbd_event.c);
     395
    367396        rc = display_window_destroy(wnd);
    368397        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    369398
    370         printf(" ** call display_close\n");
    371         display_close(disp);
    372         printf(" ** call loc_service_unregister\n");
     399        display_close(disp);
     400
    373401        rc = loc_service_unregister(sid);
    374402        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     
    424452static void test_kbd_event(void *arg, kbd_event_t *event)
    425453{
     454        test_response_t *resp = (test_response_t *) arg;
     455
     456        resp->revent.kbd_event = *event;
     457
     458        fibril_mutex_lock(&resp->kbd_event_lock);
     459        resp->kbd_event_called = true;
     460        fibril_condvar_broadcast(&resp->kbd_event_cv);
     461        fibril_mutex_unlock(&resp->kbd_event_lock);
    426462}
    427463
     
    450486
    451487        resp->get_event_called = true;
    452         if (resp->rc == EOK) {
     488        if (resp->event_cnt > 0) {
     489                --resp->event_cnt;
    453490                *wnd_id = resp->wnd_id;
    454491                *event = resp->event;
     492                return EOK;
    455493        }
    456494
    457         return resp->rc;
     495        return ENOENT;
    458496}
    459497
Note: See TracChangeset for help on using the changeset viewer.