VirtualBox

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


Ignore:
Timestamp:
Jun 21, 2022 7:42:54 PM (2 years ago)
Author:
vboxsync
Message:

tstGuestPropSvc: Unbroke testcase after notification changes, service set properties and whatnot. bugref:10185

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp

    r95329 r95331  
    4747};
    4848
     49/** Dummy helper callback. */
     50static DECLCALLBACK(int) tstHlpInfoDeregister(void *pvInstance, const char *pszName)
     51{
     52    RT_NOREF(pvInstance, pszName);
     53    return VINF_SUCCESS;
     54}
     55
     56/** Dummy helper callback. */
     57static DECLCALLBACK(int) tstHlpInfoRegister(void *pvInstance, const char *pszName, const char *pszDesc,
     58                                            PFNDBGFHANDLEREXT pfnHandler, void *pvUser)
     59{
     60    RT_NOREF(pvInstance, pszName, pszDesc, pfnHandler, pvUser);
     61    return VINF_SUCCESS;
     62}
     63
    4964/** Call completion callback for guest calls. */
    5065static DECLCALLBACK(int) callComplete(VBOXHGCMCALLHANDLE callHandle, int32_t rc)
     
    6176void initTable(VBOXHGCMSVCFNTABLE *pTable, VBOXHGCMSVCHELPERS *pHelpers)
    6277{
    63     pTable->cbSize              = sizeof (VBOXHGCMSVCFNTABLE);
     78    RT_ZERO(*pHelpers);
     79    pHelpers->pfnCallComplete   = callComplete;
     80    pHelpers->pfnInfoRegister   = tstHlpInfoRegister;
     81    pHelpers->pfnInfoDeregister = tstHlpInfoDeregister;
     82
     83    RT_ZERO(*pTable);
     84    pTable->cbSize              = sizeof(VBOXHGCMSVCFNTABLE);
    6485    pTable->u32Version          = VBOX_HGCM_SVC_VERSION;
    65     pHelpers->pfnCallComplete   = callComplete;
    6686    pTable->pHelpers            = pHelpers;
    6787}
     
    235255}
    236256
     257#if 0
    237258/** Result strings for zeroth enumeration test */
    238259static const char *g_apchEnumResult0[] =
     
    264285           "TEST NAME\0TEST VALUE\0""999999\0RDONLYHOST\0"
    265286           "/test/name\0/test/value\0""999999999999\0RDONLYGUEST\0\0\0\0\0") - 1;
     287#endif
    266288
    267289/** Result strings for first and second enumeration test */
     
    293315    /** The enumeration pattern to test */
    294316    const char     *pszPatterns;
    295     /** The size of the pattern string */
    296     const uint32_t  cchPatterns;
     317    /** The size of the pattern string (including terminator) */
     318    const uint32_t  cbPatterns;
    297319    /** The expected enumeration output strings */
    298320    const char    **papchResult;
     
    303325}   g_aEnumStrings[] =
    304326{
     327#if 0 /* unpredictable automatic variables set by the service now */
    305328    {
    306329        "", sizeof(""),
     
    309332        g_cbEnumBuffer0
    310333    },
    311     {
    312         "/*\0?E*", sizeof("/*\0?E*"),
     334#endif
     335    {
     336        "/t*\0?E*", sizeof("/t*\0?E*"),
    313337        g_apchEnumResult1,
    314338        g_acbEnumResult1,
     
    316340    },
    317341    {
    318         "/*|?E*", sizeof("/*|?E*"),
     342        "/t*|?E*", sizeof("/t*|?E*"),
    319343        g_apchEnumResult1,
    320344        g_acbEnumResult1,
     
    340364
    341365        /* Check that we get buffer overflow with a too small buffer. */
    342         HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cchPatterns);
     366        HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cbPatterns);
    343367        HGCMSvcSetPv(&aParms[1], (void *)abBuffer, g_aEnumStrings[i].cbBuffer - 1);
    344368        memset(abBuffer, 0x55, sizeof(abBuffer));
     
    350374            if (RT_SUCCESS(rc2))
    351375                RTTESTI_CHECK_MSG(cbNeeded == g_aEnumStrings[i].cbBuffer,
    352                                   ("expected %u, got %u, pattern %d\n", g_aEnumStrings[i].cbBuffer, cbNeeded, i));
     376                                  ("expected %#x, got %#x, pattern %d\n", g_aEnumStrings[i].cbBuffer, cbNeeded, i));
    353377        }
    354378        else
     
    356380
    357381        /* Make a successfull call. */
    358         HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cchPatterns);
     382        HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cbPatterns);
    359383        HGCMSvcSetPv(&aParms[1], (void *)abBuffer, g_aEnumStrings[i].cbBuffer);
    360384        memset(abBuffer, 0x55, sizeof(abBuffer));
     
    366390            {
    367391                bool found = false;
    368                 for (unsigned k = 0; !found && k <   g_aEnumStrings[i].cbBuffer
    369                                                    - g_aEnumStrings[i].pacchResult[j];
    370                      ++k)
    371                     if (memcmp(abBuffer + k, g_aEnumStrings[i].papchResult[j],
    372                         g_aEnumStrings[i].pacchResult[j]) == 0)
     392                for (unsigned k = 0; !found && k < g_aEnumStrings[i].cbBuffer - g_aEnumStrings[i].pacchResult[j]; ++k)
     393                    if (memcmp(abBuffer + k, g_aEnumStrings[i].papchResult[j], g_aEnumStrings[i].pacchResult[j]) == 0)
    373394                        found = true;
    374395                if (!found)
     
    399420                  bool useSetProp)
    400421{
     422    RTThreadSleep(1); /* stupid, stupid timestamp fudge to avoid asserting in getOldNotification() */
     423
    401424    VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS };
    402425    int command = GUEST_PROP_FN_SET_PROP_VALUE;
     
    534557        /** Should this succeed or be rejected with VERR_PERMISSION_DENIED? */
    535558        bool isAllowed;
    536     }
    537     s_aDelProperties[] =
     559    } s_aDelProperties[] =
    538560    {
    539561        { "Red", false, true },
     
    549571    for (unsigned i = 0; i < RT_ELEMENTS(s_aDelProperties); ++i)
    550572    {
    551         int rc = doDelProp(pTable, s_aDelProperties[i].pcszName,
    552                            s_aDelProperties[i].isHost);
     573        int rc = doDelProp(pTable, s_aDelProperties[i].pcszName, s_aDelProperties[i].isHost);
    553574        if (s_aDelProperties[i].isAllowed && RT_FAILURE(rc))
    554575            RTTestIFailed("Deleting property '%s' failed with rc=%Rrc.",
     
    666687g_aGetNotifications[] =
    667688{
    668     { "Red\0Stop!\0TRANSIENT", sizeof("Red\0Stop!\0TRANSIENT") },
    669     { "Amber\0Caution!\0", sizeof("Amber\0Caution!\0") },
    670     { "Green\0Go!\0READONLY", sizeof("Green\0Go!\0READONLY") },
    671     { "Blue\0What on earth...?\0", sizeof("Blue\0What on earth...?\0") },
    672     { "/VirtualBox/GuestAdd/SomethingElse\0test\0",
    673       sizeof("/VirtualBox/GuestAdd/SomethingElse\0test\0") },
    674     { "/VirtualBox/GuestAdd/SharedFolders/MountDir\0test\0RDONLYGUEST",
    675       sizeof("/VirtualBox/GuestAdd/SharedFolders/MountDir\0test\0RDONLYGUEST") },
    676     { "/VirtualBox/HostInfo/VRDP/Client/1/Name\0test\0TRANSIENT, RDONLYGUEST, TRANSRESET",
    677       sizeof("/VirtualBox/HostInfo/VRDP/Client/1/Name\0test\0TRANSIENT, RDONLYGUEST, TRANSRESET") },
    678     { "Red\0\0", sizeof("Red\0\0") },
    679     { "Amber\0\0", sizeof("Amber\0\0") },
     689    // Name\0Value\0Flags\0fWasDeleted\0
     690#define STR_AND_SIZE(a_sz) { a_sz, sizeof(a_sz) }
     691    STR_AND_SIZE("Red\0Stop!\0TRANSIENT\0" "0"), /* first test is used by testAsyncNotification, - testGetNotification skips it. (mess) */
     692    STR_AND_SIZE("Red\0Stop!\0TRANSIENT\0" "1"),
     693    STR_AND_SIZE("Amber\0Caution!\0\0" "1"),
     694    STR_AND_SIZE("Green\0Go!\0READONLY\0" "0"),
     695    STR_AND_SIZE("Blue\0What on earth...?\0\0" "0"),
     696    STR_AND_SIZE("/VirtualBox/GuestAdd/SomethingElse\0test\0\0" "0"),
     697    STR_AND_SIZE("/VirtualBox/GuestAdd/SharedFolders/MountDir\0test\0RDONLYGUEST\0" "0"),
     698    STR_AND_SIZE("/VirtualBox/HostInfo/VRDP/Client/1/Name\0test\0TRANSIENT, RDONLYGUEST, TRANSRESET\0" "0"),
     699    STR_AND_SIZE("Red\0\0\0" "1"),
     700    STR_AND_SIZE("Amber\0\0\0" "1"),
     701#undef STR_AND_SIZE
    680702};
    681703
     
    690712
    691713    /* Test "buffer too small" */
    692     static char                 s_szPattern[] = "";
     714    static char                 s_szPattern[] = "/VirtualBox/GuestAdd/*|/VirtualBox/HostInfo/VRDP/Client*|Red*|Amber*|Green*|Blue*";
    693715    VBOXHGCMCALLHANDLE_TYPEDEF  callHandle = { VINF_SUCCESS };
    694716    VBOXHGCMSVCPARM             aParms[4];
    695     uint32_t                    cbRetNeeded;
     717    uint32_t                    cbRetNeeded = 0;
    696718
    697719    for (uint32_t cbBuf = 1;
    698          cbBuf < g_aGetNotifications[0].cbBuffer - 1;
     720         cbBuf < g_aGetNotifications[1].cbBuffer - 1;
    699721         cbBuf++)
    700722    {
     
    703725        memset(pvBuf, 0x55, cbBuf);
    704726
    705         HGCMSvcSetPv(&aParms[0], (void *)s_szPattern, sizeof(s_szPattern));
     727        HGCMSvcSetStr(&aParms[0], s_szPattern);
    706728        HGCMSvcSetU64(&aParms[1], 1);
    707729        HGCMSvcSetPv(&aParms[2], pvBuf, cbBuf);
     
    710732        if (   callHandle.rc != VERR_BUFFER_OVERFLOW
    711733            || RT_FAILURE(HGCMSvcGetU32(&aParms[3], &cbRetNeeded))
    712             || cbRetNeeded != g_aGetNotifications[0].cbBuffer
     734            || cbRetNeeded != g_aGetNotifications[1].cbBuffer
    713735           )
    714         {
    715             RTTestIFailed("Getting notification for property '%s' with a too small buffer did not fail correctly: %Rrc",
    716                           g_aGetNotifications[0].pchBuffer, callHandle.rc);
    717         }
     736            RTTestIFailed("Getting notification for property '%s' with a too small buffer did not fail correctly: rc=%Rrc, cbRetNeeded=%#x (expected %#x)",
     737                          g_aGetNotifications[1].pchBuffer, callHandle.rc, cbRetNeeded, g_aGetNotifications[1].cbBuffer);
    718738        RTTestGuardedFree(g_hTest, pvBuf);
    719739    }
     
    722742     * to get the oldest available notification. */
    723743    uint64_t u64Timestamp = 1;
    724     for (unsigned i = 0; i < RT_ELEMENTS(g_aGetNotifications); ++i)
     744    for (unsigned i = 1; i < RT_ELEMENTS(g_aGetNotifications); ++i)
    725745    {
    726746        uint32_t cbBuf = g_aGetNotifications[i].cbBuffer + _1K;
     
    729749        memset(pvBuf, 0x55, cbBuf);
    730750
    731         HGCMSvcSetPv(&aParms[0], (void *)s_szPattern, sizeof(s_szPattern));
     751        HGCMSvcSetStr(&aParms[0], s_szPattern);
    732752        HGCMSvcSetU64(&aParms[1], u64Timestamp);
    733753        HGCMSvcSetPv(&aParms[2], pvBuf, cbBuf);
     
    741761           )
    742762        {
    743             RTTestIFailed("Failed to get notification for property '%s' (rc=%Rrc).",
    744                           g_aGetNotifications[i].pchBuffer, callHandle.rc);
     763            RTTestIFailed("Failed to get notification for property '%s' (#%u): rc=%Rrc (expected %Rrc), cbRetNeeded=%#x (expected %#x)\n"
     764                          "%.*Rhxd\n---expected:---\n%.*Rhxd",
     765                          g_aGetNotifications[i].pchBuffer, i, callHandle.rc, i == 0 ? VWRN_NOT_FOUND : VINF_SUCCESS,
     766                          cbRetNeeded, g_aGetNotifications[i].cbBuffer, RT_MIN(cbRetNeeded, cbBuf), pvBuf,
     767                          g_aGetNotifications[i].cbBuffer, g_aGetNotifications[i].pchBuffer);
    745768        }
    746769        RTTestGuardedFree(g_hTest, pvBuf);
     
    767790    static char s_szPattern[] = "";
    768791
    769     HGCMSvcSetPv(&g_AsyncNotification.aParms[0], (void *)s_szPattern, sizeof(s_szPattern));
     792    HGCMSvcSetStr(&g_AsyncNotification.aParms[0], s_szPattern);
    770793    HGCMSvcSetU64(&g_AsyncNotification.aParms[1], 0);
    771     HGCMSvcSetPv(&g_AsyncNotification.aParms[2], (void *)g_AsyncNotification.abBuffer,
    772                  sizeof(g_AsyncNotification.abBuffer));
     794    HGCMSvcSetPv(&g_AsyncNotification.aParms[2], g_AsyncNotification.abBuffer, sizeof(g_AsyncNotification.abBuffer));
    773795    g_AsyncNotification.callHandle.rc = VINF_HGCM_ASYNC_EXECUTE;
    774796    pTable->pfnCall(pTable->pvService, &g_AsyncNotification.callHandle, 0, NULL,
     
    787809    RT_NOREF1(pTable);
    788810    uint64_t u64Timestamp;
    789     uint32_t u32Size;
     811    uint32_t cb;
    790812    if (   g_AsyncNotification.callHandle.rc != VINF_SUCCESS
    791813        || RT_FAILURE(HGCMSvcGetU64(&g_AsyncNotification.aParms[1], &u64Timestamp))
    792         || RT_FAILURE(HGCMSvcGetU32(&g_AsyncNotification.aParms[3], &u32Size))
    793         || u32Size != g_aGetNotifications[0].cbBuffer
    794         || memcmp(g_AsyncNotification.abBuffer, g_aGetNotifications[0].pchBuffer, u32Size) != 0
     814        || RT_FAILURE(HGCMSvcGetU32(&g_AsyncNotification.aParms[3], &cb))
     815        || cb != g_aGetNotifications[0].cbBuffer
     816        || memcmp(g_AsyncNotification.abBuffer, g_aGetNotifications[0].pchBuffer, cb) != 0
    795817       )
    796818    {
    797         RTTestIFailed("Asynchronous GET_NOTIFICATION call did not complete as expected, rc=%Rrc.",
    798                       g_AsyncNotification.callHandle.rc);
     819        RTTestIFailed("Asynchronous GET_NOTIFICATION call did not complete as expected: rc=%Rrc, cb=%#x (expected %#x)\n"
     820                      "abBuffer=%.*Rhxs\n"
     821                      "expected=%.*Rhxs",
     822                      g_AsyncNotification.callHandle.rc, cb, g_aGetNotifications[0].cbBuffer,
     823                      cb, g_AsyncNotification.abBuffer, g_aGetNotifications[0].cbBuffer, g_aGetNotifications[0].pchBuffer);
    799824    }
    800825}
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