TianoCore EDK2 master
Loading...
Searching...
No Matches
TestDevicePathStringConversions.c
Go to the documentation of this file.
1
9#include "TestDevicePathLib.h"
10
11typedef struct {
13 CONST CHAR16 *DevPathString;
15
17{
18 // PCI device path - root port (0x2:0x0)
19 {
22 {
23 (UINT8)(sizeof (PCI_DEVICE_PATH)),
24 (UINT8)((sizeof (PCI_DEVICE_PATH)) >> 8)
25 }
26 },
27 0x2,
28 0x0
29};
30
31GLOBAL_REMOVE_IF_UNREFERENCED ACPI_HID_DEVICE_PATH mAcpiPciRootHidDevicePathNode =
32{
33 // ACPI PCI root - PciRoot(0x0)
34 {
36 ACPI_DP,
37 {
38 (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
39 (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
40 }
41 },
42 EISA_PNP_ID (0x0A03),
43 0
44};
45
46GLOBAL_REMOVE_IF_UNREFERENCED ACPI_HID_DEVICE_PATH mAcpiNonPciRootHidDevicePathNode =
47{
48 // Random ACPI device - ACPI(PNPB0C0, 1)
49 {
51 ACPI_DP,
52 {
53 (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
54 (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
55 }
56 },
57 EISA_PNP_ID (0xB0C0),
58 1
59};
60
61#define HID_STR_SIZE 8
62#define CID_STR_SIZE 8
63#define UID_STR_SIZE 8
64
65typedef struct {
67 CHAR8 HidStr[HID_STR_SIZE];
68 CHAR8 CidStr[CID_STR_SIZE];
69 CHAR8 UidStr[UID_STR_SIZE];
71
73{
74 // ACPI Extended HID PciRoot device node
75 {
76 {
79 {
80 (UINT8)(sizeof (ACPI_EXTENDED_HID_DEVICE_PATH_FULL)),
81 (UINT8)((sizeof (ACPI_EXTENDED_HID_DEVICE_PATH_FULL)) >> 8)
82 }
83 },
84 0,
85 0,
86 0,
87 },
88 { 'P', 'N', 'P', 'B', '0', 'C', '0', '\0' }, // HIDSTR
89 { 'P', 'N', 'P', '0', '0', '0', '1', '\0' }, // CIDSTR
90 { 'U', 'I', 'D', '0', '0', '0', '0', '\0' } // UIDSTR
91};
92
93typedef struct {
95 CHAR8 HidStr[HID_STR_SIZE];
97
99{
100 {
101 {
104 {
106 (UINT8)((sizeof (ACPI_EXTENDED_HID_DEVICE_PATH_PARTIAL)) >> 8)
107 }
108 },
109 0,
110 2,
111 0,
112 },
113 { 'P', 'N', 'P', 'B', '0', '\0', '\0', '\0' }, // HIDSTR
114};
115
116typedef struct {
118 CHAR8 UidStr[UID_STR_SIZE];
120
121GLOBAL_REMOVE_IF_UNREFERENCED ACPI_EXPANDED_DEVICE_PATH mAcpiExpandedDevicePathUidOnly =
122{
123 {
124 {
127 {
128 (UINT8)(sizeof (ACPI_EXPANDED_DEVICE_PATH)),
129 (UINT8)((sizeof (ACPI_EXPANDED_DEVICE_PATH)) >> 8)
130 }
131 },
132 EISA_PNP_ID (0xAAAA),
133 0,
134 0,
135 },
136 { '\0', 'U', 'I', 'D', '0', '0', '\0', '\0' } // UIDSTR
137};
138
139GLOBAL_REMOVE_IF_UNREFERENCED ACPI_EXPANDED_DEVICE_PATH mAcpiExpandedDevicePathUidOnlyWithCid =
140{
141 {
142 {
145 {
146 (UINT8)(sizeof (ACPI_EXPANDED_DEVICE_PATH)),
147 (UINT8)((sizeof (ACPI_EXPANDED_DEVICE_PATH)) >> 8)
148 }
149 },
150 EISA_PNP_ID (0xAAAA),
151 0,
152 EISA_PNP_ID (0xAADD),
153 },
154 { '\0', 'U', 'I', 'D', '0', '0', '\0', '\0' } // UIDSTR
155};
156
158 {
159 (EFI_DEVICE_PATH_PROTOCOL *)&mPciDevicePathNode,
160 L"Pci(0x0,0x2)"
161 },
162 {
163 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiPciRootHidDevicePathNode,
164 L"PciRoot(0x0)"
165 },
166 {
167 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiNonPciRootHidDevicePathNode,
168 L"Acpi(PNPB0C0,0x1)"
169 },
170 {
171 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiExtendedDevicePathFull,
172 L"AcpiEx(@@@0000,@@@0000,0x0,PNPB0C0,UID0000,PNP0001)"
173 },
174 {
175 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiExtendedDevicePathPartial,
176 L"AcpiEx(@@@0000,@@@0000,0x2,PNPB0,,)"
177 },
178 {
179 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiExpandedDevicePathUidOnly,
180 L"AcpiExp(PNPAAAA,0,UID00)"
181 },
182 {
183 (EFI_DEVICE_PATH_PROTOCOL *)&mAcpiExpandedDevicePathUidOnlyWithCid,
184 L"AcpiExp(PNPAAAA,PNPAADD,UID00)"
185 }
186};
187
188typedef struct {
189 ACPI_HID_DEVICE_PATH AcpiPath;
190 PCI_DEVICE_PATH PciPathRootPort;
191 PCI_DEVICE_PATH PciPathEndPoint;
192 USB_DEVICE_PATH UsbPath;
195
197 { // ACPI device path with root bridge EISA_PNP_ID
198 {
200 ACPI_DP,
201 {
202 (UINT8)(sizeof (ACPI_HID_DEVICE_PATH)),
203 (UINT8)((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)
204 }
205 },
206 EISA_PNP_ID (0x0A03),
207 0
208 },
209 { // PCI device path - root port (0x2:0x0)
210 {
212 HW_PCI_DP,
213 {
214 (UINT8)(sizeof (PCI_DEVICE_PATH)),
215 (UINT8)((sizeof (PCI_DEVICE_PATH)) >> 8)
216 }
217 },
218 0x2,
219 0x0
220 },
221 { // PCI device path - endpoint (0x0:0x0)
222 {
224 HW_PCI_DP,
225 {
226 (UINT8)(sizeof (PCI_DEVICE_PATH)),
227 (UINT8)((sizeof (PCI_DEVICE_PATH)) >> 8)
228 }
229 },
230 0x0,
231 0x0
232 },
233 { // USB interface
234 {
237 {
238 (UINT8)(sizeof (USB_DEVICE_PATH)),
239 (UINT8)((sizeof (USB_CLASS_DEVICE_PATH)) >> 8)
240 }
241 },
242 0,
243 2
244 },
245 {
246 END_DEVICE_PATH_TYPE,
247 END_ENTIRE_DEVICE_PATH_SUBTYPE,
248 {
249 (UINT8)(sizeof (EFI_DEVICE_PATH_PROTOCOL)),
250 (UINT8)((sizeof (EFI_DEVICE_PATH_PROTOCOL)) >> 8)
251 }
252 }
253};
254
256 {
257 (EFI_DEVICE_PATH_PROTOCOL *)&mConversionsDevicePath,
258 L"PciRoot(0x0)/Pci(0x0,0x2)/Pci(0x0,0x0)/USB(0x0,0x2)"
259 }
260};
261
263EFIAPI
264TestConvertDevicePathToText (
265 IN UNIT_TEST_CONTEXT Context
266 )
267{
268 CHAR16 *DevPathString;
270
271 TestContext = (DEVICE_PATH_CONVERSIONS_TEST_CONTEXT *)Context;
272
273 DevPathString = ConvertDevicePathToText (TestContext->DevPath, FALSE, FALSE);
274 UT_ASSERT_EQUAL (StrLen (DevPathString), StrLen (TestContext->DevPathString));
275 UT_ASSERT_MEM_EQUAL (DevPathString, TestContext->DevPathString, StrLen (TestContext->DevPathString));
276 FreePool (DevPathString);
277
278 return UNIT_TEST_PASSED;
279}
280
282EFIAPI
283TestConvertTextToDevicePath (
284 IN UNIT_TEST_CONTEXT Context
285 )
286{
287 EFI_DEVICE_PATH_PROTOCOL *ConvertedDevPath;
289
290 TestContext = (DEVICE_PATH_CONVERSIONS_TEST_CONTEXT *)Context;
291
292 ConvertedDevPath = ConvertTextToDevicePath (TestContext->DevPathString);
293 UT_ASSERT_EQUAL (GetDevicePathSize (ConvertedDevPath), GetDevicePathSize (TestContext->DevPath));
294 UT_ASSERT_MEM_EQUAL (ConvertedDevPath, TestContext->DevPath, GetDevicePathSize (TestContext->DevPath));
295 FreePool (ConvertedDevPath);
296
297 return UNIT_TEST_PASSED;
298}
299
301EFIAPI
302TestConvertDeviceNodeToText (
303 IN UNIT_TEST_CONTEXT Context
304 )
305{
306 CHAR16 *DevPathNodeString;
308
309 TestContext = (DEVICE_PATH_CONVERSIONS_TEST_CONTEXT *)Context;
310
311 DevPathNodeString = ConvertDeviceNodeToText (TestContext->DevPath, FALSE, FALSE);
312 UT_ASSERT_EQUAL (StrLen (DevPathNodeString), StrLen (TestContext->DevPathString));
313 UT_ASSERT_MEM_EQUAL (DevPathNodeString, TestContext->DevPathString, StrLen (TestContext->DevPathString));
314 FreePool (DevPathNodeString);
315
316 return UNIT_TEST_PASSED;
317}
318
320EFIAPI
321TestConvertTextToDeviceNode (
322 IN UNIT_TEST_CONTEXT Context
323 )
324{
327
328 TestContext = (DEVICE_PATH_CONVERSIONS_TEST_CONTEXT *)Context;
329
330 DevPath = ConvertTextToDeviceNode (TestContext->DevPathString);
331 UT_ASSERT_EQUAL (DevicePathNodeLength (DevPath), DevicePathNodeLength (TestContext->DevPath));
332 UT_ASSERT_MEM_EQUAL (DevPath, TestContext->DevPath, DevicePathNodeLength (TestContext->DevPath));
333 FreePool (DevPath);
334
335 return UNIT_TEST_PASSED;
336}
337
339CreateDevicePathStringConversionsTestSuite (
340 IN UNIT_TEST_FRAMEWORK_HANDLE Framework
341 )
342{
343 EFI_STATUS Status;
344 UNIT_TEST_SUITE_HANDLE DevicePathTextConversionSuite = NULL;
345 UINTN Index;
346
347 Status = CreateUnitTestSuite (&DevicePathTextConversionSuite, Framework, "Device path text conversion operations test suite", "Common.DevicePath.TextConversions", NULL, NULL);
348 if (EFI_ERROR (Status)) {
349 DEBUG ((DEBUG_ERROR, "Failed to create device path text conversions test suite\n"));
350 return Status;
351 }
352
353 for (Index = 0; Index < ARRAY_SIZE (mDevPathNodeToFromTextContext); Index++) {
354 AddTestCase (DevicePathTextConversionSuite, "Test ConvertDeviceNodeToText", "TestConvertDeviceNodeToText", TestConvertDeviceNodeToText, NULL, NULL, &mDevPathNodeToFromTextContext[Index]);
355 }
356
357 for (Index = 0; Index < ARRAY_SIZE (mDevPathNodeToFromTextContext); Index++) {
358 AddTestCase (DevicePathTextConversionSuite, "Test ConvertTextToDeviceNode", "TestConvertTextToDeviceNode", TestConvertTextToDeviceNode, NULL, NULL, &mDevPathNodeToFromTextContext[Index]);
359 }
360
361 for (Index = 0; Index < ARRAY_SIZE (mDevPathToFromTextContext); Index++) {
362 AddTestCase (DevicePathTextConversionSuite, "Test ConvertDevicePathToText", "TestConvertDevicePathToText", TestConvertDevicePathToText, NULL, NULL, &mDevPathToFromTextContext[Index]);
363 }
364
365 for (Index = 0; Index < ARRAY_SIZE (mDevPathToFromTextContext); Index++) {
366 AddTestCase (DevicePathTextConversionSuite, "Test ConvertTextToDevicePath", "TestConvertTextToDevicePath", TestConvertTextToDevicePath, NULL, NULL, &mDevPathToFromTextContext[Index]);
367 }
368
369 return EFI_SUCCESS;
370}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define ACPI_DEVICE_PATH
Definition: DevicePath.h:190
#define MSG_USB_DP
Definition: DevicePath.h:418
#define ACPI_DP
Definition: DevicePath.h:195
#define ACPI_EXTENDED_DP
Definition: DevicePath.h:217
#define HW_PCI_DP
Definition: DevicePath.h:73
#define MESSAGING_DEVICE_PATH
Definition: DevicePath.h:321
UINTN EFIAPI DevicePathNodeLength(IN CONST VOID *Node)
CHAR16 *EFIAPI ConvertDeviceNodeToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
UINTN EFIAPI GetDevicePathSize(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI ConvertTextToDevicePath(IN CONST CHAR16 *TextDevicePath)
EFI_DEVICE_PATH_PROTOCOL *EFIAPI ConvertTextToDeviceNode(IN CONST CHAR16 *TextDeviceNode)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define FALSE
Definition: Base.h:307
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
Definition: UnitTestLib.h:389
#define UT_ASSERT_EQUAL(ValueA, ValueB)
Definition: UnitTestLib.h:375
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
Definition: UnitTestLib.c:326
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
Definition: UnitTestLib.c:426
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16