dm: treewide: Use uclass_first_device_err when accessing one device
[platform/kernel/u-boot.git] / test / dm / acpi.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Tests for ACPI table generation
4  *
5  * Copyright 2019 Google LLC
6  * Written by Simon Glass <sjg@chromium.org>
7  */
8
9 #include <common.h>
10 #include <console.h>
11 #include <dm.h>
12 #include <malloc.h>
13 #include <mapmem.h>
14 #include <timestamp.h>
15 #include <version.h>
16 #include <tables_csum.h>
17 #include <version.h>
18 #include <acpi/acpigen.h>
19 #include <acpi/acpi_device.h>
20 #include <acpi/acpi_table.h>
21 #include <asm/global_data.h>
22 #include <dm/acpi.h>
23 #include <dm/test.h>
24 #include <test/ut.h>
25 #include "acpi.h"
26
27 #define BUF_SIZE                4096
28
29 #define OEM_REVISION ((((U_BOOT_VERSION_NUM / 1000) % 10) << 28) | \
30                       (((U_BOOT_VERSION_NUM / 100) % 10) << 24) | \
31                       (((U_BOOT_VERSION_NUM / 10) % 10) << 20) | \
32                       ((U_BOOT_VERSION_NUM % 10) << 16) | \
33                       (((U_BOOT_VERSION_NUM_PATCH / 10) % 10) << 12) | \
34                       ((U_BOOT_VERSION_NUM_PATCH % 10) << 8) | \
35                       0x01)
36
37 /**
38  * struct testacpi_plat - Platform data for the test ACPI device
39  *
40  * @no_name: true to emit an empty ACPI name from testacpi_get_name()
41  * @return_error: true to return an error instead of a name
42  */
43 struct testacpi_plat {
44         bool return_error;
45         bool no_name;
46 };
47
48 /**
49  * setup_ctx_and_base_tables() - Set up context along with RSDP, RSDT and XSDT
50  *
51  * Set up the context with the given start position. Some basic tables are
52  * always needed, so set them up as well.
53  *
54  * @ctx: Context to set up
55  */
56 static int setup_ctx_and_base_tables(struct unit_test_state *uts,
57                                      struct acpi_ctx *ctx, ulong start)
58 {
59         struct acpi_writer *entry = ACPI_WRITER_GET(0base);
60
61         acpi_setup_ctx(ctx, start);
62
63         ctx->tab_start = ctx->current;
64         ut_assertok(acpi_write_one(ctx, entry));
65
66         return 0;
67 }
68
69 static int testacpi_write_tables(const struct udevice *dev,
70                                  struct acpi_ctx *ctx)
71 {
72         struct acpi_dmar *dmar;
73         int ret;
74
75         dmar = (struct acpi_dmar *)ctx->current;
76         acpi_create_dmar(dmar, DMAR_INTR_REMAP);
77         ctx->current += sizeof(struct acpi_dmar);
78         ret = acpi_add_table(ctx, dmar);
79         if (ret)
80                 return log_msg_ret("add", ret);
81
82         return 0;
83 }
84
85 static int testacpi_get_name(const struct udevice *dev, char *out_name)
86 {
87         struct testacpi_plat *plat = dev_get_plat(dev);
88
89         if (plat->return_error)
90                 return -EINVAL;
91         if (plat->no_name) {
92                 *out_name = '\0';
93                 return 0;
94         }
95         if (device_get_uclass_id(dev->parent) == UCLASS_TEST_ACPI)
96                 return acpi_copy_name(out_name, ACPI_TEST_CHILD_NAME);
97         else
98                 return acpi_copy_name(out_name, ACPI_TEST_DEV_NAME);
99 }
100
101 static int testacpi_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
102 {
103         const char *data;
104
105         data = dev_read_string(dev, "acpi-ssdt-test-data");
106         if (data) {
107                 while (*data)
108                         acpigen_emit_byte(ctx, *data++);
109         }
110
111         return 0;
112 }
113
114 static int testacpi_inject_dsdt(const struct udevice *dev, struct acpi_ctx *ctx)
115 {
116         const char *data;
117
118         data = dev_read_string(dev, "acpi-dsdt-test-data");
119         if (data) {
120                 while (*data)
121                         acpigen_emit_byte(ctx, *data++);
122         }
123
124         return 0;
125 }
126
127 struct acpi_ops testacpi_ops = {
128         .get_name       = testacpi_get_name,
129         .write_tables   = testacpi_write_tables,
130         .fill_ssdt      = testacpi_fill_ssdt,
131         .inject_dsdt    = testacpi_inject_dsdt,
132 };
133
134 static const struct udevice_id testacpi_ids[] = {
135         { .compatible = "denx,u-boot-acpi-test" },
136         { }
137 };
138
139 U_BOOT_DRIVER(testacpi_drv) = {
140         .name   = "testacpi_drv",
141         .of_match       = testacpi_ids,
142         .id     = UCLASS_TEST_ACPI,
143         .bind   = dm_scan_fdt_dev,
144         .plat_auto      = sizeof(struct testacpi_plat),
145         ACPI_OPS_PTR(&testacpi_ops)
146 };
147
148 UCLASS_DRIVER(testacpi) = {
149         .name           = "testacpi",
150         .id             = UCLASS_TEST_ACPI,
151 };
152
153 /* Test ACPI get_name() */
154 static int dm_test_acpi_get_name(struct unit_test_state *uts)
155 {
156         char name[ACPI_NAME_MAX];
157         struct udevice *dev, *dev2, *i2c, *spi, *timer, *sound;
158         struct udevice *pci, *root;
159
160         /* Test getting the name from the driver */
161         ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
162         ut_assertok(acpi_get_name(dev, name));
163         ut_asserteq_str(ACPI_TEST_DEV_NAME, name);
164
165         /* Test getting the name from the device tree */
166         ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
167                                               &dev2));
168         ut_assertok(acpi_get_name(dev2, name));
169         ut_asserteq_str("GHIJ", name);
170
171         /* Test getting the name from acpi_device_get_name() */
172         ut_assertok(uclass_first_device_err(UCLASS_I2C, &i2c));
173         ut_assertok(acpi_get_name(i2c, name));
174         ut_asserteq_str("I2C0", name);
175
176         ut_assertok(uclass_first_device_err(UCLASS_SPI, &spi));
177         ut_assertok(acpi_get_name(spi, name));
178         ut_asserteq_str("SPI0", name);
179
180         /* ACPI doesn't know about the timer */
181         ut_assertok(uclass_first_device_err(UCLASS_TIMER, &timer));
182         ut_asserteq(-ENOENT, acpi_get_name(timer, name));
183
184         /* May as well test the rest of the cases */
185         ut_assertok(uclass_first_device_err(UCLASS_SOUND, &sound));
186         ut_assertok(acpi_get_name(sound, name));
187         ut_asserteq_str("HDAS", name);
188
189         ut_assertok(uclass_first_device_err(UCLASS_PCI, &pci));
190         ut_assertok(acpi_get_name(pci, name));
191         ut_asserteq_str("PCI0", name);
192
193         ut_assertok(uclass_first_device_err(UCLASS_ROOT, &root));
194         ut_assertok(acpi_get_name(root, name));
195         ut_asserteq_str("\\_SB", name);
196
197         /* Note that we don't have tests for acpi_name_from_id() */
198
199         return 0;
200 }
201 DM_TEST(dm_test_acpi_get_name, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
202
203 /* Test acpi_get_table_revision() */
204 static int dm_test_acpi_get_table_revision(struct unit_test_state *uts)
205 {
206         ut_asserteq(1, acpi_get_table_revision(ACPITAB_MCFG));
207         ut_asserteq(2, acpi_get_table_revision(ACPITAB_RSDP));
208         ut_asserteq(4, acpi_get_table_revision(ACPITAB_TPM2));
209         ut_asserteq(-EINVAL, acpi_get_table_revision(ACPITAB_COUNT));
210
211         return 0;
212 }
213 DM_TEST(dm_test_acpi_get_table_revision,
214         UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
215
216 /* Test acpi_create_dmar() */
217 static int dm_test_acpi_create_dmar(struct unit_test_state *uts)
218 {
219         struct acpi_dmar dmar;
220         struct udevice *cpu;
221
222         ut_assertok(uclass_first_device_err(UCLASS_CPU, &cpu));
223         ut_assertnonnull(cpu);
224         ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP));
225         ut_asserteq(DMAR_INTR_REMAP, dmar.flags);
226         ut_asserteq(32 - 1, dmar.host_address_width);
227
228         return 0;
229 }
230 DM_TEST(dm_test_acpi_create_dmar, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
231
232 /* Test acpi_fill_header() */
233 static int dm_test_acpi_fill_header(struct unit_test_state *uts)
234 {
235         struct acpi_table_header hdr;
236
237         /* Make sure these 5 fields are not changed */
238         hdr.length = 0x11;
239         hdr.revision = 0x22;
240         hdr.checksum = 0x33;
241         hdr.aslc_revision = 0x44;
242         acpi_fill_header(&hdr, "ABCD");
243
244         ut_asserteq_mem("ABCD", hdr.signature, sizeof(hdr.signature));
245         ut_asserteq(0x11, hdr.length);
246         ut_asserteq(0x22, hdr.revision);
247         ut_asserteq(0x33, hdr.checksum);
248         ut_asserteq_mem(OEM_ID, hdr.oem_id, sizeof(hdr.oem_id));
249         ut_asserteq_mem(OEM_TABLE_ID, hdr.oem_table_id,
250                         sizeof(hdr.oem_table_id));
251         ut_asserteq(OEM_REVISION, hdr.oem_revision);
252         ut_asserteq_mem(ASLC_ID, hdr.aslc_id, sizeof(hdr.aslc_id));
253         ut_asserteq(0x44, hdr.aslc_revision);
254
255         return 0;
256 }
257 DM_TEST(dm_test_acpi_fill_header, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
258
259 /* Test ACPI write_tables() */
260 static int dm_test_acpi_write_tables(struct unit_test_state *uts)
261 {
262         struct acpi_dmar *dmar;
263         struct acpi_ctx ctx;
264         ulong addr;
265         void *buf;
266         int i;
267
268         buf = malloc(BUF_SIZE);
269         ut_assertnonnull(buf);
270         addr = map_to_sysmem(buf);
271
272         ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr));
273         dmar = ctx.current;
274         ut_assertok(acpi_write_dev_tables(&ctx));
275
276         /*
277          * We should have three dmar tables, one for each
278          * "denx,u-boot-acpi-test" device
279          */
280         ut_asserteq_ptr(dmar + 3, ctx.current);
281         ut_asserteq(DMAR_INTR_REMAP, dmar->flags);
282         ut_asserteq(32 - 1, dmar->host_address_width);
283
284         ut_asserteq(DMAR_INTR_REMAP, dmar[1].flags);
285         ut_asserteq(32 - 1, dmar[1].host_address_width);
286
287         ut_asserteq(DMAR_INTR_REMAP, dmar[2].flags);
288         ut_asserteq(32 - 1, dmar[2].host_address_width);
289
290         /* Check that the pointers were added correctly */
291         for (i = 0; i < 3; i++) {
292                 ut_asserteq(map_to_sysmem(dmar + i), ctx.rsdt->entry[i]);
293                 ut_asserteq(map_to_sysmem(dmar + i), ctx.xsdt->entry[i]);
294         }
295         ut_asserteq(0, ctx.rsdt->entry[3]);
296         ut_asserteq(0, ctx.xsdt->entry[3]);
297
298         return 0;
299 }
300 DM_TEST(dm_test_acpi_write_tables, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
301
302 /* Test basic ACPI functions */
303 static int dm_test_acpi_basic(struct unit_test_state *uts)
304 {
305         struct acpi_ctx ctx;
306
307         /* Check align works */
308         ctx.current = (void *)5;
309         acpi_align(&ctx);
310         ut_asserteq_ptr((void *)16, ctx.current);
311
312         /* Check that align does nothing if already aligned */
313         acpi_align(&ctx);
314         ut_asserteq_ptr((void *)16, ctx.current);
315         acpi_align64(&ctx);
316         ut_asserteq_ptr((void *)64, ctx.current);
317         acpi_align64(&ctx);
318         ut_asserteq_ptr((void *)64, ctx.current);
319
320         /* Check incrementing */
321         acpi_inc(&ctx, 3);
322         ut_asserteq_ptr((void *)67, ctx.current);
323         acpi_inc_align(&ctx, 3);
324         ut_asserteq_ptr((void *)80, ctx.current);
325
326         return 0;
327 }
328 DM_TEST(dm_test_acpi_basic, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
329
330 /* Test setup_ctx_and_base_tables */
331 static int dm_test_setup_ctx_and_base_tables(struct unit_test_state *uts)
332 {
333         struct acpi_rsdp *rsdp;
334         struct acpi_rsdt *rsdt;
335         struct acpi_xsdt *xsdt;
336         struct acpi_ctx ctx;
337         void *buf, *end;
338         ulong addr;
339
340         /*
341          * Use an unaligned address deliberately, by allocating an aligned
342          * address and then adding 4 to it
343          */
344         buf = memalign(64, BUF_SIZE);
345         ut_assertnonnull(buf);
346         addr = map_to_sysmem(buf);
347         ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr + 4));
348         ut_asserteq(map_to_sysmem(PTR_ALIGN(buf + 4, 16)), gd_acpi_start());
349
350         rsdp = buf + 16;
351         ut_asserteq_ptr(rsdp, ctx.rsdp);
352         ut_asserteq_mem(RSDP_SIG, rsdp->signature, sizeof(rsdp->signature));
353         ut_asserteq(sizeof(*rsdp), rsdp->length);
354         ut_assertok(table_compute_checksum(rsdp, 20));
355         ut_assertok(table_compute_checksum(rsdp, sizeof(*rsdp)));
356
357         rsdt = PTR_ALIGN((void *)rsdp + sizeof(*rsdp), 16);
358         ut_asserteq_ptr(rsdt, ctx.rsdt);
359         ut_asserteq_mem("RSDT", rsdt->header.signature, ACPI_NAME_LEN);
360         ut_asserteq(sizeof(*rsdt), rsdt->header.length);
361         ut_assertok(table_compute_checksum(rsdt, sizeof(*rsdt)));
362
363         xsdt = PTR_ALIGN((void *)rsdt + sizeof(*rsdt), 16);
364         ut_asserteq_ptr(xsdt, ctx.xsdt);
365         ut_asserteq_mem("XSDT", xsdt->header.signature, ACPI_NAME_LEN);
366         ut_asserteq(sizeof(*xsdt), xsdt->header.length);
367         ut_assertok(table_compute_checksum(xsdt, sizeof(*xsdt)));
368
369         end = PTR_ALIGN((void *)xsdt + sizeof(*xsdt), 64);
370         ut_asserteq_ptr(end, ctx.current);
371
372         ut_asserteq(map_to_sysmem(rsdt), rsdp->rsdt_address);
373         ut_asserteq(map_to_sysmem(xsdt), rsdp->xsdt_address);
374
375         return 0;
376 }
377 DM_TEST(dm_test_setup_ctx_and_base_tables,
378         UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
379
380 /* Test 'acpi list' command */
381 static int dm_test_acpi_cmd_list(struct unit_test_state *uts)
382 {
383         struct acpi_ctx ctx;
384         ulong addr;
385         void *buf;
386
387         buf = memalign(16, BUF_SIZE);
388         ut_assertnonnull(buf);
389         addr = map_to_sysmem(buf);
390         ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr));
391
392         ut_assertok(acpi_write_dev_tables(&ctx));
393
394         console_record_reset();
395         run_command("acpi list", 0);
396         ut_assert_nextline("Name      Base   Size  Detail");
397         ut_assert_nextline("----  --------  -----  ------");
398         ut_assert_nextline("RSDP  %08lx  %5zx  v02 U-BOOT", addr,
399                            sizeof(struct acpi_rsdp));
400         addr = ALIGN(addr + sizeof(struct acpi_rsdp), 16);
401         ut_assert_nextline("RSDT  %08lx  %5zx  v01 U-BOOT U-BOOTBL %x INTL 0",
402                            addr, sizeof(struct acpi_table_header) +
403                            3 * sizeof(u32), OEM_REVISION);
404         addr = ALIGN(addr + sizeof(struct acpi_rsdt), 16);
405         ut_assert_nextline("XSDT  %08lx  %5zx  v01 U-BOOT U-BOOTBL %x INTL 0",
406                            addr, sizeof(struct acpi_table_header) +
407                            3 * sizeof(u64), OEM_REVISION);
408         addr = ALIGN(addr + sizeof(struct acpi_xsdt), 64);
409         ut_assert_nextline("DMAR  %08lx  %5zx  v01 U-BOOT U-BOOTBL %x INTL 0",
410                            addr, sizeof(struct acpi_dmar), OEM_REVISION);
411         addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
412         ut_assert_nextline("DMAR  %08lx  %5zx  v01 U-BOOT U-BOOTBL %x INTL 0",
413                            addr, sizeof(struct acpi_dmar), OEM_REVISION);
414         addr = ALIGN(addr + sizeof(struct acpi_dmar), 16);
415         ut_assert_nextline("DMAR  %08lx  %5zx  v01 U-BOOT U-BOOTBL %x INTL 0",
416                            addr, sizeof(struct acpi_dmar), OEM_REVISION);
417         ut_assert_console_end();
418
419         return 0;
420 }
421 DM_TEST(dm_test_acpi_cmd_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
422
423 /* Test 'acpi dump' command */
424 static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
425 {
426         struct acpi_ctx ctx;
427         ulong addr;
428         void *buf;
429
430         buf = memalign(16, BUF_SIZE);
431         ut_assertnonnull(buf);
432         addr = map_to_sysmem(buf);
433         ut_assertok(setup_ctx_and_base_tables(uts, &ctx, addr));
434
435         ut_assertok(acpi_write_dev_tables(&ctx));
436
437         /* First search for a non-existent table */
438         console_record_reset();
439         run_command("acpi dump rdst", 0);
440         ut_assert_nextline("Table 'RDST' not found");
441         ut_assert_console_end();
442
443         /* Now a real table */
444         console_record_reset();
445         run_command("acpi dump dmar", 0);
446         addr = ALIGN(map_to_sysmem(ctx.xsdt) + sizeof(struct acpi_xsdt), 64);
447         ut_assert_nextline("DMAR @ %08lx", addr);
448         ut_assert_nextlines_are_dump(0x30);
449         ut_assert_console_end();
450
451         return 0;
452 }
453 DM_TEST(dm_test_acpi_cmd_dump, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
454
455 /* Test acpi_device_path() */
456 static int dm_test_acpi_device_path(struct unit_test_state *uts)
457 {
458         struct testacpi_plat *plat;
459         char buf[ACPI_PATH_MAX];
460         struct udevice *dev, *child;
461
462         ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
463         ut_assertok(acpi_device_path(dev, buf, sizeof(buf)));
464         ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME, buf);
465
466         /* Test running out of space */
467         buf[5] = '\0';
468         ut_asserteq(-ENOSPC, acpi_device_path(dev, buf, 5));
469         ut_asserteq('\0', buf[5]);
470
471         /* Test a three-component name */
472         ut_assertok(device_first_child_err(dev, &child));
473         ut_assertok(acpi_device_path(child, buf, sizeof(buf)));
474         ut_asserteq_str("\\_SB." ACPI_TEST_DEV_NAME "." ACPI_TEST_CHILD_NAME,
475                         buf);
476
477         /* Test handling of a device which doesn't produce a name */
478         plat = dev_get_plat(dev);
479         plat->no_name = true;
480         ut_assertok(acpi_device_path(child, buf, sizeof(buf)));
481         ut_asserteq_str("\\_SB." ACPI_TEST_CHILD_NAME, buf);
482
483         /* Test handling of a device which returns an error */
484         plat = dev_get_plat(dev);
485         plat->return_error = true;
486         ut_asserteq(-EINVAL, acpi_device_path(child, buf, sizeof(buf)));
487
488         return 0;
489 }
490 DM_TEST(dm_test_acpi_device_path, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
491
492 /* Test acpi_device_status() */
493 static int dm_test_acpi_device_status(struct unit_test_state *uts)
494 {
495         struct udevice *dev;
496
497         ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
498         ut_asserteq(ACPI_DSTATUS_ALL_ON, acpi_device_status(dev));
499
500         return 0;
501 }
502 DM_TEST(dm_test_acpi_device_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
503
504 /* Test acpi_fill_ssdt() */
505 static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)
506 {
507         struct acpi_ctx ctx;
508         u8 *buf;
509
510         buf = malloc(BUF_SIZE);
511         ut_assertnonnull(buf);
512
513         acpi_reset_items();
514         ctx.current = buf;
515         buf[4] = 'z';   /* sentinel */
516         ut_assertok(acpi_fill_ssdt(&ctx));
517
518         /*
519          * These values come from acpi-test2's acpi-ssdt-test-data property.
520          * This device comes first because of u-boot,acpi-ssdt-order
521          */
522         ut_asserteq('c', buf[0]);
523         ut_asserteq('d', buf[1]);
524
525         /* These values come from acpi-test's acpi-ssdt-test-data property */
526         ut_asserteq('a', buf[2]);
527         ut_asserteq('b', buf[3]);
528
529         ut_asserteq('z', buf[4]);
530
531         return 0;
532 }
533 DM_TEST(dm_test_acpi_fill_ssdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
534
535 /* Test acpi_inject_dsdt() */
536 static int dm_test_acpi_inject_dsdt(struct unit_test_state *uts)
537 {
538         struct acpi_ctx ctx;
539         u8 *buf;
540
541         buf = malloc(BUF_SIZE);
542         ut_assertnonnull(buf);
543
544         acpi_reset_items();
545         ctx.current = buf;
546         buf[4] = 'z';   /* sentinel */
547         ut_assertok(acpi_inject_dsdt(&ctx));
548
549         /*
550          * These values come from acpi-test's acpi-dsdt-test-data property.
551          * There is no u-boot,acpi-dsdt-order so device-tree order is used.
552          */
553         ut_asserteq('h', buf[0]);
554         ut_asserteq('i', buf[1]);
555
556         /* These values come from acpi-test's acpi-dsdt-test-data property */
557         ut_asserteq('j', buf[2]);
558         ut_asserteq('k', buf[3]);
559
560         ut_asserteq('z', buf[4]);
561
562         return 0;
563 }
564 DM_TEST(dm_test_acpi_inject_dsdt, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
565
566 /* Test 'acpi items' command */
567 static int dm_test_acpi_cmd_items(struct unit_test_state *uts)
568 {
569         struct acpi_ctx ctx;
570         ulong addr;
571         void *buf;
572
573         buf = malloc(BUF_SIZE);
574         ut_assertnonnull(buf);
575         addr = map_to_sysmem(buf);
576
577         acpi_reset_items();
578         ctx.current = buf;
579         ut_assertok(acpi_fill_ssdt(&ctx));
580         console_record_reset();
581         run_command("acpi items", 0);
582         ut_assert_nextline("Seq  Type       Base   Size  Device/Writer");
583         ut_assert_nextline("---  -----  --------   ----  -------------");
584         ut_assert_nextline("  0  ssdt   %8lx      2  acpi-test", addr);
585         ut_assert_nextline("  1  ssdt   %8lx      2  acpi-test2", addr + 2);
586         ut_assert_console_end();
587
588         acpi_reset_items();
589         ctx.current = buf;
590         ut_assertok(acpi_inject_dsdt(&ctx));
591         console_record_reset();
592         run_command("acpi items", 0);
593         ut_assert_nextlinen("Seq");
594         ut_assert_nextlinen("---");
595         ut_assert_nextline("  0  dsdt   %8lx      2  acpi-test", addr);
596         ut_assert_nextline("  1  dsdt   %8lx      2  acpi-test2", addr + 2);
597         ut_assert_console_end();
598
599         console_record_reset();
600         run_command("acpi items -d", 0);
601         ut_assert_nextlinen("Seq");
602         ut_assert_nextlinen("---");
603         ut_assert_nextline("  0  dsdt   %8lx      2  acpi-test", addr);
604         ut_assert_nextlines_are_dump(2);
605         ut_assert_nextline("%s", "");
606         ut_assert_nextline("  1  dsdt   %8lx      2  acpi-test2", addr + 2);
607         ut_assert_nextlines_are_dump(2);
608         ut_assert_nextline("%s", "");
609         ut_assert_console_end();
610
611         return 0;
612 }
613 DM_TEST(dm_test_acpi_cmd_items, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);