Changeset 82902 in vbox for trunk/src/VBox/Devices/testcase/tstDevicePdmDevHlp.cpp
- Timestamp:
- Jan 29, 2020 10:03:17 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/testcase/tstDevicePdmDevHlp.cpp
r82883 r82902 43 43 AssertPtr(pDevIns); \ 44 44 Assert(pDevIns->u32Version == PDM_DEVINS_VERSION); \ 45 Assert(pDevIns->CTX_SUFF(pvInstanceData ) == (void *)&pDevIns->achInstanceData[0]); \45 Assert(pDevIns->CTX_SUFF(pvInstanceDataFor) == (void *)&pDevIns->achInstanceData[0]); \ 46 46 } while (0) 47 47 #else … … 50 50 51 51 52 /** Frequency of the real clock. */ 53 #define TMCLOCK_FREQ_REAL UINT32_C(1000) 54 /** Frequency of the virtual clock. */ 55 #define TMCLOCK_FREQ_VIRTUAL UINT32_C(1000000000) 56 52 57 /********************************************************************************************************************************* 53 58 * Structures and Typedefs * … … 66 71 *********************************************************************************************************************************/ 67 72 73 74 /** 75 * Resolves a path reference to a configuration item. 76 * 77 * @returns VBox status code. 78 * @param paDevCfg The array of config items. 79 * @param pszName Name of a byte string value. 80 * @param ppItem Where to store the pointer to the item. 81 */ 82 static int tstDev_CfgmR3ResolveItem(PCTSTDEVCFGITEM paDevCfg, const char *pszName, PCTSTDEVCFGITEM *ppItem) 83 { 84 *ppItem = NULL; 85 if (!paDevCfg) 86 return VERR_CFGM_VALUE_NOT_FOUND; 87 88 size_t cchName = strlen(pszName); 89 PCTSTDEVCFGITEM pDevCfgItem = paDevCfg; 90 while (pDevCfgItem->pszKey != NULL) 91 { 92 size_t cchKey = strlen(pDevCfgItem->pszKey); 93 if (cchName == cchKey) 94 { 95 int iDiff = memcmp(pszName, pDevCfgItem->pszKey, cchName); 96 if (iDiff <= 0) 97 { 98 if (iDiff != 0) 99 break; 100 *ppItem = pDevCfgItem; 101 return VINF_SUCCESS; 102 } 103 } 104 105 /* next */ 106 pDevCfgItem++; 107 } 108 return VERR_CFGM_VALUE_NOT_FOUND; 109 } 68 110 69 111 … … 1105 1147 static DECLCALLBACK(uint64_t) pdmR3DevHlp_TimerGetFreq(PPDMDEVINS pDevIns, TMTIMERHANDLE hTimer) 1106 1148 { 1107 RT_NOREF(pDevIns, hTimer); 1108 AssertFailed(); 1109 return 0; 1149 PDMDEV_ASSERT_DEVINS(pDevIns); 1150 1151 PTMTIMERR3 pTimer = (PTMTIMERR3)hTimer; 1152 switch (pTimer->enmClock) 1153 { 1154 case TMCLOCK_VIRTUAL: 1155 case TMCLOCK_VIRTUAL_SYNC: 1156 return TMCLOCK_FREQ_VIRTUAL; 1157 1158 case TMCLOCK_REAL: 1159 return TMCLOCK_FREQ_REAL; 1160 1161 default: 1162 AssertMsgFailed(("Invalid enmClock=%d\n", pTimer->enmClock)); 1163 return 0; 1164 } 1110 1165 } 1111 1166 … … 1327 1382 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQuerySize(PCFGMNODE pNode, const char *pszName, size_t *pcb) 1328 1383 { 1329 RT_NOREF(pNode, pszName, pcb); 1330 AssertFailed(); 1331 return VERR_NOT_IMPLEMENTED; 1384 if (!pNode) 1385 return VERR_CFGM_NO_PARENT; 1386 1387 PCTSTDEVCFGITEM pCfgItem; 1388 int rc = tstDev_CfgmR3ResolveItem(pNode->pDut->pTestcaseReg->paDevCfg, pszName, &pCfgItem); 1389 if (RT_SUCCESS(rc)) 1390 { 1391 switch (pCfgItem->enmType) 1392 { 1393 case TSTDEVCFGITEMTYPE_INTEGER: 1394 *pcb = sizeof(uint64_t); 1395 break; 1396 1397 case TSTDEVCFGITEMTYPE_STRING: 1398 *pcb = strlen(pCfgItem->pszVal) + 1; 1399 break; 1400 1401 case TSTDEVCFGITEMTYPE_BYTES: 1402 AssertFailed(); 1403 break; 1404 1405 default: 1406 rc = VERR_CFGM_IPE_1; 1407 AssertMsgFailed(("Invalid value type %d\n", pCfgItem->enmType)); 1408 break; 1409 } 1410 } 1411 return rc; 1332 1412 } 1333 1413 … … 1335 1415 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryInteger(PCFGMNODE pNode, const char *pszName, uint64_t *pu64) 1336 1416 { 1337 RT_NOREF(pNode, pszName, pu64); 1338 AssertFailed(); 1339 return VERR_NOT_IMPLEMENTED; 1417 if (!pNode) 1418 return VERR_CFGM_NO_PARENT; 1419 1420 PCTSTDEVCFGITEM pCfgItem; 1421 int rc = tstDev_CfgmR3ResolveItem(pNode->pDut->pTestcaseReg->paDevCfg, pszName, &pCfgItem); 1422 if (RT_SUCCESS(rc)) 1423 { 1424 if (pCfgItem->enmType == TSTDEVCFGITEMTYPE_INTEGER) 1425 *pu64 = RTStrToUInt64(pCfgItem->pszVal); 1426 else 1427 rc = VERR_CFGM_NOT_INTEGER; 1428 } 1429 1430 return rc; 1340 1431 } 1341 1432 … … 1343 1434 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryIntegerDef(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def) 1344 1435 { 1345 RT_NOREF(pNode, pszName, pu64, u64Def); 1346 AssertFailed(); 1347 return VERR_NOT_IMPLEMENTED; 1436 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, pu64); 1437 if (RT_FAILURE(rc)) 1438 { 1439 *pu64 = u64Def; 1440 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 1441 rc = VINF_SUCCESS; 1442 } 1443 1444 return rc; 1348 1445 } 1349 1446 … … 1351 1448 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryString(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString) 1352 1449 { 1353 RT_NOREF(pNode, pszName, pszString, cchString); 1354 AssertFailed(); 1355 return VERR_NOT_IMPLEMENTED; 1450 if (!pNode) 1451 return VERR_CFGM_NO_PARENT; 1452 1453 PCTSTDEVCFGITEM pCfgItem; 1454 int rc = tstDev_CfgmR3ResolveItem(pNode->pDut->pTestcaseReg->paDevCfg, pszName, &pCfgItem); 1455 if (RT_SUCCESS(rc)) 1456 { 1457 switch (pCfgItem->enmType) 1458 { 1459 case TSTDEVCFGITEMTYPE_STRING: 1460 { 1461 size_t cchVal = strlen(pCfgItem->pszVal); 1462 if (cchString <= cchVal + 1) 1463 memcpy(pszString, pCfgItem->pszVal, cchVal); 1464 else 1465 rc = VERR_CFGM_NOT_ENOUGH_SPACE; 1466 break; 1467 } 1468 case TSTDEVCFGITEMTYPE_INTEGER: 1469 case TSTDEVCFGITEMTYPE_BYTES: 1470 default: 1471 rc = VERR_CFGM_IPE_1; 1472 AssertMsgFailed(("Invalid value type %d\n", pCfgItem->enmType)); 1473 break; 1474 } 1475 } 1476 else 1477 rc = VERR_CFGM_VALUE_NOT_FOUND; 1478 1479 return rc; 1356 1480 } 1357 1481 … … 1359 1483 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryStringDef(PCFGMNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef) 1360 1484 { 1361 RT_NOREF(pNode, pszName, pszString, cchString, pszDef); 1362 AssertFailed(); 1363 return VERR_NOT_IMPLEMENTED; 1485 int rc = pdmR3DevHlp_CFGMQueryString(pNode, pszName, pszString, cchString); 1486 if (RT_FAILURE(rc) && rc != VERR_CFGM_NOT_ENOUGH_SPACE) 1487 { 1488 size_t cchDef = strlen(pszDef); 1489 if (cchString > cchDef) 1490 { 1491 memcpy(pszString, pszDef, cchDef); 1492 memset(pszString + cchDef, 0, cchString - cchDef); 1493 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 1494 rc = VINF_SUCCESS; 1495 } 1496 else if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 1497 rc = VERR_CFGM_NOT_ENOUGH_SPACE; 1498 } 1499 1500 return rc; 1364 1501 } 1365 1502 … … 1375 1512 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU64(PCFGMNODE pNode, const char *pszName, uint64_t *pu64) 1376 1513 { 1377 RT_NOREF(pNode, pszName, pu64); 1378 AssertFailed(); 1379 return VERR_NOT_IMPLEMENTED; 1514 return pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, pu64); 1380 1515 } 1381 1516 … … 1383 1518 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU64Def(PCFGMNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def) 1384 1519 { 1385 RT_NOREF(pNode, pszName, pu64, u64Def); 1386 AssertFailed(); 1387 return VERR_NOT_IMPLEMENTED; 1520 return pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, pu64, u64Def); 1388 1521 } 1389 1522 … … 1407 1540 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU32(PCFGMNODE pNode, const char *pszName, uint32_t *pu32) 1408 1541 { 1409 RT_NOREF(pNode, pszName, pu32); 1410 AssertFailed(); 1411 return VERR_NOT_IMPLEMENTED; 1542 uint64_t u64; 1543 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1544 if (RT_SUCCESS(rc)) 1545 { 1546 if (!(u64 & UINT64_C(0xffffffff00000000))) 1547 *pu32 = (uint32_t)u64; 1548 else 1549 rc = VERR_CFGM_INTEGER_TOO_BIG; 1550 } 1551 return rc; 1412 1552 } 1413 1553 … … 1415 1555 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU32Def(PCFGMNODE pNode, const char *pszName, uint32_t *pu32, uint32_t u32Def) 1416 1556 { 1417 RT_NOREF(pNode, pszName, pu32, u32Def); 1418 AssertFailed(); 1419 return VERR_NOT_IMPLEMENTED; 1557 uint64_t u64; 1558 int rc = pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, &u64, u32Def); 1559 if (RT_SUCCESS(rc)) 1560 { 1561 if (!(u64 & UINT64_C(0xffffffff00000000))) 1562 *pu32 = (uint32_t)u64; 1563 else 1564 rc = VERR_CFGM_INTEGER_TOO_BIG; 1565 } 1566 if (RT_FAILURE(rc)) 1567 *pu32 = u32Def; 1568 return rc; 1420 1569 } 1421 1570 … … 1423 1572 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryS32(PCFGMNODE pNode, const char *pszName, int32_t *pi32) 1424 1573 { 1425 RT_NOREF(pNode, pszName, pi32); 1426 AssertFailed(); 1427 return VERR_NOT_IMPLEMENTED; 1574 uint64_t u64; 1575 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1576 if (RT_SUCCESS(rc)) 1577 { 1578 if ( !(u64 & UINT64_C(0xffffffff80000000)) 1579 || (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000)) 1580 *pi32 = (int32_t)u64; 1581 else 1582 rc = VERR_CFGM_INTEGER_TOO_BIG; 1583 } 1584 return rc; 1428 1585 } 1429 1586 … … 1431 1588 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryS32Def(PCFGMNODE pNode, const char *pszName, int32_t *pi32, int32_t i32Def) 1432 1589 { 1433 RT_NOREF(pNode, pszName, pi32, i32Def); 1434 AssertFailed(); 1435 return VERR_NOT_IMPLEMENTED; 1590 uint64_t u64; 1591 int rc = pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, &u64, i32Def); 1592 if (RT_SUCCESS(rc)) 1593 { 1594 if ( !(u64 & UINT64_C(0xffffffff80000000)) 1595 || (u64 & UINT64_C(0xffffffff80000000)) == UINT64_C(0xffffffff80000000)) 1596 *pi32 = (int32_t)u64; 1597 else 1598 rc = VERR_CFGM_INTEGER_TOO_BIG; 1599 } 1600 if (RT_FAILURE(rc)) 1601 *pi32 = i32Def; 1602 return rc; 1436 1603 } 1437 1604 … … 1439 1606 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU16(PCFGMNODE pNode, const char *pszName, uint16_t *pu16) 1440 1607 { 1441 RT_NOREF(pNode, pszName, pu16); 1442 AssertFailed(); 1443 return VERR_NOT_IMPLEMENTED; 1608 uint64_t u64; 1609 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1610 if (RT_SUCCESS(rc)) 1611 { 1612 if (!(u64 & UINT64_C(0xffffffffffff0000))) 1613 *pu16 = (int16_t)u64; 1614 else 1615 rc = VERR_CFGM_INTEGER_TOO_BIG; 1616 } 1617 return rc; 1444 1618 } 1445 1619 … … 1447 1621 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU16Def(PCFGMNODE pNode, const char *pszName, uint16_t *pu16, uint16_t u16Def) 1448 1622 { 1449 RT_NOREF(pNode, pszName, pu16, u16Def); 1450 AssertFailed(); 1451 return VERR_NOT_IMPLEMENTED; 1623 uint64_t u64; 1624 int rc = pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, &u64, u16Def); 1625 if (RT_SUCCESS(rc)) 1626 { 1627 if (!(u64 & UINT64_C(0xffffffffffff0000))) 1628 *pu16 = (int16_t)u64; 1629 else 1630 rc = VERR_CFGM_INTEGER_TOO_BIG; 1631 } 1632 if (RT_FAILURE(rc)) 1633 *pu16 = u16Def; 1634 return rc; 1452 1635 } 1453 1636 … … 1471 1654 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU8(PCFGMNODE pNode, const char *pszName, uint8_t *pu8) 1472 1655 { 1473 RT_NOREF(pNode, pszName, pu8); 1474 AssertFailed(); 1475 return VERR_NOT_IMPLEMENTED; 1656 uint64_t u64; 1657 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1658 if (RT_SUCCESS(rc)) 1659 { 1660 if (!(u64 & UINT64_C(0xffffffffffffff00))) 1661 *pu8 = (uint8_t)u64; 1662 else 1663 rc = VERR_CFGM_INTEGER_TOO_BIG; 1664 } 1665 return rc; 1476 1666 } 1477 1667 … … 1479 1669 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryU8Def(PCFGMNODE pNode, const char *pszName, uint8_t *pu8, uint8_t u8Def) 1480 1670 { 1481 RT_NOREF(pNode, pszName, pu8, u8Def); 1482 AssertFailed(); 1483 return VERR_NOT_IMPLEMENTED; 1671 uint64_t u64; 1672 int rc = pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, &u64, u8Def); 1673 if (RT_SUCCESS(rc)) 1674 { 1675 if (!(u64 & UINT64_C(0xffffffffffffff00))) 1676 *pu8 = (uint8_t)u64; 1677 else 1678 rc = VERR_CFGM_INTEGER_TOO_BIG; 1679 } 1680 if (RT_FAILURE(rc)) 1681 *pu8 = u8Def; 1682 return rc; 1484 1683 } 1485 1684 … … 1503 1702 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryBool(PCFGMNODE pNode, const char *pszName, bool *pf) 1504 1703 { 1505 RT_NOREF(pNode, pszName, pf); 1506 AssertFailed(); 1507 return VERR_NOT_IMPLEMENTED; 1704 uint64_t u64; 1705 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1706 if (RT_SUCCESS(rc)) 1707 *pf = u64 ? true : false; 1708 return rc; 1508 1709 } 1509 1710 … … 1511 1712 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryBoolDef(PCFGMNODE pNode, const char *pszName, bool *pf, bool fDef) 1512 1713 { 1513 RT_NOREF(pNode, pszName, pf, fDef); 1514 AssertFailed(); 1515 return VERR_NOT_IMPLEMENTED; 1714 uint64_t u64; 1715 int rc = pdmR3DevHlp_CFGMQueryIntegerDef(pNode, pszName, &u64, fDef); 1716 *pf = u64 ? true : false; 1717 return rc; 1516 1718 } 1517 1719 … … 1527 1729 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryPortDef(PCFGMNODE pNode, const char *pszName, PRTIOPORT pPort, RTIOPORT PortDef) 1528 1730 { 1529 RT_NOREF(pNode, pszName, pPort, PortDef); 1530 AssertFailed(); 1531 return VERR_NOT_IMPLEMENTED; 1731 AssertCompileSize(RTIOPORT, 2); 1732 return pdmR3DevHlp_CFGMQueryU16Def(pNode, pszName, pPort, PortDef); 1532 1733 } 1533 1734 … … 1567 1768 static DECLCALLBACK(int) pdmR3DevHlp_CFGMQueryPtr(PCFGMNODE pNode, const char *pszName, void **ppv) 1568 1769 { 1569 RT_NOREF(pNode, pszName, ppv); 1570 AssertFailed(); 1571 return VERR_NOT_IMPLEMENTED; 1770 uint64_t u64; 1771 int rc = pdmR3DevHlp_CFGMQueryInteger(pNode, pszName, &u64); 1772 if (RT_SUCCESS(rc)) 1773 { 1774 uintptr_t u = (uintptr_t)u64; 1775 if (u64 == u) 1776 *ppv = (void *)u; 1777 else 1778 rc = VERR_CFGM_INTEGER_TOO_BIG; 1779 } 1780 return rc; 1572 1781 } 1573 1782 … … 1759 1968 static DECLCALLBACK(bool) pdmR3DevHlp_CFGMAreValuesValid(PCFGMNODE pNode, const char *pszzValid) 1760 1969 { 1761 RT_NOREF(pNode, pszzValid); 1762 AssertFailed(); 1763 return false; 1970 if (pNode && pNode->pDut->pTestcaseReg->paDevCfg) 1971 { 1972 PCTSTDEVCFGITEM pDevCfgItem = pNode->pDut->pTestcaseReg->paDevCfg; 1973 while (pDevCfgItem->pszKey != NULL) 1974 { 1975 size_t cchKey = strlen(pDevCfgItem->pszKey); 1976 1977 /* search pszzValid for the name */ 1978 const char *psz = pszzValid; 1979 while (*psz) 1980 { 1981 size_t cch = strlen(psz); 1982 if ( cch == cchKey 1983 && !memcmp(psz, pDevCfgItem->pszKey, cch)) 1984 break; 1985 1986 /* next */ 1987 psz += cch + 1; 1988 } 1989 1990 /* if at end of pszzValid we didn't find it => failure */ 1991 if (!*psz) 1992 return false; 1993 1994 pDevCfgItem++; 1995 } 1996 } 1997 1998 return true; 1764 1999 } 1765 2000 … … 1770 2005 { 1771 2006 RT_NOREF(pNode, pszNode, pszValidValues, pszValidNodes, pszWho, uInstance); 1772 AssertFailed(); 1773 return VERR_NOT_IMPLEMENTED; 2007 #if 1 2008 return VINF_SUCCESS; 2009 #else 2010 AssertFailed(); 2011 return VERR_NOT_IMPLEMENTED; 2012 #endif 1774 2013 } 1775 2014 … … 2062 2301 LogFlow(("pdmR3DevHlp_MMHeapFree: caller='%s'/%d: pv=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pv)); 2063 2302 2064 AssertFailed(); 2303 PTSTDEVMMHEAPALLOC pHeapAlloc = (PTSTDEVMMHEAPALLOC)((uint8_t *)pv - RT_UOFFSETOF(TSTDEVMMHEAPALLOC, abAlloc[0])); 2304 PTSTDEVDUTINT pThis = pHeapAlloc->pDut; 2305 2306 tstDevDutLockExcl(pThis); 2307 RTListNodeRemove(&pHeapAlloc->NdMmHeap); 2308 tstDevDutUnlockExcl(pThis); 2309 2310 /* Poison */ 2311 memset(&pHeapAlloc->abAlloc[0], 0xfc, pHeapAlloc->cbAlloc); 2312 RTMemFree(pHeapAlloc); 2065 2313 2066 2314 LogFlow(("pdmR3DevHlp_MMHeapAlloc: caller='%s'/%d: returns void\n", pDevIns->pReg->szName, pDevIns->iInstance)); … … 3102 3350 PDMDEV_ASSERT_DEVINS(pDevIns); 3103 3351 3104 RT_NOREF(pDevIns, pCritSect, rcBusy, uId, RT_SRC_POS_ARGS); 3105 int rc = VERR_NOT_IMPLEMENTED; 3106 AssertFailed(); 3107 return rc; 3352 RT_NOREF(pDevIns, rcBusy, uId, RT_SRC_POS_ARGS); 3353 return RTCritSectEnter(&pCritSect->s.CritSect); 3108 3354 } 3109 3355 … … 3138 3384 PDMDEV_ASSERT_DEVINS(pDevIns); 3139 3385 3140 RT_NOREF(pDevIns, pCritSect); 3141 int rc = VERR_NOT_IMPLEMENTED; 3142 AssertFailed(); 3143 return rc; 3386 return RTCritSectLeave(&pCritSect->s.CritSect); 3144 3387 } 3145 3388 … … 3150 3393 PDMDEV_ASSERT_DEVINS(pDevIns); 3151 3394 3152 RT_NOREF(pDevIns, pCritSect); 3153 AssertFailed(); 3154 return false; 3395 return RTCritSectIsOwner(&pCritSect->s.CritSect); 3155 3396 } 3156 3397
Note:
See TracChangeset
for help on using the changeset viewer.