summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/testcase/tstDeviceCfg.h
blob: c514f987b82eb5c079a00ac805487c43d455a28e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/** @file
 * tstDevice: Configuration handling.
 */

/*
 * Copyright (C) 2020-2023 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifndef VBOX_INCLUDED_SRC_testcase_tstDeviceCfg_h
#define VBOX_INCLUDED_SRC_testcase_tstDeviceCfg_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

#include <VBox/param.h>
#include <VBox/types.h>
#include <iprt/err.h>

RT_C_DECLS_BEGIN

/**
 * Config item type.
 */
typedef enum TSTDEVCFGITEMTYPE
{
    /** Invalid type. */
    TSTDEVCFGITEMTYPE_INVALID = 0,
    /** String type. */
    TSTDEVCFGITEMTYPE_STRING,
    /** Integer value encoded in the string. */
    TSTDEVCFGITEMTYPE_INTEGER,
    /** Raw bytes. */
    TSTDEVCFGITEMTYPE_BYTES,
    /** 32bit hack. */
    TSTDEVCFGITEMTYPE_32BIT_HACK = 0x7fffffff
} TSTDEVCFGITEMTYPE;
/** Pointer to a config item type. */
typedef TSTDEVCFGITEMTYPE *PTSTDEVCFGITEMTYPE;


/**
 * Testcase config item.
 */
typedef struct TSTDEVCFGITEM
{
    /** The key of the item. */
    const char          *pszKey;
    /** Type of the config item. */
    TSTDEVCFGITEMTYPE   enmType;
    /** Type dependent data. */
    union
    {
        /** String value. */
        const char      *psz;
        /** Integer value. */
        int64_t         i64;
        /** Raw bytes. */
        struct
        {
            /** Size of the byte buffer. */
            size_t      cb;
            /** Pointer to the raw buffer. */
            const void  *pv;
        } RawBytes;
    } u;
} TSTDEVCFGITEM;
/** Pointer to a testcase config item. */
typedef TSTDEVCFGITEM *PTSTDEVCFGITEM;
/** Pointer to a constant testcase config item. */
typedef const TSTDEVCFGITEM *PCTSTDEVCFGITEM;


/**
 * A single test.
 */
typedef struct TSTDEVTEST
{
    /** Flag whether to enable the R0 part for testing. */
    bool                        fR0Enabled;
    /** Flag whether to enable the RC part for testing. */
    bool                        fRCEnabled;
    /** Number of configuration items for the device. */
    uint32_t                    cCfgItems;
    /** Pointer to array of configuration items for the device. */
    PCTSTDEVCFGITEM             paCfgItems;
    /** Number of testcases to run with that device instance. */
    uint32_t                    cTestcases;
    /** Pointer to the array of testcase IDs. */
    const char                  **papszTestcaseIds;
    /** Pointer to the array of testcase configuration item numbers. */
    uint32_t                    *pacTestcaseCfgItems;
    /** Pointer to the array of configuration item array pointers for each testcase. */
    PCTSTDEVCFGITEM             *papTestcaseCfg;
} TSTDEVTEST;
/** Pointer to a single test. */
typedef TSTDEVTEST *PTSTDEVTEST;
/** Pointer to a const single test. */
typedef const TSTDEVTEST *PCTSTDEVTEST;


/**
 * A device test configuration.
 */
typedef struct TSTDEVCFG
{
    /** The identifier of the device to test. */
    const char                  *pszDevName;

    /** R3 PDM module to load containing the device to test. */
    const char                  *pszPdmR3Mod;
    /** R0 PDM module to load containing the device to test. */
    const char                  *pszPdmR0Mod;
    /** RC PDM module to load containing the device to test. */
    const char                  *pszPdmRCMod;

    /** Testcase module to load. */
    const char                  *pszTstDevMod;

    /** Number of tests configured in the config. */
    uint32_t                    cTests;
    /** The array of tests to execute for the given device - variable in size. */
    TSTDEVTEST                  aTests[1];
} TSTDEVCFG;
/** Pointer to a device test configuration. */
typedef TSTDEVCFG *PTSTDEVCFG;
/** Pointer to a const device test configuration. */
typedef const TSTDEVCFG *PCTSTDEVCFG;
/** Pointer to a device test configuration pointer. */
typedef TSTDEVCFG *PPTSTDEVCFG;


/**
 * Loads the config from the given file returning the configuration structure on success.
 *
 * @returns VBox status code.
 * @param   pszCfgFilename          The configuration file path to load.
 * @param   pErrInfo                Where to store additional error information if loading the config fails, optional.
 * @param   ppDevTstCfg             Where to store the pointer to the created test configuration on success.
 */
DECLHIDDEN(int) tstDevCfgLoad(const char *pszCfgFilename, PRTERRINFO pErrInfo, PCTSTDEVCFG *ppDevTstCfg);

/**
 * Destroys the given test configuration freeing all allocated resources.
 *
 * @param   pDevTstCfg              The test configuration to destroy.
 */
DECLHIDDEN(void) tstDevCfgDestroy(PCTSTDEVCFG pDevTstCfg);

RT_C_DECLS_END

#endif /* !VBOX_INCLUDED_SRC_testcase_tstDeviceCfg_h */