Changeset 69183 in vbox
- Timestamp:
- Oct 23, 2017 6:47:18 PM (7 years ago)
- Location:
- trunk/src/VBox/Devices
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Makefile.kmk
r69162 r69183 1352 1352 PROGRAMS += tstDevice 1353 1353 tstDevice_TEMPLATE = VBOXR3TSTEXE 1354 tstDevice_DEFS += IN_SUP_R3 1354 1355 tstDevice_LIBS.linux = $(PATH_STAGE_BIN)/tstDeviceVBoxVMMStubs.so 1355 1356 tstDevice_LIBS.darwin = $(PATH_STAGE_BIN)/tstDeviceVBoxVMMStubs.dylib … … 1359 1360 testcase/tstDevice.cpp \ 1360 1361 testcase/tstDevicePdmDevHlp.cpp \ 1361 testcase/tstDeviceVMM.cpp 1362 testcase/tstDeviceVMM.cpp \ 1363 testcase/tstDeviceSUP.cpp 1362 1364 endif 1363 1365 -
trunk/src/VBox/Devices/testcase/tstDevice.cpp
r69162 r69183 22 22 #define LOG_GROUP LOG_GROUP_DEFAULT /** @todo */ 23 23 #include <VBox/types.h> 24 #include <VBox/sup.h> 24 25 #include <VBox/version.h> 25 26 #include <iprt/assert.h> … … 774 775 * @returns VBox status code. 775 776 * @param pThis The device under test instance. 776 * @param pszR0Mod The R0 module. 777 * @param pszMod The module name. 778 * @param enmModType The module type if the module needs to be loaded. 777 779 * @param pszSymbol The symbol to resolve. 778 780 * @param ppfn Where to store the value on success. 779 781 */ 780 DECLHIDDEN(int) tstDevPdmLdrGetSymbol(P DEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType,782 DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType, 781 783 const char *pszSymbol, PFNRT *ppfn) 782 784 { … … 809 811 810 812 813 static TSTDEVCFGITEM s_aTestcaseCfg[] = 814 { 815 {"CtrlMemBufSize", TSTDEVCFGITEMTYPE_INTEGER, "0" }, 816 {NULL, TSTDEVCFGITEMTYPE_INVALID, NULL } 817 }; 818 811 819 static TSTDEVTESTCASEREG s_TestcaseDef = 812 820 { 813 821 "test", 814 822 "Testcase during implementation", 815 " serial",823 "nvme", 816 824 0, 817 NULL,825 &s_aTestcaseCfg[0], 818 826 NULL, 819 827 }; … … 832 840 { 833 841 TSTDEVDUTINT Dut; 834 Dut.pTestcaseReg = &s_TestcaseDef; 835 Dut.enmCtx = TSTDEVDUTCTX_R3; 842 Dut.pTestcaseReg = &s_TestcaseDef; 843 Dut.enmCtx = TSTDEVDUTCTX_R3; 844 Dut.pVm = NULL; 845 Dut.SupSession.pDut = &Dut; 836 846 RTListInit(&Dut.LstIoPorts); 837 847 RTListInit(&Dut.LstTimers); 848 RTListInit(&Dut.LstMmHeap); 849 RTListInit(&Dut.LstPdmThreads); 850 RTListInit(&Dut.SupSession.LstSupSem); 838 851 CFGMNODE Cfg; 839 852 Cfg.pVmmCallbacks = &g_tstDevVmmCallbacks; 840 853 Cfg.pDut = &Dut; 854 855 rc = RTCritSectRwInit(&Dut.CritSectLists); 856 AssertRC(rc); 841 857 842 858 PPDMDEVINS pDevIns = (PPDMDEVINS)RTMemAllocZ(RT_OFFSETOF(PDMDEVINS, achInstanceData[pPdmDev->pReg->cbInstance])); … … 884 900 rc = tstDevPdmLoadMod(argv[1], TSTDEVPDMMODTYPE_R3); 885 901 if (RT_SUCCESS(rc)) 886 rc = tstDevPdmDevCreate(" serial");902 rc = tstDevPdmDevCreate("nvme"); 887 903 else 888 904 rcExit = RTEXITCODE_FAILURE; -
trunk/src/VBox/Devices/testcase/tstDeviceInternal.h
r69162 r69183 30 30 #include <iprt/assert.h> 31 31 #include <iprt/list.h> 32 #include <iprt/semaphore.h> 32 33 33 34 #include "tstDevicePlugin.h" … … 35 36 36 37 RT_C_DECLS_BEGIN 38 39 40 /** Converts PDM device instance to the device under test structure. */ 41 #define TSTDEV_PDMDEVINS_2_DUT(a_pDevIns) ((a_pDevIns)->Internal.s.pDut) 37 42 38 43 /** … … 77 82 /** Opaque user data - R0. */ 78 83 void *pvUserR0; 79 /** Out handler - R 3. */84 /** Out handler - R0. */ 80 85 PFNIOMIOPORTOUT pfnOutR0; 81 /** In handler - R 3. */86 /** In handler - R0. */ 82 87 PFNIOMIOPORTIN pfnInR0; 83 /** Out string handler - R 3. */88 /** Out string handler - R0. */ 84 89 PFNIOMIOPORTOUTSTRING pfnOutStrR0; 85 /** In string handler - R 3. */90 /** In string handler - R0. */ 86 91 PFNIOMIOPORTINSTRING pfnInStrR0; 87 92 88 /** @todo: RC */ 93 #ifdef TSTDEV_SUPPORTS_RC 94 /** Opaque user data - RC. */ 95 void *pvUserRC; 96 /** Out handler - RC. */ 97 PFNIOMIOPORTOUT pfnOutRC; 98 /** In handler - RC. */ 99 PFNIOMIOPORTIN pfnInRC; 100 /** Out string handler - RC. */ 101 PFNIOMIOPORTOUTSTRING pfnOutStrRC; 102 /** In string handler - RC. */ 103 PFNIOMIOPORTINSTRING pfnInStrRC; 104 #endif 89 105 } RTDEVDUTIOPORT; 90 106 /** Pointer to a registered I/O port handler. */ … … 92 108 /** Pointer to a const I/O port handler. */ 93 109 typedef const RTDEVDUTIOPORT *PCRTDEVDUTIOPORT; 110 111 /** 112 * The Support Driver session state. 113 */ 114 typedef struct TSTDEVSUPDRVSESSION 115 { 116 /** Pointer to the owning device under test instance. */ 117 PTSTDEVDUTINT pDut; 118 /** List of event semaphores. */ 119 RTLISTANCHOR LstSupSem; 120 } TSTDEVSUPDRVSESSION; 121 /** Pointer to the Support Driver session state. */ 122 typedef TSTDEVSUPDRVSESSION *PTSTDEVSUPDRVSESSION; 123 124 /** Converts a Support Driver session handle to the internal state. */ 125 #define TSTDEV_PSUPDRVSESSION_2_PTSTDEVSUPDRVSESSION(a_pSession) ((PTSTDEVSUPDRVSESSION)(a_pSession)) 126 /** Converts the internal session state to a Support Driver session handle. */ 127 #define TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(a_pSession) ((PSUPDRVSESSION)(a_pSession)) 128 129 /** 130 * Support driver event semaphore. 131 */ 132 typedef struct TSTDEVSUPSEMEVENT 133 { 134 /** Node for the event semaphore list. */ 135 RTLISTNODE NdSupSem; 136 /** Flag whether this is multi event semaphore. */ 137 bool fMulti; 138 /** Event smeaphore handles depending on the flag above. */ 139 union 140 { 141 RTSEMEVENT hSemEvt; 142 RTSEMEVENTMULTI hSemEvtMulti; 143 } u; 144 } TSTDEVSUPSEMEVENT; 145 /** Pointer to a support event semaphore state. */ 146 typedef TSTDEVSUPSEMEVENT *PTSTDEVSUPSEMEVENT; 147 148 /** Converts a Support event semaphore handle to the internal state. */ 149 #define TSTDEV_SUPSEMEVENT_2_PTSTDEVSUPSEMEVENT(a_pSupSemEvt) ((PTSTDEVSUPSEMEVENT)(a_pSupSemEvt)) 150 /** Converts the internal session state to a Support event semaphore handle. */ 151 #define TSTDEV_PTSTDEVSUPSEMEVENT_2_SUPSEMEVENT(a_pSupSemEvt) ((SUPSEMEVENT)(a_pSupSemEvt)) 94 152 95 153 /** … … 111 169 112 170 /** 171 * PCI region descriptor. 172 */ 173 typedef struct TSTDEVDUTPCIREGION 174 { 175 /** Size of the region. */ 176 RTGCPHYS cbRegion; 177 /** Address space type. */ 178 PCIADDRESSSPACE enmType; 179 /** Region mapping callback. */ 180 PFNPCIIOREGIONMAP pfnRegionMap; 181 } TSTDEVDUTPCIREGION; 182 /** Pointer to a PCI region descriptor. */ 183 typedef TSTDEVDUTPCIREGION *PTSTDEVDUTPCIREGION; 184 /** Pointer to a const PCI region descriptor. */ 185 typedef const TSTDEVDUTPCIREGION *PCTSTDEVDUTPCIREGION; 186 187 /** 113 188 * Device under test instance data. 114 189 */ … … 121 196 /** Current device context. */ 122 197 TSTDEVDUTCTX enmCtx; 198 /** Critical section protecting the lists below. */ 199 RTCRITSECTRW CritSectLists; 123 200 /** List of registered I/O port handlers. */ 124 201 RTLISTANCHOR LstIoPorts; 125 202 /** List of timers registered. */ 126 203 RTLISTANCHOR LstTimers; 204 /** List of registered MMIO regions. */ 205 RTLISTANCHOR LstMmio; 206 /** List of MM Heap allocations. */ 207 RTLISTANCHOR LstMmHeap; 208 /** List of PDM threads. */ 209 RTLISTANCHOR LstPdmThreads; 210 /** The SUP session we emulate. */ 211 TSTDEVSUPDRVSESSION SupSession; 212 /** The VM state assoicated with this device. */ 213 PVM pVm; 214 /** The registered PCI device instance if this is a PCI device. */ 215 PPDMPCIDEV pPciDev; 216 /** PCI Region descriptors. */ 217 TSTDEVDUTPCIREGION aPciRegions[VBOX_PCI_NUM_REGIONS]; 127 218 } TSTDEVDUTINT; 128 /** Pointer to the internal device under test instance data. */ 129 typedef TSTDEVDUTINT *PDEVDUTINT; 130 131 DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PDEVDUTINT pThis, const char *pszR0Mod, TSTDEVPDMMODTYPE enmModType, 219 220 221 DECLHIDDEN(int) tstDevPdmLdrGetSymbol(PTSTDEVDUTINT pThis, const char *pszMod, TSTDEVPDMMODTYPE enmModType, 132 222 const char *pszSymbol, PFNRT *ppfn); 133 223 224 225 DECLINLINE(int) tstDevDutLockShared(PTSTDEVDUTINT pThis) 226 { 227 return RTCritSectRwEnterShared(&pThis->CritSectLists); 228 } 229 230 DECLINLINE(int) tstDevDutUnlockShared(PTSTDEVDUTINT pThis) 231 { 232 return RTCritSectRwLeaveShared(&pThis->CritSectLists); 233 } 234 235 DECLINLINE(int) tstDevDutLockExcl(PTSTDEVDUTINT pThis) 236 { 237 return RTCritSectRwEnterExcl(&pThis->CritSectLists); 238 } 239 240 DECLINLINE(int) tstDevDutUnlockExcl(PTSTDEVDUTINT pThis) 241 { 242 return RTCritSectRwLeaveExcl(&pThis->CritSectLists); 243 } 244 134 245 RT_C_DECLS_END 135 246 -
trunk/src/VBox/Devices/testcase/tstDevicePdmDevHlp.cpp
r69162 r69183 25 25 #include <VBox/vmm/pdmpci.h> 26 26 27 #include <iprt/assert.h> 27 28 #include <iprt/mem.h> 28 29 … … 125 126 pDevIns->pReg->szName, pDevIns->iInstance, Port, cPorts, pvUser, pszOut, pszOut, pszIn, pszIn, pszOutStr, pszOutStr, pszInStr, pszInStr, pszDesc, pszDesc)); 126 127 127 P DEVDUTINT pThis = pDevIns->Internal.s.pDut;128 PTSTDEVDUTINT pThis = pDevIns->Internal.s.pDut; 128 129 PRTDEVDUTIOPORT pIoPort; 129 130 int rc = VERR_NOT_FOUND; … … 551 552 pDevIns->pReg->szName, pDevIns->iInstance)); 552 553 553 P SUPDRVSESSION pSession = 0;554 AssertFailed();554 PTSTDEVDUTINT pThis = TSTDEV_PDMDEVINS_2_DUT(pDevIns); 555 PSUPDRVSESSION pSession = TSTDEV_PTSTDEVSUPDRVSESSION_2_PSUPDRVSESSION(&pThis->SupSession); 555 556 556 557 LogFlow(("pdmR3DevHlp_GetSupDrvSession: caller='%s'/%d: returns %#p\n", pDevIns->pReg->szName, pDevIns->iInstance, pSession)); … … 703 704 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb)); 704 705 706 PTSTDEVDUTINT pThis = TSTDEV_PDMDEVINS_2_DUT(pDevIns); 707 705 708 void *pv = NULL; 706 AssertFailed(); 709 PTSTDEVMMHEAPALLOC pHeapAlloc = (PTSTDEVMMHEAPALLOC)RTMemAllocZ(cb + sizeof(TSTDEVMMHEAPALLOC) - 1); 710 if (pHeapAlloc) 711 { 712 /* Poison */ 713 memset(&pHeapAlloc->abAlloc[0], 0xfe, cb); 714 pHeapAlloc->cbAlloc = cb; 715 pHeapAlloc->pVmmCallbacks = pDevIns->Internal.s.pVmmCallbacks; 716 pHeapAlloc->pDut = pThis; 717 718 tstDevDutLockExcl(pThis); 719 RTListAppend(&pThis->LstMmHeap, &pHeapAlloc->NdMmHeap); 720 tstDevDutUnlockExcl(pThis); 721 722 pv = &pHeapAlloc->abAlloc[0]; 723 } 707 724 708 725 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv)); … … 717 734 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: cb=%#x\n", pDevIns->pReg->szName, pDevIns->iInstance, cb)); 718 735 719 void *pv = NULL; 720 AssertFailed(); 736 void *pv = pdmR3DevHlp_MMHeapAlloc(pDevIns, cb); 737 if (VALID_PTR(pv)) 738 memset(pv, 0, cb); 721 739 722 740 LogFlow(("pdmR3DevHlp_MMHeapAllocZ: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv)); … … 728 746 static DECLCALLBACK(void) pdmR3DevHlp_MMHeapFree(PPDMDEVINS pDevIns, void *pv) 729 747 { 730 PDMDEV_ASSERT_DEVINS(pDevIns); RT_NOREF_PV(pDevIns);748 PDMDEV_ASSERT_DEVINS(pDevIns); 731 749 LogFlow(("pdmR3DevHlp_MMHeapFree: caller='%s'/%d: pv=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv)); 732 750 733 AssertFailed();751 MMR3HeapFree(pv); 734 752 735 753 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance)); … … 935 953 ("'%s'/%d: Invalid flags: %#x\n", pDevIns->pReg->szName, pDevIns->iInstance, fFlags), 936 954 VERR_INVALID_FLAGS); 937 int rc = V ERR_NOT_IMPLEMENTED;938 AssertFailed();955 int rc = VINF_SUCCESS; 956 pDevIns->Internal.s.pDut->pPciDev = pPciDev; 939 957 940 958 LogFlow(("pdmR3DevHlp_PCIRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 950 968 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, pMsiReg, pMsiReg->cMsiVectors, pMsiReg->cMsixVectors)); 951 969 952 int rc = VERR_NOT_IMPLEMENTED; 953 AssertFailed(); 970 int rc = VERR_NOT_SUPPORTED; /** @todo */ 954 971 955 972 LogFlow(("pdmR3DevHlp_PCIRegisterMsi: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 966 983 pDevIns->pReg->szName, pDevIns->iInstance, pPciDev, pPciDev->uDevFn, iRegion, cbRegion, enmType, pfnCallback)); 967 984 968 int rc = VERR_NOT_IMPLEMENTED; 969 AssertFailed(); 985 AssertLogRelMsgReturn(iRegion < VBOX_PCI_NUM_REGIONS, 986 ("Region %u exceeds maximum region index %u\n", iRegion, VBOX_PCI_NUM_REGIONS), 987 VERR_INVALID_PARAMETER); 988 989 int rc = VINF_SUCCESS; 990 PTSTDEVDUTINT pThis = TSTDEV_PDMDEVINS_2_DUT(pDevIns); 991 PTSTDEVDUTPCIREGION pRegion = &pThis->aPciRegions[iRegion]; 992 pRegion->cbRegion = cbRegion; 993 pRegion->enmType = enmType; 994 pRegion->pfnRegionMap = pfnCallback; 970 995 971 996 LogFlow(("pdmR3DevHlp_PCIIORegionRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 1489 1514 { 1490 1515 PDMDEV_ASSERT_DEVINS(pDevIns); 1491 AssertFailed(); 1516 PTSTDEVDUTINT pThis = TSTDEV_PDMDEVINS_2_DUT(pDevIns); 1517 PVM pVM = pThis->pVm; 1492 1518 LogFlow(("pdmR3DevHlp_GetVM: caller='%s'/%d: returns %p\n", pDevIns->pReg->szName, pDevIns->iInstance, NULL)); 1493 return NULL;1519 return pVM; 1494 1520 } 1495 1521 -
trunk/src/VBox/Devices/testcase/tstDeviceVMM.cpp
r69162 r69183 24 24 #include <VBox/version.h> 25 25 #include <VBox/vmm/pdmpci.h> 26 27 #include <iprt/mem.h> 26 28 27 29 #include "tstDeviceInternal.h" … … 274 276 static DECLCALLBACK(int) tstDevVmm_CFGMR3QueryString(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString) 275 277 { 276 RT_NOREF(pNode, pszName, pszString, cchString); 277 AssertFailed(); 278 return VERR_NOT_IMPLEMENTED; 278 if (!pNode) 279 return VERR_CFGM_NO_PARENT; 280 281 PCTSTDEVCFGITEM pCfgItem; 282 int rc = tstDev_CfgmR3ResolveItem(pNode->pDut->pTestcaseReg->paDevCfg, pszName, &pCfgItem); 283 if (RT_SUCCESS(rc)) 284 { 285 switch (pCfgItem->enmType) 286 { 287 case TSTDEVCFGITEMTYPE_STRING: 288 { 289 size_t cchVal = strlen(pCfgItem->pszVal); 290 if (cchString <= cchVal + 1) 291 memcpy(pszString, pCfgItem->pszVal, cchVal); 292 else 293 rc = VERR_CFGM_NOT_ENOUGH_SPACE; 294 break; 295 } 296 case TSTDEVCFGITEMTYPE_INTEGER: 297 case TSTDEVCFGITEMTYPE_BYTES: 298 default: 299 rc = VERR_CFGM_IPE_1; 300 AssertMsgFailed(("Invalid value type %d\n", pCfgItem->enmType)); 301 break; 302 } 303 } 304 else 305 rc = VERR_CFGM_VALUE_NOT_FOUND; 306 307 return rc; 279 308 } 280 309 … … 371 400 static DECLCALLBACK(void) tstDevVmm_MMR3HeapFree(void *pv) 372 401 { 373 RT_NOREF(pv); 374 AssertFailed(); 402 PTSTDEVMMHEAPALLOC pHeapAlloc = (PTSTDEVMMHEAPALLOC)((uint8_t *)pv - RT_OFFSETOF(TSTDEVMMHEAPALLOC, abAlloc[0])); 403 PTSTDEVDUTINT pThis = pHeapAlloc->pDut; 404 405 tstDevDutLockExcl(pThis); 406 RTListNodeRemove(&pHeapAlloc->NdMmHeap); 407 tstDevDutUnlockExcl(pThis); 408 409 /* Poison */ 410 memset(&pHeapAlloc->abAlloc[0], 0xfc, pHeapAlloc->cbAlloc); 411 RTMemFree(pHeapAlloc); 375 412 } 376 413 -
trunk/src/VBox/Devices/testcase/tstDeviceVMMInternal.h
r69162 r69183 162 162 { 163 163 /** Pointer to the callback table. */ 164 PCTSTDEVVMMCALLBACKS pVmmCallbacks; 165 /** @todo: */ 164 PCTSTDEVVMMCALLBACKS pVmmCallbacks; 165 /** Pointer to the device under test. */ 166 PTSTDEVDUTINT pDut; 167 /** Node for the list of PDM threads. */ 168 RTLISTNODE NdPdmThreads; 166 169 } PDMTHREADINT; 167 170 AssertCompile(sizeof(PDMTHREADINT) <= 64); 171 172 /** 173 * MM Heap allocation. 174 */ 175 typedef struct TSTDEVMMHEAPALLOC 176 { 177 /** Node for the list of allocations. */ 178 RTLISTNODE NdMmHeap; 179 /** Pointer to the callback table. */ 180 PCTSTDEVVMMCALLBACKS pVmmCallbacks; 181 /** Pointer to the device under test the allocation was made for. */ 182 PTSTDEVDUTINT pDut; 183 /** Size of the allocation. */ 184 size_t cbAlloc; 185 /** Align the next member on a 16byte boundary. */ 186 size_t uAlignment0; 187 /** Start of the real allocation. */ 188 uint8_t abAlloc[RT_FLEXIBLE_ARRAY]; 189 } TSTDEVMMHEAPALLOC; 190 /** Pointer to a MM Heap allocation. */ 191 typedef TSTDEVMMHEAPALLOC *PTSTDEVMMHEAPALLOC; 192 /** Pointer to a const MM Heap allocation. */ 193 typedef const TSTDEVMMHEAPALLOC *PCTSTDEVMMHEAPALLOC; 194 195 AssertCompileMemberAlignment(TSTDEVMMHEAPALLOC, abAlloc, HC_ARCH_BITS == 64 ? 16 : 8); 168 196 169 197 #if 0 -
trunk/src/VBox/Devices/testcase/tstDeviceVMMStubs.cpp
r69162 r69183 614 614 VMMR3DECL(void) MMR3HeapFree(void *pv) 615 615 { 616 RTMemFree(pv); /** @todo */ 616 PTSTDEVMMHEAPALLOC pHeapAlloc = (PTSTDEVMMHEAPALLOC)((uint8_t *)pv - RT_OFFSETOF(TSTDEVMMHEAPALLOC, abAlloc[0])); 617 pHeapAlloc->pVmmCallbacks->pfnMMR3HeapFree(pv); 617 618 } 618 619
Note:
See TracChangeset
for help on using the changeset viewer.