]> git.proxmox.com Git - mirror_edk2.git/blame - UnitTestFrameworkPkg/ReadMe.md
Maintainers.txt: Update email address
[mirror_edk2.git] / UnitTestFrameworkPkg / ReadMe.md
CommitLineData
0f7fb5c5
MK
1# Unit Test Framework Package\r
2\r
3## About\r
4\r
5This package adds a unit test framework capable of building tests for multiple contexts including\r
6the UEFI shell environment and host-based environments. It allows for unit test development to focus\r
7on the tests and leave error logging, result formatting, context persistance, and test running to the framework.\r
8The unit test framework works well for low level unit tests as well as system level tests and\r
9fits easily in automation frameworks.\r
10\r
11### UnitTestLib\r
12\r
13The main "framework" library. The core of the framework is the Framework object, which can have any number\r
14of test cases and test suites registered with it. The Framework object is also what drives test execution.\r
15\r
16The Framework also provides helper macros and functions for checking test conditions and\r
17reporting errors. Status and error info will be logged into the test context. There are a number\r
18of Assert macros that make the unit test code friendly to view and easy to understand.\r
19\r
20Finally, the Framework also supports logging strings during the test execution. This data is logged\r
21to the test context and will be available in the test reporting phase. This should be used for\r
22logging test details and helpful messages to resolve test failures.\r
23\r
24### UnitTestPersistenceLib\r
25\r
26Persistence lib has the main job of saving and restoring test context to a storage medium so that for tests\r
27that require exiting the active process and then resuming state can be maintained. This is critical\r
28in supporting a system reboot in the middle of a test run.\r
29\r
30### UnitTestResultReportLib\r
31\r
32Library provides function to run at the end of a framework test run and handles formatting the report.\r
33This is a common customization point and allows the unit test framework to fit its output reports into\r
34other test infrastructure. In this package a simple library instances has been supplied to output test\r
35results to the console as plain text.\r
36\r
37## Samples\r
38\r
39There is a sample unit test provided as both an example of how to write a unit test and leverage\r
40many of the features of the framework. This sample can be found in the `Test/UnitTest/Sample/SampleUnitTest`\r
41directory.\r
42\r
43The sample is provided in PEI, SMM, DXE, and UEFI App flavors. It also has a flavor for the HOST_APPLICATION\r
44build type, which can be run on a host system without needing a target.\r
45\r
46## Usage\r
47\r
48This section is built a lot like a "Getting Started". We'll go through some of the components that are needed\r
49when constructing a unit test and some of the decisions that are made by the test writer. We'll also describe\r
50how to check for expected conditions in test cases and a bit of the logging characteristics.\r
51\r
52Most of these examples will refer to the SampleUnitTestUefiShell app found in this package.\r
53\r
54### Requirements - INF\r
55\r
56In our INF file, we'll need to bring in the `UnitTestLib` library. Conveniently, the interface\r
57header for the `UnitTestLib` is located in `MdePkg`, so you shouldn't need to depend on any other\r
58packages. As long as your DSC file knows where to find the lib implementation that you want to use,\r
59you should be good to go.\r
60\r
4403bbd7 61See this example in 'SampleUnitTestUefiShell.inf'...\r
0f7fb5c5
MK
62\r
63```\r
64[Packages]\r
65 MdePkg/MdePkg.dec\r
66\r
67[LibraryClasses]\r
68 UefiApplicationEntryPoint\r
69 BaseLib\r
70 DebugLib\r
71 UnitTestLib\r
72 PrintLib\r
73```\r
74\r
4403bbd7
BB
75Also, if you want you test to automatically be picked up by the Test Runner plugin, you will need\r
76to make sure that the module `BASE_NAME` contains the word `Test`...\r
77\r
78```\r
79[Defines]\r
80 BASE_NAME = SampleUnitTestUefiShell\r
81```\r
82\r
0f7fb5c5
MK
83### Requirements - Code\r
84\r
85Not to state the obvious, but let's make sure we have the following include before getting too far along...\r
86\r
87```c\r
88#include <Library/UnitTestLib.h>\r
89```\r
90\r
91Now that we've got that squared away, let's look at our 'Main()'' routine (or DriverEntryPoint() or whatever).\r
92\r
93### Configuring the Framework\r
94\r
95Everything in the UnitTestPkg framework is built around an object called -- conveniently -- the Framework.\r
96This Framework object will contain all the information about our test, the test suites and test cases associated\r
97with it, the current location within the test pass, and any results that have been recorded so far.\r
98\r
99To get started with a test, we must first create a Framework instance. The function for this is\r
100`InitUnitTestFramework`. It takes in `CHAR8` strings for the long name, short name, and test version.\r
101The long name and version strings are just for user presentation and relatively flexible. The short name\r
102will be used to name any cache files and/or test results, so should be a name that makes sense in that context.\r
103These strings are copied internally to the Framework, so using stack-allocated or literal strings is fine.\r
104\r
105In the 'SampleUnitTestUefiShell' app, the module name is used as the short name, so the init looks like this.\r
106\r
107```c\r
108DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION ));\r
109\r
110//\r
111// Start setting up the test framework for running the tests.\r
112//\r
113Status = InitUnitTestFramework( &Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION );\r
114```\r
115\r
116The `&Framework` returned here is the handle to the Framework. If it's successfully returned, we can start adding\r
117test suites and test cases.\r
118\r
119Test suites exist purely to help organize test cases and to differentiate the results in reports. If you're writing\r
120a small unit test, you can conceivably put all test cases into a single suite. However, if you end up with 20+ test\r
121cases, it may be beneficial to organize them according to purpose. You _must_ have at least one test suite, even if\r
122it's just a catch-all. The function to create a test suite is `CreateUnitTestSuite`. It takes in a handle to\r
123the Framework object, a `CHAR8` string for the suite title and package name, and optional function pointers for\r
124a setup function and a teardown function.\r
125\r
126The suite title is for user presentation. The package name is for xUnit type reporting and uses a '.'-separated\r
127hierarchical format (see 'SampleUnitTestApp' for example). If provided, the setup and teardown functions will be\r
128called once at the start of the suite (before _any_ tests have run) and once at the end of the suite (after _all_\r
129tests have run), respectively. If either or both of these are unneeded, pass `NULL`. The function prototypes are\r
130`UNIT_TEST_SUITE_SETUP` and `UNIT_TEST_SUITE_TEARDOWN`.\r
131\r
132Looking at 'SampleUnitTestUefiShell' app, you can see that the first test suite is created as below...\r
133\r
134```c\r
135//\r
136// Populate the SimpleMathTests Unit Test Suite.\r
137//\r
138Status = CreateUnitTestSuite( &SimpleMathTests, Fw, "Simple Math Tests", "Sample.Math", NULL, NULL );\r
139```\r
140\r
141This test suite has no setup or teardown functions. The `&SimpleMathTests` returned here is a handle to the suite and\r
142will be used when adding test cases.\r
143\r
144Great! Now we've finished some of the cruft, red tape, and busy work. We're ready to add some tests. Adding a test\r
145to a test suite is accomplished with the -- you guessed it -- `AddTestCase` function. It takes in the suite handle;\r
146a `CHAR8` string for the description and class name; a function pointer for the test case itself; additional, optional\r
147function pointers for prerequisite check and cleanup routines; and and optional pointer to a context structure.\r
148\r
149Okay, that's a lot. Let's take it one piece at a time. The description and class name strings are very similar in\r
150usage to the suite title and package name strings in the test suites. The former is for user presentation and the\r
151latter is for xUnit parsing. The test case function pointer is what is actually executed as the "test" and the\r
152prototype should be `UNIT_TEST_FUNCTION`. The last three parameters require a little bit more explaining.\r
153\r
154The prerequisite check function has a prototype of `UNIT_TEST_PREREQUISITE` and -- if provided -- will be called\r
155immediately before the test case. If this function returns any error, the test case will not be run and will be\r
156recorded as `UNIT_TEST_ERROR_PREREQUISITE_NOT_MET`. The cleanup function (prototype `UNIT_TEST_CLEANUP`) will be called\r
157immediately after the test case to provide an opportunity to reset any global state that may have been changed in the\r
158test case. In the event of a prerequisite failure, the cleanup function will also be skipped. If either of these\r
159functions is not needed, pass `NULL`.\r
160\r
161The context pointer is entirely case-specific. It will be passed to the test case upon execution. One of the purposes\r
162of the context pointer is to allow test case reuse with different input data. (Another use is for testing that wraps\r
163around a system reboot, but that's beyond the scope of this guide.) The test case must know how to interpret the context\r
164pointer, so it could be a simple value, or it could be a complex structure. If unneeded, pass `NULL`.\r
165\r
166In 'SampleUnitTestUefiShell' app, the first test case is added using the code below...\r
167\r
168```c\r
169AddTestCase( SimpleMathTests, "Adding 1 to 1 should produce 2", "Addition", OnePlusOneShouldEqualTwo, NULL, NULL, NULL );\r
170```\r
171\r
172This test case calls the function `OnePlusOneShouldEqualTwo` and has no prerequisite, cleanup, or context.\r
173\r
174Once all the suites and cases are added, it's time to run the Framework.\r
175\r
176```c\r
177//\r
178// Execute the tests.\r
179//\r
180Status = RunAllTestSuites( Framework );\r
181```\r
182\r
183### A Simple Test Case\r
184\r
185We'll take a look at the below test case from 'SampleUnitTestApp'...\r
186\r
187```c\r
188UNIT_TEST_STATUS\r
189EFIAPI\r
190OnePlusOneShouldEqualTwo (\r
191 IN UNIT_TEST_FRAMEWORK_HANDLE Framework,\r
192 IN UNIT_TEST_CONTEXT Context\r
193 )\r
194{\r
195 UINTN A, B, C;\r
196\r
197 A = 1;\r
198 B = 1;\r
199 C = A + B;\r
200\r
201 UT_ASSERT_EQUAL(C, 2);\r
202 return UNIT_TEST_PASSED;\r
203} // OnePlusOneShouldEqualTwo()\r
204```\r
205\r
206The prototype for this function matches the `UNIT_TEST_FUNCTION` prototype. It takes in a handle to the Framework\r
207itself and the context pointer. The context pointer could be cast and interpreted as anything within this test case,\r
208which is why it's important to configure contexts carefully. The test case returns a value of `UNIT_TEST_STATUS`, which\r
209will be recorded in the Framework and reported at the end of all suites.\r
210\r
211In this test case, the `UT_ASSERT_EQUAL` assertion is being used to establish that the business logic has functioned\r
212correctly. There are several assertion macros, and you are encouraged to use one that matches as closely to your\r
213intended test criterium as possible, because the logging is specific to the macro and more specific macros have more\r
214detailed logs. When in doubt, there are always `UT_ASSERT_TRUE` and `UT_ASSERT_FALSE`. Assertion macros that fail their\r
215test criterium will immediately return from the test case with `UNIT_TEST_ERROR_TEST_FAILED` and log an error string.\r
216_Note_ that this early return can have implications for memory leakage.\r
217\r
218At the end, if all test criteria pass, you should return `UNIT_TEST_PASSED`.\r
219\r
220### More Complex Cases\r
221\r
222To write more advanced tests, first take a look at all the Assertion and Logging macros provided in the framework.\r
223\r
224Beyond that, if you're writing host-based tests and want to take a dependency on the UnitTestFrameworkPkg, you can\r
225leverage the `cmocka.h` interface and write tests with all the features of the Cmocka framework.\r
226\r
227Documentation for Cmocka can be found here:\r
228https://api.cmocka.org/\r
229\r
230## Development\r
231\r
4698f544
BB
232### Iterating on a Single Test\r
233\r
4403bbd7
BB
234When using the EDK2 Pytools for CI testing, the host-based unit tests will be built and run on any build that includes\r
235the `NOOPT` build target.\r
0f7fb5c5 236\r
4403bbd7
BB
237If you are trying to iterate on a single test, a convenient pattern is to build only that test module. For example,\r
238the following command will build only the SafeIntLib host-based test from the MdePkg...\r
0f7fb5c5
MK
239\r
240```bash\r
241stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2017 -p MdePkg -t NOOPT BUILDMODULE=MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLib.inf\r
242```\r
243\r
4698f544
BB
244### Hooking BaseLib\r
245\r
246Most unit test mocking can be performed by the functions provided in the UnitTestFramework libraries, but since\r
247BaseLib is consumed by the Framework itself, it requires different techniques to substitute parts of the\r
248functionality.\r
249\r
250To solve some of this, the UnitTestFramework consumes a special implementation of BaseLib for host-based tests.\r
251This implementation contains a [hook table](https://github.com/tianocore/edk2/blob/e188ecc8b4aed8fdd26b731d43883861f5e5e7b4/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h#L507)\r
252that can be used to substitute test functionality for any of the BaseLib functions. By default, this implementation\r
253will use the underlying BaseLib implementation, so the unit test writer only has to supply minimal code to test a\r
254particular case.\r
255\r
256### Debugging the Framework Itself\r
257\r
258While most of the tests that are produced by the UnitTestFramework are easy to step through in a debugger, the Framework\r
259itself consumes code (mostly Cmocka) that sets its own build flags. These flags cause parts of the Framework to not\r
260export symbols and captures exceptions, and as such are harder to debug. We have provided a Stuart parameter to force\r
261symbolic debugging to be enabled.\r
262\r
263You can run a build by adding the `BLD_*_UNIT_TESTING_DEBUG=TRUE` parameter to enable this build option.\r
264\r
265```bash\r
266stuart_ci_build -c .pytool/CISettings.py TOOL_CHAIN_TAG=VS2019 -p MdePkg -t NOOPT BLD_*_UNIT_TESTING_DEBUG=TRUE\r
267```\r
268\r
269## Building and Running Host-Based Tests\r
270\r
271The EDK2 CI infrastructure provides a convenient way to run all host-based tests -- in the the entire tree or just\r
272selected packages -- and aggregate all the the reports, including highlighting any failures. This functionality is\r
273provided through the Stuart build system (published by EDK2-PyTools) and the `NOOPT` build target.\r
274\r
275### Building Locally\r
276\r
277First, to make sure you're working with the latest PyTools, run the following command:\r
278\r
279```bash\r
280# Would recommend to run this in a Python venv, but that's out of scope for this doc.\r
281python -m pip install --upgrade -r ./pip-requirements.txt\r
282```\r
283\r
284After that, the following commands will set up the build and run the host-based tests.\r
285\r
286```bash\r
287# Setup repo for building\r
288# stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.>\r
289stuart_setup -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019\r
290\r
291# Update all binary dependencies\r
292# stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.>\r
293stuart_update -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019\r
294\r
295# Build and run the tests\r
296# stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=<GCC5, VS2019, etc.> -t NOOPT [-p <Package Name>]\r
297stuart_ci_build -c ./.pytool/CISettings.py TOOL_CHAIN_TAG=VS2019 -t NOOPT -p MdePkg\r
298```\r
299\r
300### Evaluating the Results\r
301\r
302In your immediate output, any build failures will be highlighted. You can see these below as "WARNING" and "ERROR" messages.\r
303\r
304```text\r
305(edk_env) PS C:\_uefi\edk2> stuart_ci_build -c .\.pytool\CISettings.py TOOL_CHAIN_TAG=VS2019 -t NOOPT -p MdePkg\r
306\r
307SECTION - Init SDE\r
308SECTION - Loading Plugins\r
309SECTION - Start Invocable Tool\r
310SECTION - Getting Environment\r
311SECTION - Loading plugins\r
312SECTION - Building MdePkg Package\r
313PROGRESS - --Running MdePkg: Host Unit Test Compiler Plugin NOOPT --\r
314WARNING - Allowing Override for key TARGET_ARCH\r
315PROGRESS - Start time: 2020-07-27 17:18:08.521672\r
316PROGRESS - Setting up the Environment\r
317PROGRESS - Running Pre Build\r
318PROGRESS - Running Build NOOPT\r
319PROGRESS - Running Post Build\r
320SECTION - Run Host based Unit Tests\r
321SUBSECTION - Testing for architecture: X64\r
322WARNING - TestBaseSafeIntLibHost.exe Test Failed\r
323WARNING - Test SafeInt8ToUint8 - UT_ASSERT_EQUAL(0x5b:5b, Result:5c)\r
324c:\_uefi\edk2\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!\r
325ERROR - Plugin Failed: Host-Based Unit Test Runner returned 1\r
326CRITICAL - Post Build failed\r
327PROGRESS - End time: 2020-07-27 17:18:19.792313 Total time Elapsed: 0:00:11\r
328ERROR - --->Test Failed: Host Unit Test Compiler Plugin NOOPT returned 1\r
329ERROR - Overall Build Status: Error\r
330PROGRESS - There were 1 failures out of 1 attempts\r
331SECTION - Summary\r
332ERROR - Error\r
333\r
334(edk_env) PS C:\_uefi\edk2>\r
335```\r
336\r
337If a test fails, you can run it manually to get more details...\r
338\r
339```text\r
340(edk_env) PS C:\_uefi\edk2> .\Build\MdePkg\HostTest\NOOPT_VS2019\X64\TestBaseSafeIntLibHost.exe\r
341\r
342Int Safe Lib Unit Test Application v0.1\r
343---------------------------------------------------------\r
344------------ RUNNING ALL TEST SUITES --------------\r
345---------------------------------------------------------\r
346---------------------------------------------------------\r
347RUNNING TEST SUITE: Int Safe Conversions Test Suite\r
348---------------------------------------------------------\r
349[==========] Running 71 test(s).\r
350[ RUN ] Test SafeInt8ToUint8\r
351[ ERROR ] --- UT_ASSERT_EQUAL(0x5b:5b, Result:5c)\r
352[ LINE ] --- c:\_uefi\edk2\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!\r
353[ FAILED ] Test SafeInt8ToUint8\r
354[ RUN ] Test SafeInt8ToUint16\r
355[ OK ] Test SafeInt8ToUint16\r
356[ RUN ] Test SafeInt8ToUint32\r
357[ OK ] Test SafeInt8ToUint32\r
358[ RUN ] Test SafeInt8ToUintn\r
359[ OK ] Test SafeInt8ToUintn\r
360...\r
361```\r
362\r
363You can also, if you are so inclined, read the output from the exact instance of the test that was run during\r
364`stuart_ci_build`. The ouput file can be found on a path that looks like:\r
365\r
366`Build/<Package>/HostTest/<Arch>/<TestName>.<TestSuiteName>.<Arch>.result.xml`\r
367\r
368A sample of this output looks like:\r
369\r
370```xml\r
371<!--\r
372 Excerpt taken from:\r
373 Build\MdePkg\HostTest\NOOPT_VS2019\X64\TestBaseSafeIntLibHost.exe.Int Safe Conversions Test Suite.X64.result.xml\r
374 -->\r
375<?xml version="1.0" encoding="UTF-8" ?>\r
376<testsuites>\r
377 <testsuite name="Int Safe Conversions Test Suite" time="0.000" tests="71" failures="1" errors="0" skipped="0" >\r
378 <testcase name="Test SafeInt8ToUint8" time="0.000" >\r
379 <failure><![CDATA[UT_ASSERT_EQUAL(0x5c:5c, Result:5b)\r
380c:\_uefi\MdePkg\Test\UnitTest\Library\BaseSafeIntLib\TestBaseSafeIntLib.c:35: error: Failure!]]></failure>\r
381 </testcase>\r
382 <testcase name="Test SafeInt8ToUint16" time="0.000" >\r
383 </testcase>\r
384 <testcase name="Test SafeInt8ToUint32" time="0.000" >\r
385 </testcase>\r
386 <testcase name="Test SafeInt8ToUintn" time="0.000" >\r
387 </testcase>\r
388```\r
389\r
390### XML Reporting Mode\r
391\r
392Since these applications are built using the CMocka framework, they can also use the following env variables to output\r
393in a structured XML rather than text:\r
394\r
395```text\r
396CMOCKA_MESSAGE_OUTPUT=xml\r
397CMOCKA_XML_FILE=<absolute or relative path to output file>\r
398```\r
399\r
400This mode is used by the test running plugin to aggregate the results for CI test status reporting in the web view.\r
401\r
402### Important Note\r
403\r
404This works on both Windows and Linux, but is currently limited to x64 architectures. Working on getting others, but we\r
405also welcome contributions.\r
406\r
0f7fb5c5
MK
407## Known Limitations\r
408\r
409### PEI, DXE, SMM\r
410\r
411While sample tests have been provided for these execution environments, only cursory build validation\r
412has been performed. Care has been taken while designing the frameworks to allow for execution during\r
413boot phases, but only UEFI Shell and host-based tests have been thoroughly evaluated. Full support for\r
414PEI, DXE, and SMM is forthcoming, but should be considered beta/staging for now.\r
415\r
416### Host-Based Support vs Other Tests\r
417\r
418The host-based test framework is powered internally by the Cmocka framework. As such, it has abilities\r
419that the target-based tests don't (yet). It would be awesome if this meant that it was a super set of\r
420the target-based tests, and it worked just like the target-based tests but with more features. Unfortunately,\r
421this is not the case. While care has been taken to keep them as close a possible, there are a few known\r
422inconsistencies that we're still ironing out. For example, the logging messages in the target-based tests\r
423are cached internally and associated with the running test case. They can be saved later as part of the\r
424reporting lib. This isn't currently possible with host-based. Only the assertion failures are logged.\r
425\r
426We will continue trying to make these as similar as possible.\r
427\r
4403bbd7
BB
428## Unit Test Location/Layout Rules\r
429\r
430Code/Test | Location\r
431--------- | --------\r
432Host-Based Unit Tests for a Library/Protocol/PPI/GUID Interface | If what's being tested is an interface (e.g. a library with a public header file, like DebugLib), the test should be scoped to the parent package.<br/>Example: `MdePkg/Test/UnitTest/[Library/Protocol/Ppi/Guid]/`<br/><br/>A real-world example of this is the BaseSafeIntLib test in MdePkg.<br/>`MdePkg/Test/UnitTest/Library/BaseSafeIntLib/TestBaseSafeIntLibHost.inf`\r
433Host-Based Unit Tests for a Library/Driver (PEI/DXE/SMM) implementation | If what's being tested is a specific implementation (e.g. BaseDebugLibSerialPort for DebugLib), the test should be scoped to the implementation directory itself, in a UnitTest subdirectory.<br/><br/>Module Example: `MdeModulePkg/Universal/EsrtFmpDxe/UnitTest/`<br/>Library Example: `MdePkg/Library/BaseMemoryLib/UnitTest/`\r
434Host-Based Tests for a Functionality or Feature | If you're writing a functional test that operates at the module level (i.e. if it's more than a single file or library), the test should be located in the package-level Tests directory under the HostFuncTest subdirectory.<br/>For example, if you were writing a test for the entire FMP Device Framework, you might put your test in:<br/>`FmpDevicePkg/Test/HostFuncTest/FmpDeviceFramework`<br/><br/>If the feature spans multiple packages, it's location should be determined by the package owners related to the feature.\r
435Non-Host-Based (PEI/DXE/SMM/Shell) Tests for a Functionality or Feature | Similar to Host-Based, if the feature is in one package, should be located in the `*Pkg/Test/[Shell/Dxe/Smm/Pei]Test` directory.<br/><br/>If the feature spans multiple packages, it's location should be determined by the package owners related to the feature.<br/><br/>USAGE EXAMPLES<br/>PEI Example: MP_SERVICE_PPI. Or check MTRR configuration in a notification function.<br/> SMM Example: a test in a protocol callback function. (It is different with the solution that SmmAgent+ShellApp)<br/>DXE Example: a test in a UEFI event call back to check SPI/SMRAM status. <br/> Shell Example: the SMM handler audit test has a shell-based app that interacts with an SMM handler to get information. The SMM paging audit test gathers information about both DXE and SMM. And the SMM paging functional test actually forces errors into SMM via a DXE driver.\r
436\r
437### Example Directory Tree\r
438\r
439```text\r
440<PackageName>Pkg/\r
441 ComponentY/\r
442 ComponentY.inf\r
443 ComponentY.c\r
444 UnitTest/\r
445 ComponentYHostUnitTest.inf # Host-Based Test for Driver Module\r
446 ComponentYUnitTest.c\r
447\r
448 Library/\r
449 GeneralPurposeLibBase/\r
450 ...\r
451\r
452 GeneralPurposeLibSerial/\r
453 ...\r
454\r
455 SpecificLibDxe/\r
456 SpecificLibDxe.c\r
457 SpecificLibDxe.inf\r
458 UnitTest/ # Host-Based Test for Specific Library Implementation\r
459 SpecificLibDxeHostUnitTest.c\r
460 SpecificLibDxeHostUnitTest.inf\r
461 Test/\r
462 <Package>HostTest.dsc # Host-Based Test Apps\r
463 UnitTest/\r
464 InterfaceX\r
465 InterfaceXHostUnitTest.inf # Host-Based App (should be in Test/<Package>HostTest.dsc)\r
466 InterfaceXPeiUnitTest.inf # PEIM Target-Based Test (if applicable)\r
467 InterfaceXDxeUnitTest.inf # DXE Target-Based Test (if applicable)\r
468 InterfaceXSmmUnitTest.inf # SMM Target-Based Test (if applicable)\r
469 InterfaceXShellUnitTest.inf # Shell App Target-Based Test (if applicable)\r
470 InterfaceXUnitTest.c # Test Logic\r
471\r
472 GeneralPurposeLib/ # Host-Based Test for any implementation of GeneralPurposeLib\r
473 GeneralPurposeLibTest.c\r
474 GeneralPurposeLibHostUnitTest.inf\r
475\r
476 <Package>Pkg.dsc # Standard Modules and any Target-Based Test Apps (including in Test/)\r
477\r
478```\r
479\r
480### Future Locations in Consideration\r
481\r
482We don't know if these types will exist or be applicable yet, but if you write a support library or module that matches the following, please make sure they live in the correct place.\r
483\r
484Code/Test | Location\r
485--------- | --------\r
486Host-Based Library Implementations | Host-Based Implementations of common libraries (eg. MemoryAllocationLibHost) should live in the same package that declares the library interface in its .DEC file in the `*Pkg/HostLibrary` directory. Should have 'Host' in the name.\r
487Host-Based Mocks and Stubs | Mock and Stub libraries should live in the `UefiTestFrameworkPkg/StubLibrary` with either 'Mock' or 'Stub' in the library name.\r
488\r
489### If still in doubt...\r
490\r
491Hop on GitHub and ask @corthon, @mdkinney, or @spbrogan. ;)\r
492\r
0f7fb5c5
MK
493## Copyright\r
494\r
495Copyright (c) Microsoft Corporation.\r
496SPDX-License-Identifier: BSD-2-Clause-Patent\r