Changeset 95331 in vbox for trunk/src/VBox/HostServices
- Timestamp:
- Jun 21, 2022 7:42:54 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostServices/GuestProperties/testcase/tstGuestPropSvc.cpp
r95329 r95331 47 47 }; 48 48 49 /** Dummy helper callback. */ 50 static DECLCALLBACK(int) tstHlpInfoDeregister(void *pvInstance, const char *pszName) 51 { 52 RT_NOREF(pvInstance, pszName); 53 return VINF_SUCCESS; 54 } 55 56 /** Dummy helper callback. */ 57 static 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 49 64 /** Call completion callback for guest calls. */ 50 65 static DECLCALLBACK(int) callComplete(VBOXHGCMCALLHANDLE callHandle, int32_t rc) … … 61 76 void initTable(VBOXHGCMSVCFNTABLE *pTable, VBOXHGCMSVCHELPERS *pHelpers) 62 77 { 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); 64 85 pTable->u32Version = VBOX_HGCM_SVC_VERSION; 65 pHelpers->pfnCallComplete = callComplete;66 86 pTable->pHelpers = pHelpers; 67 87 } … … 235 255 } 236 256 257 #if 0 237 258 /** Result strings for zeroth enumeration test */ 238 259 static const char *g_apchEnumResult0[] = … … 264 285 "TEST NAME\0TEST VALUE\0""999999\0RDONLYHOST\0" 265 286 "/test/name\0/test/value\0""999999999999\0RDONLYGUEST\0\0\0\0\0") - 1; 287 #endif 266 288 267 289 /** Result strings for first and second enumeration test */ … … 293 315 /** The enumeration pattern to test */ 294 316 const char *pszPatterns; 295 /** The size of the pattern string */296 const uint32_t c chPatterns;317 /** The size of the pattern string (including terminator) */ 318 const uint32_t cbPatterns; 297 319 /** The expected enumeration output strings */ 298 320 const char **papchResult; … … 303 325 } g_aEnumStrings[] = 304 326 { 327 #if 0 /* unpredictable automatic variables set by the service now */ 305 328 { 306 329 "", sizeof(""), … … 309 332 g_cbEnumBuffer0 310 333 }, 311 { 312 "/*\0?E*", sizeof("/*\0?E*"), 334 #endif 335 { 336 "/t*\0?E*", sizeof("/t*\0?E*"), 313 337 g_apchEnumResult1, 314 338 g_acbEnumResult1, … … 316 340 }, 317 341 { 318 "/ *|?E*", sizeof("/*|?E*"),342 "/t*|?E*", sizeof("/t*|?E*"), 319 343 g_apchEnumResult1, 320 344 g_acbEnumResult1, … … 340 364 341 365 /* Check that we get buffer overflow with a too small buffer. */ 342 HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].c chPatterns);366 HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cbPatterns); 343 367 HGCMSvcSetPv(&aParms[1], (void *)abBuffer, g_aEnumStrings[i].cbBuffer - 1); 344 368 memset(abBuffer, 0x55, sizeof(abBuffer)); … … 350 374 if (RT_SUCCESS(rc2)) 351 375 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)); 353 377 } 354 378 else … … 356 380 357 381 /* Make a successfull call. */ 358 HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].c chPatterns);382 HGCMSvcSetPv(&aParms[0], (void *)g_aEnumStrings[i].pszPatterns, g_aEnumStrings[i].cbPatterns); 359 383 HGCMSvcSetPv(&aParms[1], (void *)abBuffer, g_aEnumStrings[i].cbBuffer); 360 384 memset(abBuffer, 0x55, sizeof(abBuffer)); … … 366 390 { 367 391 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) 373 394 found = true; 374 395 if (!found) … … 399 420 bool useSetProp) 400 421 { 422 RTThreadSleep(1); /* stupid, stupid timestamp fudge to avoid asserting in getOldNotification() */ 423 401 424 VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS }; 402 425 int command = GUEST_PROP_FN_SET_PROP_VALUE; … … 534 557 /** Should this succeed or be rejected with VERR_PERMISSION_DENIED? */ 535 558 bool isAllowed; 536 } 537 s_aDelProperties[] = 559 } s_aDelProperties[] = 538 560 { 539 561 { "Red", false, true }, … … 549 571 for (unsigned i = 0; i < RT_ELEMENTS(s_aDelProperties); ++i) 550 572 { 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); 553 574 if (s_aDelProperties[i].isAllowed && RT_FAILURE(rc)) 554 575 RTTestIFailed("Deleting property '%s' failed with rc=%Rrc.", … … 666 687 g_aGetNotifications[] = 667 688 { 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 680 702 }; 681 703 … … 690 712 691 713 /* Test "buffer too small" */ 692 static char s_szPattern[] = " ";714 static char s_szPattern[] = "/VirtualBox/GuestAdd/*|/VirtualBox/HostInfo/VRDP/Client*|Red*|Amber*|Green*|Blue*"; 693 715 VBOXHGCMCALLHANDLE_TYPEDEF callHandle = { VINF_SUCCESS }; 694 716 VBOXHGCMSVCPARM aParms[4]; 695 uint32_t cbRetNeeded ;717 uint32_t cbRetNeeded = 0; 696 718 697 719 for (uint32_t cbBuf = 1; 698 cbBuf < g_aGetNotifications[ 0].cbBuffer - 1;720 cbBuf < g_aGetNotifications[1].cbBuffer - 1; 699 721 cbBuf++) 700 722 { … … 703 725 memset(pvBuf, 0x55, cbBuf); 704 726 705 HGCMSvcSet Pv(&aParms[0], (void *)s_szPattern, sizeof(s_szPattern));727 HGCMSvcSetStr(&aParms[0], s_szPattern); 706 728 HGCMSvcSetU64(&aParms[1], 1); 707 729 HGCMSvcSetPv(&aParms[2], pvBuf, cbBuf); … … 710 732 if ( callHandle.rc != VERR_BUFFER_OVERFLOW 711 733 || RT_FAILURE(HGCMSvcGetU32(&aParms[3], &cbRetNeeded)) 712 || cbRetNeeded != g_aGetNotifications[ 0].cbBuffer734 || cbRetNeeded != g_aGetNotifications[1].cbBuffer 713 735 ) 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); 718 738 RTTestGuardedFree(g_hTest, pvBuf); 719 739 } … … 722 742 * to get the oldest available notification. */ 723 743 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) 725 745 { 726 746 uint32_t cbBuf = g_aGetNotifications[i].cbBuffer + _1K; … … 729 749 memset(pvBuf, 0x55, cbBuf); 730 750 731 HGCMSvcSet Pv(&aParms[0], (void *)s_szPattern, sizeof(s_szPattern));751 HGCMSvcSetStr(&aParms[0], s_szPattern); 732 752 HGCMSvcSetU64(&aParms[1], u64Timestamp); 733 753 HGCMSvcSetPv(&aParms[2], pvBuf, cbBuf); … … 741 761 ) 742 762 { 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); 745 768 } 746 769 RTTestGuardedFree(g_hTest, pvBuf); … … 767 790 static char s_szPattern[] = ""; 768 791 769 HGCMSvcSet Pv(&g_AsyncNotification.aParms[0], (void *)s_szPattern, sizeof(s_szPattern));792 HGCMSvcSetStr(&g_AsyncNotification.aParms[0], s_szPattern); 770 793 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)); 773 795 g_AsyncNotification.callHandle.rc = VINF_HGCM_ASYNC_EXECUTE; 774 796 pTable->pfnCall(pTable->pvService, &g_AsyncNotification.callHandle, 0, NULL, … … 787 809 RT_NOREF1(pTable); 788 810 uint64_t u64Timestamp; 789 uint32_t u32Size;811 uint32_t cb; 790 812 if ( g_AsyncNotification.callHandle.rc != VINF_SUCCESS 791 813 || RT_FAILURE(HGCMSvcGetU64(&g_AsyncNotification.aParms[1], &u64Timestamp)) 792 || RT_FAILURE(HGCMSvcGetU32(&g_AsyncNotification.aParms[3], & u32Size))793 || u32Size!= g_aGetNotifications[0].cbBuffer794 || memcmp(g_AsyncNotification.abBuffer, g_aGetNotifications[0].pchBuffer, u32Size) != 0814 || 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 795 817 ) 796 818 { 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); 799 824 } 800 825 }
Note:
See TracChangeset
for help on using the changeset viewer.