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 Expect Fail" |
#define | UNIT_TEST_VERSION "0.1" |
Variables | |
BOOLEAN | mSampleGlobalTestBoolean = FALSE |
VOID * | mSampleGlobalTestPointer = NULL |
This is a sample to demonstrate the usage of the Unit Test Library that supports the PEI, DXE, SMM, UEFI Shell, and host execution environments. All test case are always expected to fail to demonstrate the format of the log file and reports when failures occur.
Copyright (c) 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Definition in file SampleUnitTestExpectFail.c.
#define UNIT_TEST_NAME "Sample Unit Test Expect Fail" |
Definition at line 18 of file SampleUnitTestExpectFail.c.
#define UNIT_TEST_VERSION "0.1" |
Definition at line 19 of file SampleUnitTestExpectFail.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 82 of file SampleUnitTestExpectFail.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 843 of file SampleUnitTestExpectFail.c.
UNIT_TEST_STATUS EFIAPI GenerateUnexpectedAssert | ( | IN UNIT_TEST_CONTEXT | Context | ) |
Sample unit test the triggers an unexpected ASSERT()
[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 553 of file SampleUnitTestExpectFail.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 141 of file SampleUnitTestExpectFail.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 172 of file SampleUnitTestExpectFail.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 307 of file SampleUnitTestExpectFail.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 270 of file SampleUnitTestExpectFail.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 344 of file SampleUnitTestExpectFail.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 417 of file SampleUnitTestExpectFail.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 380 of file SampleUnitTestExpectFail.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 480 of file SampleUnitTestExpectFail.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 451 of file SampleUnitTestExpectFail.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 233 of file SampleUnitTestExpectFail.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 SampleUnitTestExpectFail.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 592 of file SampleUnitTestExpectFail.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 654 of file SampleUnitTestExpectFail.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 685 of file SampleUnitTestExpectFail.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 623 of file SampleUnitTestExpectFail.c.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Standard POSIX C entry point for host based unit test execution.
Definition at line 855 of file SampleUnitTestExpectFail.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 50 of file SampleUnitTestExpectFail.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 107 of file SampleUnitTestExpectFail.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 829 of file SampleUnitTestExpectFail.c.
VOID EFIAPI TestSuiteDisableAsserts | ( | VOID | ) |
Unit-Test Test Suite Setup (before) function that disables ASSERT() macros.
Definition at line 206 of file SampleUnitTestExpectFail.c.
VOID EFIAPI TestSuiteEnableAsserts | ( | VOID | ) |
Unit-Test Test Suite Setup (before) function that enables ASSERT() macros.
Definition at line 191 of file SampleUnitTestExpectFail.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 709 of file SampleUnitTestExpectFail.c.
BOOLEAN mSampleGlobalTestBoolean = FALSE |
Global variables used in unit tests
Definition at line 24 of file SampleUnitTestExpectFail.c.
VOID* mSampleGlobalTestPointer = NULL |
Definition at line 25 of file SampleUnitTestExpectFail.c.