Changeset cdf5361 in mainline


Ignore:
Timestamp:
2023-04-25T11:48:50Z (15 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
aace43d8
Parents:
97d3d9d
git-author:
Jiri Svoboda <jiri@…> (2023-04-24 17:48:39)
git-committer:
Jiri Svoboda <jiri@…> (2023-04-25 11:48:50)
Message:

Factor out test display service

So that we can use it in display-cfg unit tests.

Location:
uspace
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/display-cfg/test/seats.c

    r97d3d9d rcdf5361  
    2727 */
    2828
     29#include <async.h>
     30#include <dispcfg.h>
     31#include <dispcfg_srv.h>
    2932#include <errno.h>
    3033#include <pcut/pcut.h>
     34#include <testdc.h>
    3135#include "../display-cfg.h"
    3236#include "../seats.h"
     
    3539
    3640PCUT_TEST_SUITE(seats);
     41
     42static const char *test_dispcfg_server = "test-dispcfg";
     43static const char *test_dispcfg_svc = "test/dispcfg";
    3744
    3845/** Test dcfg_seats_create() and dcfg_seats_destroy() */
     
    8188PCUT_TEST(seats_list_populate)
    8289{
     90        errno_t rc;
     91        service_id_t sid;
     92        dispcfg_t *dispcfg = NULL;
     93        test_response_t resp;
     94
     95        async_set_fallback_port_handler(test_dispcfg_conn, &resp);
     96
     97        // FIXME This causes this test to be non-reentrant!
     98        rc = loc_server_register(test_dispcfg_server);
     99        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     100
     101        rc = loc_service_register(test_dispcfg_svc, &sid);
     102        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     103
     104        rc = dispcfg_open(test_dispcfg_svc, NULL, NULL, &dispcfg);
     105        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     106        PCUT_ASSERT_NOT_NULL(dispcfg);
     107
     108        dispcfg_close(dispcfg);
     109        rc = loc_service_unregister(sid);
     110        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    83111}
    84112
  • uspace/lib/dispcfg/include/dispcfg.h

    r97d3d9d rcdf5361  
    2727 */
    2828
    29 /** @addtogroup libwndmgt
     29/** @addtogroup libdispcfg
    3030 * @{
    3131 */
  • uspace/lib/dispcfg/include/types/dispcfg.h

    r97d3d9d rcdf5361  
    3030 * @{
    3131 */
    32 /** @file
     32/** @file Display configuration protocol types
    3333 */
    3434
  • uspace/lib/dispcfg/meson.build

    r97d3d9d rcdf5361  
    3030        'src/dispcfg.c',
    3131        'src/dispcfg_srv.c',
     32        'src/testdc.c'
    3233)
    3334
    3435test_src = files(
    3536        'test/main.c',
    36         'test/dispcfg.c',
     37        'test/dispcfg.c'
    3738)
  • uspace/lib/dispcfg/test/dispcfg.c

    r97d3d9d rcdf5361  
    3535#include <pcut/pcut.h>
    3636#include <str.h>
     37#include <testdc.h>
    3738#include "../private/dispcfg.h"
    3839
     
    4344static const char *test_dispcfg_server = "test-dispcfg";
    4445static const char *test_dispcfg_svc = "test/dispcfg";
    45 
    46 static void test_dispcfg_conn(ipc_call_t *, void *);
    47 
    48 static errno_t test_get_seat_list(void *, dispcfg_seat_list_t **);
    49 static errno_t test_get_seat_info(void *, sysarg_t, dispcfg_seat_info_t **);
    50 static errno_t test_seat_create(void *, const char *, sysarg_t *);
    51 static errno_t test_seat_delete(void *, sysarg_t);
    52 static errno_t test_dev_assign(void *, sysarg_t, sysarg_t);
    53 static errno_t test_dev_unassign(void *, sysarg_t);
    54 static errno_t test_get_asgn_dev_list(void *, sysarg_t, dispcfg_dev_list_t **);
    55 static errno_t test_get_event(void *, dispcfg_ev_t *);
    56 
    57 static void test_seat_added(void *, sysarg_t);
    58 static void test_seat_removed(void *, sysarg_t);
    59 
    60 static dispcfg_ops_t test_dispcfg_srv_ops = {
    61         .get_seat_list = test_get_seat_list,
    62         .get_seat_info = test_get_seat_info,
    63         .seat_create = test_seat_create,
    64         .seat_delete = test_seat_delete,
    65         .dev_assign = test_dev_assign,
    66         .dev_unassign = test_dev_unassign,
    67         .get_asgn_dev_list = test_get_asgn_dev_list,
    68         .get_event = test_get_event
    69 };
    70 
    71 static dispcfg_cb_t test_dispcfg_cb = {
    72         .seat_added = test_seat_added,
    73         .seat_removed = test_seat_removed
    74 };
    75 
    76 /** Describes to the server how to respond to our request and pass tracking
    77  * data back to the client.
    78  */
    79 typedef struct {
    80         errno_t rc;
    81         sysarg_t seat_id;
    82         dispcfg_ev_t event;
    83         dispcfg_ev_t revent;
    84         int event_cnt;
    85 
    86         bool get_seat_list_called;
    87         dispcfg_seat_list_t *get_seat_list_rlist;
    88 
    89         bool get_seat_info_called;
    90         sysarg_t get_seat_info_seat_id;
    91         dispcfg_seat_info_t *get_seat_info_rinfo;
    92 
    93         bool seat_create_called;
    94         char *seat_create_name;
    95         sysarg_t seat_create_seat_id;
    96 
    97         bool seat_delete_called;
    98         sysarg_t seat_delete_seat_id;
    99 
    100         bool dev_assign_called;
    101         sysarg_t dev_assign_svc_id;
    102         sysarg_t dev_assign_seat_id;
    103 
    104         bool dev_unassign_called;
    105         sysarg_t dev_unassign_svc_id;
    106 
    107         bool get_asgn_dev_list_called;
    108         sysarg_t get_asgn_dev_list_seat_id;
    109         dispcfg_dev_list_t *get_asgn_dev_list_rlist;
    110 
    111         bool get_event_called;
    112 
    113         bool seat_added_called;
    114         sysarg_t seat_added_seat_id;
    115 
    116         bool seat_removed_called;
    117         sysarg_t seat_removed_seat_id;
    118 
    119         bool seat_changed_called;
    120         sysarg_t seat_changed_seat_id;
    121 
    122         fibril_condvar_t event_cv;
    123         fibril_mutex_t event_lock;
    124         dispcfg_srv_t *srv;
    125 } test_response_t;
    12646
    12747/** dispcfg_open(), dispcfg_close() work for valid seat management service */
     
    790710}
    791711
    792 /** Test seat management service connection. */
    793 static void test_dispcfg_conn(ipc_call_t *icall, void *arg)
    794 {
    795         test_response_t *resp = (test_response_t *) arg;
    796         dispcfg_srv_t srv;
    797 
    798         /* Set up protocol structure */
    799         dispcfg_srv_initialize(&srv);
    800         srv.ops = &test_dispcfg_srv_ops;
    801         srv.arg = arg;
    802         resp->srv = &srv;
    803 
    804         /* Handle connection */
    805         dispcfg_conn(icall, &srv);
    806 
    807         resp->srv = NULL;
    808 }
    809 
    810 static void test_seat_added(void *arg, sysarg_t seat_id)
    811 {
    812         test_response_t *resp = (test_response_t *) arg;
    813 
    814         resp->revent.etype = dcev_seat_added;
    815 
    816         fibril_mutex_lock(&resp->event_lock);
    817         resp->seat_added_called = true;
    818         resp->seat_added_seat_id = seat_id;
    819         fibril_condvar_broadcast(&resp->event_cv);
    820         fibril_mutex_unlock(&resp->event_lock);
    821 }
    822 
    823 static void test_seat_removed(void *arg, sysarg_t seat_id)
    824 {
    825         test_response_t *resp = (test_response_t *) arg;
    826 
    827         resp->revent.etype = dcev_seat_removed;
    828 
    829         fibril_mutex_lock(&resp->event_lock);
    830         resp->seat_removed_called = true;
    831         resp->seat_removed_seat_id = seat_id;
    832         fibril_condvar_broadcast(&resp->event_cv);
    833         fibril_mutex_unlock(&resp->event_lock);
    834 }
    835 
    836 static errno_t test_get_seat_list(void *arg, dispcfg_seat_list_t **rlist)
    837 {
    838         test_response_t *resp = (test_response_t *) arg;
    839 
    840         resp->get_seat_list_called = true;
    841 
    842         if (resp->rc != EOK)
    843                 return resp->rc;
    844 
    845         *rlist = resp->get_seat_list_rlist;
    846         return EOK;
    847 }
    848 
    849 static errno_t test_get_seat_info(void *arg, sysarg_t seat_id,
    850     dispcfg_seat_info_t **rinfo)
    851 {
    852         test_response_t *resp = (test_response_t *) arg;
    853 
    854         resp->get_seat_info_called = true;
    855         resp->get_seat_info_seat_id = seat_id;
    856 
    857         if (resp->rc != EOK)
    858                 return resp->rc;
    859 
    860         *rinfo = resp->get_seat_info_rinfo;
    861         return EOK;
    862 }
    863 
    864 static errno_t test_seat_create(void *arg, const char *name, sysarg_t *rseat_id)
    865 {
    866         test_response_t *resp = (test_response_t *) arg;
    867 
    868         resp->seat_create_called = true;
    869         resp->seat_create_name = str_dup(name);
    870         *rseat_id = resp->seat_create_seat_id;
    871         return resp->rc;
    872 }
    873 
    874 static errno_t test_seat_delete(void *arg, sysarg_t seat_id)
    875 {
    876         test_response_t *resp = (test_response_t *) arg;
    877 
    878         resp->seat_delete_called = true;
    879         resp->seat_delete_seat_id = seat_id;
    880         return resp->rc;
    881 }
    882 
    883 static errno_t test_dev_assign(void *arg, sysarg_t svc_id, sysarg_t seat_id)
    884 {
    885         test_response_t *resp = (test_response_t *) arg;
    886 
    887         resp->dev_assign_called = true;
    888         resp->dev_assign_svc_id = svc_id;
    889         resp->dev_assign_seat_id = seat_id;
    890         return resp->rc;
    891 }
    892 
    893 static errno_t test_dev_unassign(void *arg, sysarg_t svc_id)
    894 {
    895         test_response_t *resp = (test_response_t *) arg;
    896 
    897         resp->dev_unassign_called = true;
    898         resp->dev_unassign_svc_id = svc_id;
    899         return resp->rc;
    900 }
    901 
    902 static errno_t test_get_asgn_dev_list(void *arg, sysarg_t seat_id,
    903     dispcfg_dev_list_t **rlist)
    904 {
    905         test_response_t *resp = (test_response_t *) arg;
    906 
    907         resp->get_asgn_dev_list_called = true;
    908         resp->get_asgn_dev_list_seat_id = seat_id;
    909 
    910         if (resp->rc != EOK)
    911                 return resp->rc;
    912 
    913         *rlist = resp->get_asgn_dev_list_rlist;
    914         return EOK;
    915 }
    916 
    917 static errno_t test_get_event(void *arg, dispcfg_ev_t *event)
    918 {
    919         test_response_t *resp = (test_response_t *) arg;
    920 
    921         resp->get_event_called = true;
    922         if (resp->event_cnt > 0) {
    923                 --resp->event_cnt;
    924                 *event = resp->event;
    925                 return EOK;
    926         }
    927 
    928         return ENOENT;
    929 }
    930 
    931712PCUT_EXPORT(dispcfg);
Note: See TracChangeset for help on using the changeset viewer.