]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.c
MdePkg: Apply uncrustify changes
[mirror_edk2.git] / MdePkg / Test / UnitTest / Library / BaseSafeIntLib / TestBaseSafeIntLib.c
1 /** @file
2 UEFI OS based application for unit testing the SafeIntLib.
3
4 Copyright (c) Microsoft Corporation.<BR>
5 Copyright (c) 2018 - 2020, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "TestBaseSafeIntLib.h"
11
12 #define UNIT_TEST_NAME "Int Safe Lib Unit Test Application"
13 #define UNIT_TEST_VERSION "0.1"
14
15 //
16 // Conversion function tests:
17 //
18 UNIT_TEST_STATUS
19 EFIAPI
20 TestSafeInt8ToUint8 (
21 IN UNIT_TEST_CONTEXT Context
22 )
23 {
24 EFI_STATUS Status;
25 INT8 Operand;
26 UINT8 Result;
27
28 //
29 // Positive UINT8 should result in just a cast
30 //
31 Operand = 0x5b;
32 Result = 0;
33 Status = SafeInt8ToUint8 (Operand, &Result);
34 UT_ASSERT_NOT_EFI_ERROR (Status);
35 UT_ASSERT_EQUAL (0x5b, Result);
36
37 //
38 // Negative number should result in an error status
39 //
40 Operand = (-56);
41 Status = SafeInt8ToUint8 (Operand, &Result);
42 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
43
44 return UNIT_TEST_PASSED;
45 }
46
47 UNIT_TEST_STATUS
48 EFIAPI
49 TestSafeInt8ToUint16 (
50 IN UNIT_TEST_CONTEXT Context
51 )
52 {
53 EFI_STATUS Status;
54 INT8 Operand;
55 UINT16 Result;
56
57 //
58 // Positive UINT8 should result in just a cast
59 //
60 Operand = 0x5b;
61 Result = 0;
62 Status = SafeInt8ToUint16 (Operand, &Result);
63 UT_ASSERT_NOT_EFI_ERROR (Status);
64 UT_ASSERT_EQUAL (0x5b, Result);
65
66 //
67 // Negative number should result in an error status
68 //
69 Operand = (-56);
70 Status = SafeInt8ToUint16 (Operand, &Result);
71 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
72
73 return UNIT_TEST_PASSED;
74 }
75
76 UNIT_TEST_STATUS
77 EFIAPI
78 TestSafeInt8ToUint32 (
79 IN UNIT_TEST_CONTEXT Context
80 )
81 {
82 EFI_STATUS Status;
83 INT8 Operand;
84 UINT32 Result;
85
86 //
87 // Positive UINT8 should result in just a cast
88 //
89 Operand = 0x5b;
90 Result = 0;
91 Status = SafeInt8ToUint32 (Operand, &Result);
92 UT_ASSERT_NOT_EFI_ERROR (Status);
93 UT_ASSERT_EQUAL (0x5b, Result);
94
95 //
96 // Negative number should result in an error status
97 //
98 Operand = (-56);
99 Status = SafeInt8ToUint32 (Operand, &Result);
100 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
101
102 return UNIT_TEST_PASSED;
103 }
104
105 UNIT_TEST_STATUS
106 EFIAPI
107 TestSafeInt8ToUintn (
108 IN UNIT_TEST_CONTEXT Context
109 )
110 {
111 EFI_STATUS Status;
112 INT8 Operand;
113 UINTN Result;
114
115 //
116 // Positive UINT8 should result in just a cast
117 //
118 Operand = 0x5b;
119 Result = 0;
120 Status = SafeInt8ToUintn (Operand, &Result);
121 UT_ASSERT_NOT_EFI_ERROR (Status);
122 UT_ASSERT_EQUAL (0x5b, Result);
123
124 //
125 // Negative number should result in an error status
126 //
127 Operand = (-56);
128 Status = SafeInt8ToUintn (Operand, &Result);
129 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
130
131 return UNIT_TEST_PASSED;
132 }
133
134 UNIT_TEST_STATUS
135 EFIAPI
136 TestSafeInt8ToUint64 (
137 IN UNIT_TEST_CONTEXT Context
138 )
139 {
140 EFI_STATUS Status;
141 INT8 Operand;
142 UINT64 Result;
143
144 //
145 // Positive UINT8 should result in just a cast
146 //
147 Operand = 0x5b;
148 Result = 0;
149 Status = SafeInt8ToUint64 (Operand, &Result);
150 UT_ASSERT_NOT_EFI_ERROR (Status);
151 UT_ASSERT_EQUAL (0x5b, Result);
152
153 //
154 // Negative number should result in an error status
155 //
156 Operand = (-56);
157 Status = SafeInt8ToUint64 (Operand, &Result);
158 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
159
160 return UNIT_TEST_PASSED;
161 }
162
163 UNIT_TEST_STATUS
164 EFIAPI
165 TestSafeUint8ToInt8 (
166 IN UNIT_TEST_CONTEXT Context
167 )
168 {
169 EFI_STATUS Status;
170 UINT8 Operand;
171 INT8 Result;
172
173 //
174 // Operand <= 0x7F (MAX_INT8) should result in a cast
175 //
176 Operand = 0x5b;
177 Result = 0;
178 Status = SafeUint8ToInt8 (Operand, &Result);
179 UT_ASSERT_NOT_EFI_ERROR (Status);
180 UT_ASSERT_EQUAL (0x5b, Result);
181
182 //
183 // Operand larger than 0x7f should result in an error status
184 //
185 Operand = 0xaf;
186 Status = SafeUint8ToInt8 (Operand, &Result);
187 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
188
189 return UNIT_TEST_PASSED;
190 }
191
192 UNIT_TEST_STATUS
193 EFIAPI
194 TestSafeUint8ToChar8 (
195 IN UNIT_TEST_CONTEXT Context
196 )
197 {
198 EFI_STATUS Status;
199 UINT8 Operand;
200 CHAR8 Result;
201
202 //
203 // CHAR8 is typedefed as char, which by default is signed, thus
204 // CHAR8 is same as INT8, so same tests as above:
205 //
206
207 //
208 // Operand <= 0x7F (MAX_INT8) should result in a cast
209 //
210 Operand = 0x5b;
211 Result = 0;
212 Status = SafeUint8ToChar8 (Operand, &Result);
213 UT_ASSERT_NOT_EFI_ERROR (Status);
214 UT_ASSERT_EQUAL (0x5b, Result);
215
216 //
217 // Operand larger than 0x7f should result in an error status
218 //
219 Operand = 0xaf;
220 Status = SafeUint8ToChar8 (Operand, &Result);
221 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
222
223 return UNIT_TEST_PASSED;
224 }
225
226 UNIT_TEST_STATUS
227 EFIAPI
228 TestSafeInt16ToInt8 (
229 IN UNIT_TEST_CONTEXT Context
230 )
231 {
232 EFI_STATUS Status;
233 INT16 Operand;
234 INT8 Result;
235
236 //
237 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
238 //
239 Operand = 0x5b;
240 Result = 0;
241 Status = SafeInt16ToInt8 (Operand, &Result);
242 UT_ASSERT_NOT_EFI_ERROR (Status);
243 UT_ASSERT_EQUAL (0x5b, Result);
244
245 Operand = (-35);
246 Status = SafeInt16ToInt8 (Operand, &Result);
247 UT_ASSERT_NOT_EFI_ERROR (Status);
248 UT_ASSERT_EQUAL ((-35), Result);
249
250 //
251 // Otherwise should result in an error status
252 //
253 Operand = 0x1234;
254 Status = SafeInt16ToInt8 (Operand, &Result);
255 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
256
257 Operand = (-17835);
258 Status = SafeInt16ToInt8 (Operand, &Result);
259 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
260
261 return UNIT_TEST_PASSED;
262 }
263
264 UNIT_TEST_STATUS
265 EFIAPI
266 TestSafeInt16ToChar8 (
267 IN UNIT_TEST_CONTEXT Context
268 )
269 {
270 EFI_STATUS Status;
271 INT16 Operand;
272 CHAR8 Result;
273
274 //
275 // CHAR8 is typedefed as char, which may be signed or unsigned based
276 // on the compiler. Thus, for compatibility CHAR8 should be between 0 and MAX_INT8.
277 //
278
279 //
280 // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast
281 //
282 Operand = 0x5b;
283 Result = 0;
284 Status = SafeInt16ToChar8 (Operand, &Result);
285 UT_ASSERT_NOT_EFI_ERROR (Status);
286 UT_ASSERT_EQUAL (0x5b, Result);
287
288 Operand = 0;
289 Result = 0;
290 Status = SafeInt16ToChar8 (Operand, &Result);
291 UT_ASSERT_NOT_EFI_ERROR (Status);
292 UT_ASSERT_EQUAL (0, Result);
293
294 Operand = MAX_INT8;
295 Result = 0;
296 Status = SafeInt16ToChar8 (Operand, &Result);
297 UT_ASSERT_NOT_EFI_ERROR (Status);
298 UT_ASSERT_EQUAL (MAX_INT8, Result);
299
300 //
301 // Otherwise should result in an error status
302 //
303 Operand = (-35);
304 Status = SafeInt16ToChar8 (Operand, &Result);
305 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
306
307 Operand = 0x1234;
308 Status = SafeInt16ToChar8 (Operand, &Result);
309 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
310
311 Operand = (-17835);
312 Status = SafeInt16ToChar8 (Operand, &Result);
313 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
314
315 return UNIT_TEST_PASSED;
316 }
317
318 UNIT_TEST_STATUS
319 EFIAPI
320 TestSafeInt16ToUint8 (
321 IN UNIT_TEST_CONTEXT Context
322 )
323 {
324 EFI_STATUS Status;
325 INT16 Operand;
326 UINT8 Result;
327
328 //
329 // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast
330 //
331 Operand = 0x5b;
332 Result = 0;
333 Status = SafeInt16ToUint8 (Operand, &Result);
334 UT_ASSERT_NOT_EFI_ERROR (Status);
335 UT_ASSERT_EQUAL (0x5b, Result);
336
337 //
338 // Otherwise should result in an error status
339 //
340 Operand = 0x1234;
341 Status = SafeInt16ToUint8 (Operand, &Result);
342 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
343
344 Operand = (-17835);
345 Status = SafeInt16ToUint8 (Operand, &Result);
346 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
347
348 return UNIT_TEST_PASSED;
349 }
350
351 UNIT_TEST_STATUS
352 EFIAPI
353 TestSafeInt16ToUint16 (
354 IN UNIT_TEST_CONTEXT Context
355 )
356 {
357 EFI_STATUS Status;
358 INT16 Operand = 0x5b5b;
359 UINT16 Result = 0;
360
361 //
362 // If Operand is non-negative, then it's a cast
363 //
364 Status = SafeInt16ToUint16 (Operand, &Result);
365 UT_ASSERT_NOT_EFI_ERROR (Status);
366 UT_ASSERT_EQUAL (0x5b5b, Result);
367
368 //
369 // Otherwise should result in an error status
370 //
371 Operand = (-17835);
372 Status = SafeInt16ToUint16 (Operand, &Result);
373 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
374
375 return UNIT_TEST_PASSED;
376 }
377
378 UNIT_TEST_STATUS
379 EFIAPI
380 TestSafeInt16ToUint32 (
381 IN UNIT_TEST_CONTEXT Context
382 )
383 {
384 EFI_STATUS Status;
385 INT16 Operand;
386 UINT32 Result;
387
388 //
389 // If Operand is non-negative, then it's a cast
390 //
391 Operand = 0x5b5b;
392 Result = 0;
393 Status = SafeInt16ToUint32 (Operand, &Result);
394 UT_ASSERT_NOT_EFI_ERROR (Status);
395 UT_ASSERT_EQUAL (0x5b5b, Result);
396
397 //
398 // Otherwise should result in an error status
399 //
400 Operand = (-17835);
401 Status = SafeInt16ToUint32 (Operand, &Result);
402 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
403
404 return UNIT_TEST_PASSED;
405 }
406
407 UNIT_TEST_STATUS
408 EFIAPI
409 TestSafeInt16ToUintn (
410 IN UNIT_TEST_CONTEXT Context
411 )
412 {
413 EFI_STATUS Status;
414 INT16 Operand;
415 UINTN Result;
416
417 //
418 // If Operand is non-negative, then it's a cast
419 //
420 Operand = 0x5b5b;
421 Result = 0;
422 Status = SafeInt16ToUintn (Operand, &Result);
423 UT_ASSERT_NOT_EFI_ERROR (Status);
424 UT_ASSERT_EQUAL (0x5b5b, Result);
425
426 //
427 // Otherwise should result in an error status
428 //
429 Operand = (-17835);
430 Status = SafeInt16ToUintn (Operand, &Result);
431 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
432
433 return UNIT_TEST_PASSED;
434 }
435
436 UNIT_TEST_STATUS
437 EFIAPI
438 TestSafeInt16ToUint64 (
439 IN UNIT_TEST_CONTEXT Context
440 )
441 {
442 EFI_STATUS Status;
443 INT16 Operand;
444 UINT64 Result;
445
446 //
447 // If Operand is non-negative, then it's a cast
448 //
449 Operand = 0x5b5b;
450 Result = 0;
451 Status = SafeInt16ToUint64 (Operand, &Result);
452 UT_ASSERT_NOT_EFI_ERROR (Status);
453 UT_ASSERT_EQUAL (0x5b5b, Result);
454
455 //
456 // Otherwise should result in an error status
457 //
458 Operand = (-17835);
459 Status = SafeInt16ToUint64 (Operand, &Result);
460 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
461
462 return UNIT_TEST_PASSED;
463 }
464
465 UNIT_TEST_STATUS
466 EFIAPI
467 TestSafeUint16ToInt8 (
468 IN UNIT_TEST_CONTEXT Context
469 )
470 {
471 EFI_STATUS Status;
472 UINT16 Operand;
473 INT8 Result;
474
475 //
476 // If Operand is <= MAX_INT8, it's a cast
477 //
478 Operand = 0x5b;
479 Result = 0;
480 Status = SafeUint16ToInt8 (Operand, &Result);
481 UT_ASSERT_NOT_EFI_ERROR (Status);
482 UT_ASSERT_EQUAL (0x5b, Result);
483
484 //
485 // Otherwise should result in an error status
486 //
487 Operand = (0x5b5b);
488 Status = SafeUint16ToInt8 (Operand, &Result);
489 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
490
491 return UNIT_TEST_PASSED;
492 }
493
494 UNIT_TEST_STATUS
495 EFIAPI
496 TestSafeUint16ToChar8 (
497 IN UNIT_TEST_CONTEXT Context
498 )
499 {
500 EFI_STATUS Status;
501 UINT16 Operand;
502 CHAR8 Result;
503
504 // CHAR8 is typedefed as char, which by default is signed, thus
505 // CHAR8 is same as INT8, so same tests as above:
506
507 //
508 // If Operand is <= MAX_INT8, it's a cast
509 //
510 Operand = 0x5b;
511 Result = 0;
512 Status = SafeUint16ToChar8 (Operand, &Result);
513 UT_ASSERT_NOT_EFI_ERROR (Status);
514 UT_ASSERT_EQUAL (0x5b, Result);
515
516 //
517 // Otherwise should result in an error status
518 //
519 Operand = (0x5b5b);
520 Status = SafeUint16ToChar8 (Operand, &Result);
521 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
522
523 return UNIT_TEST_PASSED;
524 }
525
526 UNIT_TEST_STATUS
527 EFIAPI
528 TestSafeUint16ToUint8 (
529 IN UNIT_TEST_CONTEXT Context
530 )
531 {
532 EFI_STATUS Status;
533 UINT16 Operand;
534 UINT8 Result;
535
536 //
537 // If Operand is <= MAX_UINT8 (0xff), it's a cast
538 //
539 Operand = 0xab;
540 Result = 0;
541 Status = SafeUint16ToUint8 (Operand, &Result);
542 UT_ASSERT_NOT_EFI_ERROR (Status);
543 UT_ASSERT_EQUAL (0xab, Result);
544
545 //
546 // Otherwise should result in an error status
547 //
548 Operand = (0x5b5b);
549 Status = SafeUint16ToUint8 (Operand, &Result);
550 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
551
552 return UNIT_TEST_PASSED;
553 }
554
555 UNIT_TEST_STATUS
556 EFIAPI
557 TestSafeUint16ToInt16 (
558 IN UNIT_TEST_CONTEXT Context
559 )
560 {
561 EFI_STATUS Status;
562 UINT16 Operand;
563 INT16 Result;
564
565 //
566 // If Operand is <= MAX_INT16 (0x7fff), it's a cast
567 //
568 Operand = 0x5b5b;
569 Result = 0;
570 Status = SafeUint16ToInt16 (Operand, &Result);
571 UT_ASSERT_NOT_EFI_ERROR (Status);
572 UT_ASSERT_EQUAL (0x5b5b, Result);
573
574 //
575 // Otherwise should result in an error status
576 //
577 Operand = (0xabab);
578 Status = SafeUint16ToInt16 (Operand, &Result);
579 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
580
581 return UNIT_TEST_PASSED;
582 }
583
584 UNIT_TEST_STATUS
585 EFIAPI
586 TestSafeInt32ToInt8 (
587 IN UNIT_TEST_CONTEXT Context
588 )
589 {
590 EFI_STATUS Status;
591 INT32 Operand;
592 INT8 Result;
593
594 //
595 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
596 //
597 Operand = 0x5b;
598 Result = 0;
599 Status = SafeInt32ToInt8 (Operand, &Result);
600 UT_ASSERT_NOT_EFI_ERROR (Status);
601 UT_ASSERT_EQUAL (0x5b, Result);
602
603 Operand = (-57);
604 Status = SafeInt32ToInt8 (Operand, &Result);
605 UT_ASSERT_NOT_EFI_ERROR (Status);
606 UT_ASSERT_EQUAL ((-57), Result);
607
608 //
609 // Otherwise should result in an error status
610 //
611 Operand = (0x5bababab);
612 Status = SafeInt32ToInt8 (Operand, &Result);
613 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
614
615 Operand = (-1537977259);
616 Status = SafeInt32ToInt8 (Operand, &Result);
617 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
618
619 return UNIT_TEST_PASSED;
620 }
621
622 UNIT_TEST_STATUS
623 EFIAPI
624 TestSafeInt32ToChar8 (
625 IN UNIT_TEST_CONTEXT Context
626 )
627 {
628 EFI_STATUS Status;
629 INT32 Operand;
630 CHAR8 Result;
631
632 //
633 // CHAR8 is typedefed as char, which may be signed or unsigned based
634 // on the compiler. Thus, for compatibility CHAR8 should be between 0 and MAX_INT8.
635 //
636
637 //
638 // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast
639 //
640 Operand = 0x5b;
641 Result = 0;
642 Status = SafeInt32ToChar8 (Operand, &Result);
643 UT_ASSERT_NOT_EFI_ERROR (Status);
644 UT_ASSERT_EQUAL (0x5b, Result);
645
646 Operand = 0;
647 Result = 0;
648 Status = SafeInt32ToChar8 (Operand, &Result);
649 UT_ASSERT_NOT_EFI_ERROR (Status);
650 UT_ASSERT_EQUAL (0, Result);
651
652 Operand = MAX_INT8;
653 Result = 0;
654 Status = SafeInt32ToChar8 (Operand, &Result);
655 UT_ASSERT_NOT_EFI_ERROR (Status);
656 UT_ASSERT_EQUAL (MAX_INT8, Result);
657
658 //
659 // Otherwise should result in an error status
660 //
661 Operand = (-57);
662 Status = SafeInt32ToChar8 (Operand, &Result);
663 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
664
665 Operand = (0x5bababab);
666 Status = SafeInt32ToChar8 (Operand, &Result);
667 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
668
669 Operand = (-1537977259);
670 Status = SafeInt32ToChar8 (Operand, &Result);
671 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
672
673 return UNIT_TEST_PASSED;
674 }
675
676 UNIT_TEST_STATUS
677 EFIAPI
678 TestSafeInt32ToUint8 (
679 IN UNIT_TEST_CONTEXT Context
680 )
681 {
682 EFI_STATUS Status;
683 INT32 Operand;
684 UINT8 Result;
685
686 //
687 // If Operand is between 0 and MAX_INT8 inclusive, then it's a cast
688 //
689 Operand = 0x5b;
690 Result = 0;
691 Status = SafeInt32ToUint8 (Operand, &Result);
692 UT_ASSERT_NOT_EFI_ERROR (Status);
693 UT_ASSERT_EQUAL (0x5b, Result);
694
695 //
696 // Otherwise should result in an error status
697 //
698 Operand = (-57);
699 Status = SafeInt32ToUint8 (Operand, &Result);
700 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
701
702 Operand = (0x5bababab);
703 Status = SafeInt32ToUint8 (Operand, &Result);
704 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
705
706 Operand = (-1537977259);
707 Status = SafeInt32ToUint8 (Operand, &Result);
708 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
709
710 return UNIT_TEST_PASSED;
711 }
712
713 UNIT_TEST_STATUS
714 EFIAPI
715 TestSafeInt32ToInt16 (
716 IN UNIT_TEST_CONTEXT Context
717 )
718 {
719 EFI_STATUS Status;
720 INT32 Operand;
721 INT16 Result;
722
723 //
724 // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a cast
725 //
726 Operand = 0x5b5b;
727 Result = 0;
728 Status = SafeInt32ToInt16 (Operand, &Result);
729 UT_ASSERT_NOT_EFI_ERROR (Status);
730 UT_ASSERT_EQUAL (0x5b5b, Result);
731
732 Operand = (-17857);
733 Status = SafeInt32ToInt16 (Operand, &Result);
734 UT_ASSERT_NOT_EFI_ERROR (Status);
735 UT_ASSERT_EQUAL ((-17857), Result);
736
737 //
738 // Otherwise should result in an error status
739 //
740 Operand = (0x5bababab);
741 Status = SafeInt32ToInt16 (Operand, &Result);
742 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
743
744 Operand = (-1537977259);
745 Status = SafeInt32ToInt16 (Operand, &Result);
746 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
747
748 return UNIT_TEST_PASSED;
749 }
750
751 UNIT_TEST_STATUS
752 EFIAPI
753 TestSafeInt32ToUint16 (
754 IN UNIT_TEST_CONTEXT Context
755 )
756 {
757 EFI_STATUS Status;
758 INT32 Operand;
759 UINT16 Result;
760
761 //
762 // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast
763 //
764 Operand = 0xabab;
765 Result = 0;
766 Status = SafeInt32ToUint16 (Operand, &Result);
767 UT_ASSERT_NOT_EFI_ERROR (Status);
768 UT_ASSERT_EQUAL (0xabab, Result);
769
770 //
771 // Otherwise should result in an error status
772 //
773 Operand = (-17857);
774 Status = SafeInt32ToUint16 (Operand, &Result);
775 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
776
777 Operand = (0x5bababab);
778 Status = SafeInt32ToUint16 (Operand, &Result);
779 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
780
781 Operand = (-1537977259);
782 Status = SafeInt32ToUint16 (Operand, &Result);
783 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
784
785 return UNIT_TEST_PASSED;
786 }
787
788 UNIT_TEST_STATUS
789 EFIAPI
790 TestSafeInt32ToUint32 (
791 IN UNIT_TEST_CONTEXT Context
792 )
793 {
794 EFI_STATUS Status;
795 INT32 Operand;
796 UINT32 Result;
797
798 //
799 // If Operand is non-negative, then it's a cast
800 //
801 Operand = 0x5bababab;
802 Result = 0;
803 Status = SafeInt32ToUint32 (Operand, &Result);
804 UT_ASSERT_NOT_EFI_ERROR (Status);
805 UT_ASSERT_EQUAL (0x5bababab, Result);
806
807 //
808 // Otherwise should result in an error status
809 //
810 Operand = (-1537977259);
811 Status = SafeInt32ToUint32 (Operand, &Result);
812 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
813
814 return UNIT_TEST_PASSED;
815 }
816
817 UNIT_TEST_STATUS
818 EFIAPI
819 TestSafeInt32ToUint64 (
820 IN UNIT_TEST_CONTEXT Context
821 )
822 {
823 EFI_STATUS Status;
824 INT32 Operand;
825 UINT64 Result;
826
827 //
828 // If Operand is non-negative, then it's a cast
829 //
830 Operand = 0x5bababab;
831 Result = 0;
832 Status = SafeInt32ToUint64 (Operand, &Result);
833 UT_ASSERT_NOT_EFI_ERROR (Status);
834 UT_ASSERT_EQUAL (0x5bababab, Result);
835
836 //
837 // Otherwise should result in an error status
838 //
839 Operand = (-1537977259);
840 Status = SafeInt32ToUint64 (Operand, &Result);
841 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
842
843 return UNIT_TEST_PASSED;
844 }
845
846 UNIT_TEST_STATUS
847 EFIAPI
848 TestSafeUint32ToInt8 (
849 IN UNIT_TEST_CONTEXT Context
850 )
851 {
852 EFI_STATUS Status;
853 UINT32 Operand;
854 INT8 Result;
855
856 //
857 // If Operand is <= MAX_INT8, then it's a cast
858 //
859 Operand = 0x5b;
860 Result = 0;
861 Status = SafeUint32ToInt8 (Operand, &Result);
862 UT_ASSERT_NOT_EFI_ERROR (Status);
863 UT_ASSERT_EQUAL (0x5b, Result);
864
865 //
866 // Otherwise should result in an error status
867 //
868 Operand = (0x5bababab);
869 Status = SafeUint32ToInt8 (Operand, &Result);
870 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
871
872 return UNIT_TEST_PASSED;
873 }
874
875 UNIT_TEST_STATUS
876 EFIAPI
877 TestSafeUint32ToChar8 (
878 IN UNIT_TEST_CONTEXT Context
879 )
880 {
881 EFI_STATUS Status;
882 UINT32 Operand;
883 CHAR8 Result;
884
885 // CHAR8 is typedefed as char, which by default is signed, thus
886 // CHAR8 is same as INT8, so same tests as above:
887
888 //
889 // If Operand is <= MAX_INT8, then it's a cast
890 //
891 Operand = 0x5b;
892 Result = 0;
893 Status = SafeUint32ToChar8 (Operand, &Result);
894 UT_ASSERT_NOT_EFI_ERROR (Status);
895 UT_ASSERT_EQUAL (0x5b, Result);
896
897 //
898 // Otherwise should result in an error status
899 //
900 Operand = (0x5bababab);
901 Status = SafeUint32ToChar8 (Operand, &Result);
902 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
903
904 return UNIT_TEST_PASSED;
905 }
906
907 UNIT_TEST_STATUS
908 EFIAPI
909 TestSafeUint32ToUint8 (
910 IN UNIT_TEST_CONTEXT Context
911 )
912 {
913 EFI_STATUS Status;
914 UINT32 Operand;
915 UINT8 Result;
916
917 //
918 // If Operand is <= MAX_UINT8, then it's a cast
919 //
920 Operand = 0xab;
921 Result = 0;
922 Status = SafeUint32ToUint8 (Operand, &Result);
923 UT_ASSERT_NOT_EFI_ERROR (Status);
924 UT_ASSERT_EQUAL (0xab, Result);
925
926 //
927 // Otherwise should result in an error status
928 //
929 Operand = (0xabababab);
930 Status = SafeUint32ToUint8 (Operand, &Result);
931 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
932
933 return UNIT_TEST_PASSED;
934 }
935
936 UNIT_TEST_STATUS
937 EFIAPI
938 TestSafeUint32ToInt16 (
939 IN UNIT_TEST_CONTEXT Context
940 )
941 {
942 EFI_STATUS Status;
943 UINT32 Operand;
944 INT16 Result;
945
946 //
947 // If Operand is <= MAX_INT16, then it's a cast
948 //
949 Operand = 0x5bab;
950 Result = 0;
951 Status = SafeUint32ToInt16 (Operand, &Result);
952 UT_ASSERT_NOT_EFI_ERROR (Status);
953 UT_ASSERT_EQUAL (0x5bab, Result);
954
955 //
956 // Otherwise should result in an error status
957 //
958 Operand = (0xabababab);
959 Status = SafeUint32ToInt16 (Operand, &Result);
960 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
961
962 return UNIT_TEST_PASSED;
963 }
964
965 UNIT_TEST_STATUS
966 EFIAPI
967 TestSafeUint32ToUint16 (
968 IN UNIT_TEST_CONTEXT Context
969 )
970 {
971 EFI_STATUS Status;
972 UINT32 Operand;
973 UINT16 Result;
974
975 //
976 // If Operand is <= MAX_UINT16, then it's a cast
977 //
978 Operand = 0xabab;
979 Result = 0;
980 Status = SafeUint32ToUint16 (Operand, &Result);
981 UT_ASSERT_NOT_EFI_ERROR (Status);
982 UT_ASSERT_EQUAL (0xabab, Result);
983
984 //
985 // Otherwise should result in an error status
986 //
987 Operand = (0xabababab);
988 Status = SafeUint32ToUint16 (Operand, &Result);
989 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
990
991 return UNIT_TEST_PASSED;
992 }
993
994 UNIT_TEST_STATUS
995 EFIAPI
996 TestSafeUint32ToInt32 (
997 IN UNIT_TEST_CONTEXT Context
998 )
999 {
1000 EFI_STATUS Status;
1001 UINT32 Operand;
1002 INT32 Result;
1003
1004 //
1005 // If Operand is <= MAX_INT32, then it's a cast
1006 //
1007 Operand = 0x5bababab;
1008 Result = 0;
1009 Status = SafeUint32ToInt32 (Operand, &Result);
1010 UT_ASSERT_NOT_EFI_ERROR (Status);
1011 UT_ASSERT_EQUAL (0x5bababab, Result);
1012
1013 //
1014 // Otherwise should result in an error status
1015 //
1016 Operand = (0xabababab);
1017 Status = SafeUint32ToInt32 (Operand, &Result);
1018 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1019
1020 return UNIT_TEST_PASSED;
1021 }
1022
1023 UNIT_TEST_STATUS
1024 EFIAPI
1025 TestSafeIntnToInt8 (
1026 IN UNIT_TEST_CONTEXT Context
1027 )
1028 {
1029 EFI_STATUS Status;
1030 INTN Operand;
1031 INT8 Result;
1032
1033 //
1034 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
1035 //
1036 Operand = 0x5b;
1037 Result = 0;
1038 Status = SafeIntnToInt8 (Operand, &Result);
1039 UT_ASSERT_NOT_EFI_ERROR (Status);
1040 UT_ASSERT_EQUAL (0x5b, Result);
1041
1042 Operand = (-53);
1043 Status = SafeIntnToInt8 (Operand, &Result);
1044 UT_ASSERT_NOT_EFI_ERROR (Status);
1045 UT_ASSERT_EQUAL ((-53), Result);
1046
1047 //
1048 // Otherwise should result in an error status
1049 //
1050 Operand = (0x5bababab);
1051 Status = SafeIntnToInt8 (Operand, &Result);
1052 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1053
1054 Operand = (-1537977259);
1055 Status = SafeIntnToInt8 (Operand, &Result);
1056 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1057
1058 return UNIT_TEST_PASSED;
1059 }
1060
1061 UNIT_TEST_STATUS
1062 EFIAPI
1063 TestSafeIntnToChar8 (
1064 IN UNIT_TEST_CONTEXT Context
1065 )
1066 {
1067 EFI_STATUS Status;
1068 INTN Operand;
1069 CHAR8 Result;
1070
1071 //
1072 // CHAR8 is typedefed as char, which may be signed or unsigned based
1073 // on the compiler. Thus, for compatibility CHAR8 should be between 0 and MAX_INT8.
1074 //
1075
1076 //
1077 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
1078 //
1079 Operand = 0x5b;
1080 Result = 0;
1081 Status = SafeIntnToChar8 (Operand, &Result);
1082 UT_ASSERT_NOT_EFI_ERROR (Status);
1083 UT_ASSERT_EQUAL (0x5b, Result);
1084
1085 Operand = 0;
1086 Result = 0;
1087 Status = SafeIntnToChar8 (Operand, &Result);
1088 UT_ASSERT_NOT_EFI_ERROR (Status);
1089 UT_ASSERT_EQUAL (0, Result);
1090
1091 Operand = MAX_INT8;
1092 Result = 0;
1093 Status = SafeIntnToChar8 (Operand, &Result);
1094 UT_ASSERT_NOT_EFI_ERROR (Status);
1095 UT_ASSERT_EQUAL (MAX_INT8, Result);
1096
1097 //
1098 // Otherwise should result in an error status
1099 //
1100 Operand = (-53);
1101 Status = SafeIntnToChar8 (Operand, &Result);
1102 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1103
1104 Operand = (0x5bababab);
1105 Status = SafeIntnToChar8 (Operand, &Result);
1106 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1107
1108 Operand = (-1537977259);
1109 Status = SafeIntnToChar8 (Operand, &Result);
1110 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1111
1112 return UNIT_TEST_PASSED;
1113 }
1114
1115 UNIT_TEST_STATUS
1116 EFIAPI
1117 TestSafeIntnToUint8 (
1118 IN UNIT_TEST_CONTEXT Context
1119 )
1120 {
1121 EFI_STATUS Status;
1122 INTN Operand;
1123 UINT8 Result;
1124
1125 //
1126 // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast
1127 //
1128 Operand = 0xab;
1129 Result = 0;
1130 Status = SafeIntnToUint8 (Operand, &Result);
1131 UT_ASSERT_NOT_EFI_ERROR (Status);
1132 UT_ASSERT_EQUAL (0xab, Result);
1133
1134 //
1135 // Otherwise should result in an error status
1136 //
1137 Operand = (0x5bababab);
1138 Status = SafeIntnToUint8 (Operand, &Result);
1139 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1140
1141 Operand = (-1537977259);
1142 Status = SafeIntnToUint8 (Operand, &Result);
1143 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1144
1145 return UNIT_TEST_PASSED;
1146 }
1147
1148 UNIT_TEST_STATUS
1149 EFIAPI
1150 TestSafeIntnToInt16 (
1151 IN UNIT_TEST_CONTEXT Context
1152 )
1153 {
1154 EFI_STATUS Status;
1155 INTN Operand;
1156 INT16 Result;
1157
1158 //
1159 // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a cast
1160 //
1161 Operand = 0x5bab;
1162 Result = 0;
1163 Status = SafeIntnToInt16 (Operand, &Result);
1164 UT_ASSERT_NOT_EFI_ERROR (Status);
1165 UT_ASSERT_EQUAL (0x5bab, Result);
1166
1167 Operand = (-23467);
1168 Status = SafeIntnToInt16 (Operand, &Result);
1169 UT_ASSERT_NOT_EFI_ERROR (Status);
1170 UT_ASSERT_EQUAL ((-23467), Result);
1171
1172 //
1173 // Otherwise should result in an error status
1174 //
1175 Operand = (0x5bababab);
1176 Status = SafeIntnToInt16 (Operand, &Result);
1177 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1178
1179 Operand = (-1537977259);
1180 Status = SafeIntnToInt16 (Operand, &Result);
1181 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1182
1183 return UNIT_TEST_PASSED;
1184 }
1185
1186 UNIT_TEST_STATUS
1187 EFIAPI
1188 TestSafeIntnToUint16 (
1189 IN UNIT_TEST_CONTEXT Context
1190 )
1191 {
1192 EFI_STATUS Status;
1193 INTN Operand;
1194 UINT16 Result;
1195
1196 //
1197 // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast
1198 //
1199 Operand = 0xabab;
1200 Result = 0;
1201 Status = SafeIntnToUint16 (Operand, &Result);
1202 UT_ASSERT_NOT_EFI_ERROR (Status);
1203 UT_ASSERT_EQUAL (0xabab, Result);
1204
1205 //
1206 // Otherwise should result in an error status
1207 //
1208 Operand = (0x5bababab);
1209 Status = SafeIntnToUint16 (Operand, &Result);
1210 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1211
1212 Operand = (-1537977259);
1213 Status = SafeIntnToUint16 (Operand, &Result);
1214 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1215
1216 return UNIT_TEST_PASSED;
1217 }
1218
1219 UNIT_TEST_STATUS
1220 EFIAPI
1221 TestSafeIntnToUintn (
1222 IN UNIT_TEST_CONTEXT Context
1223 )
1224 {
1225 EFI_STATUS Status;
1226 INTN Operand;
1227 UINTN Result;
1228
1229 //
1230 // If Operand is non-negative, then it's a cast
1231 //
1232 Operand = 0x5bababab;
1233 Result = 0;
1234 Status = SafeIntnToUintn (Operand, &Result);
1235 UT_ASSERT_NOT_EFI_ERROR (Status);
1236 UT_ASSERT_EQUAL (0x5bababab, Result);
1237
1238 //
1239 // Otherwise should result in an error status
1240 //
1241 Operand = (-1537977259);
1242 Status = SafeIntnToUintn (Operand, &Result);
1243 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1244
1245 return UNIT_TEST_PASSED;
1246 }
1247
1248 UNIT_TEST_STATUS
1249 EFIAPI
1250 TestSafeIntnToUint64 (
1251 IN UNIT_TEST_CONTEXT Context
1252 )
1253 {
1254 EFI_STATUS Status;
1255 INTN Operand;
1256 UINT64 Result;
1257
1258 //
1259 // If Operand is non-negative, then it's a cast
1260 //
1261 Operand = 0x5bababab;
1262 Result = 0;
1263 Status = SafeIntnToUint64 (Operand, &Result);
1264 UT_ASSERT_NOT_EFI_ERROR (Status);
1265 UT_ASSERT_EQUAL (0x5bababab, Result);
1266
1267 //
1268 // Otherwise should result in an error status
1269 //
1270 Operand = (-1537977259);
1271 Status = SafeIntnToUint64 (Operand, &Result);
1272 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1273
1274 return UNIT_TEST_PASSED;
1275 }
1276
1277 UNIT_TEST_STATUS
1278 EFIAPI
1279 TestSafeUintnToInt8 (
1280 IN UNIT_TEST_CONTEXT Context
1281 )
1282 {
1283 EFI_STATUS Status;
1284 UINTN Operand;
1285 INT8 Result;
1286
1287 //
1288 // If Operand is <= MAX_INT8, then it's a cast
1289 //
1290 Operand = 0x5b;
1291 Result = 0;
1292 Status = SafeUintnToInt8 (Operand, &Result);
1293 UT_ASSERT_NOT_EFI_ERROR (Status);
1294 UT_ASSERT_EQUAL (0x5b, Result);
1295
1296 //
1297 // Otherwise should result in an error status
1298 //
1299 Operand = (0xabab);
1300 Status = SafeUintnToInt8 (Operand, &Result);
1301 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1302
1303 return UNIT_TEST_PASSED;
1304 }
1305
1306 UNIT_TEST_STATUS
1307 EFIAPI
1308 TestSafeUintnToChar8 (
1309 IN UNIT_TEST_CONTEXT Context
1310 )
1311 {
1312 EFI_STATUS Status;
1313 UINTN Operand;
1314 CHAR8 Result;
1315
1316 // CHAR8 is typedefed as char, which by default is signed, thus
1317 // CHAR8 is same as INT8, so same tests as above:
1318
1319 //
1320 // If Operand is <= MAX_INT8, then it's a cast
1321 //
1322 Operand = 0x5b;
1323 Result = 0;
1324 Status = SafeUintnToChar8 (Operand, &Result);
1325 UT_ASSERT_NOT_EFI_ERROR (Status);
1326 UT_ASSERT_EQUAL (0x5b, Result);
1327
1328 //
1329 // Otherwise should result in an error status
1330 //
1331 Operand = (0xabab);
1332 Status = SafeUintnToChar8 (Operand, &Result);
1333 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1334
1335 return UNIT_TEST_PASSED;
1336 }
1337
1338 UNIT_TEST_STATUS
1339 EFIAPI
1340 TestSafeUintnToUint8 (
1341 IN UNIT_TEST_CONTEXT Context
1342 )
1343 {
1344 EFI_STATUS Status;
1345 UINTN Operand;
1346 UINT8 Result;
1347
1348 //
1349 // If Operand is <= MAX_UINT8, then it's a cast
1350 //
1351 Operand = 0xab;
1352 Result = 0;
1353 Status = SafeUintnToUint8 (Operand, &Result);
1354 UT_ASSERT_NOT_EFI_ERROR (Status);
1355 UT_ASSERT_EQUAL (0xab, Result);
1356
1357 //
1358 // Otherwise should result in an error status
1359 //
1360 Operand = (0xabab);
1361 Status = SafeUintnToUint8 (Operand, &Result);
1362 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1363
1364 return UNIT_TEST_PASSED;
1365 }
1366
1367 UNIT_TEST_STATUS
1368 EFIAPI
1369 TestSafeUintnToInt16 (
1370 IN UNIT_TEST_CONTEXT Context
1371 )
1372 {
1373 EFI_STATUS Status;
1374 UINTN Operand;
1375 INT16 Result;
1376
1377 //
1378 // If Operand is <= MAX_INT16, then it's a cast
1379 //
1380 Operand = 0x5bab;
1381 Result = 0;
1382 Status = SafeUintnToInt16 (Operand, &Result);
1383 UT_ASSERT_NOT_EFI_ERROR (Status);
1384 UT_ASSERT_EQUAL (0x5bab, Result);
1385
1386 //
1387 // Otherwise should result in an error status
1388 //
1389 Operand = (0xabab);
1390 Status = SafeUintnToInt16 (Operand, &Result);
1391 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1392
1393 return UNIT_TEST_PASSED;
1394 }
1395
1396 UNIT_TEST_STATUS
1397 EFIAPI
1398 TestSafeUintnToUint16 (
1399 IN UNIT_TEST_CONTEXT Context
1400 )
1401 {
1402 EFI_STATUS Status;
1403 UINTN Operand;
1404 UINT16 Result;
1405
1406 //
1407 // If Operand is <= MAX_UINT16, then it's a cast
1408 //
1409 Operand = 0xabab;
1410 Result = 0;
1411 Status = SafeUintnToUint16 (Operand, &Result);
1412 UT_ASSERT_NOT_EFI_ERROR (Status);
1413 UT_ASSERT_EQUAL (0xabab, Result);
1414
1415 //
1416 // Otherwise should result in an error status
1417 //
1418 Operand = (0xabababab);
1419 Status = SafeUintnToUint16 (Operand, &Result);
1420 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1421
1422 return UNIT_TEST_PASSED;
1423 }
1424
1425 UNIT_TEST_STATUS
1426 EFIAPI
1427 TestSafeUintnToInt32 (
1428 IN UNIT_TEST_CONTEXT Context
1429 )
1430 {
1431 EFI_STATUS Status;
1432 UINTN Operand;
1433 INT32 Result;
1434
1435 //
1436 // If Operand is <= MAX_INT32, then it's a cast
1437 //
1438 Operand = 0x5bababab;
1439 Result = 0;
1440 Status = SafeUintnToInt32 (Operand, &Result);
1441 UT_ASSERT_NOT_EFI_ERROR (Status);
1442 UT_ASSERT_EQUAL (0x5bababab, Result);
1443
1444 //
1445 // Otherwise should result in an error status
1446 //
1447 Operand = (0xabababab);
1448 Status = SafeUintnToInt32 (Operand, &Result);
1449 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1450
1451 return UNIT_TEST_PASSED;
1452 }
1453
1454 UNIT_TEST_STATUS
1455 EFIAPI
1456 TestSafeInt64ToInt8 (
1457 IN UNIT_TEST_CONTEXT Context
1458 )
1459 {
1460 EFI_STATUS Status;
1461 INT64 Operand;
1462 INT8 Result;
1463
1464 //
1465 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
1466 //
1467 Operand = 0x5b;
1468 Result = 0;
1469 Status = SafeInt64ToInt8 (Operand, &Result);
1470 UT_ASSERT_NOT_EFI_ERROR (Status);
1471 UT_ASSERT_EQUAL (0x5b, Result);
1472
1473 Operand = (-37);
1474 Status = SafeInt64ToInt8 (Operand, &Result);
1475 UT_ASSERT_NOT_EFI_ERROR (Status);
1476 UT_ASSERT_EQUAL ((-37), Result);
1477
1478 //
1479 // Otherwise should result in an error status
1480 //
1481 Operand = (0x5babababefefefef);
1482 Status = SafeInt64ToInt8 (Operand, &Result);
1483 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1484
1485 Operand = (-6605562033422200815);
1486 Status = SafeInt64ToInt8 (Operand, &Result);
1487 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1488
1489 return UNIT_TEST_PASSED;
1490 }
1491
1492 UNIT_TEST_STATUS
1493 EFIAPI
1494 TestSafeInt64ToChar8 (
1495 IN UNIT_TEST_CONTEXT Context
1496 )
1497 {
1498 EFI_STATUS Status;
1499 INT64 Operand;
1500 CHAR8 Result;
1501
1502 //
1503 // CHAR8 is typedefed as char, which may be signed or unsigned based
1504 // on the compiler. Thus, for compatibility CHAR8 should be between 0 and MAX_INT8.
1505 //
1506
1507 //
1508 // If Operand is between MIN_INT8 and MAX_INT8 inclusive, then it's a cast
1509 //
1510 Operand = 0x5b;
1511 Result = 0;
1512 Status = SafeInt64ToChar8 (Operand, &Result);
1513 UT_ASSERT_NOT_EFI_ERROR (Status);
1514 UT_ASSERT_EQUAL (0x5b, Result);
1515
1516 Operand = 0;
1517 Result = 0;
1518 Status = SafeInt64ToChar8 (Operand, &Result);
1519 UT_ASSERT_NOT_EFI_ERROR (Status);
1520 UT_ASSERT_EQUAL (0, Result);
1521
1522 Operand = MAX_INT8;
1523 Result = 0;
1524 Status = SafeInt64ToChar8 (Operand, &Result);
1525 UT_ASSERT_NOT_EFI_ERROR (Status);
1526 UT_ASSERT_EQUAL (MAX_INT8, Result);
1527
1528 //
1529 // Otherwise should result in an error status
1530 //
1531 Operand = (-37);
1532 Status = SafeInt64ToChar8 (Operand, &Result);
1533 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1534
1535 Operand = (0x5babababefefefef);
1536 Status = SafeInt64ToChar8 (Operand, &Result);
1537 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1538
1539 Operand = (-6605562033422200815);
1540 Status = SafeInt64ToChar8 (Operand, &Result);
1541 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1542
1543 return UNIT_TEST_PASSED;
1544 }
1545
1546 UNIT_TEST_STATUS
1547 EFIAPI
1548 TestSafeInt64ToUint8 (
1549 IN UNIT_TEST_CONTEXT Context
1550 )
1551 {
1552 EFI_STATUS Status;
1553 INT64 Operand;
1554 UINT8 Result;
1555
1556 //
1557 // If Operand is between 0 and MAX_UINT8 inclusive, then it's a cast
1558 //
1559 Operand = 0xab;
1560 Result = 0;
1561 Status = SafeInt64ToUint8 (Operand, &Result);
1562 UT_ASSERT_NOT_EFI_ERROR (Status);
1563 UT_ASSERT_EQUAL (0xab, Result);
1564
1565 //
1566 // Otherwise should result in an error status
1567 //
1568 Operand = (0x5babababefefefef);
1569 Status = SafeInt64ToUint8 (Operand, &Result);
1570 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1571
1572 Operand = (-6605562033422200815);
1573 Status = SafeInt64ToUint8 (Operand, &Result);
1574 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1575
1576 return UNIT_TEST_PASSED;
1577 }
1578
1579 UNIT_TEST_STATUS
1580 EFIAPI
1581 TestSafeInt64ToInt16 (
1582 IN UNIT_TEST_CONTEXT Context
1583 )
1584 {
1585 EFI_STATUS Status;
1586 INT64 Operand;
1587 INT16 Result;
1588
1589 //
1590 // If Operand is between MIN_INT16 and MAX_INT16 inclusive, then it's a cast
1591 //
1592 Operand = 0x5bab;
1593 Result = 0;
1594 Status = SafeInt64ToInt16 (Operand, &Result);
1595 UT_ASSERT_NOT_EFI_ERROR (Status);
1596 UT_ASSERT_EQUAL (0x5bab, Result);
1597
1598 Operand = (-23467);
1599 Status = SafeInt64ToInt16 (Operand, &Result);
1600 UT_ASSERT_NOT_EFI_ERROR (Status);
1601 UT_ASSERT_EQUAL ((-23467), Result);
1602
1603 //
1604 // Otherwise should result in an error status
1605 //
1606 Operand = (0x5babababefefefef);
1607 Status = SafeInt64ToInt16 (Operand, &Result);
1608 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1609
1610 Operand = (-6605562033422200815);
1611 Status = SafeInt64ToInt16 (Operand, &Result);
1612 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1613
1614 return UNIT_TEST_PASSED;
1615 }
1616
1617 UNIT_TEST_STATUS
1618 EFIAPI
1619 TestSafeInt64ToUint16 (
1620 IN UNIT_TEST_CONTEXT Context
1621 )
1622 {
1623 EFI_STATUS Status;
1624 INT64 Operand;
1625 UINT16 Result;
1626
1627 //
1628 // If Operand is between 0 and MAX_UINT16 inclusive, then it's a cast
1629 //
1630 Operand = 0xabab;
1631 Result = 0;
1632 Status = SafeInt64ToUint16 (Operand, &Result);
1633 UT_ASSERT_NOT_EFI_ERROR (Status);
1634 UT_ASSERT_EQUAL (0xabab, Result);
1635
1636 //
1637 // Otherwise should result in an error status
1638 //
1639 Operand = (0x5babababefefefef);
1640 Status = SafeInt64ToUint16 (Operand, &Result);
1641 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1642
1643 Operand = (-6605562033422200815);
1644 Status = SafeInt64ToUint16 (Operand, &Result);
1645 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1646
1647 return UNIT_TEST_PASSED;
1648 }
1649
1650 UNIT_TEST_STATUS
1651 EFIAPI
1652 TestSafeInt64ToInt32 (
1653 IN UNIT_TEST_CONTEXT Context
1654 )
1655 {
1656 EFI_STATUS Status;
1657 INT64 Operand;
1658 INT32 Result;
1659
1660 //
1661 // If Operand is between MIN_INT32 and MAX_INT32 inclusive, then it's a cast
1662 //
1663 Operand = 0x5bababab;
1664 Result = 0;
1665 Status = SafeInt64ToInt32 (Operand, &Result);
1666 UT_ASSERT_NOT_EFI_ERROR (Status);
1667 UT_ASSERT_EQUAL (0x5bababab, Result);
1668
1669 Operand = (-1537977259);
1670 Status = SafeInt64ToInt32 (Operand, &Result);
1671 UT_ASSERT_NOT_EFI_ERROR (Status);
1672 UT_ASSERT_EQUAL ((-1537977259), Result);
1673
1674 //
1675 // Otherwise should result in an error status
1676 //
1677 Operand = (0x5babababefefefef);
1678 Status = SafeInt64ToInt32 (Operand, &Result);
1679 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1680
1681 Operand = (-6605562033422200815);
1682 Status = SafeInt64ToInt32 (Operand, &Result);
1683 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1684
1685 return UNIT_TEST_PASSED;
1686 }
1687
1688 UNIT_TEST_STATUS
1689 EFIAPI
1690 TestSafeInt64ToUint32 (
1691 IN UNIT_TEST_CONTEXT Context
1692 )
1693 {
1694 EFI_STATUS Status;
1695 INT64 Operand;
1696 UINT32 Result;
1697
1698 //
1699 // If Operand is between 0 and MAX_UINT32 inclusive, then it's a cast
1700 //
1701 Operand = 0xabababab;
1702 Result = 0;
1703 Status = SafeInt64ToUint32 (Operand, &Result);
1704 UT_ASSERT_NOT_EFI_ERROR (Status);
1705 UT_ASSERT_EQUAL (0xabababab, Result);
1706
1707 //
1708 // Otherwise should result in an error status
1709 //
1710 Operand = (0x5babababefefefef);
1711 Status = SafeInt64ToUint32 (Operand, &Result);
1712 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1713
1714 Operand = (-6605562033422200815);
1715 Status = SafeInt64ToUint32 (Operand, &Result);
1716 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1717
1718 return UNIT_TEST_PASSED;
1719 }
1720
1721 UNIT_TEST_STATUS
1722 EFIAPI
1723 TestSafeInt64ToUint64 (
1724 IN UNIT_TEST_CONTEXT Context
1725 )
1726 {
1727 EFI_STATUS Status;
1728 INT64 Operand;
1729 UINT64 Result;
1730
1731 //
1732 // If Operand is non-negative, then it's a cast
1733 //
1734 Operand = 0x5babababefefefef;
1735 Result = 0;
1736 Status = SafeInt64ToUint64 (Operand, &Result);
1737 UT_ASSERT_NOT_EFI_ERROR (Status);
1738 UT_ASSERT_EQUAL (0x5babababefefefef, Result);
1739
1740 //
1741 // Otherwise should result in an error status
1742 //
1743 Operand = (-6605562033422200815);
1744 Status = SafeInt64ToUint64 (Operand, &Result);
1745 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1746
1747 return UNIT_TEST_PASSED;
1748 }
1749
1750 UNIT_TEST_STATUS
1751 EFIAPI
1752 TestSafeUint64ToInt8 (
1753 IN UNIT_TEST_CONTEXT Context
1754 )
1755 {
1756 EFI_STATUS Status;
1757 UINT64 Operand;
1758 INT8 Result;
1759
1760 //
1761 // If Operand is <= MAX_INT8, then it's a cast
1762 //
1763 Operand = 0x5b;
1764 Result = 0;
1765 Status = SafeUint64ToInt8 (Operand, &Result);
1766 UT_ASSERT_NOT_EFI_ERROR (Status);
1767 UT_ASSERT_EQUAL (0x5b, Result);
1768
1769 //
1770 // Otherwise should result in an error status
1771 //
1772 Operand = (0xababababefefefef);
1773 Status = SafeUint64ToInt8 (Operand, &Result);
1774 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1775
1776 return UNIT_TEST_PASSED;
1777 }
1778
1779 UNIT_TEST_STATUS
1780 EFIAPI
1781 TestSafeUint64ToChar8 (
1782 IN UNIT_TEST_CONTEXT Context
1783 )
1784 {
1785 EFI_STATUS Status;
1786 UINT64 Operand;
1787 CHAR8 Result;
1788
1789 // CHAR8 is typedefed as char, which by default is signed, thus
1790 // CHAR8 is same as INT8, so same tests as above:
1791
1792 //
1793 // If Operand is <= MAX_INT8, then it's a cast
1794 //
1795 Operand = 0x5b;
1796 Result = 0;
1797 Status = SafeUint64ToChar8 (Operand, &Result);
1798 UT_ASSERT_NOT_EFI_ERROR (Status);
1799 UT_ASSERT_EQUAL (0x5b, Result);
1800
1801 //
1802 // Otherwise should result in an error status
1803 //
1804 Operand = (0xababababefefefef);
1805 Status = SafeUint64ToChar8 (Operand, &Result);
1806 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1807
1808 return UNIT_TEST_PASSED;
1809 }
1810
1811 UNIT_TEST_STATUS
1812 EFIAPI
1813 TestSafeUint64ToUint8 (
1814 IN UNIT_TEST_CONTEXT Context
1815 )
1816 {
1817 EFI_STATUS Status;
1818 UINT64 Operand;
1819 UINT8 Result;
1820
1821 //
1822 // If Operand is <= MAX_UINT8, then it's a cast
1823 //
1824 Operand = 0xab;
1825 Result = 0;
1826 Status = SafeUint64ToUint8 (Operand, &Result);
1827 UT_ASSERT_NOT_EFI_ERROR (Status);
1828 UT_ASSERT_EQUAL (0xab, Result);
1829
1830 //
1831 // Otherwise should result in an error status
1832 //
1833 Operand = (0xababababefefefef);
1834 Status = SafeUint64ToUint8 (Operand, &Result);
1835 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1836
1837 return UNIT_TEST_PASSED;
1838 }
1839
1840 UNIT_TEST_STATUS
1841 EFIAPI
1842 TestSafeUint64ToInt16 (
1843 IN UNIT_TEST_CONTEXT Context
1844 )
1845 {
1846 EFI_STATUS Status;
1847 UINT64 Operand;
1848 INT16 Result;
1849
1850 //
1851 // If Operand is <= MAX_INT16, then it's a cast
1852 //
1853 Operand = 0x5bab;
1854 Result = 0;
1855 Status = SafeUint64ToInt16 (Operand, &Result);
1856 UT_ASSERT_NOT_EFI_ERROR (Status);
1857 UT_ASSERT_EQUAL (0x5bab, Result);
1858
1859 //
1860 // Otherwise should result in an error status
1861 //
1862 Operand = (0xababababefefefef);
1863 Status = SafeUint64ToInt16 (Operand, &Result);
1864 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1865
1866 return UNIT_TEST_PASSED;
1867 }
1868
1869 UNIT_TEST_STATUS
1870 EFIAPI
1871 TestSafeUint64ToUint16 (
1872 IN UNIT_TEST_CONTEXT Context
1873 )
1874 {
1875 EFI_STATUS Status;
1876 UINT64 Operand;
1877 UINT16 Result;
1878
1879 //
1880 // If Operand is <= MAX_UINT16, then it's a cast
1881 //
1882 Operand = 0xabab;
1883 Result = 0;
1884 Status = SafeUint64ToUint16 (Operand, &Result);
1885 UT_ASSERT_NOT_EFI_ERROR (Status);
1886 UT_ASSERT_EQUAL (0xabab, Result);
1887
1888 //
1889 // Otherwise should result in an error status
1890 //
1891 Operand = (0xababababefefefef);
1892 Status = SafeUint64ToUint16 (Operand, &Result);
1893 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1894
1895 return UNIT_TEST_PASSED;
1896 }
1897
1898 UNIT_TEST_STATUS
1899 EFIAPI
1900 TestSafeUint64ToInt32 (
1901 IN UNIT_TEST_CONTEXT Context
1902 )
1903 {
1904 EFI_STATUS Status;
1905 UINT64 Operand;
1906 INT32 Result;
1907
1908 //
1909 // If Operand is <= MAX_INT32, then it's a cast
1910 //
1911 Operand = 0x5bababab;
1912 Result = 0;
1913 Status = SafeUint64ToInt32 (Operand, &Result);
1914 UT_ASSERT_NOT_EFI_ERROR (Status);
1915 UT_ASSERT_EQUAL (0x5bababab, Result);
1916
1917 //
1918 // Otherwise should result in an error status
1919 //
1920 Operand = (0xababababefefefef);
1921 Status = SafeUint64ToInt32 (Operand, &Result);
1922 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1923
1924 return UNIT_TEST_PASSED;
1925 }
1926
1927 UNIT_TEST_STATUS
1928 EFIAPI
1929 TestSafeUint64ToUint32 (
1930 IN UNIT_TEST_CONTEXT Context
1931 )
1932 {
1933 EFI_STATUS Status;
1934 UINT64 Operand;
1935 UINT32 Result;
1936
1937 //
1938 // If Operand is <= MAX_UINT32, then it's a cast
1939 //
1940 Operand = 0xabababab;
1941 Result = 0;
1942 Status = SafeUint64ToUint32 (Operand, &Result);
1943 UT_ASSERT_NOT_EFI_ERROR (Status);
1944 UT_ASSERT_EQUAL (0xabababab, Result);
1945
1946 //
1947 // Otherwise should result in an error status
1948 //
1949 Operand = (0xababababefefefef);
1950 Status = SafeUint64ToUint32 (Operand, &Result);
1951 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1952
1953 return UNIT_TEST_PASSED;
1954 }
1955
1956 UNIT_TEST_STATUS
1957 EFIAPI
1958 TestSafeUint64ToInt64 (
1959 IN UNIT_TEST_CONTEXT Context
1960 )
1961 {
1962 EFI_STATUS Status;
1963 UINT64 Operand;
1964 INT64 Result;
1965
1966 //
1967 // If Operand is <= MAX_INT64, then it's a cast
1968 //
1969 Operand = 0x5babababefefefef;
1970 Result = 0;
1971 Status = SafeUint64ToInt64 (Operand, &Result);
1972 UT_ASSERT_NOT_EFI_ERROR (Status);
1973 UT_ASSERT_EQUAL (0x5babababefefefef, Result);
1974
1975 //
1976 // Otherwise should result in an error status
1977 //
1978 Operand = (0xababababefefefef);
1979 Status = SafeUint64ToInt64 (Operand, &Result);
1980 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
1981
1982 return UNIT_TEST_PASSED;
1983 }
1984
1985 //
1986 // Addition function tests:
1987 //
1988 UNIT_TEST_STATUS
1989 EFIAPI
1990 TestSafeUint8Add (
1991 IN UNIT_TEST_CONTEXT Context
1992 )
1993 {
1994 EFI_STATUS Status;
1995 UINT8 Augend;
1996 UINT8 Addend;
1997 UINT8 Result;
1998
1999 //
2000 // If the result of addition doesn't overflow MAX_UINT8, then it's addition
2001 //
2002 Augend = 0x3a;
2003 Addend = 0x3a;
2004 Result = 0;
2005 Status = SafeUint8Add (Augend, Addend, &Result);
2006 UT_ASSERT_NOT_EFI_ERROR (Status);
2007 UT_ASSERT_EQUAL (0x74, Result);
2008
2009 //
2010 // Otherwise should result in an error status
2011 //
2012 Augend = 0xab;
2013 Addend = 0xbc;
2014 Status = SafeUint8Add (Augend, Addend, &Result);
2015 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2016
2017 return UNIT_TEST_PASSED;
2018 }
2019
2020 UNIT_TEST_STATUS
2021 EFIAPI
2022 TestSafeUint16Add (
2023 IN UNIT_TEST_CONTEXT Context
2024 )
2025 {
2026 EFI_STATUS Status;
2027 UINT16 Augend = 0x3a3a;
2028 UINT16 Addend = 0x3a3a;
2029 UINT16 Result = 0;
2030
2031 //
2032 // If the result of addition doesn't overflow MAX_UINT16, then it's addition
2033 //
2034 Status = SafeUint16Add (Augend, Addend, &Result);
2035 UT_ASSERT_NOT_EFI_ERROR (Status);
2036 UT_ASSERT_EQUAL (0x7474, Result);
2037
2038 //
2039 // Otherwise should result in an error status
2040 //
2041 Augend = 0xabab;
2042 Addend = 0xbcbc;
2043 Status = SafeUint16Add (Augend, Addend, &Result);
2044 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2045
2046 return UNIT_TEST_PASSED;
2047 }
2048
2049 UNIT_TEST_STATUS
2050 EFIAPI
2051 TestSafeUint32Add (
2052 IN UNIT_TEST_CONTEXT Context
2053 )
2054 {
2055 EFI_STATUS Status;
2056 UINT32 Augend;
2057 UINT32 Addend;
2058 UINT32 Result;
2059
2060 //
2061 // If the result of addition doesn't overflow MAX_UINT32, then it's addition
2062 //
2063 Augend = 0x3a3a3a3a;
2064 Addend = 0x3a3a3a3a;
2065 Result = 0;
2066 Status = SafeUint32Add (Augend, Addend, &Result);
2067 UT_ASSERT_NOT_EFI_ERROR (Status);
2068 UT_ASSERT_EQUAL (0x74747474, Result);
2069
2070 //
2071 // Otherwise should result in an error status
2072 //
2073 Augend = 0xabababab;
2074 Addend = 0xbcbcbcbc;
2075 Status = SafeUint32Add (Augend, Addend, &Result);
2076 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2077
2078 return UNIT_TEST_PASSED;
2079 }
2080
2081 UNIT_TEST_STATUS
2082 EFIAPI
2083 TestSafeUint64Add (
2084 IN UNIT_TEST_CONTEXT Context
2085 )
2086 {
2087 EFI_STATUS Status;
2088 UINT64 Augend;
2089 UINT64 Addend;
2090 UINT64 Result;
2091
2092 //
2093 // If the result of addition doesn't overflow MAX_UINT64, then it's addition
2094 //
2095 Augend = 0x3a3a3a3a12121212;
2096 Addend = 0x3a3a3a3a12121212;
2097 Result = 0;
2098 Status = SafeUint64Add (Augend, Addend, &Result);
2099 UT_ASSERT_NOT_EFI_ERROR (Status);
2100 UT_ASSERT_EQUAL (0x7474747424242424, Result);
2101
2102 //
2103 // Otherwise should result in an error status
2104 //
2105 Augend = 0xababababefefefef;
2106 Addend = 0xbcbcbcbcdededede;
2107 Status = SafeUint64Add (Augend, Addend, &Result);
2108 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2109
2110 return UNIT_TEST_PASSED;
2111 }
2112
2113 UNIT_TEST_STATUS
2114 EFIAPI
2115 TestSafeInt8Add (
2116 IN UNIT_TEST_CONTEXT Context
2117 )
2118 {
2119 EFI_STATUS Status;
2120 INT8 Augend;
2121 INT8 Addend;
2122 INT8 Result;
2123
2124 //
2125 // If the result of addition doesn't overflow MAX_INT8
2126 // and doesn't underflow MIN_INT8, then it's addition
2127 //
2128 Augend = 0x3a;
2129 Addend = 0x3a;
2130 Result = 0;
2131 Status = SafeInt8Add (Augend, Addend, &Result);
2132 UT_ASSERT_NOT_EFI_ERROR (Status);
2133 UT_ASSERT_EQUAL (0x74, Result);
2134
2135 Augend = (-58);
2136 Addend = (-58);
2137 Status = SafeInt8Add (Augend, Addend, &Result);
2138 UT_ASSERT_NOT_EFI_ERROR (Status);
2139 UT_ASSERT_EQUAL ((-116), Result);
2140
2141 //
2142 // Otherwise should result in an error status
2143 //
2144 Augend = 0x5a;
2145 Addend = 0x5a;
2146 Status = SafeInt8Add (Augend, Addend, &Result);
2147 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2148
2149 Augend = (-90);
2150 Addend = (-90);
2151 Status = SafeInt8Add (Augend, Addend, &Result);
2152 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2153
2154 return UNIT_TEST_PASSED;
2155 }
2156
2157 UNIT_TEST_STATUS
2158 EFIAPI
2159 TestSafeInt16Add (
2160 IN UNIT_TEST_CONTEXT Context
2161 )
2162 {
2163 EFI_STATUS Status;
2164 INT16 Augend;
2165 INT16 Addend;
2166 INT16 Result;
2167
2168 //
2169 // If the result of addition doesn't overflow MAX_INT16
2170 // and doesn't underflow MIN_INT16, then it's addition
2171 //
2172 Augend = 0x3a3a;
2173 Addend = 0x3a3a;
2174 Result = 0;
2175 Status = SafeInt16Add (Augend, Addend, &Result);
2176 UT_ASSERT_NOT_EFI_ERROR (Status);
2177 UT_ASSERT_EQUAL (0x7474, Result);
2178
2179 Augend = (-14906);
2180 Addend = (-14906);
2181 Status = SafeInt16Add (Augend, Addend, &Result);
2182 UT_ASSERT_NOT_EFI_ERROR (Status);
2183 UT_ASSERT_EQUAL ((-29812), Result);
2184
2185 //
2186 // Otherwise should result in an error status
2187 //
2188 Augend = 0x5a5a;
2189 Addend = 0x5a5a;
2190 Status = SafeInt16Add (Augend, Addend, &Result);
2191 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2192
2193 Augend = (-23130);
2194 Addend = (-23130);
2195 Status = SafeInt16Add (Augend, Addend, &Result);
2196 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2197
2198 return UNIT_TEST_PASSED;
2199 }
2200
2201 UNIT_TEST_STATUS
2202 EFIAPI
2203 TestSafeInt32Add (
2204 IN UNIT_TEST_CONTEXT Context
2205 )
2206 {
2207 EFI_STATUS Status;
2208 INT32 Augend;
2209 INT32 Addend;
2210 INT32 Result;
2211
2212 //
2213 // If the result of addition doesn't overflow MAX_INT32
2214 // and doesn't underflow MIN_INT32, then it's addition
2215 //
2216 Augend = 0x3a3a3a3a;
2217 Addend = 0x3a3a3a3a;
2218 Result = 0;
2219 Status = SafeInt32Add (Augend, Addend, &Result);
2220 UT_ASSERT_NOT_EFI_ERROR (Status);
2221 UT_ASSERT_EQUAL (0x74747474, Result);
2222
2223 Augend = (-976894522);
2224 Addend = (-976894522);
2225 Status = SafeInt32Add (Augend, Addend, &Result);
2226 UT_ASSERT_NOT_EFI_ERROR (Status);
2227 UT_ASSERT_EQUAL ((-1953789044), Result);
2228
2229 //
2230 // Otherwise should result in an error status
2231 //
2232 Augend = 0x5a5a5a5a;
2233 Addend = 0x5a5a5a5a;
2234 Status = SafeInt32Add (Augend, Addend, &Result);
2235 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2236
2237 Augend = (-1515870810);
2238 Addend = (-1515870810);
2239 Status = SafeInt32Add (Augend, Addend, &Result);
2240 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2241
2242 return UNIT_TEST_PASSED;
2243 }
2244
2245 UNIT_TEST_STATUS
2246 EFIAPI
2247 TestSafeInt64Add (
2248 IN UNIT_TEST_CONTEXT Context
2249 )
2250 {
2251 EFI_STATUS Status;
2252 INT64 Augend;
2253 INT64 Addend;
2254 INT64 Result;
2255
2256 //
2257 // If the result of addition doesn't overflow MAX_INT64
2258 // and doesn't underflow MIN_INT64, then it's addition
2259 //
2260 Augend = 0x3a3a3a3a3a3a3a3a;
2261 Addend = 0x3a3a3a3a3a3a3a3a;
2262 Result = 0;
2263 Status = SafeInt64Add (Augend, Addend, &Result);
2264 UT_ASSERT_NOT_EFI_ERROR (Status);
2265 UT_ASSERT_EQUAL (0x7474747474747474, Result);
2266
2267 Augend = (-4195730024608447034);
2268 Addend = (-4195730024608447034);
2269 Status = SafeInt64Add (Augend, Addend, &Result);
2270 UT_ASSERT_NOT_EFI_ERROR (Status);
2271 UT_ASSERT_EQUAL ((-8391460049216894068), Result);
2272
2273 //
2274 // Otherwise should result in an error status
2275 //
2276 Augend = 0x5a5a5a5a5a5a5a5a;
2277 Addend = 0x5a5a5a5a5a5a5a5a;
2278 Status = SafeInt64Add (Augend, Addend, &Result);
2279 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2280
2281 Augend = (-6510615555426900570);
2282 Addend = (-6510615555426900570);
2283 Status = SafeInt64Add (Augend, Addend, &Result);
2284 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2285
2286 return UNIT_TEST_PASSED;
2287 }
2288
2289 //
2290 // Subtraction function tests:
2291 //
2292 UNIT_TEST_STATUS
2293 EFIAPI
2294 TestSafeUint8Sub (
2295 IN UNIT_TEST_CONTEXT Context
2296 )
2297 {
2298 EFI_STATUS Status;
2299 UINT8 Minuend;
2300 UINT8 Subtrahend;
2301 UINT8 Result;
2302
2303 //
2304 // If Minuend >= Subtrahend, then it's subtraction
2305 //
2306 Minuend = 0x5a;
2307 Subtrahend = 0x3b;
2308 Result = 0;
2309 Status = SafeUint8Sub (Minuend, Subtrahend, &Result);
2310 UT_ASSERT_NOT_EFI_ERROR (Status);
2311 UT_ASSERT_EQUAL (0x1f, Result);
2312
2313 //
2314 // Otherwise should result in an error status
2315 //
2316 Minuend = 0x5a;
2317 Subtrahend = 0x6d;
2318 Status = SafeUint8Sub (Minuend, Subtrahend, &Result);
2319 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2320
2321 return UNIT_TEST_PASSED;
2322 }
2323
2324 UNIT_TEST_STATUS
2325 EFIAPI
2326 TestSafeUint16Sub (
2327 IN UNIT_TEST_CONTEXT Context
2328 )
2329 {
2330 EFI_STATUS Status;
2331 UINT16 Minuend;
2332 UINT16 Subtrahend;
2333 UINT16 Result;
2334
2335 //
2336 // If Minuend >= Subtrahend, then it's subtraction
2337 //
2338 Minuend = 0x5a5a;
2339 Subtrahend = 0x3b3b;
2340 Result = 0;
2341 Status = SafeUint16Sub (Minuend, Subtrahend, &Result);
2342 UT_ASSERT_NOT_EFI_ERROR (Status);
2343 UT_ASSERT_EQUAL (0x1f1f, Result);
2344
2345 //
2346 // Otherwise should result in an error status
2347 //
2348 Minuend = 0x5a5a;
2349 Subtrahend = 0x6d6d;
2350 Status = SafeUint16Sub (Minuend, Subtrahend, &Result);
2351 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2352
2353 return UNIT_TEST_PASSED;
2354 }
2355
2356 UNIT_TEST_STATUS
2357 EFIAPI
2358 TestSafeUint32Sub (
2359 IN UNIT_TEST_CONTEXT Context
2360 )
2361 {
2362 EFI_STATUS Status;
2363 UINT32 Minuend;
2364 UINT32 Subtrahend;
2365 UINT32 Result;
2366
2367 //
2368 // If Minuend >= Subtrahend, then it's subtraction
2369 //
2370 Minuend = 0x5a5a5a5a;
2371 Subtrahend = 0x3b3b3b3b;
2372 Result = 0;
2373 Status = SafeUint32Sub (Minuend, Subtrahend, &Result);
2374 UT_ASSERT_NOT_EFI_ERROR (Status);
2375 UT_ASSERT_EQUAL (0x1f1f1f1f, Result);
2376
2377 //
2378 // Otherwise should result in an error status
2379 //
2380 Minuend = 0x5a5a5a5a;
2381 Subtrahend = 0x6d6d6d6d;
2382 Status = SafeUint32Sub (Minuend, Subtrahend, &Result);
2383 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2384
2385 return UNIT_TEST_PASSED;
2386 }
2387
2388 UNIT_TEST_STATUS
2389 EFIAPI
2390 TestSafeUint64Sub (
2391 IN UNIT_TEST_CONTEXT Context
2392 )
2393 {
2394 EFI_STATUS Status;
2395 UINT64 Minuend;
2396 UINT64 Subtrahend;
2397 UINT64 Result;
2398
2399 //
2400 // If Minuend >= Subtrahend, then it's subtraction
2401 //
2402 Minuend = 0x5a5a5a5a5a5a5a5a;
2403 Subtrahend = 0x3b3b3b3b3b3b3b3b;
2404 Result = 0;
2405 Status = SafeUint64Sub (Minuend, Subtrahend, &Result);
2406 UT_ASSERT_NOT_EFI_ERROR (Status);
2407 UT_ASSERT_EQUAL (0x1f1f1f1f1f1f1f1f, Result);
2408
2409 //
2410 // Otherwise should result in an error status
2411 //
2412 Minuend = 0x5a5a5a5a5a5a5a5a;
2413 Subtrahend = 0x6d6d6d6d6d6d6d6d;
2414 Status = SafeUint64Sub (Minuend, Subtrahend, &Result);
2415 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2416
2417 return UNIT_TEST_PASSED;
2418 }
2419
2420 UNIT_TEST_STATUS
2421 EFIAPI
2422 TestSafeInt8Sub (
2423 IN UNIT_TEST_CONTEXT Context
2424 )
2425 {
2426 EFI_STATUS Status;
2427 INT8 Minuend;
2428 INT8 Subtrahend;
2429 INT8 Result;
2430
2431 //
2432 // If the result of subtractions doesn't overflow MAX_INT8 or
2433 // underflow MIN_INT8, then it's subtraction
2434 //
2435 Minuend = 0x5a;
2436 Subtrahend = 0x3a;
2437 Result = 0;
2438 Status = SafeInt8Sub (Minuend, Subtrahend, &Result);
2439 UT_ASSERT_NOT_EFI_ERROR (Status);
2440 UT_ASSERT_EQUAL (0x20, Result);
2441
2442 Minuend = 58;
2443 Subtrahend = 78;
2444 Status = SafeInt8Sub (Minuend, Subtrahend, &Result);
2445 UT_ASSERT_NOT_EFI_ERROR (Status);
2446 UT_ASSERT_EQUAL ((-20), Result);
2447
2448 //
2449 // Otherwise should result in an error status
2450 //
2451 Minuend = (-80);
2452 Subtrahend = 80;
2453 Status = SafeInt8Sub (Minuend, Subtrahend, &Result);
2454 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2455
2456 Minuend = (80);
2457 Subtrahend = (-80);
2458 Status = SafeInt8Sub (Minuend, Subtrahend, &Result);
2459 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2460
2461 return UNIT_TEST_PASSED;
2462 }
2463
2464 UNIT_TEST_STATUS
2465 EFIAPI
2466 TestSafeInt16Sub (
2467 IN UNIT_TEST_CONTEXT Context
2468 )
2469 {
2470 EFI_STATUS Status;
2471 INT16 Minuend;
2472 INT16 Subtrahend;
2473 INT16 Result;
2474
2475 //
2476 // If the result of subtractions doesn't overflow MAX_INT16 or
2477 // underflow MIN_INT16, then it's subtraction
2478 //
2479 Minuend = 0x5a5a;
2480 Subtrahend = 0x3a3a;
2481 Result = 0;
2482 Status = SafeInt16Sub (Minuend, Subtrahend, &Result);
2483 UT_ASSERT_NOT_EFI_ERROR (Status);
2484 UT_ASSERT_EQUAL (0x2020, Result);
2485
2486 Minuend = 0x3a3a;
2487 Subtrahend = 0x5a5a;
2488 Status = SafeInt16Sub (Minuend, Subtrahend, &Result);
2489 UT_ASSERT_NOT_EFI_ERROR (Status);
2490 UT_ASSERT_EQUAL ((-8224), Result);
2491
2492 //
2493 // Otherwise should result in an error status
2494 //
2495 Minuend = (-31354);
2496 Subtrahend = 31354;
2497 Status = SafeInt16Sub (Minuend, Subtrahend, &Result);
2498 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2499
2500 Minuend = (31354);
2501 Subtrahend = (-31354);
2502 Status = SafeInt16Sub (Minuend, Subtrahend, &Result);
2503 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2504
2505 return UNIT_TEST_PASSED;
2506 }
2507
2508 UNIT_TEST_STATUS
2509 EFIAPI
2510 TestSafeInt32Sub (
2511 IN UNIT_TEST_CONTEXT Context
2512 )
2513 {
2514 EFI_STATUS Status;
2515 INT32 Minuend;
2516 INT32 Subtrahend;
2517 INT32 Result;
2518
2519 //
2520 // If the result of subtractions doesn't overflow MAX_INT32 or
2521 // underflow MIN_INT32, then it's subtraction
2522 //
2523 Minuend = 0x5a5a5a5a;
2524 Subtrahend = 0x3a3a3a3a;
2525 Result = 0;
2526 Status = SafeInt32Sub (Minuend, Subtrahend, &Result);
2527 UT_ASSERT_NOT_EFI_ERROR (Status);
2528 UT_ASSERT_EQUAL (0x20202020, Result);
2529
2530 Minuend = 0x3a3a3a3a;
2531 Subtrahend = 0x5a5a5a5a;
2532 Status = SafeInt32Sub (Minuend, Subtrahend, &Result);
2533 UT_ASSERT_NOT_EFI_ERROR (Status);
2534 UT_ASSERT_EQUAL ((-538976288), Result);
2535
2536 //
2537 // Otherwise should result in an error status
2538 //
2539 Minuend = (-2054847098);
2540 Subtrahend = 2054847098;
2541 Status = SafeInt32Sub (Minuend, Subtrahend, &Result);
2542 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2543
2544 Minuend = (2054847098);
2545 Subtrahend = (-2054847098);
2546 Status = SafeInt32Sub (Minuend, Subtrahend, &Result);
2547 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2548
2549 return UNIT_TEST_PASSED;
2550 }
2551
2552 UNIT_TEST_STATUS
2553 EFIAPI
2554 TestSafeInt64Sub (
2555 IN UNIT_TEST_CONTEXT Context
2556 )
2557 {
2558 EFI_STATUS Status;
2559 INT64 Minuend;
2560 INT64 Subtrahend;
2561 INT64 Result;
2562
2563 //
2564 // If the result of subtractions doesn't overflow MAX_INT64 or
2565 // underflow MIN_INT64, then it's subtraction
2566 //
2567 Minuend = 0x5a5a5a5a5a5a5a5a;
2568 Subtrahend = 0x3a3a3a3a3a3a3a3a;
2569 Result = 0;
2570 Status = SafeInt64Sub (Minuend, Subtrahend, &Result);
2571 UT_ASSERT_NOT_EFI_ERROR (Status);
2572 UT_ASSERT_EQUAL (0x2020202020202020, Result);
2573
2574 Minuend = 0x3a3a3a3a3a3a3a3a;
2575 Subtrahend = 0x5a5a5a5a5a5a5a5a;
2576 Status = SafeInt64Sub (Minuend, Subtrahend, &Result);
2577 UT_ASSERT_NOT_EFI_ERROR (Status);
2578 UT_ASSERT_EQUAL ((-2314885530818453536), Result);
2579
2580 //
2581 // Otherwise should result in an error status
2582 //
2583 Minuend = (-8825501086245354106);
2584 Subtrahend = 8825501086245354106;
2585 Status = SafeInt64Sub (Minuend, Subtrahend, &Result);
2586 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2587
2588 Minuend = (8825501086245354106);
2589 Subtrahend = (-8825501086245354106);
2590 Status = SafeInt64Sub (Minuend, Subtrahend, &Result);
2591 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2592
2593 return UNIT_TEST_PASSED;
2594 }
2595
2596 //
2597 // Multiplication function tests:
2598 //
2599 UNIT_TEST_STATUS
2600 EFIAPI
2601 TestSafeUint8Mult (
2602 IN UNIT_TEST_CONTEXT Context
2603 )
2604 {
2605 EFI_STATUS Status;
2606 UINT8 Multiplicand;
2607 UINT8 Multiplier;
2608 UINT8 Result;
2609
2610 //
2611 // If the result of multiplication doesn't overflow MAX_UINT8, it will succeed
2612 //
2613 Multiplicand = 0x12;
2614 Multiplier = 0xa;
2615 Result = 0;
2616 Status = SafeUint8Mult (Multiplicand, Multiplier, &Result);
2617 UT_ASSERT_NOT_EFI_ERROR (Status);
2618 UT_ASSERT_EQUAL (0xb4, Result);
2619
2620 //
2621 // Otherwise should result in an error status
2622 //
2623 Multiplicand = 0x12;
2624 Multiplier = 0x23;
2625 Status = SafeUint8Mult (Multiplicand, Multiplier, &Result);
2626 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2627
2628 return UNIT_TEST_PASSED;
2629 }
2630
2631 UNIT_TEST_STATUS
2632 EFIAPI
2633 TestSafeUint16Mult (
2634 IN UNIT_TEST_CONTEXT Context
2635 )
2636 {
2637 EFI_STATUS Status;
2638 UINT16 Multiplicand;
2639 UINT16 Multiplier;
2640 UINT16 Result;
2641
2642 //
2643 // If the result of multiplication doesn't overflow MAX_UINT16, it will succeed
2644 //
2645 Multiplicand = 0x212;
2646 Multiplier = 0x7a;
2647 Result = 0;
2648 Status = SafeUint16Mult (Multiplicand, Multiplier, &Result);
2649 UT_ASSERT_NOT_EFI_ERROR (Status);
2650 UT_ASSERT_EQUAL (0xfc94, Result);
2651
2652 //
2653 // Otherwise should result in an error status
2654 //
2655 Multiplicand = 0x1234;
2656 Multiplier = 0x213;
2657 Status = SafeUint16Mult (Multiplicand, Multiplier, &Result);
2658 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2659
2660 return UNIT_TEST_PASSED;
2661 }
2662
2663 UNIT_TEST_STATUS
2664 EFIAPI
2665 TestSafeUint32Mult (
2666 IN UNIT_TEST_CONTEXT Context
2667 )
2668 {
2669 EFI_STATUS Status;
2670 UINT32 Multiplicand;
2671 UINT32 Multiplier;
2672 UINT32 Result;
2673
2674 //
2675 // If the result of multiplication doesn't overflow MAX_UINT32, it will succeed
2676 //
2677 Multiplicand = 0xa122a;
2678 Multiplier = 0xd23;
2679 Result = 0;
2680 Status = SafeUint32Mult (Multiplicand, Multiplier, &Result);
2681 UT_ASSERT_NOT_EFI_ERROR (Status);
2682 UT_ASSERT_EQUAL (0x844c9dbe, Result);
2683
2684 //
2685 // Otherwise should result in an error status
2686 //
2687 Multiplicand = 0xa122a;
2688 Multiplier = 0xed23;
2689 Status = SafeUint32Mult (Multiplicand, Multiplier, &Result);
2690 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2691
2692 return UNIT_TEST_PASSED;
2693 }
2694
2695 UNIT_TEST_STATUS
2696 EFIAPI
2697 TestSafeUint64Mult (
2698 IN UNIT_TEST_CONTEXT Context
2699 )
2700 {
2701 EFI_STATUS Status;
2702 UINT64 Multiplicand;
2703 UINT64 Multiplier;
2704 UINT64 Result;
2705
2706 //
2707 // If the result of multiplication doesn't overflow MAX_UINT64, it will succeed
2708 //
2709 Multiplicand = 0x123456789a;
2710 Multiplier = 0x1234567;
2711 Result = 0;
2712 Status = SafeUint64Mult (Multiplicand, Multiplier, &Result);
2713 UT_ASSERT_NOT_EFI_ERROR (Status);
2714 UT_ASSERT_EQUAL (0x14b66db9745a07f6, Result);
2715
2716 //
2717 // Otherwise should result in an error status
2718 //
2719 Multiplicand = 0x123456789a;
2720 Multiplier = 0x12345678;
2721 Status = SafeUint64Mult (Multiplicand, Multiplier, &Result);
2722 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2723
2724 return UNIT_TEST_PASSED;
2725 }
2726
2727 UNIT_TEST_STATUS
2728 EFIAPI
2729 TestSafeInt8Mult (
2730 IN UNIT_TEST_CONTEXT Context
2731 )
2732 {
2733 EFI_STATUS Status;
2734 INT8 Multiplicand;
2735 INT8 Multiplier;
2736 INT8 Result;
2737
2738 //
2739 // If the result of multiplication doesn't overflow MAX_INT8 and doesn't
2740 // underflow MIN_UINT8, it will succeed
2741 //
2742 Multiplicand = 0x12;
2743 Multiplier = 0x7;
2744 Result = 0;
2745 Status = SafeInt8Mult (Multiplicand, Multiplier, &Result);
2746 UT_ASSERT_NOT_EFI_ERROR (Status);
2747 UT_ASSERT_EQUAL (0x7e, Result);
2748
2749 //
2750 // Otherwise should result in an error status
2751 //
2752 Multiplicand = 0x12;
2753 Multiplier = 0xa;
2754 Status = SafeInt8Mult (Multiplicand, Multiplier, &Result);
2755 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2756
2757 return UNIT_TEST_PASSED;
2758 }
2759
2760 UNIT_TEST_STATUS
2761 EFIAPI
2762 TestSafeInt16Mult (
2763 IN UNIT_TEST_CONTEXT Context
2764 )
2765 {
2766 EFI_STATUS Status;
2767 INT16 Multiplicand;
2768 INT16 Multiplier;
2769 INT16 Result;
2770
2771 //
2772 // If the result of multiplication doesn't overflow MAX_INT16 and doesn't
2773 // underflow MIN_UINT16, it will succeed
2774 //
2775 Multiplicand = 0x123;
2776 Multiplier = 0x67;
2777 Result = 0;
2778 Status = SafeInt16Mult (Multiplicand, Multiplier, &Result);
2779 UT_ASSERT_NOT_EFI_ERROR (Status);
2780 UT_ASSERT_EQUAL (0x7515, Result);
2781
2782 //
2783 // Otherwise should result in an error status
2784 //
2785 Multiplicand = 0x123;
2786 Multiplier = 0xab;
2787 Status = SafeInt16Mult (Multiplicand, Multiplier, &Result);
2788 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2789
2790 return UNIT_TEST_PASSED;
2791 }
2792
2793 UNIT_TEST_STATUS
2794 EFIAPI
2795 TestSafeInt32Mult (
2796 IN UNIT_TEST_CONTEXT Context
2797 )
2798 {
2799 EFI_STATUS Status;
2800 INT32 Multiplicand;
2801 INT32 Multiplier;
2802 INT32 Result;
2803
2804 //
2805 // If the result of multiplication doesn't overflow MAX_INT32 and doesn't
2806 // underflow MIN_UINT32, it will succeed
2807 //
2808 Multiplicand = 0x123456;
2809 Multiplier = 0x678;
2810 Result = 0;
2811 Status = SafeInt32Mult (Multiplicand, Multiplier, &Result);
2812 UT_ASSERT_NOT_EFI_ERROR (Status);
2813 UT_ASSERT_EQUAL (0x75c28c50, Result);
2814
2815 //
2816 // Otherwise should result in an error status
2817 //
2818 Multiplicand = 0x123456;
2819 Multiplier = 0xabc;
2820 Status = SafeInt32Mult (Multiplicand, Multiplier, &Result);
2821 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2822
2823 return UNIT_TEST_PASSED;
2824 }
2825
2826 UNIT_TEST_STATUS
2827 EFIAPI
2828 TestSafeInt64Mult (
2829 IN UNIT_TEST_CONTEXT Context
2830 )
2831 {
2832 EFI_STATUS Status;
2833 INT64 Multiplicand;
2834 INT64 Multiplier;
2835 INT64 Result;
2836
2837 //
2838 // If the result of multiplication doesn't overflow MAX_INT64 and doesn't
2839 // underflow MIN_UINT64, it will succeed
2840 //
2841 Multiplicand = 0x123456789;
2842 Multiplier = 0x6789abcd;
2843 Result = 0;
2844 Status = SafeInt64Mult (Multiplicand, Multiplier, &Result);
2845 UT_ASSERT_NOT_EFI_ERROR (Status);
2846 UT_ASSERT_EQUAL (0x75cd9045220d6bb5, Result);
2847
2848 //
2849 // Otherwise should result in an error status
2850 //
2851 Multiplicand = 0x123456789;
2852 Multiplier = 0xa789abcd;
2853 Status = SafeInt64Mult (Multiplicand, Multiplier, &Result);
2854 UT_ASSERT_EQUAL (RETURN_BUFFER_TOO_SMALL, Status);
2855
2856 return UNIT_TEST_PASSED;
2857 }
2858
2859 /**
2860
2861 Main fuction sets up the unit test environment
2862
2863 **/
2864 EFI_STATUS
2865 EFIAPI
2866 UefiTestMain (
2867 VOID
2868 )
2869 {
2870 EFI_STATUS Status;
2871 UNIT_TEST_FRAMEWORK_HANDLE Framework;
2872 UNIT_TEST_SUITE_HANDLE ConversionTestSuite;
2873 UNIT_TEST_SUITE_HANDLE AdditionSubtractionTestSuite;
2874 UNIT_TEST_SUITE_HANDLE MultiplicationTestSuite;
2875
2876 Framework = NULL;
2877 ConversionTestSuite = NULL;
2878 AdditionSubtractionTestSuite = NULL;
2879 MultiplicationTestSuite = NULL;
2880
2881 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
2882
2883 //
2884 // Start setting up the test framework for running the tests.
2885 //
2886 Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION);
2887 if (EFI_ERROR (Status)) {
2888 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
2889 goto EXIT;
2890 }
2891
2892 ///
2893 // Test the conversion functions
2894 //
2895 Status = CreateUnitTestSuite (&ConversionTestSuite, Framework, "Int Safe Conversions Test Suite", "Common.SafeInt.Convert", NULL, NULL);
2896 if (EFI_ERROR (Status)) {
2897 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Conversions Test Suite\n"));
2898 Status = EFI_OUT_OF_RESOURCES;
2899 goto EXIT;
2900 }
2901
2902 AddTestCase (ConversionTestSuite, "Test SafeInt8ToUint8", "TestSafeInt8ToUint8", TestSafeInt8ToUint8, NULL, NULL, NULL);
2903 AddTestCase (ConversionTestSuite, "Test SafeInt8ToUint16", "TestSafeInt8ToUint16", TestSafeInt8ToUint16, NULL, NULL, NULL);
2904 AddTestCase (ConversionTestSuite, "Test SafeInt8ToUint32", "TestSafeInt8ToUint32", TestSafeInt8ToUint32, NULL, NULL, NULL);
2905 AddTestCase (ConversionTestSuite, "Test SafeInt8ToUintn", "TestSafeInt8ToUintn", TestSafeInt8ToUintn, NULL, NULL, NULL);
2906 AddTestCase (ConversionTestSuite, "Test SafeInt8ToUint64", "TestSafeInt8ToUint64", TestSafeInt8ToUint64, NULL, NULL, NULL);
2907 AddTestCase (ConversionTestSuite, "Test SafeUint8ToInt8", "TestSafeUint8ToInt8", TestSafeUint8ToInt8, NULL, NULL, NULL);
2908 AddTestCase (ConversionTestSuite, "Test SafeUint8ToChar8", "TestSafeUint8ToChar8", TestSafeUint8ToChar8, NULL, NULL, NULL);
2909 AddTestCase (ConversionTestSuite, "Test SafeInt16ToInt8", "TestSafeInt16ToInt8", TestSafeInt16ToInt8, NULL, NULL, NULL);
2910 AddTestCase (ConversionTestSuite, "Test SafeInt16ToChar8", "TestSafeInt16ToChar8", TestSafeInt16ToChar8, NULL, NULL, NULL);
2911 AddTestCase (ConversionTestSuite, "Test SafeInt16ToUint8", "TestSafeInt16ToUint8", TestSafeInt16ToUint8, NULL, NULL, NULL);
2912 AddTestCase (ConversionTestSuite, "Test SafeInt16ToUint16", "TestSafeInt16ToUint16", TestSafeInt16ToUint16, NULL, NULL, NULL);
2913 AddTestCase (ConversionTestSuite, "Test SafeInt16ToUint32", "TestSafeInt16ToUint32", TestSafeInt16ToUint32, NULL, NULL, NULL);
2914 AddTestCase (ConversionTestSuite, "Test SafeInt16ToUintn", "TestSafeInt16ToUintn", TestSafeInt16ToUintn, NULL, NULL, NULL);
2915 AddTestCase (ConversionTestSuite, "Test SafeInt16ToUint64", "TestSafeInt16ToUint64", TestSafeInt16ToUint64, NULL, NULL, NULL);
2916 AddTestCase (ConversionTestSuite, "Test SafeUint16ToInt8", "TestSafeUint16ToInt8", TestSafeUint16ToInt8, NULL, NULL, NULL);
2917 AddTestCase (ConversionTestSuite, "Test SafeUint16ToChar8", "TestSafeUint16ToChar8", TestSafeUint16ToChar8, NULL, NULL, NULL);
2918 AddTestCase (ConversionTestSuite, "Test SafeUint16ToUint8", "TestSafeUint16ToUint8", TestSafeUint16ToUint8, NULL, NULL, NULL);
2919 AddTestCase (ConversionTestSuite, "Test SafeUint16ToInt16", "TestSafeUint16ToInt16", TestSafeUint16ToInt16, NULL, NULL, NULL);
2920 AddTestCase (ConversionTestSuite, "Test SafeInt32ToInt8", "TestSafeInt32ToInt8", TestSafeInt32ToInt8, NULL, NULL, NULL);
2921 AddTestCase (ConversionTestSuite, "Test SafeInt32ToChar8", "TestSafeInt32ToChar8", TestSafeInt32ToChar8, NULL, NULL, NULL);
2922 AddTestCase (ConversionTestSuite, "Test SafeInt32ToUint8", "TestSafeInt32ToUint8", TestSafeInt32ToUint8, NULL, NULL, NULL);
2923 AddTestCase (ConversionTestSuite, "Test SafeInt32ToInt16", "TestSafeInt32ToInt16", TestSafeInt32ToInt16, NULL, NULL, NULL);
2924 AddTestCase (ConversionTestSuite, "Test SafeInt32ToUint16", "TestSafeInt32ToUint16", TestSafeInt32ToUint16, NULL, NULL, NULL);
2925 AddTestCase (ConversionTestSuite, "Test SafeInt32ToUint32", "TestSafeInt32ToUint32", TestSafeInt32ToUint32, NULL, NULL, NULL);
2926 AddTestCase (ConversionTestSuite, "Test SafeInt32ToUintn", "TestSafeInt32ToUintn", TestSafeInt32ToUintn, NULL, NULL, NULL);
2927 AddTestCase (ConversionTestSuite, "Test SafeInt32ToUint64", "TestSafeInt32ToUint64", TestSafeInt32ToUint64, NULL, NULL, NULL);
2928 AddTestCase (ConversionTestSuite, "Test SafeUint32ToInt8", "TestSafeUint32ToInt8", TestSafeUint32ToInt8, NULL, NULL, NULL);
2929 AddTestCase (ConversionTestSuite, "Test SafeUint32ToChar8", "TestSafeUint32ToChar8", TestSafeUint32ToChar8, NULL, NULL, NULL);
2930 AddTestCase (ConversionTestSuite, "Test SafeUint32ToUint8", "TestSafeUint32ToUint8", TestSafeUint32ToUint8, NULL, NULL, NULL);
2931 AddTestCase (ConversionTestSuite, "Test SafeUint32ToInt16", "TestSafeUint32ToInt16", TestSafeUint32ToInt16, NULL, NULL, NULL);
2932 AddTestCase (ConversionTestSuite, "Test SafeUint32ToUint16", "TestSafeUint32ToUint16", TestSafeUint32ToUint16, NULL, NULL, NULL);
2933 AddTestCase (ConversionTestSuite, "Test SafeUint32ToInt32", "TestSafeUint32ToInt32", TestSafeUint32ToInt32, NULL, NULL, NULL);
2934 AddTestCase (ConversionTestSuite, "Test SafeUint32ToIntn", "TestSafeUint32ToIntn", TestSafeUint32ToIntn, NULL, NULL, NULL);
2935 AddTestCase (ConversionTestSuite, "Test SafeIntnToInt8", "TestSafeIntnToInt8", TestSafeIntnToInt8, NULL, NULL, NULL);
2936 AddTestCase (ConversionTestSuite, "Test SafeIntnToChar8", "TestSafeIntnToChar8", TestSafeIntnToChar8, NULL, NULL, NULL);
2937 AddTestCase (ConversionTestSuite, "Test SafeIntnToUint8", "TestSafeIntnToUint8", TestSafeIntnToUint8, NULL, NULL, NULL);
2938 AddTestCase (ConversionTestSuite, "Test SafeIntnToInt16", "TestSafeIntnToInt16", TestSafeIntnToInt16, NULL, NULL, NULL);
2939 AddTestCase (ConversionTestSuite, "Test SafeIntnToUint16", "TestSafeIntnToUint16", TestSafeIntnToUint16, NULL, NULL, NULL);
2940 AddTestCase (ConversionTestSuite, "Test SafeIntnToInt32", "TestSafeIntnToInt32", TestSafeIntnToInt32, NULL, NULL, NULL);
2941 AddTestCase (ConversionTestSuite, "Test SafeIntnToUint32", "TestSafeIntnToUint32", TestSafeIntnToUint32, NULL, NULL, NULL);
2942 AddTestCase (ConversionTestSuite, "Test SafeIntnToUintn", "TestSafeIntnToUintn", TestSafeIntnToUintn, NULL, NULL, NULL);
2943 AddTestCase (ConversionTestSuite, "Test SafeIntnToUint64", "TestSafeIntnToUint64", TestSafeIntnToUint64, NULL, NULL, NULL);
2944 AddTestCase (ConversionTestSuite, "Test SafeUintnToInt8", "TestSafeUintnToInt8", TestSafeUintnToInt8, NULL, NULL, NULL);
2945 AddTestCase (ConversionTestSuite, "Test SafeUintnToChar8", "TestSafeUintnToChar8", TestSafeUintnToChar8, NULL, NULL, NULL);
2946 AddTestCase (ConversionTestSuite, "Test SafeUintnToUint8", "TestSafeUintnToUint8", TestSafeUintnToUint8, NULL, NULL, NULL);
2947 AddTestCase (ConversionTestSuite, "Test SafeUintnToInt16", "TestSafeUintnToInt16", TestSafeUintnToInt16, NULL, NULL, NULL);
2948 AddTestCase (ConversionTestSuite, "Test SafeUintnToUint16", "TestSafeUintnToUint16", TestSafeUintnToUint16, NULL, NULL, NULL);
2949 AddTestCase (ConversionTestSuite, "Test SafeUintnToInt32", "TestSafeUintnToInt32", TestSafeUintnToInt32, NULL, NULL, NULL);
2950 AddTestCase (ConversionTestSuite, "Test SafeUintnToUint32", "TestSafeUintnToUint32", TestSafeUintnToUint32, NULL, NULL, NULL);
2951 AddTestCase (ConversionTestSuite, "Test SafeUintnToIntn", "TestSafeUintnToIntn", TestSafeUintnToIntn, NULL, NULL, NULL);
2952 AddTestCase (ConversionTestSuite, "Test SafeUintnToInt64", "TestSafeUintnToInt64", TestSafeUintnToInt64, NULL, NULL, NULL);
2953 AddTestCase (ConversionTestSuite, "Test SafeInt64ToInt8", "TestSafeInt64ToInt8", TestSafeInt64ToInt8, NULL, NULL, NULL);
2954 AddTestCase (ConversionTestSuite, "Test SafeInt64ToChar8", "TestSafeInt64ToChar8", TestSafeInt64ToChar8, NULL, NULL, NULL);
2955 AddTestCase (ConversionTestSuite, "Test SafeInt64ToUint8", "TestSafeInt64ToUint8", TestSafeInt64ToUint8, NULL, NULL, NULL);
2956 AddTestCase (ConversionTestSuite, "Test SafeInt64ToInt16", "TestSafeInt64ToInt16", TestSafeInt64ToInt16, NULL, NULL, NULL);
2957 AddTestCase (ConversionTestSuite, "Test SafeInt64ToUint16", "TestSafeInt64ToUint16", TestSafeInt64ToUint16, NULL, NULL, NULL);
2958 AddTestCase (ConversionTestSuite, "Test SafeInt64ToInt32", "TestSafeInt64ToInt32", TestSafeInt64ToInt32, NULL, NULL, NULL);
2959 AddTestCase (ConversionTestSuite, "Test SafeInt64ToUint32", "TestSafeInt64ToUint32", TestSafeInt64ToUint32, NULL, NULL, NULL);
2960 AddTestCase (ConversionTestSuite, "Test SafeInt64ToIntn", "TestSafeInt64ToIntn", TestSafeInt64ToIntn, NULL, NULL, NULL);
2961 AddTestCase (ConversionTestSuite, "Test SafeInt64ToUintn", "TestSafeInt64ToUintn", TestSafeInt64ToUintn, NULL, NULL, NULL);
2962 AddTestCase (ConversionTestSuite, "Test SafeInt64ToUint64", "TestSafeInt64ToUint64", TestSafeInt64ToUint64, NULL, NULL, NULL);
2963 AddTestCase (ConversionTestSuite, "Test SafeUint64ToInt8", "TestSafeUint64ToInt8", TestSafeUint64ToInt8, NULL, NULL, NULL);
2964 AddTestCase (ConversionTestSuite, "Test SafeUint64ToChar8", "TestSafeUint64ToChar8", TestSafeUint64ToChar8, NULL, NULL, NULL);
2965 AddTestCase (ConversionTestSuite, "Test SafeUint64ToUint8", "TestSafeUint64ToUint8", TestSafeUint64ToUint8, NULL, NULL, NULL);
2966 AddTestCase (ConversionTestSuite, "Test SafeUint64ToInt16", "TestSafeUint64ToInt16", TestSafeUint64ToInt16, NULL, NULL, NULL);
2967 AddTestCase (ConversionTestSuite, "Test SafeUint64ToUint16", "TestSafeUint64ToUint16", TestSafeUint64ToUint16, NULL, NULL, NULL);
2968 AddTestCase (ConversionTestSuite, "Test SafeUint64ToInt32", "TestSafeUint64ToInt32", TestSafeUint64ToInt32, NULL, NULL, NULL);
2969 AddTestCase (ConversionTestSuite, "Test SafeUint64ToUint32", "TestSafeUint64ToUint32", TestSafeUint64ToUint32, NULL, NULL, NULL);
2970 AddTestCase (ConversionTestSuite, "Test SafeUint64ToIntn", "TestSafeUint64ToIntn", TestSafeUint64ToIntn, NULL, NULL, NULL);
2971 AddTestCase (ConversionTestSuite, "Test SafeUint64ToUintn", "TestSafeUint64ToUintn", TestSafeUint64ToUintn, NULL, NULL, NULL);
2972 AddTestCase (ConversionTestSuite, "Test SafeUint64ToInt64", "TestSafeUint64ToInt64", TestSafeUint64ToInt64, NULL, NULL, NULL);
2973
2974 //
2975 // Test the addition and subtraction functions
2976 //
2977 Status = CreateUnitTestSuite (&AdditionSubtractionTestSuite, Framework, "Int Safe Add/Subtract Test Suite", "Common.SafeInt.AddSubtract", NULL, NULL);
2978 if (EFI_ERROR (Status)) {
2979 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Add/Subtract Test Suite\n"));
2980 Status = EFI_OUT_OF_RESOURCES;
2981 goto EXIT;
2982 }
2983
2984 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint8Add", "TestSafeUint8Add", TestSafeUint8Add, NULL, NULL, NULL);
2985 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint16Add", "TestSafeUint16Add", TestSafeUint16Add, NULL, NULL, NULL);
2986 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint32Add", "TestSafeUint32Add", TestSafeUint32Add, NULL, NULL, NULL);
2987 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUintnAdd", "TestSafeUintnAdd", TestSafeUintnAdd, NULL, NULL, NULL);
2988 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint64Add", "TestSafeUint64Add", TestSafeUint64Add, NULL, NULL, NULL);
2989 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt8Add", "TestSafeInt8Add", TestSafeInt8Add, NULL, NULL, NULL);
2990 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt16Add", "TestSafeInt16Add", TestSafeInt16Add, NULL, NULL, NULL);
2991 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt32Add", "TestSafeInt32Add", TestSafeInt32Add, NULL, NULL, NULL);
2992 AddTestCase (AdditionSubtractionTestSuite, "Test SafeIntnAdd", "TestSafeIntnAdd", TestSafeIntnAdd, NULL, NULL, NULL);
2993 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt64Add", "TestSafeInt64Add", TestSafeInt64Add, NULL, NULL, NULL);
2994 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint8Sub", "TestSafeUint8Sub", TestSafeUint8Sub, NULL, NULL, NULL);
2995 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint16Sub", "TestSafeUint16Sub", TestSafeUint16Sub, NULL, NULL, NULL);
2996 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint32Sub", "TestSafeUint32Sub", TestSafeUint32Sub, NULL, NULL, NULL);
2997 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUintnSub", "TestSafeUintnSub", TestSafeUintnSub, NULL, NULL, NULL);
2998 AddTestCase (AdditionSubtractionTestSuite, "Test SafeUint64Sub", "TestSafeUint64Sub", TestSafeUint64Sub, NULL, NULL, NULL);
2999 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt8Sub", "TestSafeInt8Sub", TestSafeInt8Sub, NULL, NULL, NULL);
3000 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt16Sub", "TestSafeInt16Sub", TestSafeInt16Sub, NULL, NULL, NULL);
3001 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt32Sub", "TestSafeInt32Sub", TestSafeInt32Sub, NULL, NULL, NULL);
3002 AddTestCase (AdditionSubtractionTestSuite, "Test SafeIntnSub", "TestSafeIntnSub", TestSafeIntnSub, NULL, NULL, NULL);
3003 AddTestCase (AdditionSubtractionTestSuite, "Test SafeInt64Sub", "TestSafeInt64Sub", TestSafeInt64Sub, NULL, NULL, NULL);
3004
3005 //
3006 // Test the multiplication functions
3007 //
3008 Status = CreateUnitTestSuite (&MultiplicationTestSuite, Framework, "Int Safe Multiply Test Suite", "Common.SafeInt.Multiply", NULL, NULL);
3009 if (EFI_ERROR (Status)) {
3010 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Int Safe Multiply Test Suite\n"));
3011 Status = EFI_OUT_OF_RESOURCES;
3012 goto EXIT;
3013 }
3014
3015 AddTestCase (MultiplicationTestSuite, "Test SafeUint8Mult", "TestSafeUint8Mult", TestSafeUint8Mult, NULL, NULL, NULL);
3016 AddTestCase (MultiplicationTestSuite, "Test SafeUint16Mult", "TestSafeUint16Mult", TestSafeUint16Mult, NULL, NULL, NULL);
3017 AddTestCase (MultiplicationTestSuite, "Test SafeUint32Mult", "TestSafeUint32Mult", TestSafeUint32Mult, NULL, NULL, NULL);
3018 AddTestCase (MultiplicationTestSuite, "Test SafeUintnMult", "TestSafeUintnMult", TestSafeUintnMult, NULL, NULL, NULL);
3019 AddTestCase (MultiplicationTestSuite, "Test SafeUint64Mult", "TestSafeUint64Mult", TestSafeUint64Mult, NULL, NULL, NULL);
3020 AddTestCase (MultiplicationTestSuite, "Test SafeInt8Mult", "TestSafeInt8Mult", TestSafeInt8Mult, NULL, NULL, NULL);
3021 AddTestCase (MultiplicationTestSuite, "Test SafeInt16Mult", "TestSafeInt16Mult", TestSafeInt16Mult, NULL, NULL, NULL);
3022 AddTestCase (MultiplicationTestSuite, "Test SafeInt32Mult", "TestSafeInt32Mult", TestSafeInt32Mult, NULL, NULL, NULL);
3023 AddTestCase (MultiplicationTestSuite, "Test SafeIntnMult", "TestSafeIntnMult", TestSafeIntnMult, NULL, NULL, NULL);
3024 AddTestCase (MultiplicationTestSuite, "Test SafeInt64Mult", "TestSafeInt64Mult", TestSafeInt64Mult, NULL, NULL, NULL);
3025
3026 //
3027 // Execute the tests.
3028 //
3029 Status = RunAllTestSuites (Framework);
3030
3031 EXIT:
3032 if (Framework != NULL) {
3033 FreeUnitTestFramework (Framework);
3034 }
3035
3036 return Status;
3037 }
3038
3039 EFI_STATUS
3040 EFIAPI
3041 PeiEntryPoint (
3042 IN EFI_PEI_FILE_HANDLE FileHandle,
3043 IN CONST EFI_PEI_SERVICES **PeiServices
3044 )
3045 {
3046 return UefiTestMain ();
3047 }
3048
3049 EFI_STATUS
3050 EFIAPI
3051 DxeEntryPoint (
3052 IN EFI_HANDLE ImageHandle,
3053 IN EFI_SYSTEM_TABLE *SystemTable
3054 )
3055 {
3056 return UefiTestMain ();
3057 }
3058
3059 int
3060 main (
3061 int argc,
3062 char *argv[]
3063 )
3064 {
3065 return UefiTestMain ();
3066 }