-
Notifications
You must be signed in to change notification settings - Fork 28
/
SBBRRuntimeServicesBBTestFunction.c
executable file
·614 lines (559 loc) · 19.8 KB
/
SBBRRuntimeServicesBBTestFunction.c
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*++
The material contained herein is not a license, either
expressly or impliedly, to any intellectual property owned
or controlled by any of the authors or developers of this
material or to any contribution thereto. The material
contained herein is provided on an "AS IS" basis and, to the
maximum extent permitted by applicable law, this information
is provided AS IS AND WITH ALL FAULTS, and the authors and
developers of this material hereby disclaim all other
warranties and conditions, either express, implied or
statutory, including, but not limited to, any (if any)
implied warranties, duties or conditions of merchantability,
of fitness for a particular purpose, of accuracy or
completeness of responses, of results, of workmanlike
effort, of lack of viruses and of lack of negligence, all
with regard to this material and any contribution thereto.
Designers must not rely on the absence or characteristics of
any features or instructions marked "reserved" or
"undefined." The Unified EFI Forum, Inc. reserves any
features or instructions so marked for future definition and
shall have no responsibility whatsoever for conflicts or
incompatibilities arising from future changes to them. ALSO,
THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR
NON-INFRINGEMENT WITH REGARD TO THE TEST SUITE AND ANY
CONTRIBUTION THERETO.
IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THIS MATERIAL OR
ANY CONTRIBUTION THERETO BE LIABLE TO ANY OTHER PARTY FOR
THE COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST
PROFITS, LOSS OF USE, LOSS OF DATA, OR ANY INCIDENTAL,
CONSEQUENTIAL, DIRECT, INDIRECT, OR SPECIAL DAMAGES WHETHER
UNDER CONTRACT, TORT, WARRANTY, OR OTHERWISE, ARISING IN ANY
WAY OUT OF THIS OR ANY OTHER AGREEMENT RELATING TO THIS
DOCUMENT, WHETHER OR NOT SUCH PARTY HAD ADVANCE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGES.
Copyright 2006 - 2016 Unified EFI, Inc. All
Rights Reserved, subject to all existing rights in all
matters included within this Test Suite, to which United
EFI, Inc. makes no claim of right.
Copyright (c) 2016, ARM Corporation. All rights reserved.<BR>
--*/
/*++
Module Name:
SBBRRuntimeServicesBBTestFunction.c
Abstract:
Test cases for SBBRRuntimeServices.
--*/
#include "Guid.h"
#include "SctLib.h"
#include <Library/EfiTestLib.h>
#include "SBBRRuntimeServicesBBTestMain.h"
#include "SBBRRuntimeServicesBBTestFunction.h"
#include EFI_TEST_PROTOCOL_DEFINITION(TestRecoveryLibrary)
/**
* Entrypoint for Runtime Services Test.
* @param This a pointer of EFI_BB_TEST_PROTOCOL.
* @param ClientInterface a pointer to the interface to be tested.
* @param TestLevel test "thoroughness" control.
* @param SupportHandle a handle containing protocols required.
* @return EFI_SUCCESS Finish the test successfully.
*/
EFI_STATUS
BBTestRuntimeServices (
IN EFI_BB_TEST_PROTOCOL *This,
IN VOID *ClientInterface,
IN EFI_TEST_LEVEL TestLevel,
IN EFI_HANDLE SupportHandle
)
{
EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib;
EFI_STATUS Status;
EFI_TEST_ASSERTION AssertionType;
UINT32 CRC32;
UINT32 LocalCRC32;
//
// Get the Standard Library Interface
//
Status = gtBS->HandleProtocol (
SupportHandle,
&gEfiStandardTestLibraryGuid,
(VOID **) &StandardLib
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Check the EFI Runtime Services Table
//
CRC32 = gtRT->Hdr.CRC32;
gtRT->Hdr.CRC32 = 0;
LocalCRC32 = 0;
Status = SctCalculateCrc32 ((UINT8 *)gtRT, gtRT->Hdr.HeaderSize, &LocalCRC32);
if (EFI_ERROR (Status)) {
AssertionType = EFI_TEST_ASSERTION_FAILED;
} else {
if ((gtRT->Hdr.Signature == EFI_RUNTIME_SERVICES_SIGNATURE) &&
(gtRT->Hdr.Revision >= 0x00020000 ) &&
(gtRT->Hdr.Reserved == 0x00000000 ) &&
(gtRT->GetTime != NULL ) &&
(gtRT->SetTime != NULL ) &&
(gtRT->GetWakeupTime != NULL ) &&
(gtRT->SetWakeupTime != NULL ) &&
(gtRT->SetVirtualAddressMap != NULL ) &&
(gtRT->ConvertPointer != NULL ) &&
(gtRT->GetVariable != NULL ) &&
(gtRT->GetNextVariableName != NULL ) &&
(gtRT->SetVariable != NULL ) &&
(gtRT->GetNextHighMonotonicCount != NULL ) &&
(gtRT->ResetSystem != NULL ) &&
(gtRT->QueryVariableInfo != NULL ) &&
(gtRT->QueryCapsuleCapabilities != NULL ) &&
(gtRT->UpdateCapsule != NULL ) &&
(LocalCRC32 == CRC32 )) {
AssertionType = EFI_TEST_ASSERTION_PASSED;
} else {
AssertionType = EFI_TEST_ASSERTION_FAILED;
}
gtRT->Hdr.CRC32 = CRC32;
}
StandardLib->RecordAssertion (
StandardLib,
AssertionType,
gSBBRRuntimeServicesAssertion001Guid,
L"UEFI Compliant - EFI Runtime Services Table must be implemented",
L"%a:%d:Signature - %lX, Expected - %lX",
__FILE__,
(UINTN)__LINE__,
gtRT->Hdr.Signature,
EFI_RUNTIME_SERVICES_SIGNATURE
);
//
// Record the entire EFI Runtime Services Table
//
StandardLib->RecordMessage (
StandardLib,
EFI_VERBOSE_LEVEL_DEFAULT,
L" Hdr.Signature : %lX\n"
L" Hdr.Revision : %X\n"
L" Hdr.HeaderSize : %X\n"
L" Hdr.CRC32 : %X\n"
L" Hdr.Reserved : %X\n",
gtRT->Hdr.Signature,
gtRT->Hdr.Revision,
gtRT->Hdr.HeaderSize,
gtRT->Hdr.CRC32,
gtRT->Hdr.Reserved
);
StandardLib->RecordMessage (
StandardLib,
EFI_VERBOSE_LEVEL_DEFAULT,
L" GetTime : %X\n"
L" SetTime : %X\n"
L" GetWakeupTime : %X\n"
L" SetWakeupTime : %X\n"
L" SetVirtualAddressMap : %X\n"
L" ConvertPointer : %X\n"
L" GetVariable : %X\n"
L" GetNextVariableName : %X\n"
L" SetVariable : %X\n",
gtRT->GetTime,
gtRT->SetTime,
gtRT->GetWakeupTime,
gtRT->SetWakeupTime,
gtRT->SetVirtualAddressMap,
gtRT->ConvertPointer,
gtRT->GetVariable,
gtRT->GetNextVariableName,
gtRT->SetVariable
);
StandardLib->RecordMessage (
StandardLib,
EFI_VERBOSE_LEVEL_DEFAULT,
L" GetNextHighMonotonicCount : %X\n"
L" ResetSystem : %X\n"
L" QueryVariableInfo : %X\n"
L" QueryCapsuleCapabilities : %X\n"
L" UpdateCapsule : %X\n",
gtRT->GetNextHighMonotonicCount,
gtRT->ResetSystem,
gtRT->QueryVariableInfo,
gtRT->QueryCapsuleCapabilities,
gtRT->UpdateCapsule
);
//
// Done
//
//
// Function calls like above are used to record test results.
// The actual return value of this function is used to tell
// the framework whether the tests completed successfully or
// if there was some fault in the test itself. For example, not
// being able to allocate a buffer because the system is out of
// memory would return an error, but a test case failing because
// a register being checked does not contain the right value
// would return EFI_SUCCESS.
//
return EFI_SUCCESS;
}
extern EFI_TPL TplArray [];
/**
* Entrypoint for gtRT->ResetSystem() Manual Test.
* @param This a pointer of EFI_BB_TEST_PROTOCOL.
* @param ClientInterface a pointer to the interface to be tested.
* @param TestLevel test "thoroughness" control.
* @param SupportHandle a handle containing protocols required.
* @return EFI_SUCCESS Finish the test successfully.
*/
//
// SBBR 3.5.4
//
EFI_STATUS
BBTestResetShutdown (
IN EFI_BB_TEST_PROTOCOL *This,
IN VOID *ClientInterface,
IN EFI_TEST_LEVEL TestLevel,
IN EFI_HANDLE SupportHandle
)
{
EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib;
EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib;
EFI_STATUS Status;
EFI_TEST_ASSERTION AssertionType;
UINTN Index;
EFI_TPL OldTpl;
UINT8 Buffer[1024];
RESET_DATA *ResetData;
UINTN Size;
//
// Get the Standard Library Interface
//
Status = gtBS->HandleProtocol (
SupportHandle,
&gEfiStandardTestLibraryGuid,
(VOID **) &StandardLib
);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Get the Recovery Library Interface
//
Status = gtBS->HandleProtocol (
SupportHandle,
&gEfiTestRecoveryLibraryGuid,
(VOID **) &RecoveryLib
);
if (EFI_ERROR (Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"BS.HandleProtocol - Handle recovery library",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
//
// Read reset record
//
Status = RecoveryLib->ReadResetRecord (
RecoveryLib,
&Size,
Buffer
);
ResetData = (RESET_DATA *)Buffer;
if (EFI_ERROR (Status) || (Size < sizeof (RESET_DATA))) {
//
// Step 1
//
} else if (ResetData->Step == 1) {
//
// Step 2
//
if (ResetData->TplIndex < TPL_ARRAY_SIZE) {
Index = ResetData->TplIndex;
AssertionType = EFI_TEST_ASSERTION_PASSED;
goto ManualTestStep2;
}
} else {
return EFI_LOAD_ERROR;
}
for (Index = 0; Index < TPL_ARRAY_SIZE; Index++) {
//
// 4.2.2.1 ResetSystem must succeed when ResetType is EfiResetShutdown
//
ResetData->Step = 1;
ResetData->TplIndex = Index;
Status = RecoveryLib->WriteResetRecord (
RecoveryLib,
sizeof (RESET_DATA),
Buffer
);
if (EFI_ERROR (Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"TestRecoveryLib - WriteResetRecord",
L"%a:%d:Status - %r, TPL - %d",
__FILE__,
(UINTN)__LINE__,
Status,
TplArray[Index]
);
return Status;
}
//
// Print out some information to avoid the user thought it is an error.
//
// And the stall a second is required to make sure the recovery data has
// been written into the storage device.
//
SctPrint (L"System will shut down (or cold reset) after 1 second...");
gtBS->Stall (1000000);
OldTpl = gtBS->RaiseTPL (TplArray[Index]);
gtRT->ResetSystem (
EfiResetShutdown,
EFI_SUCCESS,
0,
NULL
);
gtBS->RestoreTPL (OldTpl);
AssertionType = EFI_TEST_ASSERTION_FAILED;
ManualTestStep2:
StandardLib->RecordAssertion (
StandardLib,
AssertionType,
Index==0? \
gSBBRRuntimeServicesAssertion003Guid: \
(Index == 1? \
gSBBRRuntimeServicesAssertion002Guid: \
gSBBRRuntimeServicesAssertion003Guid),
L"RT.ResetSystem - EfiResetShutdown",
L"%a:%d:Status - %r, TPL - %d",
__FILE__,
(UINTN)__LINE__,
Status,
TplArray[Index]
);
}
return EFI_SUCCESS;
}
/**
* Entrypoint for NonVolatileVariable test.
* @param This a pointer of EFI_BB_TEST_PROTOCOL.
* @param ClientInterface a pointer to the interface to be tested.
* @param TestLevel test "thoroughness" control.
* @param SupportHandle a handle containing protocols required.
* @return EFI_SUCCESS Finish the test successfully.
*/
//
// SBBR 3.5.5
//
EFI_STATUS
BBTestNonVolatileVariable (
IN EFI_BB_TEST_PROTOCOL *This,
IN VOID *ClientInterface,
IN EFI_TEST_LEVEL TestLevel,
IN EFI_HANDLE SupportHandle
)
{
EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib;
EFI_TEST_RECOVERY_LIBRARY_PROTOCOL *RecoveryLib;
EFI_STATUS Status;
EFI_TEST_ASSERTION AssertionType;
UINT8 Buffer[20];
EFI_GUID ResetGuid = SBBRRUNTIMESERVICES_NONVOLATILEVARIABLE_RESET_GUID;
EFI_GUID *TestResetGuid;
EFI_GUID VarVendorGuid = VENDOR_GUID;
UINTN Size;
UINT32 Attributes;
UINT32 VariableValue = UEFI_VARIABLE_TEST_VALUE;
UINT32 *TestVariableValue;
//
// Get the Standard Library Interface
//
Status = gtBS->HandleProtocol (
SupportHandle,
&gEfiStandardTestLibraryGuid,
(VOID **) &StandardLib
);
if (EFI_ERROR(Status)) {
return Status;
}
//
// Get the Recovery Library Interface
//
Status = gtBS->HandleProtocol (
SupportHandle,
&gEfiTestRecoveryLibraryGuid,
(VOID **) &RecoveryLib
);
if (EFI_ERROR(Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"BS.HandleProtocol - Handle recovery library",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
//
// Read reset record
//
Status = RecoveryLib->ReadResetRecord (
RecoveryLib,
&Size,
Buffer
);
TestResetGuid = (EFI_GUID *)Buffer;
if (EFI_ERROR(Status) || SctCompareGuid((void *)TestResetGuid, (void *)&ResetGuid) != 0) {
//
// Writing a new non-volatile variable for testing after making sure it doesn't already exist.
//
// Making a variable of the same name and vendor GUID with a size of zero to delete anything that might be left over
Size = 0;
Status = gtRT->SetVariable (
TEST_VAR_NAME,
&VarVendorGuid,
NULL,
Size,
NULL
);
if (EFI_ERROR(Status) && Status != EFI_NOT_FOUND) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"RS.SetVariable",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
// Writing a known value into the UEFI variable with nonvolatile flag
Size = sizeof (UINT32);
Attributes = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS;
Status = gtRT->SetVariable (
TEST_VAR_NAME,
&VarVendorGuid,
Attributes,
Size,
(VOID *)&VariableValue
);
if (EFI_ERROR(Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"RS.SetVariable",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
// Writing reset record and doing a cold reset
SctPrint (L"System will cold reboot...");
Status = RecoveryLib->WriteResetRecord (
RecoveryLib,
sizeof (EFI_GUID),
&ResetGuid
);
gtBS->Stall (1000000);
gtRT->ResetSystem (
EfiResetCold,
EFI_SUCCESS,
0,
NULL
);
// Execution should never get here
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"RT.ResetSystem",
L"%a:%d - System failed to reboot.",
__FILE__,
(UINTN)__LINE__
);
return EFI_ABORTED;
} else if (SctCompareGuid((void *)TestResetGuid, (void *)&ResetGuid) == 0) {
//
// Reading non-volatile variable to see if it's value was retained.
//
// Calling GetVariable to see if our new variable is still there.
Status = gtRT->GetVariable (
TEST_VAR_NAME,
&VarVendorGuid,
&Attributes,
&Size,
Buffer
);
if (EFI_ERROR(Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"RS.GetVariable",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
// Erasing the variable we created from the system
Size = 0;
Status = gtRT->SetVariable (
TEST_VAR_NAME,
&VarVendorGuid,
NULL,
Size,
NULL
);
if (EFI_ERROR(Status)) {
StandardLib->RecordAssertion (
StandardLib,
EFI_TEST_ASSERTION_FAILED,
gTestGenericFailureGuid,
L"RS.SetVariable",
L"%a:%d:Status - %r",
__FILE__,
(UINTN)__LINE__,
Status
);
return Status;
}
// Checking value received against value written.
TestVariableValue = (UINT32 *)Buffer;
if (*TestVariableValue == VariableValue) {
AssertionType = EFI_TEST_ASSERTION_PASSED;
} else {
AssertionType = EFI_TEST_ASSERTION_FAILED;
}
StandardLib->RecordAssertion (
StandardLib,
AssertionType,
gSBBRRuntimeServicesAssertion004Guid,
L"NonVolatileVariable",
L"%a:%d",
__FILE__,
(UINTN)__LINE__
);
return EFI_SUCCESS;
} else {
return EFI_LOAD_ERROR;
}
}