TianoCore EDK2 master
Loading...
Searching...
No Matches
UnitTestResultReportLib.c
Go to the documentation of this file.
1
8#include <Uefi.h>
10#include <Library/BaseLib.h>
11#include <Library/DebugLib.h>
12
13VOID
14EFIAPI
15ReportPrint (
16 IN CONST CHAR8 *Format,
17 ...
18 );
19
20VOID
21ReportOutput (
22 IN CONST CHAR8 *Output
23 );
24
26 UNIT_TEST_STATUS Status;
27 CHAR8 *String;
28};
29
31 FAILURE_TYPE Type;
32 CHAR8 *String;
33};
34
35struct _UNIT_TEST_STATUS_STRING mStatusStrings[] = {
36 { UNIT_TEST_PASSED, "PASSED" },
37 { UNIT_TEST_ERROR_PREREQUISITE_NOT_MET, "NOT RUN - PREREQUISITE FAILED" },
38 { UNIT_TEST_ERROR_TEST_FAILED, "FAILED" },
39 { UNIT_TEST_RUNNING, "RUNNING" },
40 { UNIT_TEST_PENDING, "PENDING" },
41 { 0, "**UNKNOWN**" }
42};
43
44struct _UNIT_TEST_FAILURE_TYPE_STRING mFailureTypeStrings[] = {
45 { FAILURETYPE_NOFAILURE, "NO FAILURE" },
46 { FAILURETYPE_OTHER, "OTHER FAILURE" },
47 { FAILURETYPE_ASSERTTRUE, "ASSERT_TRUE FAILURE" },
48 { FAILURETYPE_ASSERTFALSE, "ASSERT_FALSE FAILURE" },
49 { FAILURETYPE_ASSERTEQUAL, "ASSERT_EQUAL FAILURE" },
50 { FAILURETYPE_ASSERTNOTEQUAL, "ASSERT_NOTEQUAL FAILURE" },
51 { FAILURETYPE_ASSERTNOTEFIERROR, "ASSERT_NOTEFIERROR FAILURE" },
52 { FAILURETYPE_ASSERTSTATUSEQUAL, "ASSERT_STATUSEQUAL FAILURE" },
53 { FAILURETYPE_ASSERTNOTNULL, "ASSERT_NOTNULL FAILURE" },
54 { FAILURETYPE_EXPECTASSERT, "EXPECT_ASSERT FAILURE" },
55 { 0, "*UNKNOWN* Failure" }
56};
57
58//
59// TEST REPORTING FUNCTIONS
60//
61
63CONST CHAR8 *
64GetStringForUnitTestStatus (
65 IN UNIT_TEST_STATUS Status
66 )
67{
68 UINTN Index;
69
70 for (Index = 0; Index < ARRAY_SIZE (mStatusStrings) - 1; Index++) {
71 if (mStatusStrings[Index].Status == Status) {
72 //
73 // Return string from matching entry
74 //
75 return mStatusStrings[Index].String;
76 }
77 }
78
79 //
80 // Return last entry if no match found.
81 //
82 return mStatusStrings[Index].String;
83}
84
86CONST CHAR8 *
87GetStringForFailureType (
88 IN FAILURE_TYPE Failure
89 )
90{
91 UINTN Index;
92
93 for (Index = 0; Index < ARRAY_SIZE (mFailureTypeStrings) - 1; Index++) {
94 if (mFailureTypeStrings[Index].Type == Failure) {
95 //
96 // Return string from matching entry
97 //
98 return mFailureTypeStrings[Index].String;
99 }
100 }
101
102 //
103 // Return last entry if no match found.
104 //
105 DEBUG ((DEBUG_INFO, "%a Failure Type does not have string defined 0x%X\n", __func__, (UINT32)Failure));
106 return mFailureTypeStrings[Index].String;
107}
108
109/*
110 Method to print the Unit Test run results
111
112 @retval Success
113*/
115EFIAPI
117 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle
118 )
119{
120 UNIT_TEST_FRAMEWORK *Framework;
121 INTN Passed;
122 INTN Failed;
123 INTN NotRun;
126 INTN SPassed;
127 INTN SFailed;
128 INTN SNotRun;
129
130 Passed = 0;
131 Failed = 0;
132 NotRun = 0;
133 Suite = NULL;
134
135 Framework = (UNIT_TEST_FRAMEWORK *)FrameworkHandle;
136 if (Framework == NULL) {
137 return EFI_INVALID_PARAMETER;
138 }
139
140 ReportPrint ("---------------------------------------------------------\n");
141 ReportPrint ("------------- UNIT TEST FRAMEWORK RESULTS ---------------\n");
142 ReportPrint ("---------------------------------------------------------\n");
143
144 // print the version and time
145
146 //
147 // Iterate all suites
148 //
149 for (Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetFirstNode (&Framework->TestSuiteList);
150 (LIST_ENTRY *)Suite != &Framework->TestSuiteList;
151 Suite = (UNIT_TEST_SUITE_LIST_ENTRY *)GetNextNode (&Framework->TestSuiteList, (LIST_ENTRY *)Suite))
152 {
153 Test = NULL;
154 SPassed = 0;
155 SFailed = 0;
156 SNotRun = 0;
157
158 ReportPrint ("/////////////////////////////////////////////////////////\n");
159 ReportPrint (" SUITE: %a\n", Suite->UTS.Title);
160 ReportPrint (" PACKAGE: %a\n", Suite->UTS.Name);
161 ReportPrint ("/////////////////////////////////////////////////////////\n");
162
163 //
164 // Iterate all tests within the suite
165 //
166 for (Test = (UNIT_TEST_LIST_ENTRY *)GetFirstNode (&(Suite->UTS.TestCaseList));
167 (LIST_ENTRY *)Test != &(Suite->UTS.TestCaseList);
168 Test = (UNIT_TEST_LIST_ENTRY *)GetNextNode (&(Suite->UTS.TestCaseList), (LIST_ENTRY *)Test))
169 {
170 ReportPrint ("*********************************************************\n");
171 ReportPrint (" CLASS NAME: %a\n", Test->UT.Name);
172 ReportPrint (" TEST: %a\n", Test->UT.Description);
173 ReportPrint (" STATUS: %a\n", GetStringForUnitTestStatus (Test->UT.Result));
174 ReportPrint (" FAILURE: %a\n", GetStringForFailureType (Test->UT.FailureType));
175 ReportPrint (" FAILURE MESSAGE:\n%a\n", Test->UT.FailureMessage);
176
177 if (Test->UT.Log != NULL) {
178 ReportPrint (" LOG:\n");
179 ReportOutput (Test->UT.Log);
180 }
181
182 switch (Test->UT.Result) {
183 case UNIT_TEST_PASSED:
184 SPassed++;
185 break;
186 case UNIT_TEST_ERROR_TEST_FAILED:
187 SFailed++;
188 break;
189 case UNIT_TEST_PENDING: // Fall through...
190 case UNIT_TEST_RUNNING: // Fall through...
191 case UNIT_TEST_ERROR_PREREQUISITE_NOT_MET:
192 SNotRun++;
193 break;
194 default:
195 break;
196 }
197
198 ReportPrint ("**********************************************************\n");
199 } // End Test iteration
200
201 ReportPrint ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
202 ReportPrint ("Suite Stats\n");
203 ReportPrint (" Passed: %d (%d%%)\n", SPassed, (SPassed * 100)/(SPassed+SFailed+SNotRun));
204 ReportPrint (" Failed: %d (%d%%)\n", SFailed, (SFailed * 100) / (SPassed + SFailed + SNotRun));
205 ReportPrint (" Not Run: %d (%d%%)\n", SNotRun, (SNotRun * 100) / (SPassed + SFailed + SNotRun));
206 ReportPrint ("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
207
208 Passed += SPassed; // add to global counters
209 Failed += SFailed; // add to global counters
210 NotRun += SNotRun; // add to global counters
211 }// End Suite iteration
212
213 ReportPrint ("=========================================================\n");
214 ReportPrint ("Total Stats\n");
215 ReportPrint (" Passed: %d (%d%%)\n", Passed, (Passed * 100) / (Passed + Failed + NotRun));
216 ReportPrint (" Failed: %d (%d%%)\n", Failed, (Failed * 100) / (Passed + Failed + NotRun));
217 ReportPrint (" Not Run: %d (%d%%)\n", NotRun, (NotRun * 100) / (Passed + Failed + NotRun));
218 ReportPrint ("=========================================================\n");
219
220 return EFI_SUCCESS;
221}
UINT64 UINTN
INT64 INTN
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
Definition: LinkedList.c:333
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
Definition: LinkedList.c:298
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
INTN EFIAPI Test(CONST VOID *b1, CONST VOID *b2)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT32 FAILURE_TYPE
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16
EFI_STATUS EFIAPI OutputUnitTestFrameworkReport(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)