VirtualBox

Changeset 93969 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Feb 28, 2022 10:21:21 AM (3 years ago)
Author:
vboxsync
Message:

Validation Kit/HGCM: Split out the HGCM testing (mocking) framework into an own header, added documentation, more code for generalizing this.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedClipboard/testcase/tstClipboardMockHGCM.cpp

    r93919 r93969  
    1616 */
    1717
     18#include <VBox/GuestHost/HGCMMock.h>
     19
    1820#include "../VBoxSharedClipboardSvc-internal.h"
    1921
    2022#include <VBox/HostServices/VBoxClipboardSvc.h>
    2123#include <VBox/VBoxGuestLib.h>
    22 
    2324#ifdef RT_OS_LINUX
    2425# include <VBox/GuestHost/SharedClipboard-x11.h>
     
    3435#include <iprt/utf16.h>
    3536
    36 static RTTEST g_hTest;
    37 
    38 extern "C" DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad (VBOXHGCMSVCFNTABLE *ptable);
    39 
     37
     38/*********************************************************************************************************************************
     39*   Static globals                                                                                                               *
     40*********************************************************************************************************************************/
     41
     42static RTTEST     g_hTest;
    4043static SHCLCLIENT g_Client;
    4144
    42 typedef uint32_t HGCMCLIENTID;
    43 # define VBGLR3DECL(type) DECL_HIDDEN_NOTHROW(type) VBOXCALL
    44 
    45 RT_C_DECLS_BEGIN
    46 
    47 /** Simple call handle structure for the guest call completion callback. */
    48 struct VBOXHGCMCALLHANDLE_TYPEDEF
    49 {
    50     /** Where to store the result code on call completion. */
    51     int32_t rc;
    52 };
    53 
    54 typedef enum TSTHGCMMOCKFNTYPE
    55 {
    56     TSTHGCMMOCKFNTYPE_NONE = 0,
    57     TSTHGCMMOCKFNTYPE_CONNECT,
    58     TSTHGCMMOCKFNTYPE_DISCONNECT,
    59     TSTHGCMMOCKFNTYPE_CALL,
    60     TSTHGCMMOCKFNTYPE_HOST_CALL
    61 } TSTHGCMMOCKFNTYPE;
    62 
    63 struct TSTHGCMMOCKSVC;
    64 
    65 typedef struct TSTHGCMMOCKCLIENT
    66 {
    67     TSTHGCMMOCKSVC            *pSvc;
    68     uint32_t                   idClient;
    69     SHCLCLIENT                 Client;
    70     VBOXHGCMCALLHANDLE_TYPEDEF hCall;
    71     bool                       fAsyncExec;
    72     RTSEMEVENT                 hEvent;
    73 } TSTHGCMMOCKCLIENT;
    74 /** Pointer to a mock HGCM client. */
    75 typedef TSTHGCMMOCKCLIENT *PTSTHGCMMOCKCLIENT;
    76 
    77 typedef struct TSTHGCMMOCKFN
    78 {
    79     RTLISTNODE         Node;
    80     TSTHGCMMOCKFNTYPE  enmType;
    81     PTSTHGCMMOCKCLIENT pClient;
    82     union
    83     {
    84         struct
    85         {
    86         } Connect;
    87         struct
    88         {
    89         } Disconnect;
    90         struct
    91         {
    92             int32_t             iFunc;
    93             uint32_t            cParms;
    94             PVBOXHGCMSVCPARM    pParms;
    95             VBOXHGCMCALLHANDLE  hCall;
    96         } Call;
    97         struct
    98         {
    99             int32_t             iFunc;
    100             uint32_t            cParms;
    101             PVBOXHGCMSVCPARM    pParms;
    102         } HostCall;
    103     } u;
    104 } TSTHGCMMOCKFN;
    105 typedef TSTHGCMMOCKFN *PTSTHGCMMOCKFN;
    106 
    107 typedef struct TSTHGCMMOCKSVC
    108 {
    109     VBOXHGCMSVCHELPERS fnHelpers;
    110     HGCMCLIENTID       uNextClientId;
    111     TSTHGCMMOCKCLIENT  aHgcmClient[4];
    112     VBOXHGCMSVCFNTABLE fnTable;
    113     RTTHREAD           hThread;
    114     RTSEMEVENT         hEventQueue;
    115     RTSEMEVENT         hEventWait;
    116     /** Event semaphore for host calls. */
    117     RTSEMEVENT         hEventHostCall;
    118     RTLISTANCHOR       lstCall;
    119     volatile bool      fShutdown;
    120 } TSTHGCMMOCKSVC;
    121 /** Pointer to a mock HGCM service. */
    122 typedef TSTHGCMMOCKSVC *PTSTHGCMMOCKSVC;
    123 
    124 static TSTHGCMMOCKSVC    s_tstHgcmSvc;
    125 
     45
     46/*********************************************************************************************************************************
     47*   Shared Clipboard testing                                                                                                     *
     48*********************************************************************************************************************************/
    12649struct TESTDESC;
    12750/** Pointer to a test description. */
     
    15477/** Pointer to an test destroy callback. */
    15578typedef FNTESTDESTROY *PFNTESTDESTROY;
    156 
    157 static int tstHgcmMockClientInit(PTSTHGCMMOCKCLIENT pClient, uint32_t idClient)
    158 {
    159     RT_BZERO(pClient, sizeof(TSTHGCMMOCKCLIENT));
    160 
    161     pClient->idClient = idClient;
    162 
    163     return RTSemEventCreate(&pClient->hEvent);
    164 }
    165 
    166 static int tstHgcmMockClientDestroy(PTSTHGCMMOCKCLIENT pClient)
    167 {
    168     int rc = RTSemEventDestroy(pClient->hEvent);
    169     if (RT_SUCCESS(rc))
    170     {
    171         pClient->hEvent = NIL_RTSEMEVENT;
    172     }
    173 
    174     return rc;
    175 }
    176 
    177 #if 0
    178 static void tstBackendWriteData(HGCMCLIENTID idClient, SHCLFORMAT uFormat, void *pvData, size_t cbData)
    179 {
    180     ShClBackendSetClipboardData(&s_tstHgcmClient[idClient].Client, uFormat, pvData, cbData);
    181 }
    182 
    183 /** Adds a host data read request message to the client's message queue. */
    184 static int tstSvcMockRequestDataFromGuest(uint32_t idClient, SHCLFORMATS fFormats, PSHCLEVENT *ppEvent)
    185 {
    186     AssertPtrReturn(ppEvent, VERR_INVALID_POINTER);
    187 
    188     int rc = ShClSvcGuestDataRequest(&s_tstHgcmClient[idClient].Client, fFormats, ppEvent);
    189     RTTESTI_CHECK_RC_OK_RET(rc, rc);
    190 
    191     return rc;
    192 }
    193 #endif
    194 
    195 static DECLCALLBACK(int) tstHgcmMockSvcConnect(PTSTHGCMMOCKSVC pSvc, void *pvService, uint32_t *pidClient)
    196 {
    197     RT_NOREF(pvService);
    198 
    199     PTSTHGCMMOCKFN pFn = (PTSTHGCMMOCKFN)RTMemAllocZ(sizeof(TSTHGCMMOCKFN));
    200     AssertPtrReturn(pFn, VERR_NO_MEMORY);
    201 
    202     PTSTHGCMMOCKCLIENT pClient = &pSvc->aHgcmClient[pSvc->uNextClientId];
    203 
    204     int rc = tstHgcmMockClientInit(pClient, pSvc->uNextClientId);
    205     if (RT_FAILURE(rc))
    206         return rc;
    207 
    208     pFn->enmType = TSTHGCMMOCKFNTYPE_CONNECT;
    209     pFn->pClient = pClient;
    210 
    211     RTListAppend(&pSvc->lstCall, &pFn->Node);
    212     pFn = NULL; /* Thread takes ownership now. */
    213 
    214     int rc2 = RTSemEventSignal(pSvc->hEventQueue);
    215     AssertRCReturn(rc2, rc2);
    216 
    217     rc2 = RTSemEventWait(pClient->hEvent, RT_MS_30SEC);
    218     AssertRCReturn(rc2, rc2);
    219 
    220     ASMAtomicIncU32(&pSvc->uNextClientId);
    221 
    222     *pidClient = pClient->idClient;
    223 
    224     return VINF_SUCCESS;
    225 }
    226 
    227 static DECLCALLBACK(int) tstHgcmMockSvcDisconnect(PTSTHGCMMOCKSVC pSvc, void *pvService, uint32_t idClient)
    228 {
    229     RT_NOREF(pvService);
    230 
    231     PTSTHGCMMOCKCLIENT pClient = &pSvc->aHgcmClient[idClient];
    232 
    233     PTSTHGCMMOCKFN pFn = (PTSTHGCMMOCKFN)RTMemAllocZ(sizeof(TSTHGCMMOCKFN));
    234     AssertPtrReturn(pFn, VERR_NO_MEMORY);
    235 
    236     pFn->enmType = TSTHGCMMOCKFNTYPE_DISCONNECT;
    237     pFn->pClient = pClient;
    238 
    239     RTListAppend(&pSvc->lstCall, &pFn->Node);
    240     pFn = NULL; /* Thread takes ownership now. */
    241 
    242     int rc2 = RTSemEventSignal(pSvc->hEventQueue);
    243     AssertRCReturn(rc2, rc2);
    244 
    245     rc2 = RTSemEventWait(pClient->hEvent, RT_MS_30SEC);
    246     AssertRCReturn(rc2, rc2);
    247 
    248     return tstHgcmMockClientDestroy(pClient);
    249 }
    250 
    251 static DECLCALLBACK(int) tstHgcmMockSvcCall(PTSTHGCMMOCKSVC pSvc, void *pvService, VBOXHGCMCALLHANDLE callHandle, uint32_t idClient, void *pvClient,
    252                                             int32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    253 {
    254     RT_NOREF(pvService, pvClient);
    255 
    256     PTSTHGCMMOCKCLIENT pClient = &pSvc->aHgcmClient[idClient];
    257 
    258     PTSTHGCMMOCKFN pFn = (PTSTHGCMMOCKFN)RTMemAllocZ(sizeof(TSTHGCMMOCKFN));
    259     AssertPtrReturn(pFn, VERR_NO_MEMORY);
    260 
    261     const size_t cbParms = cParms * sizeof(VBOXHGCMSVCPARM);
    262 
    263     pFn->enmType         = TSTHGCMMOCKFNTYPE_CALL;
    264     pFn->pClient         = pClient;
    265 
    266     pFn->u.Call.hCall    = callHandle;
    267     pFn->u.Call.iFunc    = function;
    268     pFn->u.Call.pParms   = (PVBOXHGCMSVCPARM)RTMemDup(paParms, cbParms);
    269     AssertPtrReturn(pFn->u.Call.pParms, VERR_NO_MEMORY);
    270     pFn->u.Call.cParms   = cParms;
    271 
    272     RTListAppend(&pSvc->lstCall, &pFn->Node);
    273 
    274     int rc2 = RTSemEventSignal(pSvc->hEventQueue);
    275     AssertRCReturn(rc2, rc2);
    276 
    277     rc2 = RTSemEventWait(pSvc->aHgcmClient[idClient].hEvent, RT_INDEFINITE_WAIT);
    278     AssertRCReturn(rc2, rc2);
    279 
    280     memcpy(paParms, pFn->u.Call.pParms, cbParms);
    281 
    282     return VINF_SUCCESS; /** @todo Return host call rc */
    283 }
    284 
    285 static DECLCALLBACK(int) tstHgcmMockSvcHostCall(PTSTHGCMMOCKSVC pSvc, void *pvService, int32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    286 {
    287     RT_NOREF(pvService);
    288 
    289     PTSTHGCMMOCKFN pFn = (PTSTHGCMMOCKFN)RTMemAllocZ(sizeof(TSTHGCMMOCKFN));
    290     AssertPtrReturn(pFn, VERR_INVALID_POINTER);
    291 
    292     pFn->enmType           = TSTHGCMMOCKFNTYPE_HOST_CALL;
    293     pFn->u.HostCall.iFunc  = function;
    294     pFn->u.HostCall.pParms = (PVBOXHGCMSVCPARM)RTMemDup(paParms, cParms * sizeof(VBOXHGCMSVCPARM));
    295     AssertPtrReturn(pFn->u.HostCall.pParms, VERR_NO_MEMORY);
    296     pFn->u.HostCall.cParms = cParms;
    297 
    298     RTListAppend(&pSvc->lstCall, &pFn->Node);
    299     pFn = NULL; /* Thread takes ownership now. */
    300 
    301     int rc2 = RTSemEventSignal(pSvc->hEventQueue);
    302     AssertRC(rc2);
    303 
    304     rc2 = RTSemEventWait(pSvc->hEventHostCall, RT_INDEFINITE_WAIT);
    305     AssertRCReturn(rc2, rc2);
    306 
    307     return VINF_SUCCESS; /** @todo Return host call rc */
    308 }
    309 
    310 /** Call completion callback for guest calls. */
    311 static DECLCALLBACK(int) tstHgcmMockSvcCallComplete(VBOXHGCMCALLHANDLE callHandle, int32_t rc)
    312 {
    313     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
    314 
    315     for (size_t i = 0; RT_ELEMENTS(pSvc->aHgcmClient); i++)
    316     {
    317         PTSTHGCMMOCKCLIENT pClient = &pSvc->aHgcmClient[i];
    318         if (&pClient->hCall == callHandle) /* Slow, but works for now. */
    319         {
    320             if (rc == VINF_HGCM_ASYNC_EXECUTE)
    321             {
    322                 Assert(pClient->fAsyncExec == false);
    323             }
    324             else /* Complete call + notify client. */
    325             {
    326                 callHandle->rc = rc;
    327 
    328                 int rc2 = RTSemEventSignal(pClient->hEvent);
    329                 AssertRCReturn(rc2, rc2);
    330             }
    331 
    332             return VINF_SUCCESS;
    333         }
    334     }
    335 
    336     return VERR_NOT_FOUND;
    337 }
    338 
    339 static DECLCALLBACK(int) tstHgcmMockSvcThread(RTTHREAD hThread, void *pvUser)
    340 {
    341     RT_NOREF(hThread);
    342     PTSTHGCMMOCKSVC pSvc = (PTSTHGCMMOCKSVC)pvUser;
    343 
    344     pSvc->uNextClientId  = 0;
    345     pSvc->fnTable.cbSize     = sizeof(pSvc->fnTable);
    346     pSvc->fnTable.u32Version = VBOX_HGCM_SVC_VERSION;
    347 
    348     RT_ZERO(pSvc->fnHelpers);
    349     pSvc->fnHelpers.pfnCallComplete = tstHgcmMockSvcCallComplete;
    350     pSvc->fnTable.pHelpers          = &pSvc->fnHelpers;
    351 
    352     int rc = VBoxHGCMSvcLoad(&pSvc->fnTable);
    353     if (RT_SUCCESS(rc))
    354     {
    355         RTThreadUserSignal(hThread);
    356 
    357         for (;;)
    358         {
    359             rc = RTSemEventWait(pSvc->hEventQueue, 10 /* ms */);
    360             if (ASMAtomicReadBool(&pSvc->fShutdown))
    361             {
    362                 rc = VINF_SUCCESS;
    363                 break;
    364             }
    365             if (rc == VERR_TIMEOUT)
    366                 continue;
    367 
    368             PTSTHGCMMOCKFN pFn = RTListGetFirst(&pSvc->lstCall, TSTHGCMMOCKFN, Node);
    369             if (pFn)
    370             {
    371                 switch (pFn->enmType)
    372                 {
    373                     case TSTHGCMMOCKFNTYPE_CONNECT:
    374                     {
    375                         rc = pSvc->fnTable.pfnConnect(pSvc->fnTable.pvService,
    376                                                       pFn->pClient->idClient, &pFn->pClient->Client,
    377                                                       VMMDEV_REQUESTOR_USR_NOT_GIVEN /* fRequestor */, false /* fRestoring */);
    378 
    379                         int rc2 = RTSemEventSignal(pFn->pClient->hEvent);
    380                         AssertRC(rc2);
    381 
    382                         break;
    383                     }
    384 
    385                     case TSTHGCMMOCKFNTYPE_DISCONNECT:
    386                     {
    387                         rc = pSvc->fnTable.pfnDisconnect(pSvc->fnTable.pvService,
    388                                                          pFn->pClient->idClient, &pFn->pClient->Client);
    389                         break;
    390                     }
    391 
    392                     case TSTHGCMMOCKFNTYPE_CALL:
    393                     {
    394                         pSvc->fnTable.pfnCall(NULL, pFn->u.Call.hCall, pFn->pClient->idClient, &pFn->pClient->Client,
    395                                               pFn->u.Call.iFunc, pFn->u.Call.cParms, pFn->u.Call.pParms, RTTimeMilliTS());
    396 
    397                         /* Note: Call will be completed in the call completion callback. */
    398                         break;
    399                     }
    400 
    401                     case TSTHGCMMOCKFNTYPE_HOST_CALL:
    402                     {
    403                         rc = pSvc->fnTable.pfnHostCall(NULL, pFn->u.HostCall.iFunc, pFn->u.HostCall.cParms, pFn->u.HostCall.pParms);
    404 
    405                         int rc2 = RTSemEventSignal(pSvc->hEventHostCall);
    406                         AssertRC(rc2);
    407                         break;
    408                     }
    409 
    410                     default:
    411                         AssertFailed();
    412                         break;
    413                 }
    414                 RTListNodeRemove(&pFn->Node);
    415                 RTMemFree(pFn);
    416             }
    417         }
    418     }
    419 
    420     return rc;
    421 }
    422 
    423 static PTSTHGCMMOCKCLIENT tstHgcmMockSvcWaitForConnect(PTSTHGCMMOCKSVC pSvc)
    424 {
    425     int rc = RTSemEventWait(pSvc->hEventWait, RT_MS_30SEC);
    426     if (RT_SUCCESS(rc))
    427     {
    428         Assert(pSvc->uNextClientId);
    429         return &pSvc->aHgcmClient[pSvc->uNextClientId - 1];
    430     }
    431     return NULL;
    432 }
    433 
    434 static int tstHgcmMockSvcCreate(PTSTHGCMMOCKSVC pSvc)
    435 {
    436     RT_ZERO(pSvc->aHgcmClient);
    437     pSvc->fShutdown = false;
    438     int rc = RTSemEventCreate(&pSvc->hEventQueue);
    439     if (RT_SUCCESS(rc))
    440     {
    441         rc = RTSemEventCreate(&pSvc->hEventHostCall);
    442         if (RT_SUCCESS(rc))
    443         {
    444             rc = RTSemEventCreate(&pSvc->hEventWait);
    445             if (RT_SUCCESS(rc))
    446                 RTListInit(&pSvc->lstCall);
    447         }
    448     }
    449 
    450     return rc;
    451 }
    452 
    453 static int tstHgcmMockSvcDestroy(PTSTHGCMMOCKSVC pSvc)
    454 {
    455     int rc = RTSemEventDestroy(pSvc->hEventQueue);
    456     if (RT_SUCCESS(rc))
    457     {
    458         rc = RTSemEventDestroy(pSvc->hEventHostCall);
    459         if (RT_SUCCESS(rc))
    460             RTSemEventDestroy(pSvc->hEventWait);
    461     }
    462     return rc;
    463 }
    464 
    465 static int tstHgcmMockSvcStart(PTSTHGCMMOCKSVC pSvc)
    466 {
    467     int rc = RTThreadCreate(&pSvc->hThread, tstHgcmMockSvcThread, pSvc, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE,
    468                             "MockSvc");
    469     if (RT_SUCCESS(rc))
    470         rc = RTThreadUserWait(pSvc->hThread, RT_MS_30SEC);
    471 
    472     return rc;
    473 }
    474 
    475 static int tstHgcmMockSvcStop(PTSTHGCMMOCKSVC pSvc)
    476 {
    477     ASMAtomicWriteBool(&pSvc->fShutdown, true);
    478 
    479     int rcThread;
    480     int rc = RTThreadWait(pSvc->hThread, RT_MS_30SEC, &rcThread);
    481     if (RT_SUCCESS(rc))
    482         rc = rcThread;
    483     if (RT_FAILURE(rc))
    484         RTTestFailed(g_hTest, "Shutting down mock service failed with %Rrc\n", rc);
    485 
    486     pSvc->hThread = NIL_RTTHREAD;
    487 
    488     return rc;
    489 }
    490 
    491 VBGLR3DECL(int) VbglR3HGCMConnect(const char *pszServiceName, HGCMCLIENTID *pidClient)
    492 {
    493     RT_NOREF(pszServiceName);
    494 
    495     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
    496 
    497     return tstHgcmMockSvcConnect(pSvc, pSvc->fnTable.pvService, pidClient);
    498 }
    499 
    500 VBGLR3DECL(int) VbglR3HGCMDisconnect(HGCMCLIENTID idClient)
    501 {
    502     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
    503 
    504     return tstHgcmMockSvcDisconnect(pSvc, pSvc->fnTable.pvService, idClient);
    505 }
    506 
    507 VBGLR3DECL(int) VbglR3HGCMCall(PVBGLIOCHGCMCALL pInfo, size_t cbInfo)
    508 {
    509     AssertMsg(pInfo->Hdr.cbIn  == cbInfo, ("cbIn=%#x cbInfo=%#zx\n", pInfo->Hdr.cbIn, cbInfo));
    510     AssertMsg(pInfo->Hdr.cbOut == cbInfo, ("cbOut=%#x cbInfo=%#zx\n", pInfo->Hdr.cbOut, cbInfo));
    511     Assert(sizeof(*pInfo) + pInfo->cParms * sizeof(HGCMFunctionParameter) <= cbInfo);
    512 
    513     HGCMFunctionParameter *offSrcParms = VBGL_HGCM_GET_CALL_PARMS(pInfo);
    514     PVBOXHGCMSVCPARM       paDstParms  = (PVBOXHGCMSVCPARM)RTMemAlloc(pInfo->cParms * sizeof(VBOXHGCMSVCPARM));
    515     for (uint16_t i = 0; i < pInfo->cParms; i++)
    516     {
    517         switch (offSrcParms->type)
    518         {
    519             case VMMDevHGCMParmType_32bit:
    520             {
    521                 paDstParms[i].type     = VBOX_HGCM_SVC_PARM_32BIT;
    522                 paDstParms[i].u.uint32 = offSrcParms->u.value32;
    523                 break;
    524             }
    525 
    526             case VMMDevHGCMParmType_64bit:
    527             {
    528                 paDstParms[i].type     = VBOX_HGCM_SVC_PARM_64BIT;
    529                 paDstParms[i].u.uint64 = offSrcParms->u.value64;
    530                 break;
    531             }
    532 
    533             case VMMDevHGCMParmType_LinAddr:
    534             {
    535                 paDstParms[i].type           = VBOX_HGCM_SVC_PARM_PTR;
    536                 paDstParms[i].u.pointer.addr = (void *)offSrcParms->u.LinAddr.uAddr;
    537                 paDstParms[i].u.pointer.size = offSrcParms->u.LinAddr.cb;
    538                 break;
    539             }
    540 
    541             default:
    542                 AssertFailed();
    543                 break;
    544         }
    545 
    546         offSrcParms++;
    547     }
    548 
    549     PTSTHGCMMOCKSVC const pSvc = &s_tstHgcmSvc;
    550 
    551     int rc2 = tstHgcmMockSvcCall(pSvc, pSvc->fnTable.pvService, &pSvc->aHgcmClient[pInfo->u32ClientID].hCall,
    552                                  pInfo->u32ClientID, &pSvc->aHgcmClient[pInfo->u32ClientID].Client,
    553                                  pInfo->u32Function, pInfo->cParms, paDstParms);
    554     if (RT_SUCCESS(rc2))
    555     {
    556         offSrcParms = VBGL_HGCM_GET_CALL_PARMS(pInfo);
    557 
    558         for (uint16_t i = 0; i < pInfo->cParms; i++)
    559         {
    560             paDstParms[i].type = offSrcParms->type;
    561             switch (paDstParms[i].type)
    562             {
    563                 case VMMDevHGCMParmType_32bit:
    564                     offSrcParms->u.value32 = paDstParms[i].u.uint32;
    565                     break;
    566 
    567                 case VMMDevHGCMParmType_64bit:
    568                     offSrcParms->u.value64 = paDstParms[i].u.uint64;
    569                     break;
    570 
    571                 case VMMDevHGCMParmType_LinAddr:
    572                 {
    573                     offSrcParms->u.LinAddr.cb = paDstParms[i].u.pointer.size;
    574                     break;
    575                 }
    576 
    577                 default:
    578                     AssertFailed();
    579                     break;
    580             }
    581 
    582             offSrcParms++;
    583         }
    584     }
    585 
    586     RTMemFree(paDstParms);
    587 
    588     if (RT_SUCCESS(rc2))
    589         rc2 = pSvc->aHgcmClient[pInfo->u32ClientID].hCall.rc;
    590 
    591     return rc2;
    592 }
    593 
    594 RT_C_DECLS_END
    595 
    596 
    597 /*********************************************************************************************************************************
    598 *   Shared Clipboard testing                                                                                                     *
    599 *********************************************************************************************************************************/
    60079
    60180typedef struct TESTTASK
     
    661140} SHCLCONTEXT;
    662141
     142
     143#if 0
     144static void tstBackendWriteData(HGCMCLIENTID idClient, SHCLFORMAT uFormat, void *pvData, size_t cbData)
     145{
     146    ShClBackendSetClipboardData(&s_tstHgcmClient[idClient].Client, uFormat, pvData, cbData);
     147}
     148
     149/** Adds a host data read request message to the client's message queue. */
     150static int tstSvcMockRequestDataFromGuest(uint32_t idClient, SHCLFORMATS fFormats, PSHCLEVENT *ppEvent)
     151{
     152    AssertPtrReturn(ppEvent, VERR_INVALID_POINTER);
     153
     154    int rc = ShClSvcGuestDataRequest(&s_tstHgcmClient[idClient].Client, fFormats, ppEvent);
     155    RTTESTI_CHECK_RC_OK_RET(rc, rc);
     156
     157    return rc;
     158}
     159#endif
     160
    663161static int tstSetModeRc(PTSTHGCMMOCKSVC pSvc, uint32_t uMode, int rc)
    664162{
     
    692190    RTTestISub("Testing VBOX_SHCL_HOST_FN_SET_MODE");
    693191
    694     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
     192    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
    695193
    696194    /* Reset global variable which doesn't reset itself. */
     
    721219    RTTestISub("Testing VBOX_SHCL_HOST_FN_SET_TRANSFER_MODE");
    722220
    723     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
     221    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
    724222
    725223    /* Invalid parameter. */
     
    741239    /* Disable transfers again. */
    742240    HGCMSvcSetU32(&parms[0], VBOX_SHCL_TRANSFER_MODE_DISABLED);
    743     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_TRANSFER_MODE, 1, parms);
     241    rc = tstHgcmMockSvcHostCall(pSvc, NULL, VBOX_SHCL_HOST_FN_SET_TRANSFER_MODE, 1, parms);
    744242    RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    745243}
     
    751249    RTTestISub("Setting up VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT test");
    752250
     251    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
     252
    753253    VBOXHGCMSVCPARM parms[2];
    754254    RT_ZERO(parms);
     
    756256    /* Unless we are bidirectional the host message requests will be dropped. */
    757257    HGCMSvcSetU32(&parms[0], VBOX_SHCL_MODE_BIDIRECTIONAL);
    758     int rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_MODE, 1, parms);
     258    int rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_MODE, 1, parms);
    759259    RTTESTI_CHECK_RC_OK(rc);
    760260
     
    763263    VBOXHGCMCALLHANDLE_TYPEDEF call;
    764264    rc = VERR_IPE_UNINITIALIZED_STATUS;
    765     s_tstHgcmSvc.fnTable.pfnConnect(NULL, 1 /* clientId */, &g_Client, 0, 0);
     265    pSvc->fnTable.pfnConnect(NULL, 1 /* clientId */, &g_Client, 0, 0);
    766266
    767267    HGCMSvcSetU32(&parms[0], 0);
    768268    HGCMSvcSetU32(&parms[1], 0);
    769     s_tstHgcmSvc.fnTable.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT, 2, parms, 0);
     269    pSvc->fnTable.pfnCall(NULL, &call, 1 /* clientId */, &g_Client, VBOX_SHCL_GUEST_FN_MSG_OLD_GET_WAIT, 2, parms, 0);
    770270    RTTESTI_CHECK_RC_OK(rc);
    771271
     
    838338    RTTESTI_CHECK_RC(u.Call.rc, VERR_IPE_UNINITIALIZED_STATUS);  /* This call should not complete yet. */
    839339#endif
    840     s_tstHgcmSvc.fnTable.pfnDisconnect(NULL, 1 /* clientId */, &g_Client);
     340    pSvc->fnTable.pfnDisconnect(NULL, 1 /* clientId */, &g_Client);
    841341}
    842342
     
    845345    RTTestISub("Testing client (guest) API - Simple");
    846346
    847     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
     347    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
    848348
    849349    /* Preparations. */
     
    1023523    RTTestISub("Testing HOST_FN_SET_HEADLESS");
    1024524
     525    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
     526
    1025527    VBOXHGCMSVCPARM parms[2];
    1026528    HGCMSvcSetU32(&parms[0], false);
    1027     int rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
     529    int rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
    1028530    RTTESTI_CHECK_RC_OK(rc);
    1029531    bool fHeadless = ShClSvcGetHeadless();
    1030532    RTTESTI_CHECK_MSG(fHeadless == false, ("fHeadless=%RTbool\n", fHeadless));
    1031     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 0, parms);
     533    rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 0, parms);
    1032534    RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
    1033     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 2, parms);
     535    rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 2, parms);
    1034536    RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
    1035537    HGCMSvcSetU64(&parms[0], 99);
    1036     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
     538    rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
    1037539    RTTESTI_CHECK_RC(rc, VERR_INVALID_PARAMETER);
    1038540    HGCMSvcSetU32(&parms[0], true);
    1039     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
     541    rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
    1040542    RTTESTI_CHECK_RC_OK(rc);
    1041543    fHeadless = ShClSvcGetHeadless();
    1042544    RTTESTI_CHECK_MSG(fHeadless == true, ("fHeadless=%RTbool\n", fHeadless));
    1043545    HGCMSvcSetU32(&parms[0], 99);
    1044     rc = s_tstHgcmSvc.fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
     546    rc = pSvc->fnTable.pfnHostCall(NULL, VBOX_SHCL_HOST_FN_SET_HEADLESS, 1, parms);
    1045547    RTTESTI_CHECK_RC_OK(rc);
    1046548    fHeadless = ShClSvcGetHeadless();
     
    1285787
    1286788    RTThreadSleep(5000);
     789RT_BREAKPOINT();
    1287790
    1288791    RT_ZERO(pCtx->Guest.CmdCtx);
     
    1336839    pTask->cbChunk   = pTask->cbData;
    1337840
    1338     PTSTHGCMMOCKSVC    pSvc        = &s_tstHgcmSvc;
     841    PTSTHGCMMOCKSVC    pSvc        = tstHgcmMockSvcInst();
    1339842    PTSTHGCMMOCKCLIENT pMockClient = tstHgcmMockSvcWaitForConnect(pSvc);
     843RT_BREAKPOINT();
    1340844    AssertPtrReturn(pMockClient, VERR_INVALID_POINTER);
    1341845
     
    1350854    PSHCLBACKEND pBackend = ShClSvcGetBackend();
    1351855
    1352     ShClBackendReportFormats(pBackend, &pMockClient->Client, pTask->enmFmtHst);
     856    ShClBackendReportFormats(pBackend, (PSHCLCLIENT)pMockClient->pvClient, pTask->enmFmtHst);
    1353857    tstTaskWait(pTask, RT_MS_30SEC);
    1354858#endif
     
    1459963    RTAssertSetMayPanic(false);
    1460964
     965    PTSTHGCMMOCKSVC pSvc = tstHgcmMockSvcInst();
     966
     967    tstHgcmMockSvcCreate(pSvc, sizeof(SHCLCLIENT));
     968    tstHgcmMockSvcStart(pSvc);
     969
    1461970    /*
    1462971     * Run the tests.
    1463972     */
    1464     testGuestSimple();
    1465     testGuestWrite();
    1466     testHostCall();
    1467     testHostGetMsgOld();
    1468 
    1469     PTSTHGCMMOCKSVC pSvc = &s_tstHgcmSvc;
    1470 
    1471     tstHgcmMockSvcCreate(pSvc);
    1472     tstHgcmMockSvcStart(pSvc);
     973    if (1)
     974    {
     975        testGuestSimple();
     976        testGuestWrite();
     977        testHostCall();
     978        testHostGetMsgOld();
     979    }
    1473980
    1474981    RT_ZERO(g_TstCtx);
     
    1486993    return RTTestSummaryAndDestroy(g_hTest);
    1487994}
    1488 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette