TianoCore EDK2 master
|
#include <PiPei.h>
#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/UnitTestLib.h>
#include <Library/PrintLib.h>
Go to the source code of this file.
Macros | |
#define | UNIT_TEST_NAME "Sample Unit Test" |
#define | UNIT_TEST_VERSION "0.1" |
Variables | |
BOOLEAN | mSampleGlobalTestBoolean = FALSE |
VOID * | mSampleGlobalTestPointer = NULL |
This is a sample to demostrate the usage of the Unit Test Library that supports the PEI, DXE, SMM, UEFI SHell, and host execution environments.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SampleUnitTest.c.
#define UNIT_TEST_NAME "Sample Unit Test" |
Definition at line 16 of file SampleUnitTest.c.
#define UNIT_TEST_VERSION "0.1" |
Definition at line 17 of file SampleUnitTest.c.
VOID EFIAPI ClearThePointer | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample Unit-Test Cleanup (after) function that resets the global pointer to NULL.
Functions with this prototype are registered to be dispatched by the unit test framework after a given test case. This will be called even if the test case returns an error, but not if the prerequisite fails and the test is skipped. The purpose of this function is to clean up any global state or test data.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | Test case cleanup succeeded. |
UNIT_TEST_ERROR_CLEANUP_FAILED | Test case cleanup failed. |
Definition at line 80 of file SampleUnitTest.c.
EFI_STATUS EFIAPI DxeEntryPoint | ( | IN EFI_HANDLE | ImageHandle, |
IN EFI_SYSTEM_TABLE * | SystemTable | ||
) |
Standard UEFI entry point for target based unit test execution from DXE, SMM, UEFI Shell.
Definition at line 785 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI GlobalBooleanShouldBeChangeable | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test that verifies that a global BOOLEAN is updatable.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 139 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI GlobalPointerShouldBeChangeable | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test that logs a warning message and verifies that a global pointer is updatable.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 170 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertEqual | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_EQUAL() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 305 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertFalse | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_FALSE() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 268 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertMemEqual | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_MEM_EQUAL() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 342 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertNotEfiError | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_NOT_EFI_ERROR() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 415 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertNotEqual | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_NOT_EQUAL() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 378 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertNotNull | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_NOT_NULL() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 478 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertStatusEqual | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_STATUS_EQUAL() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 449 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtAssertTrue | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_ASSERT_TRUE() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 231 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtExpectAssertFailure | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_EXPECT_ASSERT_FAILURE() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 509 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtLogError | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_LOG_ERROR() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 545 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtLogInfo | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_LOG_INFO() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 603 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtLogVerbose | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_LOG_VERBOSE() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 632 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MacroUtLogWarning | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test using the UT_LOG_WARNING() macro.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 574 of file SampleUnitTest.c.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Standard POSIX C entry point for host based unit test execution.
Definition at line 797 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI MakeSureThatPointerIsNull | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample Unit-Test Prerequisite Function that checks to make sure the global pointer used in the test is already set to NULL.
Functions with this prototype are registered to be dispatched by the unit test framework prior to a given test case. If this prereq function returns UNIT_TEST_ERROR_PREREQUISITE_NOT_MET, the test case will be skipped.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | Unit test case prerequisites are met. |
UNIT_TEST_ERROR_PREREQUISITE_NOT_MET | Test case should be skipped. |
Definition at line 48 of file SampleUnitTest.c.
UNIT_TEST_STATUS EFIAPI OnePlusOneShouldEqualTwo | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test that verifies the expected result of an unsigned integer addition operation.
[in] | Context | [Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it. |
UNIT_TEST_PASSED | The Unit test has completed and the test case was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 105 of file SampleUnitTest.c.
EFI_STATUS EFIAPI PeiEntryPoint | ( | IN EFI_PEI_FILE_HANDLE | FileHandle, |
IN CONST EFI_PEI_SERVICES ** | PeiServices | ||
) |
Standard PEIM entry point for target based unit test execution from PEI.
Definition at line 771 of file SampleUnitTest.c.
VOID EFIAPI TestSuiteDisableAsserts | ( | VOID | ) |
Unit-Test Test Suite Setup (before) function that disables ASSERT() macros.
Definition at line 204 of file SampleUnitTest.c.
VOID EFIAPI TestSuiteEnableAsserts | ( | VOID | ) |
Unit-Test Test Suite Setup (before) function that enables ASSERT() macros.
Definition at line 189 of file SampleUnitTest.c.
EFI_STATUS EFIAPI UefiTestMain | ( | VOID | ) |
Initialize the unit test framework, suite, and unit tests for the sample unit tests and run the unit tests.
EFI_SUCCESS | All test cases were dispatched. |
EFI_OUT_OF_RESOURCES | There are not enough resources available to initialize the unit tests. |
Definition at line 654 of file SampleUnitTest.c.
BOOLEAN mSampleGlobalTestBoolean = FALSE |
Global variables used in unit tests
Definition at line 22 of file SampleUnitTest.c.
VOID* mSampleGlobalTestPointer = NULL |
Definition at line 23 of file SampleUnitTest.c.