[93491] | 1 | /* $Id: tstDeviceSsmLoadDbg.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * tstDeviceSsmFuzz - SSM fuzzing testcase.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2020-2023 Oracle and/or its affiliates.
|
---|
[93491] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[93491] | 26 | */
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | /*********************************************************************************************************************************
|
---|
| 30 | * Header Files *
|
---|
| 31 | *********************************************************************************************************************************/
|
---|
| 32 | #define LOG_GROUP LOG_GROUP_DEFAULT /** @todo */
|
---|
| 33 | #include <VBox/types.h>
|
---|
| 34 | #include <iprt/errcore.h>
|
---|
| 35 | #include <iprt/mem.h>
|
---|
| 36 | #include <iprt/file.h>
|
---|
| 37 | #include <iprt/fuzz.h>
|
---|
| 38 | #include <iprt/time.h>
|
---|
| 39 | #include <iprt/string.h>
|
---|
| 40 |
|
---|
| 41 | #include "tstDeviceBuiltin.h"
|
---|
| 42 | #include "tstDeviceCfg.h"
|
---|
| 43 | #include "tstDeviceInternal.h"
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 | /*********************************************************************************************************************************
|
---|
| 47 | * Defined Constants And Macros *
|
---|
| 48 | *********************************************************************************************************************************/
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | /*********************************************************************************************************************************
|
---|
| 52 | * Structures and Typedefs *
|
---|
| 53 | *********************************************************************************************************************************/
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | static PCTSTDEVCFGITEM tstDevSsmFuzzGetCfgItem(PCTSTDEVCFGITEM paCfg, uint32_t cCfgItems, const char *pszName)
|
---|
| 57 | {
|
---|
| 58 | for (uint32_t i = 0; i < cCfgItems; i++)
|
---|
| 59 | {
|
---|
| 60 | if (!RTStrCmp(paCfg[i].pszKey, pszName))
|
---|
| 61 | return &paCfg[i];
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | return NULL;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | static const char *tstDevSsmFuzzGetCfgString(PCTSTDEVCFGITEM paCfg, uint32_t cCfgItems, const char *pszName)
|
---|
| 69 | {
|
---|
| 70 | PCTSTDEVCFGITEM pCfgItem = tstDevSsmFuzzGetCfgItem(paCfg, cCfgItems, pszName);
|
---|
| 71 | if ( pCfgItem
|
---|
| 72 | && pCfgItem->enmType == TSTDEVCFGITEMTYPE_STRING)
|
---|
| 73 | return pCfgItem->u.psz;
|
---|
| 74 |
|
---|
| 75 | return NULL;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | static uint32_t tstDevSsmFuzzGetCfgU32(PCTSTDEVCFGITEM paCfg, uint32_t cCfgItems, const char *pszName)
|
---|
| 80 | {
|
---|
| 81 | PCTSTDEVCFGITEM pCfgItem = tstDevSsmFuzzGetCfgItem(paCfg, cCfgItems, pszName);
|
---|
| 82 | if ( pCfgItem
|
---|
| 83 | && pCfgItem->enmType == TSTDEVCFGITEMTYPE_INTEGER)
|
---|
| 84 | return (uint32_t)pCfgItem->u.i64;
|
---|
| 85 |
|
---|
| 86 | return 0;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | /**
|
---|
| 91 | * Entry point for the SSM load debug.
|
---|
| 92 | *
|
---|
| 93 | * @returns VBox status code.
|
---|
| 94 | * @param hDut The device under test.
|
---|
| 95 | * @param paCfg The testcase config.
|
---|
| 96 | * @param cCfgItems Number of config items.
|
---|
| 97 | */
|
---|
| 98 | static DECLCALLBACK(int) tstDevSsmLoadDbgEntry(TSTDEVDUT hDut, PCTSTDEVCFGITEM paCfg, uint32_t cCfgItems)
|
---|
| 99 | {
|
---|
| 100 | int rc = VINF_SUCCESS;
|
---|
| 101 | const char *pszSsmUnit = tstDevSsmFuzzGetCfgString(paCfg, cCfgItems, "SsmUnit");
|
---|
| 102 | if (pszSsmUnit)
|
---|
| 103 | {
|
---|
| 104 | void *pvData = NULL;
|
---|
| 105 | size_t cbData = 0;
|
---|
| 106 |
|
---|
| 107 | rc = RTFileReadAll(pszSsmUnit, &pvData, &cbData);
|
---|
| 108 | if (RT_SUCCESS(rc))
|
---|
| 109 | {
|
---|
| 110 | /* Create a new SSM handle to use. */
|
---|
| 111 | PSSMHANDLE pSsm = (PSSMHANDLE)RTMemAllocZ(sizeof(*pSsm));
|
---|
| 112 | if (RT_LIKELY(pSsm))
|
---|
| 113 | {
|
---|
| 114 | pSsm->pDut = hDut;
|
---|
| 115 | pSsm->pbSavedState = (uint8_t *)pvData;
|
---|
| 116 | pSsm->cbSavedState = cbData;
|
---|
| 117 | pSsm->offDataBuffer = 0;
|
---|
| 118 | pSsm->uCurUnitVer = tstDevSsmFuzzGetCfgU32(paCfg, cCfgItems, "UnitVersion");
|
---|
| 119 | pSsm->rc = VINF_SUCCESS;
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | /* Get the SSM handler from the device. */
|
---|
| 123 | int rcDut = VINF_SUCCESS;
|
---|
| 124 | PTSTDEVDUTSSM pSsmClbks = RTListGetFirst(&hDut->LstSsmHandlers, TSTDEVDUTSSM, NdSsm);
|
---|
| 125 | if (pSsmClbks)
|
---|
| 126 | {
|
---|
| 127 | /* Load preparations. */
|
---|
| 128 | if (pSsmClbks->pfnLoadPrep)
|
---|
| 129 | rcDut = pSsmClbks->pfnLoadPrep(hDut->pDevIns, pSsm);
|
---|
| 130 | if (RT_SUCCESS(rcDut))
|
---|
| 131 | rcDut = pSsmClbks->pfnLoadExec(hDut->pDevIns, pSsm, pSsm->uCurUnitVer, SSM_PASS_FINAL);
|
---|
| 132 | }
|
---|
| 133 | RTMemFree(pSsm);
|
---|
| 134 | }
|
---|
| 135 | else
|
---|
| 136 | rc = VERR_NO_MEMORY;
|
---|
| 137 |
|
---|
| 138 | RTFileReadAllFree(pvData, cbData);
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 | else
|
---|
| 142 | rc = VERR_NOT_FOUND;
|
---|
| 143 |
|
---|
| 144 | return rc;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | const TSTDEVTESTCASEREG g_TestcaseSsmLoadDbg =
|
---|
| 149 | {
|
---|
| 150 | /** szName */
|
---|
| 151 | "SsmLoadDbg",
|
---|
| 152 | /** pszDesc */
|
---|
| 153 | "Load SSM states which fail to load in VBox for investigation",
|
---|
| 154 | /** fFlags */
|
---|
| 155 | 0,
|
---|
| 156 | /** pfnTestEntry */
|
---|
| 157 | tstDevSsmLoadDbgEntry
|
---|
| 158 | };
|
---|
| 159 |
|
---|