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