VirtualBox

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


Ignore:
Timestamp:
Feb 15, 2023 1:48:41 AM (22 months ago)
Author:
vboxsync
Message:

HGCMMock*.h: Split out the code into .cpp files.

Location:
trunk/src/VBox/HostServices
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestControl/testcase/Makefile.kmk

    r98533 r98576  
    4646 tstGuestControlMockHGCM_SOURCES  = \
    4747        ../VBoxGuestControlSvc.cpp \
     48        ../../testcase/TstHgcmMock.cpp \
    4849        $(PATH_ROOT)/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp \
    4950        $(PATH_ROOT)/src/VBox/HostServices/common/message.cpp \
  • trunk/src/VBox/HostServices/SharedClipboard/testcase/Makefile.kmk

    r98415 r98576  
    4343 tstClipboardMockHGCM_DEFS    = VBOX_WITH_HGCM VBOX_WITH_SHARED_CLIPBOARD
    4444 tstClipboardMockHGCM_SOURCES = \
     45        tstClipboardMockHGCM.cpp \
    4546        ../VBoxSharedClipboardSvc.cpp \
     47        ../../testcase/TstHgcmMock.cpp \
     48        ../../testcase/TstHgcmMockUtils.cpp \
    4649        $(PATH_ROOT)/src/VBox/GuestHost/SharedClipboard/clipboard-common.cpp \
    4750        $(PATH_ROOT)/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibClipboard.cpp \
    48         $(PATH_ROOT)/src/VBox/HostServices/common/message.cpp \
    49         tstClipboardMockHGCM.cpp
     51        $(PATH_ROOT)/src/VBox/HostServices/common/message.cpp
    5052 tstClipboardMockHGCM_LIBS    = $(LIB_RUNTIME)
    5153
  • trunk/src/VBox/HostServices/SharedClipboard/testcase/tstClipboardMockHGCM.cpp

    r98575 r98576  
    2626 */
    2727
     28
     29/*********************************************************************************************************************************
     30*   Header Files                                                                                                                 *
     31*********************************************************************************************************************************/
    2832#include "../VBoxSharedClipboardSvc-internal.h"
    2933
  • trunk/src/VBox/HostServices/testcase/TstHGCMMock.cpp

    r98574 r98576  
    11/* $Id$ */
    22/** @file
    3  * HGCMMock.h: Mocking framework for testing HGCM-based host services +
    4  *             Vbgl code on the host side.
    5  *
    6  *             Goal is to run host service + Vbgl code as unmodified as
    7  *             possible as part of testcases to gain test coverage which
    8  *             otherwise wouldn't possible for heavily user-centric features
    9  *             like Shared Clipboard or drag'n drop (DnD).
     3 * TstHGCMMock.cpp - Mocking framework for testing HGCM-based host services.
     4 *
     5 * The goal is to run host service + Vbgl code as unmodified as possible as
     6 * part of testcases to gain test coverage which otherwise wouldn't possible
     7 * for heavily user-centric features like Shared Clipboard or drag'n drop (DnD).
     8 *
     9 * Currently, though, it's only the service that runs unmodified, the
     10 * testcases does custom Vbgl work.
    1011 */
    1112
     
    2930 * along with this program; if not, see <https://www.gnu.org/licenses>.
    3031 *
    31  * The contents of this file may alternatively be used under the terms
    32  * of the Common Development and Distribution License Version 1.0
    33  * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
    34  * in the VirtualBox distribution, in which case the provisions of the
    35  * CDDL are applicable instead of those of the GPL.
    36  *
    37  * You may elect to license modified versions of this file under the
    38  * terms and conditions of either the GPL or the CDDL or both.
    39  *
    40  * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
    41  */
    42 
    43 #ifndef VBOX_INCLUDED_GuestHost_HGCMMock_h
    44 #define VBOX_INCLUDED_GuestHost_HGCMMock_h
    45 #ifndef RT_WITHOUT_PRAGMA_ONCE
    46 # pragma once
    47 #endif
    48 
    49 #include <iprt/types.h>
     32 * SPDX-License-Identifier: GPL-3.0-only
     33 */
     34
     35
     36/*********************************************************************************************************************************
     37*   Header Files                                                                                                                 *
     38*********************************************************************************************************************************/
     39#include <VBox/GuestHost/HGCMMock.h>
    5040
    5141#include <iprt/asm.h>
     
    6656
    6757/*********************************************************************************************************************************
    68 Definitions.                                                                                                                  *
     58 Global Variables                                                                                                             *
    6959*********************************************************************************************************************************/
    70 
    71 #if defined(IN_RING3) /* Only R3 parts implemented so far. */
    72 
    73 RT_C_DECLS_BEGIN
    74 
    75 DECLCALLBACK(DECLEXPORT(int)) VBoxHGCMSvcLoad(VBOXHGCMSVCFNTABLE *ptable);
    76 
    77 RT_C_DECLS_END
    78 
    79 # define VBGLR3DECL(type) DECL_HIDDEN_NOTHROW(type) VBOXCALL
    80 
    81 /** Simple call handle structure for the guest call completion callback. */
    82 typedef struct VBOXHGCMCALLHANDLE_TYPEDEF
    83 {
    84     /** Where to store the result code on call completion. */
    85     int32_t rc;
    86 } VBOXHGCMCALLHANDLE_TYPEDEF;
    87 
    88 /**
    89  * Enumeration for a HGCM mock function type.
    90  */
    91 typedef enum TSTHGCMMOCKFNTYPE
    92 {
    93     TSTHGCMMOCKFNTYPE_NONE = 0,
    94     TSTHGCMMOCKFNTYPE_CONNECT,
    95     TSTHGCMMOCKFNTYPE_DISCONNECT,
    96     TSTHGCMMOCKFNTYPE_CALL,
    97     TSTHGCMMOCKFNTYPE_HOST_CALL
    98 } TSTHGCMMOCKFNTYPE;
    99 
    100 /** Pointer to a mock HGCM service. */
    101 typedef struct TSTHGCMMOCKSVC *PTSTHGCMMOCKSVC;
    102 
    103 /**
    104  * Structure for mocking a server-side HGCM client.
    105  */
    106 typedef struct TSTHGCMMOCKCLIENT
    107 {
    108     /** Pointer to to mock service instance this client belongs to. */
    109     PTSTHGCMMOCKSVC            pSvc;
    110     /** Assigned HGCM client ID. */
    111     uint32_t                   idClient;
    112     /** Opaque pointer to service-specific client data.
    113      *  Can be NULL if not being used. */
    114     void                      *pvClient;
    115     /** Size (in bytes) of \a pvClient. */
    116     size_t                     cbClient;
    117     /** The client's current HGCM call handle. */
    118     VBOXHGCMCALLHANDLE_TYPEDEF hCall;
    119     /** Whether the current client call has an asynchronous
    120      *  call pending or not. */
    121     bool                       fAsyncExec;
    122     /** Event semaphore to signal call completion. */
    123     RTSEMEVENT                 hEvent;
    124 } TSTHGCMMOCKCLIENT;
    125 /** Pointer to a mock HGCM client. */
    126 typedef TSTHGCMMOCKCLIENT *PTSTHGCMMOCKCLIENT;
    127 
    128 /**
    129  * Structure for keeping HGCM mock function parameters.
    130  */
    131 typedef struct TSTHGCMMOCKFN
    132 {
    133     /** List node for storing this struct into a queue. */
    134     RTLISTNODE         Node;
    135     /** Function type. */
    136     TSTHGCMMOCKFNTYPE  enmType;
    137     /** Pointer to associated client. */
    138     PTSTHGCMMOCKCLIENT pClient;
    139     /** Union keeping function-specific parameters,
    140      *  depending on \a enmType. */
    141     union
    142     {
    143         struct
    144         {
    145             int32_t             iFunc;
    146             uint32_t            cParms;
    147             PVBOXHGCMSVCPARM    pParms;
    148             VBOXHGCMCALLHANDLE  hCall;
    149         } Call;
    150         struct
    151         {
    152             int32_t             iFunc;
    153             uint32_t            cParms;
    154             PVBOXHGCMSVCPARM    pParms;
    155         } HostCall;
    156     } u;
    157 } TSTHGCMMOCKFN;
    158 /** Pointer to a HGCM mock function parameters structure. */
    159 typedef TSTHGCMMOCKFN *PTSTHGCMMOCKFN;
    160 
    161 /**
    162  * Structure for keeping a HGCM mock service instance.
    163  */
    164 typedef struct TSTHGCMMOCKSVC
    165 {
    166     /** HGCM helper table to use. */
    167     VBOXHGCMSVCHELPERS fnHelpers;
    168     /** HGCM service function table to use. */
    169     VBOXHGCMSVCFNTABLE fnTable;
    170     /** Next HGCM client ID to assign.
    171      *  0 is considered as being invalid. */
    172     HGCMCLIENTID       uNextClientId;
    173     /** Array of connected HGCM mock clients.
    174      *  Currently limited to 4 clients maximum. */
    175     TSTHGCMMOCKCLIENT  aHgcmClient[4];
    176     /** Thread handle for the service's main loop. */
    177     RTTHREAD           hThread;
    178     /** Event semaphore for signalling a message
    179      *  queue change. */
    180     RTSEMEVENT         hEventQueue;
    181     /** Event semaphore for clients connecting to the server. */
    182     RTSEMEVENT         hEventConnect;
    183     /** Number of current host calls being served.
    184      *  Currently limited to one call at a time. */
    185     uint8_t            cHostCallers;
    186     /** Result code of last returned host call. */
    187     int                rcHostCall;
    188     /** Event semaphore for host calls. */
    189     RTSEMEVENT         hEventHostCall;
    190     /** List (queue) of function calls to process. */
    191     RTLISTANCHOR       lstCall;
    192     /** Shutdown indicator flag. */
    193     volatile bool      fShutdown;
    194 } TSTHGCMMOCKSVC;
    195 
    19660/** Static HGCM service to mock. */
    19761static TSTHGCMMOCKSVC g_tstHgcmSvc;
     
    19963
    20064/*********************************************************************************************************************************
    201 *  Prototypes.                                                                                                                   *
    202 *********************************************************************************************************************************/
    203 PTSTHGCMMOCKSVC    TstHgcmMockSvcInst(void);
    204 PTSTHGCMMOCKCLIENT TstHgcmMockSvcWaitForConnectEx(PTSTHGCMMOCKSVC pSvc, RTMSINTERVAL msTimeout);
    205 PTSTHGCMMOCKCLIENT TstHgcmMockSvcWaitForConnect(PTSTHGCMMOCKSVC pSvc);
    206 int                TstHgcmMockSvcCreate(PTSTHGCMMOCKSVC pSvc);
    207 int                TstHgcmMockSvcDestroy(PTSTHGCMMOCKSVC pSvc);
    208 int                TstHgcmMockSvcStart(PTSTHGCMMOCKSVC pSvc);
    209 int                TstHgcmMockSvcStop(PTSTHGCMMOCKSVC pSvc);
    210 
    211 int                TstHgcmMockSvcHostCall(PTSTHGCMMOCKSVC pSvc, void *pvService, int32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[]);
    212 
    213 VBGLR3DECL(int)    VbglR3HGCMConnect(const char *pszServiceName, HGCMCLIENTID *pidClient);
    214 VBGLR3DECL(int)    VbglR3HGCMDisconnect(HGCMCLIENTID idClient);
    215 VBGLR3DECL(int)    VbglR3GetSessionId(uint64_t *pu64IdSession);
    216 VBGLR3DECL(int)    VbglR3HGCMCall(PVBGLIOCHGCMCALL pInfo, size_t cbInfo);
    217 
    218 
    219 /*********************************************************************************************************************************
    220 *  Internal functions                                                                                                           *
     65*   Internal functions                                                                                                           *
    22166*********************************************************************************************************************************/
    22267
     
    269114}
    270115
    271 /* @copydoc VBOXHGCMSVCFNTABLE::pfnConnect */
     116/** @copydoc VBOXHGCMSVCFNTABLE::pfnConnect */
    272117static DECLCALLBACK(int) tstHgcmMockSvcConnect(PTSTHGCMMOCKSVC pSvc, void *pvService, uint32_t *pidClient)
    273118{
     
    304149}
    305150
    306 /* @copydoc VBOXHGCMSVCFNTABLE::pfnDisconnect */
     151/** @copydoc VBOXHGCMSVCFNTABLE::pfnDisconnect */
    307152static DECLCALLBACK(int) tstHgcmMockSvcDisconnect(PTSTHGCMMOCKSVC pSvc, void *pvService, uint32_t idClient)
    308153{
     
    329174}
    330175
    331 /* @copydoc VBOXHGCMSVCFNTABLE::pfnCall */
     176/** @copydoc VBOXHGCMSVCFNTABLE::pfnCall */
    332177static DECLCALLBACK(int) tstHgcmMockSvcCall(PTSTHGCMMOCKSVC pSvc, void *pvService, VBOXHGCMCALLHANDLE callHandle, uint32_t idClient, void *pvClient,
    333178                                            int32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
     
    367212}
    368213
    369 /* @copydoc VBOXHGCMSVCFNTABLE::pfnHostCall */
    370 /** Note: Public for also being able to test host calls via testcases. */
     214/** @copydoc VBOXHGCMSVCFNTABLE::pfnHostCall
     215 * @note Public for also being able to test host calls via testcases. */
    371216int TstHgcmMockSvcHostCall(PTSTHGCMMOCKSVC pSvc, void *pvService, int32_t function, uint32_t cParms, VBOXHGCMSVCPARM paParms[])
    372217{
     
    527372                }
    528373                RTListNodeRemove(&pFn->Node);
    529                 RTMemFree(pFn);
     374                RTMemFree(pFn);  /* Note! caller frees the parameters? Or at least it uses them again. */
    530375            }
    531376        }
     
    537382
    538383/*********************************************************************************************************************************
    539 Public functions                                                                                                           *
     384 Public functions                                                                                                             *
    540385*********************************************************************************************************************************/
    541386
     
    655500        rc = rcThread;
    656501    if (RT_SUCCESS(rc))
    657     {
    658502        pSvc->hThread = NIL_RTTHREAD;
    659     }
    660503
    661504    return rc;
     
    810653}
    811654
    812 #endif /* IN_RING3 */
    813 
    814 #endif /* !VBOX_INCLUDED_GuestHost_HGCMMock_h */
  • trunk/src/VBox/HostServices/testcase/TstHGCMMockUtils.cpp

    r98569 r98576  
    1 /* $Id */
     1/* $Id$ */
    22/** @file
    3  * HGCMMockUtils.h: Utility functions for the HGCM Mocking framework.
    4  *
    5  * The utility functions are optional to the actual HGCM Mocking framework and
    6  * can support testcases which require a more advanced setup.
    7  *
    8  * With this one can setup host and guest side threads, which in turn can simulate
    9  * specific host (i.e. HGCM service) + guest (i.e. like in the Guest Addditions
    10  * via VbglR3) scenarios.
    11  *
    12  * Glossary:
    13  *
    14  * Host thread:
    15  *   - The host thread is used as part of the actual HGCM service being tested and
    16  *     provides callbacks (@see TSTHGCMUTILSHOSTCALLBACKS) for the unit test.
    17  * Guest thread:
    18  *    - The guest thread is used as part of the guest side and mimics
    19  *      VBoxClient / VBoxTray / VBoxService parts. (i.e. for VbglR3 calls).
    20  * Task:
    21  *    - A task is the simplest unit of test execution and used between the guest
    22  *      and host mocking threads.
    23  *
    24  ** @todo Add TstHGCMSimpleHost / TstHGCMSimpleGuest wrappers along those lines:
    25  *              Callback.pfnOnClientConnected = tstOnHostClientConnected()
    26  *              TstHGCMSimpleHostInitAndStart(&Callback)
    27  *              Callback.pfnOnConnected = tstOnGuestConnected()
    28  *              TstHGCMSimpleClientInitAndStart(&Callback)
     3 * TstHGCMMockUtils.cpp - Utility functions for the HGCM Mocking framework.
    294 */
    305
     
    4823 * along with this program; if not, see <https://www.gnu.org/licenses>.
    4924 *
    50  * The contents of this file may alternatively be used under the terms
    51  * of the Common Development and Distribution License Version 1.0
    52  * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
    53  * in the VirtualBox distribution, in which case the provisions of the
    54  * CDDL are applicable instead of those of the GPL.
    55  *
    56  * You may elect to license modified versions of this file under the
    57  * terms and conditions of either the GPL or the CDDL or both.
    58  *
    59  * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
    60  */
    61 
    62 #ifndef VBOX_INCLUDED_GuestHost_HGCMMockUtils_h
    63 #define VBOX_INCLUDED_GuestHost_HGCMMockUtils_h
    64 #ifndef RT_WITHOUT_PRAGMA_ONCE
    65 # pragma once
    66 #endif
     25 * SPDX-License-Identifier: GPL-3.0-only
     26 */
     27
     28
     29/*********************************************************************************************************************************
     30*   Header Files                                                                                                                 *
     31*********************************************************************************************************************************/
     32#include <VBox/GuestHost/HGCMMockUtils.h>
    6733
    6834#include <iprt/err.h>
     
    7238
    7339
    74 #include <VBox/GuestHost/HGCMMock.h>
    75 #include <VBox/VBoxGuestLib.h>
    76 
    77 
    78 #if defined(IN_RING3) /* Only R3 parts implemented so far. */
    79 
    80 /** Pointer to a HGCM Mock utils context. */
    81 typedef struct TSTHGCMUTILSCTX *PTSTHGCMUTILSCTX;
    82 
    83 /**
    84  * Structure for keeping a HGCM Mock utils host service callback table.
    85  */
    86 typedef struct TSTHGCMUTILSHOSTCALLBACKS
    87 {
    88     DECLCALLBACKMEMBER(int, pfnOnClientConnected,(PTSTHGCMUTILSCTX pCtx, PTSTHGCMMOCKCLIENT pClient, void *pvUser));
    89 } TSTHGCMUTILSHOSTCALLBACKS;
    90 /** Pointer to a HGCM Mock utils host callbacks table. */
    91 typedef TSTHGCMUTILSHOSTCALLBACKS *PTSTHGCMUTILSHOSTCALLBACKS;
    92 
    93 /**
    94  * Structure for keeping a generic HGCM Mock utils task.
    95  *
    96  * A task is a single test unit / entity.
    97  */
    98 typedef struct TSTHGCMUTILSTASK
    99 {
    100     /** Completion event. */
    101     RTSEMEVENT                    hEvent;
    102     /** Completion rc.
    103      *  Set to VERR_IPE_UNINITIALIZED_STATUS if not completed yet. */
    104     int                           rcCompleted;
    105     /** Expected completion rc. */
    106     int                           rcExpected;
    107     /** Pointer to opaque (testcase-specific) task parameters.
    108      *  Might be NULL if not needed / used. */
    109     void                         *pvUser;
    110 } TSTHGCMUTILSTASK;
    111 /** Pointer to a HGCM Mock utils task. */
    112 typedef TSTHGCMUTILSTASK *PTSTHGCMUTILSTASK;
    113 
    114 /** Callback function for HGCM Mock utils threads. */
    115 typedef DECLCALLBACKTYPE(int, FNTSTHGCMUTILSTHREAD,(PTSTHGCMUTILSCTX pCtx, void *pvUser));
    116 /** Pointer to a HGCM Mock utils guest thread callback. */
    117 typedef FNTSTHGCMUTILSTHREAD *PFNTSTHGCMUTILSTHREAD;
    118 
    119 /**
    120  * Structure for keeping a HGCM Mock utils context.
    121  */
    122 typedef struct TSTHGCMUTILSCTX
    123 {
    124     /** Pointer to the HGCM Mock service instance to use. */
    125     PTSTHGCMMOCKSVC               pSvc;
    126     /** Currently we only support one task at a time. */
    127     TSTHGCMUTILSTASK              Task;
    128     struct
    129     {
    130         RTTHREAD                  hThread;
    131         volatile bool             fShutdown;
    132         PFNTSTHGCMUTILSTHREAD     pfnThread;
    133         void                     *pvUser;
    134     } Guest;
    135     struct
    136     {
    137         RTTHREAD                  hThread;
    138         volatile bool             fShutdown;
    139         TSTHGCMUTILSHOSTCALLBACKS Callbacks;
    140         void                     *pvUser;
    141     } Host;
    142 } TSTHGCMUTILSCTX;
    143 
    144 
    145 /*********************************************************************************************************************************
    146 *  Prototypes.                                                                                                                   *
     40/*********************************************************************************************************************************
     41*   Context                                                                                                                      *
    14742*********************************************************************************************************************************/
    148 /** @name Context handling.
    149  * @{ */
    150 void TstHGCMUtilsCtxInit(PTSTHGCMUTILSCTX pCtx, PTSTHGCMMOCKSVC pSvc);
    151 /** @} */
    152 
    153 /** @name Task handling.
    154  * @{ */
    155 PTSTHGCMUTILSTASK TstHGCMUtilsTaskGetCurrent(PTSTHGCMUTILSCTX pCtx);
    156 int TstHGCMUtilsTaskInit(PTSTHGCMUTILSTASK pTask);
    157 void TstHGCMUtilsTaskDestroy(PTSTHGCMUTILSTASK pTask);
    158 int TstHGCMUtilsTaskWait(PTSTHGCMUTILSTASK pTask, RTMSINTERVAL msTimeout);
    159 bool TstHGCMUtilsTaskOk(PTSTHGCMUTILSTASK pTask);
    160 bool TstHGCMUtilsTaskCompleted(PTSTHGCMUTILSTASK pTask);
    161 void TstHGCMUtilsTaskSignal(PTSTHGCMUTILSTASK pTask, int rc);
    162 /** @} */
    163 
    164 /** @name Threading.
    165  * @{ */
    166 int TstHGCMUtilsGuestThreadStart(PTSTHGCMUTILSCTX pCtx, PFNTSTHGCMUTILSTHREAD pFnThread, void *pvUser);
    167 int TstHGCMUtilsGuestThreadStop(PTSTHGCMUTILSCTX pCtx);
    168 int TstHGCMUtilsHostThreadStart(PTSTHGCMUTILSCTX pCtx, PTSTHGCMUTILSHOSTCALLBACKS pCallbacks, void *pvUser);
    169 int TstHGCMUtilsHostThreadStop(PTSTHGCMUTILSCTX pCtx);
    170 /** @} */
    171 
    172 
    173 /*********************************************************************************************************************************
    174  * Context                                                                                                                       *
    175  ********************************************************************************************************************************/
    17643/**
    17744 * Initializes a HGCM Mock utils context.
     
    18956
    19057/*********************************************************************************************************************************
    191  * Tasks                                                                                                                         *
    192  ********************************************************************************************************************************/
     58*   Tasks                                                                                                                        *
     59*********************************************************************************************************************************/
    19360/**
    19461 * Returns the current task of a HGCM Mock utils context.
     
    423290}
    424291
    425 #endif /* IN_RING3 */
    426 
    427 #endif /* !VBOX_INCLUDED_GuestHost_HGCMMockUtils_h */
    428 
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