VirtualBox

Ignore:
Timestamp:
Nov 11, 2008 7:16:32 PM (16 years ago)
Author:
vboxsync
Message:

HostServices/GuestProperties: fixed the GET_NOTIFICATION protocol

Location:
trunk/src/VBox/HostServices/GuestProperties/testcase
Files:
2 edited

Legend:

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

    r13916 r14104  
    3434tstGuestPropSvc_SOURCES  = tstGuestPropSvc.cpp ../service.cpp
    3535tstGuestPropSvc_LIBS     = $(LIB_RUNTIME)
     36# For now!
     37tstGuestPropSvc_CXXFLAGS.win = -EHsc
    3638
    3739# Set this in LocalConfig.kmk if you are working on the guest property service
  • trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp

    r13971 r14104  
    241241
    242242/** Result string sizes for zeroth enumeration test */
    243 static const size_t cchEnumResult0[] =
     243static const uint32_t cchEnumResult0[] =
    244244{
    245245    sizeof("test/name/\0test/value/\0""0\0"),
     
    254254 * the - 1 at the end is because of the hidden zero terminator
    255255 */
    256 static const size_t cchEnumBuffer0 =
     256static const uint32_t cchEnumBuffer0 =
    257257sizeof("test/name/\0test/value/\0""0\0\0"
    258258"test name\0test value\0""999\0TRANSIENT, READONLY\0"
     
    269269
    270270/** Result string sizes for first and second enumeration test */
    271 static const size_t cchEnumResult1[] =
     271static const uint32_t cchEnumResult1[] =
    272272{
    273273    sizeof("TEST NAME\0TEST VALUE\0""999999\0RDONLYHOST"),
     
    280280 * the - 1 at the end is because of the hidden zero terminator
    281281 */
    282 static const size_t cchEnumBuffer1 =
     282static const uint32_t cchEnumBuffer1 =
    283283sizeof("TEST NAME\0TEST VALUE\0""999999\0RDONLYHOST\0"
    284284"/test/name\0/test/value\0""999999999999\0RDONLYGUEST\0\0\0\0\0") - 1;
     
    289289    const char *pcszPatterns;
    290290    /** The size of the pattern string */
    291     const size_t cchPatterns;
     291    const uint32_t cchPatterns;
    292292    /** The expected enumeration output strings */
    293293    const char **ppcchResult;
    294294    /** The size of the output strings */
    295     const size_t *pcchResult;
     295    const uint32_t *pcchResult;
    296296    /** The size of the buffer needed for the enumeration */
    297     const size_t cchBuffer;
     297    const uint32_t cchBuffer;
    298298}
    299299enumStrings[] =
     
    693693    VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS };
    694694    char chBuffer[MAX_NAME_LEN + MAX_VALUE_LEN + MAX_FLAGS_LEN];
     695    static char szPattern[] = "";
    695696
    696697    RTPrintf("Testing the GET_NOTIFICATION call.\n");
    697     uint64_t u64Timestamp = 0;
     698    uint64_t u64Timestamp;
    698699    uint32_t u32Size = 0;
    699     VBOXHGCMSVCPARM paParms[3];
     700    VBOXHGCMSVCPARM paParms[4];
    700701
    701702    /* Test "buffer too small" */
    702     paParms[0].setUInt64 (u64Timestamp);
    703     paParms[1].setPointer ((void *) chBuffer, getNotifications[0].cchBuffer - 1);
     703    u64Timestamp = 1;
     704    paParms[0].setPointer ((void *) szPattern, sizeof(szPattern));
     705    paParms[1].setUInt64 (u64Timestamp);
     706    paParms[2].setPointer ((void *) chBuffer, getNotifications[0].cchBuffer - 1);
    704707    pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL,
    705                     GET_NOTIFICATION, 3, paParms);
     708                    GET_NOTIFICATION, 4, paParms);
    706709    if (   callHandle.rc != VERR_BUFFER_OVERFLOW
    707         || RT_FAILURE(paParms[2].getUInt32 (&u32Size))
     710        || RT_FAILURE(paParms[3].getUInt32 (&u32Size))
    708711        || u32Size != getNotifications[0].cchBuffer
    709712       )
     
    714717    }
    715718
    716     /* Test successful notification queries */
     719    /* Test successful notification queries.  Start with an unknown timestamp
     720     * to get the oldest available notification. */
     721    u64Timestamp = 1;
    717722    for (unsigned i = 0; RT_SUCCESS(rc) && (getNotifications[i].pchBuffer != NULL);
    718723         ++i)
    719724    {
    720         paParms[0].setUInt64 (u64Timestamp);
    721         paParms[1].setPointer ((void *) chBuffer, sizeof(chBuffer));
     725        paParms[0].setPointer ((void *) szPattern, sizeof(szPattern));
     726        paParms[1].setUInt64 (u64Timestamp);
     727        paParms[2].setPointer ((void *) chBuffer, sizeof(chBuffer));
    722728        pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL,
    723                         GET_NOTIFICATION, 3, paParms);
     729                        GET_NOTIFICATION, 4, paParms);
    724730        if (   RT_FAILURE(callHandle.rc)
    725             || RT_FAILURE(paParms[0].getUInt64 (&u64Timestamp))
    726             || RT_FAILURE(paParms[2].getUInt32 (&u32Size))
     731            || (i == 0 && callHandle.rc != VWRN_NOT_FOUND)
     732            || RT_FAILURE(paParms[1].getUInt64 (&u64Timestamp))
     733            || RT_FAILURE(paParms[3].getUInt32 (&u32Size))
    727734            || u32Size != getNotifications[i].cchBuffer
    728735            || memcmp(chBuffer, getNotifications[i].pchBuffer, u32Size) != 0
     
    734741        }
    735742    }
    736 
    737     /* Test a query with an unknown timestamp */
    738     paParms[0].setUInt64 (1);
    739     paParms[1].setPointer ((void *) chBuffer, sizeof(chBuffer));
    740     if (RT_SUCCESS(rc))
    741         pTable->pfnCall(pTable->pvService, &callHandle, 0, NULL,
    742                         GET_NOTIFICATION, 3, paParms);
    743     if (   RT_SUCCESS(rc)
    744         && (   callHandle.rc != VWRN_NOT_FOUND
    745             || RT_FAILURE(callHandle.rc)
    746             || RT_FAILURE(paParms[0].getUInt64 (&u64Timestamp))
    747             || RT_FAILURE(paParms[2].getUInt32 (&u32Size))
    748             || u32Size != getNotifications[0].cchBuffer
    749             || memcmp(chBuffer, getNotifications[0].pchBuffer, u32Size) != 0
    750            )
    751        )
    752     {
    753         RTPrintf("Problem getting notification for property '%s' with unknown timestamp, rc=%Rrc.\n",
    754                  getNotifications[0].pchBuffer, callHandle.rc);
    755         rc = VERR_UNRESOLVED_ERROR;
    756     }
    757743    return rc;
    758744}
    759745
    760 /**
    761  * Test the GET_NOTIFICATION function when no notifications are available.
     746/** Paramters for the asynchronous guest notification call */
     747struct asyncNotification_
     748{
     749    /** Call parameters */
     750    VBOXHGCMSVCPARM aParms[4];
     751    /** Result buffer */
     752    char chBuffer[MAX_NAME_LEN + MAX_VALUE_LEN + MAX_FLAGS_LEN];
     753    /** Return value */
     754    VBOXHGCMCALLHANDLE_TYPEDEF callHandle;
     755} asyncNotification;
     756
     757/**
     758 * Set up the test for the asynchronous GET_NOTIFICATION function.
    762759 * @returns iprt status value to indicate whether the test went as expected.
    763760 * @note    prints its own diagnostic information to stdout.
    764761 */
    765 int testNoNotifications(VBOXHGCMSVCFNTABLE *pTable, VBOXHGCMCALLHANDLE_TYPEDEF *callHandle,
    766                         VBOXHGCMSVCPARM *paParms, char *pchBuffer, size_t cchBuffer)
     762int setupAsyncNotification(VBOXHGCMSVCFNTABLE *pTable)
    767763{
    768764    int rc = VINF_SUCCESS;
     
    771767    uint64_t u64Timestamp = 0;
    772768    uint32_t u32Size = 0;
    773 
    774     paParms[0].setUInt64 (u64Timestamp);
    775     paParms[1].setPointer ((void *) pchBuffer, cchBuffer);
    776     callHandle->rc = VINF_HGCM_ASYNC_EXECUTE;
    777     pTable->pfnCall(pTable->pvService, callHandle, 0, NULL,
    778                     GET_NOTIFICATION, 3, paParms);
    779     if (callHandle->rc != VINF_HGCM_ASYNC_EXECUTE)
    780     {
    781         RTPrintf("GET_NOTIFICATION call completed when new notifications should be available.\n");
     769    static char szPattern[] = "";
     770
     771    asyncNotification.aParms[0].setPointer ((void *) szPattern, sizeof(szPattern));
     772    asyncNotification.aParms[1].setUInt64 (u64Timestamp);
     773    asyncNotification.aParms[2].setPointer ((void *) asyncNotification.chBuffer,
     774                                            sizeof(asyncNotification.chBuffer));
     775    asyncNotification.callHandle.rc = VINF_HGCM_ASYNC_EXECUTE;
     776    pTable->pfnCall(pTable->pvService, &asyncNotification.callHandle, 0, NULL,
     777                    GET_NOTIFICATION, 4, asyncNotification.aParms);
     778    if (RT_FAILURE(asyncNotification.callHandle.rc))
     779    {
     780        RTPrintf("GET_NOTIFICATION call failed, rc=%Rrc.\n", asyncNotification.callHandle.rc);
     781        rc = VERR_UNRESOLVED_ERROR;
     782    }
     783    else if (asyncNotification.callHandle.rc != VINF_HGCM_ASYNC_EXECUTE)
     784    {
     785        RTPrintf("GET_NOTIFICATION call completed when no new notifications should be available.\n");
     786        rc = VERR_UNRESOLVED_ERROR;
     787    }
     788    return rc;
     789}
     790
     791/**
     792 * Test the asynchronous GET_NOTIFICATION function.
     793 * @returns iprt status value to indicate whether the test went as expected.
     794 * @note    prints its own diagnostic information to stdout.
     795 */
     796int testAsyncNotification(VBOXHGCMSVCFNTABLE *pTable)
     797{
     798    int rc = VINF_SUCCESS;
     799    uint64_t u64Timestamp;
     800    uint32_t u32Size;
     801    if (   asyncNotification.callHandle.rc != VINF_SUCCESS
     802        || RT_FAILURE(asyncNotification.aParms[1].getUInt64 (&u64Timestamp))
     803        || RT_FAILURE(asyncNotification.aParms[3].getUInt32 (&u32Size))
     804        || u32Size != getNotifications[0].cchBuffer
     805        || memcmp(asyncNotification.chBuffer, getNotifications[0].pchBuffer, u32Size) != 0
     806       )
     807    {
     808        RTPrintf("Asynchronous GET_NOTIFICATION call did not complete as expected, rc=%Rrc\n",
     809                 asyncNotification.callHandle.rc);
    782810        rc = VERR_UNRESOLVED_ERROR;
    783811    }
     
    789817    VBOXHGCMSVCFNTABLE svcTable;
    790818    VBOXHGCMSVCHELPERS svcHelpers;
    791     /* Paramters for the asynchronous guest notification call */
    792     VBOXHGCMSVCPARM aParm[3];
    793     char chBuffer[MAX_NAME_LEN + MAX_VALUE_LEN + MAX_FLAGS_LEN];
    794     VBOXHGCMCALLHANDLE_TYPEDEF callHandleStruct;
    795819
    796820    initTable(&svcTable, &svcHelpers);
     
    808832    if (RT_FAILURE(testEnumPropsHost(&svcTable)))
    809833        return 1;
    810     /* Asynchronous notification call */
    811     if (RT_FAILURE(testNoNotifications(&svcTable, &callHandleStruct, aParm,
    812                    chBuffer, sizeof(chBuffer))))
     834    /* Set up the asynchronous notification test */
     835    if (RT_FAILURE(setupAsyncNotification(&svcTable)))
    813836        return 1;
    814837    if (RT_FAILURE(testSetProp(&svcTable)))
     
    816839    RTPrintf("Checking the data returned by the asynchronous notification call.\n");
    817840    /* Our previous notification call should have completed by now. */
    818     uint64_t u64Timestamp;
    819     uint32_t u32Size;
    820     if (   callHandleStruct.rc != VINF_SUCCESS
    821         || RT_FAILURE(aParm[0].getUInt64 (&u64Timestamp))
    822         || RT_FAILURE(aParm[2].getUInt32 (&u32Size))
    823         || u32Size != getNotifications[0].cchBuffer
    824         || memcmp(chBuffer, getNotifications[0].pchBuffer, u32Size) != 0
    825        )
    826     {
    827         RTPrintf("Asynchronous GET_NOTIFICATION call did not complete as expected, rc=%Rrc\n",
    828                  callHandleStruct.rc);
    829         return 1;
    830     }
     841    if (RT_FAILURE(testAsyncNotification(&svcTable)))
     842        return 1;
    831843    if (RT_FAILURE(testDelProp(&svcTable)))
    832844        return 1;
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