2 Provides the basic types and common elements of the unit test framework
4 Copyright (c) Microsoft Corporation.<BR>
5 Copyright (c) 2019 - 2020, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef __UNIT_TEST_TYPES_H__
11 #define __UNIT_TEST_TYPES_H__
13 #include <Library/UnitTestLib.h>
16 /// The maximum length of a string stored in the unit test framework
18 #define UNIT_TEST_MAX_STRING_LENGTH (120)
21 /// The size of a firngerprint used to save/resume execution of a unit test
22 /// framework. This is the size of a CRC32 value which is 32-bit value.
25 #define UNIT_TEST_FINGERPRINT_SIZE (sizeof (UINT32))
28 /// The maximum length of a test failure message stored in the unit test
31 #define UNIT_TEST_TESTFAILUREMSG_LENGTH (120)
34 /// FAILURE_TYPE used to record the type of assert that was triggered by a unit
37 typedef UINT32 FAILURE_TYPE
;
38 #define FAILURETYPE_NOFAILURE (0)
39 #define FAILURETYPE_OTHER (1)
40 #define FAILURETYPE_ASSERTTRUE (2)
41 #define FAILURETYPE_ASSERTFALSE (3)
42 #define FAILURETYPE_ASSERTEQUAL (4)
43 #define FAILURETYPE_ASSERTNOTEQUAL (5)
44 #define FAILURETYPE_ASSERTNOTEFIERROR (6)
45 #define FAILURETYPE_ASSERTSTATUSEQUAL (7)
46 #define FAILURETYPE_ASSERTNOTNULL (8)
49 /// Unit Test context structure tracked by the unit test framework.
53 CHAR8
*Name
; //can't have spaces and should be short
55 FAILURE_TYPE FailureType
;
56 CHAR8 FailureMessage
[UNIT_TEST_TESTFAILUREMSG_LENGTH
];
57 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
];
58 UNIT_TEST_STATUS Result
;
59 UNIT_TEST_FUNCTION RunTest
;
60 UNIT_TEST_PREREQUISITE Prerequisite
;
61 UNIT_TEST_CLEANUP CleanUp
;
62 UNIT_TEST_CONTEXT Context
;
63 UNIT_TEST_SUITE_HANDLE ParentSuite
;
67 /// Structure used to store the set of unit tests in a unit test suite as a list.
72 } UNIT_TEST_LIST_ENTRY
;
75 /// Unit Test Suite context structure tracked by the unit test framework.
81 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
];
82 UNIT_TEST_SUITE_SETUP Setup
;
83 UNIT_TEST_SUITE_TEARDOWN Teardown
;
84 LIST_ENTRY TestCaseList
; // UNIT_TEST_LIST_ENTRY
85 UNIT_TEST_FRAMEWORK_HANDLE ParentFramework
;
89 /// Structure used to store the set of unit test suites in a unit test framework
95 } UNIT_TEST_SUITE_LIST_ENTRY
;
98 /// Unit Test Framework context structure tracked by the unit test framework.
102 CHAR8
*ShortTitle
; // This title should contain NO spaces or non-filename characters. Is used in reporting and serialization.
103 CHAR8
*VersionString
;
105 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
];
106 LIST_ENTRY TestSuiteList
; // UNIT_TEST_SUITE_LIST_ENTRY
109 UNIT_TEST
*CurrentTest
;
110 VOID
*SavedState
; // This is an instance of UNIT_TEST_SAVE_HEADER*, if present.
111 } UNIT_TEST_FRAMEWORK
;
114 /// Serialized version of a unit test
117 UINT32 Size
; // Size of the UNIT_TEST_SAVE_TEST including Log[]
118 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
]; // Fingerprint of the test itself.
119 CHAR8 FailureMessage
[UNIT_TEST_TESTFAILUREMSG_LENGTH
];
120 FAILURE_TYPE FailureType
;
121 UNIT_TEST_STATUS Result
;
123 } UNIT_TEST_SAVE_TEST
;
126 /// Serialized version of a unit test context
129 UINT32 Size
; // Size of the UNIT_TEST_SAVE_CONTEXT including Data[]
130 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
]; // Fingerprint of the corresponding test.
131 UINT8 Data
[]; // Actual data of the context.
132 } UNIT_TEST_SAVE_CONTEXT
;
135 /// Serialized version of unit test framework
139 UINT32 SaveStateSize
; // Size of the entire serialized buffer.
140 UINT8 Fingerprint
[UNIT_TEST_FINGERPRINT_SIZE
]; // Fingerprint of the framework that has been saved.
143 BOOLEAN HasSavedContext
;
144 // UNIT_TEST_SAVE_TEST Tests[]; // Array of structures starts here.
145 // UNIT_TEST_SAVE_CONTEXT SavedContext[]; // Saved context for the currently running test.
146 // CHAR8 Log[]; // NOTE: Not yet implemented!!
147 } UNIT_TEST_SAVE_HEADER
;
150 This function is responsible for initializing the log buffer for a single test. It can
151 be used internally, but may also be consumed by the test framework to add pre-existing
152 data to a log before it's used.
154 @param[in,out] TestHandle A handle to the test being initialized.
155 @param[in] Buffer [Optional] A pointer to pre-existing log data that should
156 be used to initialize the log. Should include a NULL terminator.
157 @param[in] BufferSize [Optional] The size of the pre-existing log data.
163 IN OUT UNIT_TEST
*Test
,
164 IN UINT8
*Buffer OPTIONAL
,
165 IN UINTN BufferSize OPTIONAL
169 Internal helper function to return a handle to the currently executing framework.
170 This function is generally used for communication within the UnitTest framework, but is
171 defined here so that it can be consumed by the Assertion and Logging macros.
173 There should be no need to consume as a test writer, but it's there if you need it.
175 @retval Handle to the currently executing test framework.
178 UNIT_TEST_FRAMEWORK_HANDLE
179 GetActiveFrameworkHandle (