VirtualBox

Changeset 40550 in vbox for trunk


Ignore:
Timestamp:
Mar 20, 2012 1:46:33 PM (13 years ago)
Author:
vboxsync
Message:

Additions/VBoxGuest: Solaris STREAMS driver: cleanups, fixes and more tests.

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris-streams.c

    r40533 r40550  
    222222     * absolute mouse position reporting.
    223223     */
    224     unsigned           cMaxScreenX;
     224    int                cMaxScreenX;
    225225    /* The current greatest vertical pixel offset on the screen, used for
    226226     * absolute mouse position reporting.
    227227     */
    228     unsigned           cMaxScreenY;
     228    int                cMaxScreenY;
    229229} VBGR0STATE, *PVBGR0STATE;
    230230
     
    541541
    542542#ifdef TESTCASE
     543/* Constants, definitions and test functions for testWPut. */
     544static const int g_ccTestWPutFirmEvent = VUID_FIRM_EVENT;
     545# define PVGFORMAT (&g_ccTestWPutFirmEvent)
     546# define CBGFORMAT (sizeof(g_ccTestWPutFirmEvent))
     547static const Ms_screen_resolution g_TestResolution = { 640, 480 };
     548# define PMSIOSRES (&g_TestResolution)
     549# define CBMSIOSRES (sizeof(g_TestResolution))
     550
     551static inline void testSetResolution(RTTEST hTest, queue_t *pWriteQueue,
     552                                     struct msgb *pMBlk)
     553{
     554    PVBGR0STATE pState = (PVBGR0STATE)pWriteQueue->q_ptr;
     555    RTTEST_CHECK_MSG(hTest,    pState->cMaxScreenX
     556                            == g_TestResolution.width - 1,
     557                     (hTest, "pState->cMaxScreenX=%d\n", pState->cMaxScreenX));
     558    RTTEST_CHECK_MSG(hTest,    pState->cMaxScreenY
     559                            == g_TestResolution.height - 1,
     560                     (hTest, "pState->cMaxScreenY=%d\n", pState->cMaxScreenY));
     561}
     562
     563/** Data table for testWPut. */
     564static struct
     565{
     566    unsigned char iDBType;
     567    int iIOCCmd;
     568    size_t cbData;
     569    const void *pvDataIn;
     570    size_t cbDataIn;
     571    const void *pvDataOut;
     572    size_t cbDataOut;
     573    int rcExp;
     574    void (*pfnExtra)(RTTEST hTest, queue_t *pWriteQueue, struct msgb *pMBlk);
     575} g_asTestWPut[] =
     576{
     577   /* iDBType  iIOCCmd          cbData       pvDataIn   cbDataIn
     578      pvDataOut   cbDataOut rcExp pfnExtra */
     579    { M_IOCTL, VUIDGFORMAT,     sizeof(int), NULL,      0,
     580      PVGFORMAT, CBGFORMAT, 0,    NULL },
     581    { M_IOCTL, VUIDSFORMAT,     sizeof(int), PVGFORMAT, CBGFORMAT,
     582      NULL,       0,        0,    NULL },
     583    { M_IOCTL, MSIOSRESOLUTION, CBMSIOSRES,  PMSIOSRES, CBMSIOSRES,
     584      NULL,       0,        0,    testSetResolution }
     585};
     586
     587# undef PVGFORMAT
     588# undef CBGFORMAT
     589# undef PMSIOSRES
     590# undef CBMSIOSRES
     591
    543592/** Test WPut's handling of different IOCtls, which is bulk of the logic in
    544593 * this file. */
     
    551600    struct iocblk IOCBlk;
    552601    int rc, cFormat = 0;
     602    unsigned i;
    553603
    554604    /* Single simple test to start with.  We can try to make it more systematic
    555605     * next. */
    556606    RTTestSub(hTest, "Testing vbgr0WPut");
    557     RT_ZERO(aQueues);
    558     doInitQueues(&aQueues[0]);
    559     rc = vbgr0SolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
    560     RTTEST_CHECK(hTest, rc == 0);
    561     RTTEST_CHECK(hTest, g_aOpenNodeStates[1].pWriteQueue == WR(&aQueues[0]));
    562     RT_ZERO(MBlk);
    563     RT_ZERO(DBlk);
    564     RT_ZERO(IOCBlk);
    565     RT_ZERO(MBlkCont);
    566     DBlk.db_type = M_IOCTL;
    567     IOCBlk.ioc_cmd = VUIDSFORMAT;
    568     IOCBlk.ioc_count = sizeof(int);
    569     MBlkCont.b_rptr = (unsigned char *)&cFormat;
    570     MBlkCont.b_rptr = (unsigned char *)&cFormat + sizeof(cFormat);
    571     MBlk.b_cont = &MBlkCont;
    572     MBlk.b_rptr = (unsigned char *)&IOCBlk;
    573     MBlkCont.b_rptr = (unsigned char *)&IOCBlk + sizeof(IOCBlk);
    574     MBlk.b_datap = &DBlk;
    575     rc = vbgr0SolWPut(WR(&aQueues[0]), &MBlk);
    576     RTTEST_CHECK(hTest, rc == 0);
    577     vbgr0SolClose(RD(&aQueues[1]), 0, NULL);
     607    for (i = 0; i < RT_ELEMENTS(g_asTestWPut); ++i)
     608    {
     609        unsigned char acData[1024];
     610
     611        RT_ZERO(aQueues);
     612        doInitQueues(&aQueues[0]);
     613        rc = vbgr0SolOpen(RD(&aQueues[0]), &device, 0, 0, NULL);
     614        RTTEST_CHECK_MSG(hTest, rc == 0, (hTest, "i=%u, rc=%d\n", i, rc));
     615        RTTEST_CHECK_MSG(hTest,    g_aOpenNodeStates[1].pWriteQueue
     616                                == WR(&aQueues[0]), (hTest, "i=%u\n", i));
     617        RT_ZERO(MBlk);
     618        RT_ZERO(DBlk);
     619        RT_ZERO(IOCBlk);
     620        RT_ZERO(MBlkCont);
     621        DBlk.db_type = g_asTestWPut[i].iDBType;
     622        IOCBlk.ioc_cmd = g_asTestWPut[i].iIOCCmd;
     623        IOCBlk.ioc_count = g_asTestWPut[i].cbData;
     624        AssertReturnVoid(g_asTestWPut[i].cbDataIn <= sizeof(acData));
     625        memcpy(acData, g_asTestWPut[i].pvDataIn, g_asTestWPut[i].cbDataIn);
     626        MBlkCont.b_rptr = acData;
     627        MBlkCont.b_wptr = acData + g_asTestWPut[i].cbDataIn;
     628        MBlk.b_cont = &MBlkCont;
     629        MBlk.b_rptr = (unsigned char *)&IOCBlk;
     630        MBlk.b_wptr = (unsigned char *)&IOCBlk + sizeof(IOCBlk);
     631        MBlk.b_datap = &DBlk;
     632        rc = vbgr0SolWPut(WR(&aQueues[0]), &MBlk);
     633        RTTEST_CHECK_MSG(hTest, rc == g_asTestWPut[i].rcExp,
     634                         (hTest, "i=%u, rc=%d\n", i, rc));
     635        RTTEST_CHECK_MSG(hTest, IOCBlk.ioc_count == g_asTestWPut[i].cbDataOut,
     636                         (hTest, "i=%u, ioc_count=%u\n", i, IOCBlk.ioc_count));
     637        RTTEST_CHECK_MSG(hTest, !memcmp(acData, g_asTestWPut[i].pvDataOut,
     638                                        g_asTestWPut[i].cbDataOut),
     639                         (hTest, "i=%u\n", i));
     640        if (g_asTestWPut[i].pfnExtra)
     641            g_asTestWPut[i].pfnExtra(hTest, WR(&aQueues[0]), &MBlk);
     642        vbgr0SolClose(RD(&aQueues[1]), 0, NULL);
     643    }
    578644}
    579645#endif
     
    599665 * IOCtl handler function.
    600666 * @returns 0 on success, error code on failure.
    601  * @param cCmd      The IOCtl command number.
     667 * @param iCmd      The IOCtl command number.
    602668 * @param pvData    Buffer for the user data.
    603669 * @param cbBuffer  Size of the buffer in @a pvData or zero.
     
    608674 *                  implemention.
    609675 */
    610 typedef int FNVBGR0SOLIOCTL(PVBGR0STATE pState, int cCmd, void *pvData,
     676typedef int FNVBGR0SOLIOCTL(PVBGR0STATE pState, int iCmd, void *pvData,
    611677                            size_t cbBuffer, size_t *pcbData, int *prc);
    612678typedef FNVBGR0SOLIOCTL *PFNVBGR0SOLIOCTL;
     
    615681static int vbgr0SolHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    616682                               PFNVBGR0SOLIOCTL pfnHandler,
    617                                int cCmd, size_t cbTransparent,
     683                               int iCmd, size_t cbTransparent,
    618684                               enum IOCTLDIRECTION enmDirection);
    619 static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     685static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int iCmd, void *pvData,
    620686                             size_t cbBuffer, size_t *pcbData, int *prc);
    621 static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     687static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int iCmd, void *pvData,
    622688                              size_t cbBuffer, size_t *pcbData, int *prc);
    623689
     
    626692{
    627693    /** The IOCtl number. */
    628     int cCmd;
     694    int iCmd;
    629695    /** The size of the buffer which needs to be copied between user and kernel
    630696     * space, or zero if unknown (must be known for tranparent IOCtls). */
     
    660726{
    661727    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
    662     int cCmd = pIOCBlk->ioc_cmd, cCmdType = (cCmd >> 8) & ~0xff;
     728    int iCmd = pIOCBlk->ioc_cmd, iCmdType = iCmd & ~0xff;
    663729    size_t cbBuffer;
    664730    enum IOCTLDIRECTION enmDirection;
    665731
    666     LogFlowFunc((DEVICE_NAME "::cCmdType=%c, cCmd=%d\n", cCmdType, cCmd));
    667     switch (cCmdType)
     732    LogFlowFunc((DEVICE_NAME "::iCmdType=%c, iCmd=%d\n", iCmdType, iCmd));
     733    switch (iCmdType)
    668734    {
    669735        case MSIOC:
     
    673739           
    674740            for (i = 0; i < RT_ELEMENTS(g_aVUIDIOCtlDescriptions); ++i)
    675                 if (g_aVUIDIOCtlDescriptions[i].cCmd == cCmd)
     741                if (g_aVUIDIOCtlDescriptions[i].iCmd == iCmd)
    676742                {
    677743                    cbBuffer     = g_aVUIDIOCtlDescriptions[i].cbBuffer;
    678744                    enmDirection = g_aVUIDIOCtlDescriptions[i].enmDirection;
    679745                    return vbgr0SolHandleIOCtl(pWriteQueue, pMBlk,
    680                                                vbgr0SolVUIDIOCtl, cCmd,
     746                                               vbgr0SolVUIDIOCtl, iCmd,
    681747                                               cbBuffer, enmDirection);
    682748                }
    683749            return EINVAL;
    684750        }
    685         case 'V':
     751        case 'V' << 8:
    686752            return vbgr0SolHandleIOCtl(pWriteQueue, pMBlk, vbgr0SolGuestIOCtl,
    687                                        cCmd, 0, UNSPECIFIED);
     753                                       iCmd, 0, UNSPECIFIED);
    688754        default:
    689755            return ENOTTY;
     
    694760/* Helpers for vbgr0SolHandleIOCtl. */
    695761static int vbgr0SolHandleIOCtlData(queue_t *pWriteQueue, mblk_t *pMBlk,
    696                                    PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     762                                   PFNVBGR0SOLIOCTL pfnHandler, int iCmd,
    697763                                   size_t cbTransparent,
    698764                                   enum IOCTLDIRECTION enmDirection);
     
    700766static int vbgr0SolHandleTransparentIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    701767                                          PFNVBGR0SOLIOCTL pfnHandler,
    702                                           int cCmd, size_t cbTransparent,
     768                                          int iCmd, size_t cbTransparent,
    703769                                          enum IOCTLDIRECTION enmDirection);
    704770
    705771static int vbgr0SolHandleIStrIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    706                                    PFNVBGR0SOLIOCTL pfnHandler, int cCmd);
     772                                   PFNVBGR0SOLIOCTL pfnHandler, int iCmd);
    707773
    708774/**
     
    719785 * @param  pfnHandler     pointer to the right IOCtl handler function for this
    720786 *                        IOCtl number.
    721  * @param  cCmd           IOCtl command number.
     787 * @param  iCmd           IOCtl command number.
    722788 * @param  cbTransparent  size of the user space buffer for this IOCtl number,
    723789 *                        used for processing transparent IOCtls.  Pass zero
     
    728794 */
    729795static int vbgr0SolHandleIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    730                                PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     796                               PFNVBGR0SOLIOCTL pfnHandler, int iCmd,
    731797                               size_t cbTransparent,
    732798                               enum IOCTLDIRECTION enmDirection)
     
    736802
    737803    if (pMBlk->b_datap->db_type == M_IOCDATA)
    738         return vbgr0SolHandleIOCtlData(pWriteQueue, pMBlk, pfnHandler, cCmd,
     804        return vbgr0SolHandleIOCtlData(pWriteQueue, pMBlk, pfnHandler, iCmd,
    739805                                       cbTransparent, enmDirection);
    740806    else if (   pMBlk->b_datap->db_type == M_IOCTL
    741807             && pIOCBlk->ioc_count == TRANSPARENT)
    742808        return vbgr0SolHandleTransparentIOCtl(pWriteQueue, pMBlk, pfnHandler,
    743                                               cCmd, cbTransparent,
     809                                              iCmd, cbTransparent,
    744810                                              enmDirection);
    745811    else if (pMBlk->b_datap->db_type == M_IOCTL)
    746         return vbgr0SolHandleIStrIOCtl(pWriteQueue, pMBlk, pfnHandler, cCmd);
     812        return vbgr0SolHandleIStrIOCtl(pWriteQueue, pMBlk, pfnHandler, iCmd);
    747813    return EINVAL;
    748814}
     
    756822 */
    757823static int vbgr0SolHandleIOCtlData(queue_t *pWriteQueue, mblk_t *pMBlk,
    758                                    PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     824                                   PFNVBGR0SOLIOCTL pfnHandler, int iCmd,
    759825                                   size_t cbTransparent,
    760826                                   enum IOCTLDIRECTION enmDirection)
     
    781847            return EINVAL;
    782848        pvData = pMBlk->b_cont->b_rptr;
    783         err = pfnHandler(pState, cCmd, pvData, cbTransparent, &cbData, NULL);
     849        err = pfnHandler(pState, iCmd, pvData, cbTransparent, &cbData, NULL);
    784850        if (!err && enmDirection == BOTH)
    785851            mcopyout(pMBlk, NULL, cbData, pCopyResp->cp_private, NULL);
     
    803869 */
    804870int vbgr0SolHandleTransparentIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    805                                    PFNVBGR0SOLIOCTL pfnHandler, int cCmd,
     871                                   PFNVBGR0SOLIOCTL pfnHandler, int iCmd,
    806872                                   size_t cbTransparent,
    807873                                   enum IOCTLDIRECTION enmDirection)
     
    830896            return EAGAIN;
    831897        pvData = pMBlkOut->b_rptr;
    832         err = pfnHandler(pState, cCmd, pvData, cbTransparent, &cbData, NULL);
     898        err = pfnHandler(pState, iCmd, pvData, cbTransparent, &cbData, NULL);
    833899        if (!err)
    834900            mcopyout(pMBlk, NULL, cbData, NULL, pMBlkOut);
     
    839905    {
    840906        AssertReturn(enmDirection == NONE, EINVAL);
    841         err = pfnHandler(pState, cCmd, NULL, 0, NULL, &rc);
     907        err = pfnHandler(pState, iCmd, NULL, 0, NULL, &rc);
    842908        if (!err)
    843909            miocack(pWriteQueue, pMBlk, 0, rc);
     
    852918 */
    853919static int vbgr0SolHandleIStrIOCtl(queue_t *pWriteQueue, mblk_t *pMBlk,
    854                                    PFNVBGR0SOLIOCTL pfnHandler, int cCmd)
     920                                   PFNVBGR0SOLIOCTL pfnHandler, int iCmd)
    855921{
    856922    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
     
    871937        pvData = pMBlk->b_cont->b_rptr;
    872938    }
    873     err = pfnHandler(pState, cCmd, pvData, cbBuffer, &cbData, &rc);
     939    err = pfnHandler(pState, iCmd, pvData, cbBuffer, &cbData, &rc);
    874940    if (!err)
    875941        miocack(pWriteQueue, pMBlk, cbData, rc);
     
    882948 * @copydoc FNVBGR0SOLIOCTL
    883949 */
    884 static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     950static int vbgr0SolVUIDIOCtl(PVBGR0STATE pState, int iCmd, void *pvData,
    885951                             size_t cbBuffer, size_t *pcbData, int *prc)
    886952{
    887953    LogFlowFunc((DEVICE_NAME ":: " /* no '\n' */));
    888     switch (cCmd)
     954    switch (iCmd)
    889955    {
    890956        case VUIDGFORMAT:
     
    9601026            return EINVAL;
    9611027        default:
    962             LogFlowFunc(("Invalid IOCtl command %x\n", cCmd));
     1028            LogFlowFunc(("Invalid IOCtl command %x\n", iCmd));
    9631029            return EINVAL;
    9641030    }
     
    9701036 * @copydoc FNVBGR0SOLIOCTL
    9711037 */
    972 static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int cCmd, void *pvData,
     1038static int vbgr0SolGuestIOCtl(PVBGR0STATE pState, int iCmd, void *pvData,
    9731039                              size_t cbBuffer, size_t *pcbData, int *prc)
    9741040{
    975     int rc = VBoxGuestCommonIOCtl(cCmd, &g_DevExt, pState->pSession, pvData, cbBuffer, pcbData);
     1041    int rc = VBoxGuestCommonIOCtl(iCmd, &g_DevExt, pState->pSession, pvData, cbBuffer, pcbData);
    9761042    if (RT_SUCCESS(rc))
    9771043    {
     
    9861052         * which are not really failures that require logging.
    9871053         */
    988         Log((DEVICE_NAME "::IOCtl: VBoxGuestCommonIOCtl failed. Cmd=%#x rc=%d\n", cCmd, rc));
     1054        Log((DEVICE_NAME "::IOCtl: VBoxGuestCommonIOCtl failed. Cmd=%#x rc=%d\n", iCmd, rc));
    9891055        rc = RTErrConvertToErrno(rc);
    9901056        return rc;
  • trunk/src/VBox/Additions/common/VBoxGuest/testcase/solaris.h

    r40533 r40550  
    322322#define flushq(...) do {} while(0)
    323323#define qreply(...) do {} while(0)
    324 #define miocack(...) do {} while(0)
    325 #define miocnak(...) do {} while(0)
    326324#define mcopyin(...) do {} while(0)
    327325#define mcopyout(...) do {} while(0)
     
    388386}
    389387
     388static inline void miocack(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData,
     389                           int rc)
     390{
     391    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
     392
     393    pMBlk->b_datap->db_type = M_IOCACK;
     394    pIOCBlk->ioc_count = cbData;
     395    pIOCBlk->ioc_error = 0;
     396    pIOCBlk->ioc_rval = rc;
     397    qreply(pWriteQueue, pMBlk);
     398}
     399
     400static inline void miocnak(queue_t *pWriteQueue, mblk_t *pMBlk, int cbData,
     401                           int iErr)
     402{
     403    struct iocblk *pIOCBlk = (struct iocblk *)pMBlk->b_rptr;
     404
     405    pMBlk->b_datap->db_type = M_IOCNAK;
     406    pIOCBlk->ioc_count = cbData;
     407    pIOCBlk->ioc_error = iErr;
     408    qreply(pWriteQueue, pMBlk);
     409}
     410
    390411/* API stubs with controllable logic */
    391412
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