VirtualBox

Changeset 46781 in vbox


Ignore:
Timestamp:
Jun 25, 2013 2:04:17 PM (11 years ago)
Author:
vboxsync
Message:

CFGM: Made the CFGMR3CreateTree usable with pUVM == NULL for testing purposes.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/CFGM.cpp

    r45189 r46781  
    6666#include <VBox/log.h>
    6767#include <iprt/assert.h>
     68#include <iprt/mem.h>
    6869#include <iprt/param.h>
    6970#include <iprt/string.h>
     
    8182static int  cfgmR3InsertLeaf(PCFGMNODE pNode, const char *pszName, PCFGMLEAF *ppLeaf);
    8283static void cfgmR3RemoveLeaf(PCFGMNODE pNode, PCFGMLEAF pLeaf);
    83 static void cfgmR3FreeValue(PCFGMLEAF pLeaf);
     84static void cfgmR3FreeValue(PVM pVM, PCFGMLEAF pLeaf);
     85
     86
     87/**
     88 * Allocator wrapper.
     89 *
     90 * @returns Pointer to the allocated memory, NULL on failure.
     91 * @param   pVM                 The VM handle, if tree associated with one.
     92 * @param   enmTag              The allocation tag.
     93 * @param   cb                  The size of the allocation.
     94 */
     95static void *cfgmR3MemAlloc(PVM pVM, MMTAG enmTag, size_t cb)
     96{
     97    if (pVM)
     98        return MMR3HeapAlloc(pVM, enmTag, cb);
     99    return RTMemAlloc(cb);
     100}
     101
     102
     103/**
     104 * Free wrapper.
     105 *
     106 * @returns Pointer to the allocated memory, NULL on failure.
     107 * @param   pVM                 The VM handle, if tree associated with one.
     108 * @param   pv                  The memory block to free.
     109 */
     110static void cfgmR3MemFree(PVM pVM, void *pv)
     111{
     112    if (pVM)
     113        MMR3HeapFree(pv);
     114    else
     115        RTMemFree(pv);
     116}
     117
     118
     119/**
     120 * String allocator wrapper.
     121 *
     122 * @returns Pointer to the allocated memory, NULL on failure.
     123 * @param   pVM                 The VM handle, if tree associated with one.
     124 * @param   enmTag              The allocation tag.
     125 * @param   cbString            The size of the allocation, terminator included.
     126 */
     127static char *cfgmR3StrAlloc(PVM pVM, MMTAG enmTag,  size_t cbString)
     128{
     129    if (pVM)
     130        return (char *)MMR3HeapAlloc(pVM, enmTag, cbString);
     131    return (char *)RTStrAlloc(cbString);
     132}
     133
     134
     135/**
     136 * String free wrapper.
     137 *
     138 * @returns Pointer to the allocated memory, NULL on failure.
     139 * @param   pVM                 The VM handle, if tree associated with one.
     140 * @param   pszString           The memory block to free.
     141 */
     142static void cfgmR3StrFree(PVM pVM, char *pszString)
     143{
     144    if (pVM)
     145        MMR3HeapFree(pszString);
     146    else
     147        RTStrFree(pszString);
     148}
     149
     150
     151/**
     152 * Frees one node, leaving any children or leaves to the caller.
     153 *
     154 * @param   pNode               The node structure to free.
     155 */
     156static void cfgmR3FreeNodeOnly(PCFGMNODE pNode)
     157{
     158    pNode->pFirstLeaf    = NULL;
     159    pNode->pFirstChild   = NULL;
     160    pNode->pNext         = NULL;
     161    pNode->pPrev         = NULL;
     162    if (!pNode->pVM)
     163        RTMemFree(pNode);
     164    else
     165    {
     166        pNode->pVM       = NULL;
     167        MMR3HeapFree(pNode);
     168    }
     169}
     170
    84171
    85172
     
    12031290 * @returns Pointer to the root node, NULL on error (out of memory or invalid
    12041291 *          VM handle).
    1205  * @param   pUVM            The user mode VM handle.
     1292 * @param   pUVM            The user mode VM handle.  For testcase (and other
     1293 *                          purposes, NULL can be used.  However, the resulting
     1294 *                          tree cannot be inserted into a tree that has a
     1295 *                          non-NULL value.  Using NULL can be usedful for
     1296 *                          testcases and similar, non VMM uses.
    12061297 */
    12071298VMMR3DECL(PCFGMNODE) CFGMR3CreateTree(PUVM pUVM)
    12081299{
    1209     UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
    1210     VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, NULL);
    1211 
    1212     PCFGMNODE pNew = (PCFGMNODE)MMR3HeapAllocU(pUVM, MM_TAG_CFGM, sizeof(*pNew));
     1300    if (pUVM)
     1301    {
     1302        UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
     1303        VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, NULL);
     1304    }
     1305
     1306    PCFGMNODE pNew;
     1307    if (pUVM)
     1308        pNew = (PCFGMNODE)MMR3HeapAllocU(pUVM, MM_TAG_CFGM, sizeof(*pNew));
     1309    else
     1310        pNew = (PCFGMNODE)RTMemAlloc(sizeof(*pNew));
    12131311    if (pNew)
    12141312    {
     
    12181316        pNew->pFirstChild   = NULL;
    12191317        pNew->pFirstLeaf    = NULL;
    1220         pNew->pVM           = pUVM->pVM;
     1318        pNew->pVM           = pUVM ? pUVM->pVM : NULL;
    12211319        pNew->fRestrictedRoot = false;
    12221320        pNew->cchName       = 0;
     
    12421340     * Create a new tree.
    12431341     */
    1244     PCFGMNODE pNewRoot = CFGMR3CreateTree(pRoot->pVM->pUVM);
     1342    PCFGMNODE pNewRoot = CFGMR3CreateTree(pRoot->pVM ? pRoot->pVM->pUVM : NULL);
    12451343    if (!pNewRoot)
    12461344        return VERR_NO_MEMORY;
     
    13521450    AssertReturn(pNode != pSubTree, VERR_INVALID_PARAMETER);
    13531451    AssertReturn(!pSubTree->pParent, VERR_INVALID_PARAMETER);
    1354     AssertReturn(pSubTree->pVM, VERR_INVALID_PARAMETER);
     1452    AssertReturn(pNode->pVM == pSubTree->pVM, VERR_INVALID_PARAMETER);
    13551453    Assert(!pSubTree->pNext);
    13561454    Assert(!pSubTree->pPrev);
     
    13761474
    13771475        /* free the old subtree root */
    1378         pSubTree->pVM = NULL;
    1379         pSubTree->pFirstLeaf = NULL;
    1380         pSubTree->pFirstChild = NULL;
    1381         MMR3HeapFree(pSubTree);
     1476        cfgmR3FreeNodeOnly(pSubTree);
    13821477    }
    13831478    return rc;
     
    14071502    AssertReturn(pRoot != pNewRoot, VERR_INVALID_PARAMETER);
    14081503    AssertReturn(!pNewRoot->pParent, VERR_INVALID_PARAMETER);
    1409     AssertReturn(pNewRoot->pVM, VERR_INVALID_PARAMETER);
    14101504    AssertReturn(pNewRoot->pVM == pRoot->pVM, VERR_INVALID_PARAMETER);
    14111505    AssertReturn(!pNewRoot->pNext, VERR_INVALID_PARAMETER);
     
    14291523        pChild->pParent     = pRoot;
    14301524
    1431     pNewRoot->pFirstLeaf    = NULL;
    1432     pNewRoot->pFirstChild   = NULL;
    1433     pNewRoot->pVM           = NULL;
    1434     MMR3HeapFree(pNewRoot);
     1525    cfgmR3FreeNodeOnly(pNewRoot);
    14351526
    14361527    return VINF_SUCCESS;
     
    16441735             * Allocate and init node.
    16451736             */
    1646             PCFGMNODE pNew = (PCFGMNODE)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
     1737            PCFGMNODE pNew = (PCFGMNODE)cfgmR3MemAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
    16471738            if (pNew)
    16481739            {
     
    17861877             * Allocate and init node.
    17871878             */
    1788             PCFGMLEAF pNew = (PCFGMLEAF)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
     1879            PCFGMLEAF pNew = (PCFGMLEAF)cfgmR3MemAlloc(pNode->pVM, MM_TAG_CFGM, sizeof(*pNew) + cchName);
    17891880            if (pNew)
    17901881            {
     
    18561947
    18571948        /*
    1858          * Free ourselves. (bit of paranoia first)
     1949         * Free ourselves.
    18591950         */
    1860         pNode->pVM = NULL;
    1861         pNode->pNext = NULL;
    1862         pNode->pPrev = NULL;
    1863         pNode->pParent = NULL;
    1864         MMR3HeapFree(pNode);
     1951        cfgmR3FreeNodeOnly(pNode);
    18651952    }
    18661953}
     
    18901977         * Free value and node.
    18911978         */
    1892         cfgmR3FreeValue(pLeaf);
     1979        cfgmR3FreeValue(pNode->pVM, pLeaf);
    18931980        pLeaf->pNext = NULL;
    18941981        pLeaf->pPrev = NULL;
    1895         MMR3HeapFree(pLeaf);
     1982        cfgmR3MemFree(pNode->pVM, pLeaf);
    18961983    }
    18971984}
     
    19041991 * The caller must either free the leaf or assign a new value to it.
    19051992 *
     1993 * @param   pVM         Used to select the heap.
    19061994 * @param   pLeaf       Pointer to the leaf which value should be free.
    19071995 */
    1908 static void cfgmR3FreeValue(PCFGMLEAF pLeaf)
     1996static void cfgmR3FreeValue(PVM pVM, PCFGMLEAF pLeaf)
    19091997{
    19101998    if (pLeaf)
     
    19132001        {
    19142002            case CFGMVALUETYPE_BYTES:
    1915                 MMR3HeapFree(pLeaf->Value.Bytes.pau8);
     2003                cfgmR3MemFree(pVM, pLeaf->Value.Bytes.pau8);
    19162004                pLeaf->Value.Bytes.pau8 = NULL;
    19172005                pLeaf->Value.Bytes.cb = 0;
     
    19192007
    19202008            case CFGMVALUETYPE_STRING:
    1921                 MMR3HeapFree(pLeaf->Value.String.psz);
     2009                cfgmR3StrFree(pVM, pLeaf->Value.String.psz);
    19222010                pLeaf->Value.String.psz = NULL;
    19232011                pLeaf->Value.String.cb = 0;
     
    19742062         * Allocate string object first.
    19752063         */
    1976         char *pszStringCopy = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cchString + 1);
     2064        char *pszStringCopy = (char *)cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cchString + 1);
    19772065        if (pszStringCopy)
    19782066        {
     
    19922080            }
    19932081            else
    1994                 MMR3HeapFree(pszStringCopy);
     2082                cfgmR3StrFree(pNode->pVM, pszStringCopy);
    19952083        }
    19962084        else
     
    20372125         * Allocate string object first.
    20382126         */
    2039         char *pszString = MMR3HeapAPrintfVU(pNode->pVM->pUVM, MM_TAG_CFGM_STRING, pszFormat, va);
     2127        char *pszString;
     2128        if (!pNode->pVM)
     2129            pszString = RTStrAPrintf2(pszFormat, va);
     2130        else
     2131            pszString = MMR3HeapAPrintfVU(pNode->pVM->pUVM, MM_TAG_CFGM_STRING, pszFormat, va);
    20402132        if (pszString)
    20412133        {
     
    20522144            }
    20532145            else
    2054                 MMR3HeapFree(pszString);
     2146                cfgmR3StrFree(pNode->pVM, pszString);
    20552147        }
    20562148        else
     
    21242216             * Allocate string object first.
    21252217             */
    2126             void *pvCopy = MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cbBytes);
     2218            void *pvCopy = cfgmR3MemAlloc(pNode->pVM, MM_TAG_CFGM_STRING, cbBytes);
    21272219            if (pvCopy || !cbBytes)
    21282220            {
     
    21402232                    pLeaf->Value.Bytes.pau8 = (uint8_t *)pvCopy;
    21412233                }
     2234                else
     2235                    cfgmR3MemFree(pNode->pVM, pvCopy);
    21422236            }
    21432237            else
     
    29183012 * @param   pszName         Value name. This value must be of zero terminated character string type.
    29193013 * @param   ppszString      Where to store the string pointer.
    2920  *                          Free this using MMR3HeapFree().
     3014 *                          Free this using MMR3HeapFree() (or RTStrFree if not
     3015 *                          associated with a pUVM - see CFGMR3CreateTree).
    29213016 */
    29223017VMMR3DECL(int) CFGMR3QueryStringAlloc(PCFGMNODE pNode, const char *pszName, char **ppszString)
     
    29263021    if (RT_SUCCESS(rc))
    29273022    {
    2928         char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
     3023        char *pszString = cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbString);
    29293024        if (pszString)
    29303025        {
     
    29333028                *ppszString = pszString;
    29343029            else
    2935                 MMR3HeapFree(pszString);
     3030                cfgmR3StrFree(pNode->pVM, pszString);
    29363031        }
    29373032        else
     
    29533048 * @param   pszName         Value name. This value must be of zero terminated character string type.
    29543049 * @param   ppszString      Where to store the string pointer. Not set on failure.
    2955  *                          Free this using MMR3HeapFree().
     3050 *                          Free this using MMR3HeapFree() (or RTStrFree if not
     3051 *                          associated with a pUVM - see CFGMR3CreateTree).
    29563052 * @param   pszDef          The default return value.  This can be NULL.
    29573053 */
     
    29713067        {
    29723068            size_t const cbSrc = pLeaf->Value.String.cb;
    2973             char *pszString = (char *)MMR3HeapAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbSrc);
     3069            char *pszString = cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbSrc);
    29743070            if (pszString)
    29753071            {
     
    29883084            *ppszString = NULL;
    29893085        else
    2990             *ppszString = MMR3HeapStrDup(pNode->pVM, MM_TAG_CFGM_USER, pszDef);
     3086        {
     3087            size_t const cbDef = strlen(pszDef) + 1;
     3088            *ppszString = cfgmR3StrAlloc(pNode->pVM, MM_TAG_CFGM_USER, cbDef);
     3089            memcpy(*ppszString, pszDef, cbDef);
     3090        }
    29913091        if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
    29923092            rc = VINF_SUCCESS;
  • trunk/src/VBox/VMM/testcase/tstCFGM.cpp

    r44528 r46781  
    3131#include <iprt/initterm.h>
    3232#include <iprt/stream.h>
     33#include <iprt/mem.h>
    3334#include <iprt/string.h>
    3435
     36#include <iprt/test.h>
     37
     38
     39static void doGeneralTests(PCFGMNODE pRoot)
     40{
     41    /* test multilevel node creation */
     42    PCFGMNODE pChild = NULL;
     43    RTTESTI_CHECK_RC_RETV(CFGMR3InsertNode(pRoot, "First/Second/Third//Final", &pChild), VINF_SUCCESS);
     44    RTTESTI_CHECK_RETV(RT_VALID_PTR(pChild));
     45    RTTESTI_CHECK(CFGMR3GetChild(pRoot, "First/Second/Third/Final") == pChild);
     46
     47    /*
     48     * Boolean queries.
     49     */
     50    RTTESTI_CHECK_RC(CFGMR3InsertInteger(pChild, "BoolValue", 1), VINF_SUCCESS);
     51    bool f = false;
     52    RTTESTI_CHECK_RC(CFGMR3QueryBool(pChild, "BoolValue", &f), VINF_SUCCESS);
     53    RTTESTI_CHECK(f == true);
     54
     55    RTTESTI_CHECK_RC(CFGMR3QueryBool(pRoot, "BoolValue", &f), VERR_CFGM_VALUE_NOT_FOUND);
     56    RTTESTI_CHECK_RC(CFGMR3QueryBool(NULL, "BoolValue", &f), VERR_CFGM_NO_PARENT);
     57
     58    RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, true), VINF_SUCCESS);
     59    RTTESTI_CHECK(f == true);
     60    RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(pChild, "ValueNotFound", &f, false), VINF_SUCCESS);
     61    RTTESTI_CHECK(f == false);
     62
     63    RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, true), VINF_SUCCESS);
     64    RTTESTI_CHECK(f == true);
     65    RTTESTI_CHECK_RC(CFGMR3QueryBoolDef(NULL, "BoolValue", &f, false), VINF_SUCCESS);
     66    RTTESTI_CHECK(f == false);
     67
     68}
     69
     70
     71
     72static void doTestsOnDefaultValues(PCFGMNODE pRoot)
     73{
     74    /* integer */
     75    uint64_t u64;
     76    RTTESTI_CHECK_RC(CFGMR3QueryU64(pRoot, "RamSize", &u64), VINF_SUCCESS);
     77
     78    size_t cb = 0;
     79    RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "RamSize", &cb), VINF_SUCCESS);
     80    RTTESTI_CHECK(cb == sizeof(uint64_t));
     81
     82    /* string */
     83    char *pszName = NULL;
     84    RTTESTI_CHECK_RC(CFGMR3QueryStringAlloc(pRoot, "Name", &pszName), VINF_SUCCESS);
     85    RTTESTI_CHECK_RC(CFGMR3QuerySize(pRoot, "Name", &cb), VINF_SUCCESS);
     86    RTTESTI_CHECK(cb == strlen(pszName) + 1);
     87    MMR3HeapFree(pszName);
     88}
     89
     90
     91static void doInVmmTests(RTTEST hTest)
     92{
     93    /*
     94     * Create empty VM structure and init SSM.
     95     */
     96    int rc = SUPR3Init(NULL);
     97    if (RT_FAILURE(rc))
     98    {
     99        RTTestSkipped(hTest, "SUPR3Init failed with rc=%Rrc",  rc);
     100        return;
     101    }
     102
     103    PVM pVM;
     104    RTTESTI_CHECK_RC_RETV(SUPR3PageAlloc(RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT, (void **)&pVM), VINF_SUCCESS);
     105
     106
     107    PUVM pUVM = (PUVM)RTMemPageAlloc(sizeof(*pUVM));
     108    pUVM->u32Magic = UVM_MAGIC;
     109    pUVM->pVM = pVM;
     110    pVM->pUVM = pUVM;
     111
     112    /*
     113     * Do the testing.
     114     */
     115    RTTESTI_CHECK_RC_RETV(STAMR3InitUVM(pUVM), VINF_SUCCESS);
     116    RTTESTI_CHECK_RC_RETV(MMR3InitUVM(pUVM), VINF_SUCCESS);
     117    RTTESTI_CHECK_RC_RETV(CFGMR3Init(pVM, NULL, NULL), VINF_SUCCESS);
     118    RTTESTI_CHECK_RETV(CFGMR3GetRoot(pVM) != NULL);
     119
     120    doTestsOnDefaultValues(CFGMR3GetRoot(pVM));
     121    doGeneralTests(CFGMR3GetRoot(pVM));
     122
     123
     124    /* done */
     125    RTTESTI_CHECK_RC_RETV(CFGMR3Term(pVM), VINF_SUCCESS);
     126}
     127
     128
     129static void doStandaloneTests(void)
     130{
     131    RTTestISub("Standalone");
     132    PCFGMNODE pRoot;;
     133    RTTESTI_CHECK_RETV((pRoot = CFGMR3CreateTree(NULL)) != NULL);
     134    doGeneralTests(pRoot);
     135}
    35136
    36137int main()
     
    39140     * Init runtime.
    40141     */
     142    RTTEST hTest;
    41143    RTR3InitExeNoArguments(RTR3INIT_FLAGS_SUPLIB);
     144    RTEXITCODE rcExit = RTTestInitAndCreate("tstCFGM", &hTest);
     145    if (rcExit != RTEXITCODE_SUCCESS)
     146        return rcExit;
    42147
    43     /*
    44      * Create empty VM structure and init SSM.
    45      */
    46     PVM         pVM;
    47     int rc = SUPR3Init(NULL);
    48     if (RT_SUCCESS(rc))
    49         rc = SUPR3PageAlloc(RT_ALIGN_Z(sizeof(*pVM), PAGE_SIZE) >> PAGE_SHIFT, (void **)&pVM);
    50     if (RT_FAILURE(rc))
    51     {
    52         RTPrintf("Fatal error: SUP Failure! rc=%Rrc\n", rc);
    53         return 1;
    54     }
     148    doInVmmTests(hTest);
     149    doStandaloneTests();
    55150
    56     static UVM s_UVM;
    57     PUVM pUVM = &s_UVM;
    58     pUVM->pVM = pVM;
    59     pVM->pUVM = pUVM;
     151    return RTTestSummaryAndDestroy(hTest);
     152}
    60153
    61     rc = STAMR3InitUVM(pUVM);
    62     if (RT_FAILURE(rc))
    63     {
    64         RTPrintf("FAILURE: STAMR3Init failed. rc=%Rrc\n", rc);
    65         return 1;
    66     }
    67 
    68     rc = MMR3InitUVM(pUVM);
    69     if (RT_FAILURE(rc))
    70     {
    71         RTPrintf("FAILURE: STAMR3Init failed. rc=%Rrc\n", rc);
    72         return 1;
    73     }
    74 
    75     rc = CFGMR3Init(pVM, NULL, NULL);
    76     if (RT_FAILURE(rc))
    77     {
    78         RTPrintf("FAILURE: CFGMR3Init failed. rc=%Rrc\n", rc);
    79         return 1;
    80     }
    81 
    82     if (!CFGMR3GetRoot(pVM))
    83     {
    84         RTPrintf("FAILURE: CFGMR3GetRoot failed\n");
    85         return 1;
    86     }
    87 
    88     /* integer */
    89     uint64_t u64;
    90     rc = CFGMR3QueryU64(CFGMR3GetRoot(pVM), "RamSize", &u64);
    91     if (RT_FAILURE(rc))
    92     {
    93         RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\",) failed. rc=%Rrc\n", rc);
    94         return 1;
    95     }
    96 
    97     size_t cb;
    98     rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "RamSize", &cb);
    99     if (RT_FAILURE(rc))
    100     {
    101         RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Rrc\n", rc);
    102         return 1;
    103     }
    104     if (cb != sizeof(uint64_t))
    105     {
    106         RTPrintf("FAILURE: Incorrect valuesize %d for \"RamSize\" value.\n", cb);
    107         return 1;
    108     }
    109 
    110     /* string */
    111     char *pszName = NULL;
    112     rc = CFGMR3QueryStringAlloc(CFGMR3GetRoot(pVM), "Name", &pszName);
    113     if (RT_FAILURE(rc))
    114     {
    115         RTPrintf("FAILURE: CFGMR3QueryStringAlloc(,\"Name\" failed. rc=%Rrc\n", rc);
    116         return 1;
    117     }
    118 
    119     rc = CFGMR3QuerySize(CFGMR3GetRoot(pVM), "Name", &cb);
    120     if (RT_FAILURE(rc))
    121     {
    122         RTPrintf("FAILURE: CFGMR3QuerySize(,\"RamSize\",) failed. rc=%Rrc\n", rc);
    123         return 1;
    124     }
    125     if (cb != strlen(pszName) + 1)
    126     {
    127         RTPrintf("FAILURE: Incorrect valuesize %d for \"Name\" value '%s'.\n", cb, pszName);
    128         return 1;
    129     }
    130     MMR3HeapFree(pszName);
    131 
    132 
    133     /* test multilevel node creation */
    134     PCFGMNODE pChild = NULL;
    135     rc = CFGMR3InsertNode(CFGMR3GetRoot(pVM), "First/Second/Third//Final", &pChild);
    136     if (RT_FAILURE(rc))
    137     {
    138         RTPrintf("FAILURE: CFGMR3InsertNode(,\"First/Second/Third//Final\" failed. rc=%Rrc\n", rc);
    139         return 1;
    140     }
    141     rc = CFGMR3InsertInteger(pChild, "BoolValue", 1);
    142     if (RT_FAILURE(rc))
    143     {
    144         RTPrintf("FAILURE: CFGMR3InsertInteger(,\"BoolValue\", 1) failed. rc=%Rrc\n", rc);
    145         return 1;
    146     }
    147     PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "First/Second/Third/Final");
    148     if (pNode != pChild)
    149     {
    150         RTPrintf("FAILURE: CFGMR3GetChild(,\"First/Second/Third/Final/BoolValue\") failed. pNode=%p expected %p\n", pNode, pChild);
    151         return 1;
    152     }
    153     bool f = false;
    154     rc = CFGMR3QueryBool(pNode, "BoolValue", &f);
    155     if (RT_FAILURE(rc) || !f)
    156     {
    157         RTPrintf("FAILURE: CFGMR3QueryBool(,\"BoolValue\",) failed. rc=%Rrc f=%d\n", rc, f);
    158         return 1;
    159     }
    160 
    161 
    162     /* done */
    163     rc = CFGMR3Term(pVM);
    164     if (RT_FAILURE(rc))
    165     {
    166         RTPrintf("FAILURE: CFGMR3QueryU64(,\"RamSize\" failed. rc=%Rrc\n", rc);
    167         return 1;
    168     }
    169 
    170     RTPrintf("tstCFGM: SUCCESS\n");
    171     return rc;
    172 }
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