blob: 25d5c9c41e60e2de7da58a2b69afa151240730bc (
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/** @file
Provides the basic types and common elements of the unit test framework
Copyright (c) Microsoft Corporation.<BR>
Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#ifndef __UNIT_TEST_TYPES_H__
#define __UNIT_TEST_TYPES_H__
#include <Library/UnitTestLib.h>
///
/// The maximum length of a string stored in the unit test framework
///
#define UNIT_TEST_MAX_STRING_LENGTH (120)
///
/// The size of a firngerprint used to save/resume execution of a unit test
/// framework. This is the size of a CRC32 value which is 32-bit value.
///
///
#define UNIT_TEST_FINGERPRINT_SIZE (sizeof (UINT32))
///
/// The maximum length of a test failure message stored in the unit test
/// framework
///
#define UNIT_TEST_TESTFAILUREMSG_LENGTH (120)
///
/// FAILURE_TYPE used to record the type of assert that was triggered by a unit
/// test.
///
typedef UINT32 FAILURE_TYPE;
#define FAILURETYPE_NOFAILURE (0)
#define FAILURETYPE_OTHER (1)
#define FAILURETYPE_ASSERTTRUE (2)
#define FAILURETYPE_ASSERTFALSE (3)
#define FAILURETYPE_ASSERTEQUAL (4)
#define FAILURETYPE_ASSERTNOTEQUAL (5)
#define FAILURETYPE_ASSERTNOTEFIERROR (6)
#define FAILURETYPE_ASSERTSTATUSEQUAL (7)
#define FAILURETYPE_ASSERTNOTNULL (8)
#define FAILURETYPE_EXPECTASSERT (9)
///
/// Unit Test context structure tracked by the unit test framework.
///
typedef struct {
CHAR8 *Description;
CHAR8 *Name; //can't have spaces and should be short
CHAR8 *Log;
FAILURE_TYPE FailureType;
CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
UNIT_TEST_STATUS Result;
UNIT_TEST_FUNCTION RunTest;
UNIT_TEST_PREREQUISITE Prerequisite;
UNIT_TEST_CLEANUP CleanUp;
UNIT_TEST_CONTEXT Context;
UNIT_TEST_SUITE_HANDLE ParentSuite;
} UNIT_TEST;
///
/// Structure used to store the set of unit tests in a unit test suite as a list.
///
typedef struct {
LIST_ENTRY Entry;
UNIT_TEST UT;
} UNIT_TEST_LIST_ENTRY;
///
/// Unit Test Suite context structure tracked by the unit test framework.
///
typedef struct {
UINTN NumTests;
CHAR8 *Title;
CHAR8 *Name;
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
UNIT_TEST_SUITE_SETUP Setup;
UNIT_TEST_SUITE_TEARDOWN Teardown;
LIST_ENTRY TestCaseList; // UNIT_TEST_LIST_ENTRY
UNIT_TEST_FRAMEWORK_HANDLE ParentFramework;
} UNIT_TEST_SUITE;
///
/// Structure used to store the set of unit test suites in a unit test framework
/// as a list.
///
typedef struct {
LIST_ENTRY Entry;
UNIT_TEST_SUITE UTS;
} UNIT_TEST_SUITE_LIST_ENTRY;
///
/// Unit Test Framework context structure tracked by the unit test framework.
///
typedef struct {
CHAR8 *Title;
CHAR8 *ShortTitle; // This title should contain NO spaces or non-filename characters. Is used in reporting and serialization.
CHAR8 *VersionString;
CHAR8 *Log;
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE];
LIST_ENTRY TestSuiteList; // UNIT_TEST_SUITE_LIST_ENTRY
EFI_TIME StartTime;
EFI_TIME EndTime;
UNIT_TEST *CurrentTest;
VOID *SavedState; // This is an instance of UNIT_TEST_SAVE_HEADER*, if present.
} UNIT_TEST_FRAMEWORK;
///
/// Serialized version of a unit test
///
typedef struct {
UINT32 Size; // Size of the UNIT_TEST_SAVE_TEST including Log[]
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the test itself.
CHAR8 FailureMessage[UNIT_TEST_TESTFAILUREMSG_LENGTH];
FAILURE_TYPE FailureType;
UNIT_TEST_STATUS Result;
CHAR8 Log[];
} UNIT_TEST_SAVE_TEST;
///
/// Serialized version of a unit test context
///
typedef struct {
UINT32 Size; // Size of the UNIT_TEST_SAVE_CONTEXT including Data[]
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the corresponding test.
UINT8 Data[]; // Actual data of the context.
} UNIT_TEST_SAVE_CONTEXT;
///
/// Serialized version of unit test framework
///
typedef struct {
UINT8 Version;
UINT32 SaveStateSize; // Size of the entire serialized buffer.
UINT8 Fingerprint[UNIT_TEST_FINGERPRINT_SIZE]; // Fingerprint of the framework that has been saved.
EFI_TIME StartTime;
UINT32 TestCount;
BOOLEAN HasSavedContext;
// UNIT_TEST_SAVE_TEST Tests[]; // Array of structures starts here.
// UNIT_TEST_SAVE_CONTEXT SavedContext[]; // Saved context for the currently running test.
// CHAR8 Log[]; // NOTE: Not yet implemented!!
} UNIT_TEST_SAVE_HEADER;
/**
This function is responsible for initializing the log buffer for a single test. It can
be used internally, but may also be consumed by the test framework to add pre-existing
data to a log before it's used.
@param[in,out] TestHandle A handle to the test being initialized.
@param[in] Buffer [Optional] A pointer to pre-existing log data that should
be used to initialize the log. Should include a NULL terminator.
@param[in] BufferSize [Optional] The size of the pre-existing log data.
**/
VOID
EFIAPI
UnitTestLogInit (
IN OUT UNIT_TEST *Test,
IN UINT8 *Buffer OPTIONAL,
IN UINTN BufferSize OPTIONAL
);
/**
Internal helper function to return a handle to the currently executing framework.
This function is generally used for communication within the UnitTest framework, but is
defined here so that it can be consumed by the Assertion and Logging macros.
There should be no need to consume as a test writer, but it's there if you need it.
@retval Handle to the currently executing test framework.
**/
UNIT_TEST_FRAMEWORK_HANDLE
GetActiveFrameworkHandle (
VOID
);
#endif
|