Changeset 98735eb in mainline for uspace/srv/hid/display/test/client.c


Ignore:
Timestamp:
2021-06-10T13:22:33Z (3 years ago)
Author:
jxsvoboda <5887334+jxsvoboda@…>
Branches:
master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
90f1f19
Parents:
d7f82635
git-author:
Jiri Svoboda <jiri@…> (2021-06-08 17:55:50)
git-committer:
jxsvoboda <5887334+jxsvoboda@…> (2021-06-10 13:22:33)
Message:

Purge events from client event queue when destroying window

If the client had events queued for a particular window and that got
destroyed, later these events, pointing to freed (and reused) memory
would be handed to the client with the wrong window ID (which was
read from the wrong/recycled memory block).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/display/test/client.c

    rd7f82635 r98735eb  
    553553}
    554554
     555/** Test ds_client_purge_window_events() */
     556PCUT_TEST(client_purge_window_events)
     557{
     558        ds_display_t *disp;
     559        ds_client_t *client;
     560        ds_seat_t *seat;
     561        ds_window_t *wnd;
     562        display_wnd_params_t params;
     563        ds_window_t *rwindow;
     564        display_wnd_ev_t revent;
     565        bool called_cb = NULL;
     566        errno_t rc;
     567
     568        rc = ds_display_create(NULL, df_none, &disp);
     569        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     570
     571        rc = ds_client_create(disp, &test_ds_client_cb, &called_cb, &client);
     572        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     573
     574        rc = ds_seat_create(disp, &seat);
     575        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     576
     577        display_wnd_params_init(&params);
     578        params.rect.p0.x = params.rect.p0.y = 0;
     579        params.rect.p1.x = params.rect.p1.y = 1;
     580
     581        rc = ds_window_create(client, &params, &wnd);
     582        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     583
     584        /* New window gets focused event */
     585        PCUT_ASSERT_TRUE(called_cb);
     586
     587        /* Purge it */
     588        ds_client_purge_window_events(client, wnd);
     589
     590        /* The queue should be empty now */
     591        rc = ds_client_get_event(client, &rwindow, &revent);
     592        PCUT_ASSERT_ERRNO_VAL(ENOENT, rc);
     593
     594        ds_window_destroy(wnd);
     595        ds_seat_destroy(seat);
     596        ds_client_destroy(client);
     597        ds_display_destroy(disp);
     598}
     599
    555600/** Test client being destroyed while still having a window.
    556601 *
Note: See TracChangeset for help on using the changeset viewer.