Skip to contentSkip to conversation

efi_loader: Complete the bootflow_efi() test

PATCH In review Simon Glass 5 participants 35 messages Jan 6, 2025 – Jan 31, 2025 USB

lore
Share & tools
lore
#0 lore raw

cover efi_loader: Complete the bootflow_efi() test

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Simon Glass (8):
sandbox: Make USB controller as having active DMA
efi_loader: Fix display of addresses in log
efi_loader: Return the memory map in pointer format
efi_loader: Correct bounce-buffer setup
efi_loader: Check memory allocations in bootflow_efi test()
efi_loader: Update testapp to get memory map correctly
efi_loader: Check that the bootflow is not removed by app
efi_loader: Test that active-DMA devices are removed

 drivers/usb/host/usb-sandbox.c |  1 +
 lib/efi_loader/efi_log.c       |  5 +--
 lib/efi_loader/efi_memory.c    |  9 ++--
 lib/efi_loader/testapp.c       | 37 ++++++++++++++++
 test/boot/bootflow.c           | 78 +++++++++++++++++++++++++++++++++-
 5 files changed, 122 insertions(+), 8 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/8 sandbox: Make USB controller as having active DMA

Set the DM_FLAG_ACTIVE_DMA flag on this device so that it is removed before booting.

---

 drivers/usb/host/usb-sandbox.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/host/usb-sandbox.c +1 -0
index f687fe2c430..6d75ce80dcd 100644
@@ -180,4 +180,5 @@ U_BOOT_DRIVER(usb_sandbox) = {
 	.probe = sandbox_usb_probe,
 	.ops	= &sandbox_usb_ops,
 	.priv_auto	= sizeof(struct sandbox_usb_ctrl),
+	.flags	= DM_FLAG_ACTIVE_DMA,
 };
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/8 efi_loader: Fix display of addresses in log

In reply to Simon Glass

The allocate/free-pages functions return an address, so there is no need to convert it. Fix this.

Fixes c824a96d76d ("efi_loader: Use the log with memory-related...")

---

 lib/efi_loader/efi_log.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/efi_loader/efi_log.c +2 -3
index 4b9c6727fe7..ad490bb431c 100644
@@ -340,8 +340,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
 		show_ulong("pgs", (ulong)rec->pages);
 		show_addr("mem", (ulong)rec->memory);
 		if (rec_hdr->ended) {
-			show_addr("*mem",
-				  (ulong)map_to_sysmem((void *)rec->e_memory));
+			show_addr("*mem", rec->e_memory);
 			show_ret(rec_hdr->e_ret);
 		}
 		break;
@@ -349,7 +348,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
 	case EFILT_FREE_PAGES: {
 		struct efil_free_pages *rec = start;
 
-		show_addr("mem", map_to_sysmem((void *)rec->memory));
+		show_addr("mem", rec->memory);
 		show_ulong("pag", (ulong)rec->pages);
 		if (rec_hdr->ended)
 			show_ret(rec_hdr->e_ret);
Signature · 1 line
2.34.1
#3 lore raw

Re: [PATCH 2/8] efi_loader: Fix display of addresses in log

Hi Simon,

Quoted 6 lines · Simon Glass

The allocate/free-pages functions return an address, so there is no need to convert it. Fix this.

Fixes c824a96d76d ("efi_loader: Use the log with memory-related...")

I can't find that commit in -master. Is there anything I am missing?

Thanks
/Ilias

Quoted 31 lines

---

 lib/efi_loader/efi_log.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/efi_loader/efi_log.c +2 -4
index 4b9c6727fe7..ad490bb431c 100644
@@ -340,8 +340,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
                show_ulong("pgs", (ulong)rec->pages);
                show_addr("mem", (ulong)rec->memory);
                if (rec_hdr->ended) {
-                       show_addr("*mem",
-                                 (ulong)map_to_sysmem((void *)rec->e_memory));
+                       show_addr("*mem", rec->e_memory);
                        show_ret(rec_hdr->e_ret);
                }
                break;
@@ -349,7 +348,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
        case EFILT_FREE_PAGES: {
                struct efil_free_pages *rec = start;
 
-               show_addr("mem", map_to_sysmem((void *)rec->memory));
+               show_addr("mem", rec->memory);
                show_ulong("pag", (ulong)rec->pages);
                if (rec_hdr->ended)
                        show_ret(rec_hdr->e_ret);
--

2.34.1

#4 lore raw

Re: [PATCH 2/8] efi_loader: Fix display of addresses in log

Hi Ilias,

Quoted 5 lines · Ilias Apalodimas

Hi Simon,

Quoted 1 line · Simon Glass
Quoted 7 lines
Quoted 5 lines

The allocate/free-pages functions return an address, so there is no need to convert it. Fix this.

Fixes c824a96d76d ("efi_loader: Use the log with memory-related...")

I can't find that commit in -master. Is there anything I am missing?

Sort-of. You, Tom and Heinrich NAKed this series. See [1]

Quoted 21 lines
Quoted 21 lines
 lib/efi_loader/efi_log.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/efi_loader/efi_log.c +1 -2
index 4b9c6727fe7..ad490bb431c 100644
@@ -340,8 +340,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
                show_ulong("pgs", (ulong)rec->pages);
                show_addr("mem", (ulong)rec->memory);
                if (rec_hdr->ended) {
-                       show_addr("*mem",
-                                 (ulong)map_to_sysmem((void *)rec->e_memory));
+                       show_addr("*mem", rec->e_memory);
                        show_ret(rec_hdr->e_ret);
                }
                break;
@@ -349,7 +348,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
        case EFILT_FREE_PAGES: {
                struct efil_free_pages *rec = start;
 
Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_log.c +1 -2
-               show_addr("mem", map_to_sysmem((void *)rec->memory));
+               show_addr("mem", rec->memory);
                show_ulong("pag", (ulong)rec->pages);
                if (rec_hdr->ended)
                        show_ret(rec_hdr->e_ret);
--

2.34.1

Regards,
Simon

[1] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/

#5 lore raw

Re: [PATCH 2/8] efi_loader: Fix display of addresses in log

Quoted 13 lines · Simon Glass

Hi Ilias,

Quoted 8 lines · Ilias Apalodimas

Hi Simon,

Quoted 4 lines · Simon Glass

The allocate/free-pages functions return an address, so there is no need to convert it. Fix this.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Fixes c824a96d76d ("efi_loader: Use the log with memory-related...")

I can't find that commit in -master. Is there anything I am missing?

Sort-of. You, Tom and Heinrich NAKed this series. See [1]

Ok, please don't cc me on patches that are not destined for master or next. I have no interest in out-of-tree work

Thanks
/Ilias

Quoted 35 lines
Quoted 22 lines
Quoted 22 lines
 lib/efi_loader/efi_log.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
lib/efi_loader/efi_log.c +1 -2
index 4b9c6727fe7..ad490bb431c 100644
@@ -340,8 +340,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
                show_ulong("pgs", (ulong)rec->pages);
                show_addr("mem", (ulong)rec->memory);
                if (rec_hdr->ended) {
-                       show_addr("*mem",
-                                 (ulong)map_to_sysmem((void *)rec->e_memory));
+                       show_addr("*mem", rec->e_memory);
                        show_ret(rec_hdr->e_ret);
                }
                break;
@@ -349,7 +348,7 @@ void show_rec(int seq, struct efil_rec_hdr *rec_hdr)
        case EFILT_FREE_PAGES: {
                struct efil_free_pages *rec = start;
 
Quoted 8 lines
Quoted 8 lines
lib/efi_loader/efi_log.c +1 -2
-               show_addr("mem", map_to_sysmem((void *)rec->memory));
+               show_addr("mem", rec->memory);
                show_ulong("pag", (ulong)rec->pages);
                if (rec_hdr->ended)
                        show_ret(rec_hdr->e_ret);
--

2.34.1

Regards,
Simon

[1] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/

#6 lore raw

Re: [PATCH 2/8] efi_loader: Fix display of addresses in log

Hi Ilias,

Quoted 18 lines · Ilias Apalodimas
Quoted 16 lines · Simon Glass

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Hi Simon,

Quoted 6 lines · Simon Glass

The allocate/free-pages functions return an address, so there is no need to convert it. Fix this.

Fixes c824a96d76d ("efi_loader: Use the log with memory-related...")
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I can't find that commit in -master. Is there anything I am missing?

Sort-of. You, Tom and Heinrich NAKed this series. See [1]

Ok, please don't cc me on patches that are not destined for master or next. I have no interest in out-of-tree work

Everything is out-of-tree until it is applied.

Yes, I'll try to drop you from future patches.

Regards,
Simon

#7 lore raw

PATCH 3/8 efi_loader: Return the memory map in pointer format

In reply to Simon Glass

An EFI app expects pointers to be returned, cast to u64. The conversion to use addresses missed this, so fix the call.

---

 lib/efi_loader/efi_memory.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
lib/efi_loader/efi_memory.c +3 -2
index 321a8c3cf31..2e197e94edd 100644
@@ -735,10 +735,11 @@ efi_status_t efi_get_memory_map(efi_uintn_t *memory_map_size,
 	list_for_each_entry(lmem, &efi_mem, link) {
 		memory_map->type = lmem->type;
 		memory_map->reserved = 0;
-		memory_map->physical_start = lmem->base;
+		memory_map->physical_start = (u64)(ulong)map_sysmem(lmem->base,
+					lmem->num_pages * EFI_PAGE_SIZE);
 
 		/* virtual and physical are always the same */
-		memory_map->virtual_start = lmem->base;
+		memory_map->virtual_start = memory_map->physical_start;
 		memory_map->num_pages = lmem->num_pages;
 		memory_map->attribute = lmem->attribute;
 		memory_map--;
Signature · 1 line
2.34.1
#8 lore raw

PATCH 4/8 efi_loader: Correct bounce-buffer setup

In reply to Simon Glass

This should set the bounce buffer to a pointer, not an address. Fix it.

---

 lib/efi_loader/efi_memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/efi_loader/efi_memory.c +2 -2
index 2e197e94edd..9374f77d3b7 100644
@@ -837,11 +837,11 @@ int efi_memory_init(void)
 	uint64_t efi_bounce_buffer_addr = 0xffffffff;
 
 	if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_BOOT_SERVICES_DATA,
-			       (64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
+			       SZ_64M >> EFI_PAGE_SHIFT,
 			       &efi_bounce_buffer_addr) != EFI_SUCCESS)
 		return -1;
 
-	efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
+	efi_bounce_buffer = map_sysmem(efi_bounce_buffer_addr, SZ_64M);
 #endif
 
 	return 0;
Signature · 1 line
2.34.1
#9 lore raw

Re: [PATCH 4/8] efi_loader: Correct bounce-buffer setup

Hi Simon,

Is this patch for -master of your tree?

Quoted 14 lines · Simon Glass

This should set the bounce buffer to a pointer, not an address. Fix it.

---

 lib/efi_loader/efi_memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
lib/efi_loader/efi_memory.c +0 -0
index 2e197e94edd..9374f77d3b7 100644

lib/efi_loader/efi_memory.c int efi_memory_init(void) · line 844

Quoted 10 lines
lib/efi_loader/efi_memory.c +2 -2
@@ -837,11 +837,11 @@ int efi_memory_init(void)
        uint64_t efi_bounce_buffer_addr = 0xffffffff;
 
        if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS, EFI_BOOT_SERVICES_DATA,
-                              (64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
+                              SZ_64M >> EFI_PAGE_SHIFT,
                               &efi_bounce_buffer_addr) != EFI_SUCCESS)
                return -1;
 
-       efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
+       efi_bounce_buffer = map_sysmem(efi_bounce_buffer_addr, SZ_64M);

map_sysmem does *exactly* the same thing so you need to adjust your commit message.
Does this solve any sandbox crashes?

/Ilias

Quoted 6 lines
lib/efi_loader/efi_memory.c +0 -1
 #endif
 
        return 0;
--

2.34.1

#10 lore raw

Re: [PATCH 4/8] efi_loader: Correct bounce-buffer setup

Hi Ilias,

Quoted 4 lines · Ilias Apalodimas

Hi Simon,

Is this patch for -master of your tree?

Yes, but I haven't applied it yet. The updated bootflow_efi() test ([1] which this is part of) is throwing up problems with how testing is done. We cannot today reinit EFI so only get to run one test which does an EFI boot. I'd like to improve that at some point.

The address/pointer tidy-up was rejected as well, I think by you, but perhaps Heinrich?

Quoted 11 lines · Simon Glass
Quoted 9 lines

This should set the bounce buffer to a pointer, not an address. Fix it.

---

 lib/efi_loader/efi_memory.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 8 lines

lib/efi_loader/efi_memory.c int efi_memory_init(void) · line 839

Quoted 8 lines
lib/efi_loader/efi_memory.c +0 -0
index 2e197e94edd..9374f77d3b7 100644
@@ -837,11 +837,11 @@ int efi_memory_init(void)
        uint64_t efi_bounce_buffer_addr = 0xffffffff;
 
        if (efi_allocate_pages(EFI_ALLOCATE_MAX_ADDRESS,

EFI_BOOT_SERVICES_DATA,

Quoted 5 lines
Quoted 5 lines
lib/efi_loader/efi_memory.c +1 -1
-                              (64 * 1024 * 1024) >> EFI_PAGE_SHIFT,
+                              SZ_64M >> EFI_PAGE_SHIFT,
                               &efi_bounce_buffer_addr) != EFI_SUCCESS)
                return -1;
 
Quoted 7 lines

lib/efi_loader/efi_memory.c int efi_memory_init(void) · line 844

Quoted 2 lines
lib/efi_loader/efi_memory.c +1 -1
-       efi_bounce_buffer = (void*)(uintptr_t)efi_bounce_buffer_addr;
+       efi_bounce_buffer = map_sysmem(efi_bounce_buffer_addr, SZ_64M);

map_sysmem does *exactly* the same thing so you need to adjust your commit message.

Does this solve any sandbox crashes?

No, sandbox doesn't test this feature yet, but the new code is more correct. Whenever you see an address, use map_sysmem() to turn it into a pointer.

Quoted 8 lines

/Ilias

Quoted 6 lines
lib/efi_loader/efi_memory.c +0 -1
 #endif
 
        return 0;
--

2.34.1

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/list/?series=439021
[2] https://patchwork.ozlabs.org/project/uboot/list/?series=436241

#11 lore raw

PATCH 5/8 efi_loader: Check memory allocations in bootflow_efi test()

In reply to Simon Glass

Add checks that all memory allocations complete successfully and that only expected parameters are provided. Check that memory addresses are within range.

---

 test/boot/bootflow.c | 64 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 63 insertions(+), 1 deletion(-)
test/boot/bootflow.c +63 -1
index 35580cee90c..8b1bc9f10ab 100644
@@ -6,6 +6,7 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#include <bloblist.h>
 #include <bootdev.h>
 #include <bootflow.h>
 #include <bootmeth.h>
@@ -14,6 +15,7 @@
 #include <dm.h>
 #include <efi.h>
 #include <efi_loader.h>
+#include <efi_log.h>
 #include <expo.h>
 #include <mapmem.h>
 #ifdef CONFIG_SANDBOX
@@ -1271,10 +1273,13 @@ BOOTSTD_TEST(bootflow_android_image_v2, UTF_CONSOLE | UTF_DM | UTF_SCAN_FDT);
 /* Test EFI bootmeth */
 static int bootflow_efi(struct unit_test_state *uts)
 {
+	struct efil_hdr *hdr = bloblist_find(BLOBLISTT_EFI_LOG, 0);
 	static const char *order[] = {"mmc1", "usb", NULL};
+	struct efil_rec_hdr *rec_hdr;
 	struct bootstd_priv *std;
 	struct udevice *bootstd;
 	const char **old_order;
+	int i;
 
 	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
 	std = dev_get_priv(bootstd);
@@ -1325,7 +1330,64 @@ static int bootflow_efi(struct unit_test_state *uts)
 
 	ut_assert_console_end();
 
-	ut_assertok(bootstd_test_drop_bootdev_order(uts));
+	/* check memory allocations are as expected */
+	if (!hdr)
+		return 0;
+
+	for (i = 0, rec_hdr = (void *)hdr + sizeof(*hdr);
+	     (void *)rec_hdr - (void *)hdr < hdr->upto;
+	     i++, rec_hdr = (void *)rec_hdr + rec_hdr->size) {
+		void *start = (void *)rec_hdr + sizeof(struct efil_rec_hdr);
+
+		switch (rec_hdr->tag) {
+		case EFILT_ALLOCATE_PAGES: {
+			struct efil_allocate_pages *rec = start;
+
+			ut_assert(rec_hdr->ended);
+			ut_assertok(rec_hdr->e_ret);
+			ut_asserteq(EFI_ALLOCATE_ANY_PAGES, rec->type);
+			log_debug("rec->memory_type %d\n", rec->memory_type);
+			ut_assert(rec->memory_type == EFI_RUNTIME_SERVICES_DATA ||
+				  rec->memory_type == EFI_BOOT_SERVICES_DATA ||
+				  rec->memory_type == EFI_ACPI_MEMORY_NVS ||
+				  rec->memory_type == EFI_LOADER_CODE);
+			ut_assert(rec->e_memory < gd->ram_size);
+			break;
+		}
+		case EFILT_FREE_PAGES: {
+			struct efil_free_pages *rec = start;
+
+			ut_assert(rec_hdr->ended);
+			ut_assertok(rec_hdr->e_ret);
+			ut_assert(rec->memory < gd->ram_size);
+			break;
+		}
+		case EFILT_ALLOCATE_POOL: {
+			struct efil_allocate_pool *rec = start;
+
+			ut_assert(rec_hdr->ended);
+			ut_assertok(rec_hdr->e_ret);
+			log_debug("rec->pool_type %d\n", rec->pool_type);
+			ut_assert(rec->pool_type == EFI_RUNTIME_SERVICES_DATA ||
+				  rec->pool_type == EFI_BOOT_SERVICES_DATA ||
+				  rec->pool_type == EFI_ACPI_MEMORY_NVS);
+			ut_assert(map_to_sysmem((void *)rec->e_buffer) <
+				  gd->ram_size);
+			break;
+		}
+		case EFILT_FREE_POOL: {
+			struct efil_free_pool *rec = start;
+
+			ut_assert(rec_hdr->ended);
+			ut_assertok(rec_hdr->e_ret);
+			ut_assert(map_to_sysmem((void *)rec->buffer) <
+				  gd->ram_size);
+			break;
+		}
+		default:
+			break;
+		}
+	}
 
 	return 0;
 }
Signature · 1 line
2.34.1
#12 lore raw

PATCH 6/8 efi_loader: Update testapp to get memory map correctly

In reply to Simon Glass

Allocate enough memory for the memory map so that it can be received successfully.

---

 lib/efi_loader/testapp.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
lib/efi_loader/testapp.c +28 -0
index 804ca7e4679..171ecdab043 100644
@@ -28,7 +28,12 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
 			     struct efi_system_table *systab)
 {
 	struct efi_loaded_image *loaded_image;
+	struct efi_mem_desc *map;
 	efi_status_t ret;
+	efi_uintn_t map_size;
+	efi_uintn_t map_key;
+	efi_uintn_t desc_size;
+	u32 desc_version;
 
 	systable = systab;
 	boottime = systable->boottime;
@@ -48,6 +53,29 @@ efi_status_t EFIAPI efi_main(efi_handle_t handle,
 	con_out->output_string(con_out, u"U-Boot test app for EFI_LOADER\r\n");
 
 out:
+	map_size = 0;
+	ret = boottime->get_memory_map(&map_size, NULL, &map_key, &desc_size,
+				       &desc_version);
+	if (ret != EFI_BUFFER_TOO_SMALL) {
+		con_out->output_string(con_out, u"map error A\n");
+		return ret;
+	}
+
+	ret = boottime->allocate_pool(EFI_BOOT_SERVICES_DATA, map_size,
+				      (void **)&map);
+	if (ret) {
+		con_out->output_string(con_out, u"map error B\n");
+		return ret;
+	}
+	/* Allocate extra space for newly allocated memory */
+	map_size += sizeof(struct efi_mem_desc);
+	ret = boottime->get_memory_map(&map_size, map, &map_key, &desc_size,
+				       &desc_version);
+	if (ret) {
+		con_out->output_string(con_out, u"map error C\n");
+		return ret;
+	}
+
 	con_out->output_string(con_out, u"Exiting test app\n");
 	ret = boottime->exit(handle, ret, 0, NULL);
 
Signature · 1 line
2.34.1
#13 lore raw

PATCH 7/8 efi_loader: Check that the bootflow is not removed by app

In reply to Simon Glass

The bootflow should not be affected by the app running and returning. Add a check that it is still valid after the app completes execution.

---

 test/boot/bootflow.c | 3 +++
 1 file changed, 3 insertions(+)
test/boot/bootflow.c +3 -0
index 8b1bc9f10ab..81e81f3cfbf 100644
@@ -1330,6 +1330,9 @@ static int bootflow_efi(struct unit_test_state *uts)
 
 	ut_assert_console_end();
 
+	/* make sure the bootflow is still present */
+	ut_assertnonnull(std->cur_bootflow);
+
 	/* check memory allocations are as expected */
 	if (!hdr)
 		return 0;
Signature · 1 line
2.34.1
#14 lore raw

PATCH 8/8 efi_loader: Test that active-DMA devices are removed

In reply to Simon Glass

When exit-boot-services is called, active devices should be removed.

Update testapp to call this method and check that the USB controller is removed as expected.

---

 lib/efi_loader/testapp.c |  9 +++++++++
 test/boot/bootflow.c     | 11 +++++++++++
 2 files changed, 20 insertions(+)
lib/efi_loader/testapp.c +9 -0
index 171ecdab043..2c89e14bc5d 100644
@@ -76,6 +76,15 @@ out:
 		return ret;
 	}
 
+	/* exit boot services so that this part of U-Boot can be tested */
+	con_out->output_string(con_out, u"Exiting boot services\n");
+	ret = boottime->exit_boot_services(handle, map_key);
+	if (ret) {
+		con_out->output_string(con_out, u"Failed exit-boot-services\n");
+		return ret;
+	}
+
+	/* now exit for real */
 	con_out->output_string(con_out, u"Exiting test app\n");
 	ret = boottime->exit(handle, ret, 0, NULL);
 
test/boot/bootflow.c +11 -0
index 81e81f3cfbf..bd96564c915 100644
@@ -23,6 +23,7 @@
 #endif
 #include <dm/device-internal.h>
 #include <dm/lists.h>
+#include <dm/uclass-internal.h>
 #include <linux/libfdt.h>
 #include <test/suites.h>
 #include <test/ut.h>
@@ -1279,6 +1280,7 @@ static int bootflow_efi(struct unit_test_state *uts)
 	struct bootstd_priv *std;
 	struct udevice *bootstd;
 	const char **old_order;
+	struct udevice *usb;
 	int i;
 
 	ut_assertok(uclass_first_device_err(UCLASS_BOOTSTD, &bootstd));
@@ -1315,6 +1317,10 @@ static int bootflow_efi(struct unit_test_state *uts)
 
 	systab.fw_vendor = test_vendor;
 
+	/* the USB block-device should have beeen probed */
+	ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
+	ut_assert(device_active(usb));
+
 	ut_asserteq(1, run_command("bootflow boot", 0));
 	ut_assert_nextline(
 		"** Booting bootflow 'usb_mass_storage.lun0.bootdev.part_1' with efi");
@@ -1325,6 +1331,7 @@ static int bootflow_efi(struct unit_test_state *uts)
 
 	/* TODO: Why the \r ? */
 	ut_assert_nextline("U-Boot test app for EFI_LOADER\r");
+	ut_assert_nextline("Exiting boot services");
 	ut_assert_nextline("Exiting test app");
 	ut_assert_nextline("Boot failed (err=-14)");
 
@@ -1333,6 +1340,10 @@ static int bootflow_efi(struct unit_test_state *uts)
 	/* make sure the bootflow is still present */
 	ut_assertnonnull(std->cur_bootflow);
 
+	/* the USB block-device should have beeen removed */
+	ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 1, &usb));
+	ut_assert(!device_active(usb));
+
 	/* check memory allocations are as expected */
 	if (!hdr)
 		return 0;
Signature · 1 line
2.34.1
#15 lore raw
In reply to Simon Glass
Quoted 7 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

Quoted 7 lines

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

Tom suggested not to send patches that are for private enjoyment to the mailing list.

Best regards

Heinrich

Quoted 19 lines

Simon Glass (8):
sandbox: Make USB controller as having active DMA
efi_loader: Fix display of addresses in log
efi_loader: Return the memory map in pointer format
efi_loader: Correct bounce-buffer setup
efi_loader: Check memory allocations in bootflow_efi test()
efi_loader: Update testapp to get memory map correctly
efi_loader: Check that the bootflow is not removed by app
efi_loader: Test that active-DMA devices are removed

  drivers/usb/host/usb-sandbox.c |  1 +
  lib/efi_loader/efi_log.c       |  5 +--
  lib/efi_loader/efi_memory.c    |  9 ++--
  lib/efi_loader/testapp.c       | 37 ++++++++++++++++
  test/boot/bootflow.c           | 78 +++++++++++++++++++++++++++++++++-
  5 files changed, 122 insertions(+), 8 deletions(-)
#16 lore raw

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

Quoted 5 lines
Quoted 2 lines

This series is based on sjg/master since the EFI logging was rejected so far.

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

Quoted 3 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Regards,
Simon

#17 lore raw
Quoted 17 lines · Simon Glass

Hi Heinrich,

Quoted 14 lines · Heinrich Schuchardt
Quoted 12 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

This series is based on sjg/master since the EFI logging was rejected so far.

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

Best regards

Heinrich

Quoted 11 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Regards,
Simon

#18 lore raw

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

#19 lore raw
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Signature · 1 line
Tom
#20 lore raw
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Best regards

Heinrich

#21 lore raw
Quoted 99 lines · Heinrich Schuchardt
Quoted 82 lines · Tom Rini
Quoted 72 lines · Simon Glass

Hi Heinrich,

Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Simon Glass

Hi Heinrich,

Quoted 25 lines · Heinrich Schuchardt
Quoted 16 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to
complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still
uses the defunct board_quiesce_devices() so a nice cleanup would be to
call the bootm function instead, with suitable modifications. That would
allow bootstage to work too.

Quoted 3 lines

This series is based on sjg/master since the EFI logging was rejected so
far.

Yes, it was rejected because a solution at the lib/log.c level would be
more generic.

Quoted 5 lines
Quoted 1 line

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

Tom suggested not to send patches that are for private enjoyment to the
mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Regards,
Simon

Quoted 8 lines

[1] https://patchwork.ozlabs.org/project/uboot/
patch/[email protected]/
[2] https://lore.kernel.org/u-boot/
CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/
CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/D513D326-41A6-425E-
[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

Quoted 8 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Isn't this precisely what monkeypatching is for in unit tests? imho this does not make sense as a logging API but expanding FTRACE to have more capabilities (like Linux trace has) so that it can save arguments and then having some nice interface to assert that certain functions were called in a certain order with certain arguments would be a scalable way to go (and surely useful in other cases too).

Honestly though it seems quite wrong for the bootflow test to inspect EFI memory allocations, these are completely different levels of API and any tests like this are going to be prone to breaking over time just because they're making assumptions across so many layers.

Kind regards,

Quoted 12 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Best regards

Heinrich

Signature · 1 line
// Caleb (they/them)
#22 lore raw

Hi Caleb,

Quoted 112 lines · Caleb Connolly
Quoted 99 lines · Heinrich Schuchardt
Quoted 82 lines · Tom Rini
Quoted 72 lines · Simon Glass

Hi Heinrich,

Quoted 32 lines · Heinrich Schuchardt
Quoted 30 lines · Simon Glass

Hi Heinrich,

Quoted 25 lines · Heinrich Schuchardt
Quoted 16 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to
complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still
uses the defunct board_quiesce_devices() so a nice cleanup would be to
call the bootm function instead, with suitable modifications. That would
allow bootstage to work too.

Quoted 3 lines

This series is based on sjg/master since the EFI logging was rejected so
far.

Yes, it was rejected because a solution at the lib/log.c level would be
more generic.

Quoted 5 lines
Quoted 1 line

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 9 lines
Quoted 9 lines
Quoted 5 lines

Tom suggested not to send patches that are for private enjoyment to the
mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Regards,
Simon

Quoted 8 lines

[1] https://patchwork.ozlabs.org/project/uboot/
patch/[email protected]/
[2] https://lore.kernel.org/u-boot/
CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/
CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/D513D326-41A6-425E-
[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

Quoted 8 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 6 lines

Isn't this precisely what monkeypatching is for in unit tests? imho this does not make sense as a logging API but expanding FTRACE to have more capabilities (like Linux trace has) so that it can save arguments and then having some nice interface to assert that certain functions were called in a certain order with certain arguments would be a scalable way to go (and surely useful in other cases too).

Yes, that would be nice.

Quoted 5 lines

Honestly though it seems quite wrong for the bootflow test to inspect EFI memory allocations, these are completely different levels of API and any tests like this are going to be prone to breaking over time just because they're making assumptions across so many layers.

It certainly is a bit odd. My goal (not necessarily shared with others) is to ensure that EFI memory-allocations are only done if an EFI app is booted.

But if you look at the checks here, they do make sense. If someone allocates memory of a different type, we would want to know about it. If an allocation was outside the range of DRAM, ditto. I actually would *not* expect these tests to break with future changes. The bootflow_efi test is specifically targetting the EFI layer. I suppose you could say that it is also testing bootstd in general, but there are many other tests which are much better at that. So this test is taking a bit of a look of what EFI is doing under the hood.

Anyway, I'll keep developing the idea, on and off, and we'll see where it goes.

Quoted 10 lines

Kind regards,

Quoted 8 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Regards,
Simon

#23 lore raw
In reply to Heinrich Schuchardt

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

We can cross that bridge when we come to it.

Quoted 7 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

#24 lore raw
Quoted 98 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 1 line
Quoted 4 lines
Quoted 2 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

Quoted 27 lines
Quoted 8 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

Quoted 8 lines

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion. And if you don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Signature · 1 line
Tom
#25 lore raw

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 35 lines
Quoted 35 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

Quoted 8 lines
Quoted 1 line

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

Quoted 4 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Regards,
Simon

#26 lore raw
Quoted 115 lines · Simon Glass

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

Quoted 4 lines

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

As I'm in a bisect-hell in our C tests you'll have to forgive me for not thinking the C tests are noticeably faster than python tests. Or that they aren't their own potential source of corner-case bugs. But I digress..

And yes, taking a bunch of text and parsing it, is what python is fast at. And easier to write.

Quoted 2 lines

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being called in both cases are generic.

Quoted 47 lines

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 35 lines
Quoted 35 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

Quoted 8 lines
Quoted 1 line

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

Quoted 5 lines

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

I mean yes, it would be good if you went back and expanded on the trace functionality you did before.

Quoted 8 lines
Quoted 4 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a test for the underlying problem. We need more functional boot tests, but we need those to be in python too, and not more C code.

And you're not just coming up with a test, you're refactoring a bunch of code and introducing new subsystems in order to do that. When as I keep pointing out, we don't need that. We could easily extend the existing OS boot tests we have to script booting an ISO. And we only run those when say "ENABLE_SLOW_TESTS" is set, and only do that on tagged releases.

Signature · 1 line
Tom
#27 lore raw

Hi Tom,

Quoted 122 lines · Tom Rini
Quoted 115 lines · Simon Glass

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

Quoted 4 lines

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

Quoted 4 lines

As I'm in a bisect-hell in our C tests you'll have to forgive me for not thinking the C tests are noticeably faster than python tests. Or that they aren't their own potential source of corner-case bugs. But I digress..

Welcome to my world. I bisected my lab devices so many times to try to isolate all the breakages that have crept in. What is the problem, maybe I can help?

Quoted 10 lines

And yes, taking a bunch of text and parsing it, is what python is fast at. And easier to write.

Quoted 2 lines

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being called in both cases are generic.

The code in EFI is:

if (!efi_st_keep_devices) {
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}

It does call somewhat the same functions, but is doing its own thing, not even using the arch-specific code. As I mentioned, a nice clean-up would be to make bootm_announce_and_cleanup() common.

Actually, now that I see efi_st_keep_devices, I wonder why Heinrich didn't want my ANSI patch[6] which serves a similar function.

Quoted 48 lines
Quoted 48 lines

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 43 lines
Quoted 28 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

Quoted 8 lines

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

Quoted 8 lines
Quoted 5 lines

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

I mean yes, it would be good if you went back and expanded on the trace functionality you did before.

I still don't believe it is the best solution and seems like yet another ocean I should avoid sticking my heater into.

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Quoted 8 lines
Quoted 3 lines

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a test for the underlying problem. We need more functional boot tests, but we need those to be in python too, and not more C code.

That is a nice improvement, but did not fix the underlying problem. The underlying problem was that EFI was calling exit-boot-services, causing U-Boot to free up data structures which were needed to boot. This was on x86_64. I never quite figured out which one (very hard when you cannot get back to U-Boot to check).

There were quite a lot of problems, actually. There v2 series is at [7]

Only a C test can check what actually happens inside U-Boot.

Quoted 6 lines

And you're not just coming up with a test, you're refactoring a bunch of code and introducing new subsystems in order to do that. When as I keep pointing out, we don't need that. We could easily extend the existing OS boot tests we have to script booting an ISO. And we only run those when say "ENABLE_SLOW_TESTS" is set, and only do that on tagged releases.

Yes of course we need to refactor to make tests work. This is not necessarily a bad thing, as it helps us break code down into testable chunks. We cannot rely only on large functional-tests, not that you are suggesting that. See [8], but they are too slow, too hard to debug when they fail. They also tend to devolve into chaos as people get lazy and stop writing unit/smaller tests.

Regards,
Simon

Quoted 3 lines

--
Tom

[6] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[7] https://patchwork.ozlabs.org/project/uboot/cover/[email protected]/
[8] https://circleci.com/blog/testing-pyramid/

#28 lore raw
Quoted 125 lines · Simon Glass

Hi Tom,

Quoted 122 lines · Tom Rini
Quoted 119 lines · Simon Glass

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

Quoted 8 lines
Quoted 4 lines

As I'm in a bisect-hell in our C tests you'll have to forgive me for not thinking the C tests are noticeably faster than python tests. Or that they aren't their own potential source of corner-case bugs. But I digress..

Welcome to my world. I bisected my lab devices so many times to try to isolate all the breakages that have crept in. What is the problem, maybe I can help?

Sure. test/cmd/hash.c::dm_test_cmd_hash_md5 fails randomly, in maybe 1 out of 100 runs, via pytest, in sandbox. Not via "./u-boot -T -c 'ut dm dm_test_cmd_hash_md5'" however (I stopped checking after 1000 iterations). I was iterating over "and built with clang" but I think it happens with gcc too, from the actual failures in CI. And you can use "-k ut" to limit to just what's matched there, so it's a quicker iteration.

Quoted 20 lines
Quoted 9 lines

And yes, taking a bunch of text and parsing it, is what python is fast at. And easier to write.

Quoted 2 lines

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being called in both cases are generic.

The code in EFI is:

if (!efi_st_keep_devices) {
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}

Quoted 3 lines

It does call somewhat the same functions, but is doing its own thing, not even using the arch-specific code. As I mentioned, a nice clean-up would be to make bootm_announce_and_cleanup() common.

Yes, we almost agree? Both the EFI code, and arch/$(ARCH)/lib/bootm.c have functions that make the above calls. A nice clean-up would be to have something common.

Quoted 3 lines

Actually, now that I see efi_st_keep_devices, I wonder why Heinrich didn't want my ANSI patch[6] which serves a similar function.

No? Your patch disables ANSI output in those tests, that variable is for making sure those tests can accomplish (if I skim things right) similar kinds of tests you've asked for before, but with an EFI app instead? But perhaps better to not start yet another tangent here...

Quoted 53 lines
Quoted 53 lines
Quoted 52 lines

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 35 lines
Quoted 35 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

Quoted 8 lines
Quoted 1 line

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

Quoted 5 lines
Quoted 2 lines

I mean yes, it would be good if you went back and expanded on the trace functionality you did before.

I still don't believe it is the best solution and seems like yet another ocean I should avoid sticking my heater into.

I strongly disagree. If you go back to the trace code you brought in to start with and make it more useful / include newer features existing elsewhere you're not going to end up in conflict with everyone asking why you're doing something subsystem specific.

Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Quoted 8 lines
Quoted 3 lines

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a test for the underlying problem. We need more functional boot tests, but we need those to be in python too, and not more C code.

That is a nice improvement, but did not fix the underlying problem. The underlying problem was that EFI was calling exit-boot-services, causing U-Boot to free up data structures which were needed to boot. This was on x86_64. I never quite figured out which one (very hard when you cannot get back to U-Boot to check).

Quoted 3 lines

There were quite a lot of problems, actually. There v2 series is at [7]

Only a C test can check what actually happens inside U-Boot.

Yes, I think now we get back to disagreeing on which symptoms lead to which code problems and then what to do about them.

Quoted 6 lines
Quoted 5 lines

And you're not just coming up with a test, you're refactoring a bunch of code and introducing new subsystems in order to do that. When as I keep pointing out, we don't need that. We could easily extend the existing OS boot tests we have to script booting an ISO. And we only run those when say "ENABLE_SLOW_TESTS" is set, and only do that on tagged releases.

Quoted 6 lines

Yes of course we need to refactor to make tests work. This is not necessarily a bad thing, as it helps us break code down into testable chunks. We cannot rely only on large functional-tests, not that you are suggesting that. See [8], but they are too slow, too hard to debug when they fail. They also tend to devolve into chaos as people get lazy and stop writing unit/smaller tests.

I'll just note that I don't ever even think to use "make tests" or "qcheck" or any of the others since they never work for me. With only a little bit of wrappering I can however run pytest like in CI.

Signature · 1 line
Tom
#29 lore raw

Hi Tom,

Quoted 136 lines · Tom Rini
Quoted 125 lines · Simon Glass

Hi Tom,

Quoted 122 lines · Tom Rini
Quoted 119 lines · Simon Glass

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt
Quoted 14 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to
complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still
uses the defunct board_quiesce_devices() so a nice cleanup would be to
call the bootm function instead, with suitable modifications. That would
allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so
far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

Quoted 8 lines
Quoted 4 lines

As I'm in a bisect-hell in our C tests you'll have to forgive me for not thinking the C tests are noticeably faster than python tests. Or that they aren't their own potential source of corner-case bugs. But I digress..

Welcome to my world. I bisected my lab devices so many times to try to isolate all the breakages that have crept in. What is the problem, maybe I can help?

Quoted 7 lines

Sure. test/cmd/hash.c::dm_test_cmd_hash_md5 fails randomly, in maybe 1 out of 100 runs, via pytest, in sandbox. Not via "./u-boot -T -c 'ut dm dm_test_cmd_hash_md5'" however (I stopped checking after 1000 iterations). I was iterating over "and built with clang" but I think it happens with gcc too, from the actual failures in CI. And you can use "-k ut" to limit to just what's matched there, so it's a quicker iteration.

Hmmm do you have a link? It's hard to imagine what it is, but perhaps a dependency on a previous test.

At present 'ut all' fails so I am going to take a look at that. Quite a bit of clean-up needed in test system, though. Ideally we could run the tests in random order so we can find and fix the dependencies. For driver model we reinit as needed, but that's not the case for EFI, for example.

Quoted 21 lines
Quoted 21 lines
Quoted 10 lines

And yes, taking a bunch of text and parsing it, is what python is fast at. And easier to write.

Quoted 2 lines

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being called in both cases are generic.

The code in EFI is:

if (!efi_st_keep_devices) {
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}

Quoted 7 lines
Quoted 3 lines

It does call somewhat the same functions, but is doing its own thing, not even using the arch-specific code. As I mentioned, a nice clean-up would be to make bootm_announce_and_cleanup() common.

Yes, we almost agree? Both the EFI code, and arch/$(ARCH)/lib/bootm.c have functions that make the above calls. A nice clean-up would be to have something common.

Yes indeed. It still does not provide a test for the EFI bootmeth, though, where I found half a dozen bugs.

Quoted 9 lines
Quoted 4 lines

Actually, now that I see efi_st_keep_devices, I wonder why Heinrich didn't want my ANSI patch[6] which serves a similar function.

No? Your patch disables ANSI output in those tests, that variable is for making sure those tests can accomplish (if I skim things right) similar kinds of tests you've asked for before, but with an EFI app instead? But perhaps better to not start yet another tangent here...

I wouldn't know where to start, anyway...

Quoted 56 lines
Quoted 56 lines
Quoted 55 lines
Quoted 47 lines

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 35 lines
Quoted 35 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

Quoted 8 lines
Quoted 1 line

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

Quoted 5 lines

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

I mean yes, it would be good if you went back and expanded on the trace functionality you did before.

Quoted 7 lines
Quoted 2 lines

I still don't believe it is the best solution and seems like yet another ocean I should avoid sticking my heater into.

I strongly disagree. If you go back to the trace code you brought in to start with and make it more useful / include newer features existing elsewhere you're not going to end up in conflict with everyone asking why you're doing something subsystem specific.

Perhaps someone else could do this? It would be a substantial amount of work to bring runtime tooling into U-Boot, bpf and the like. It would be quite a pain to use, I suspect, and certainly not possible to write a simple C test as I have done here.

Quoted 21 lines
Quoted 21 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Quoted 8 lines
Quoted 3 lines

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a test for the underlying problem. We need more functional boot tests, but we need those to be in python too, and not more C code.

That is a nice improvement, but did not fix the underlying problem. The underlying problem was that EFI was calling exit-boot-services, causing U-Boot to free up data structures which were needed to boot. This was on x86_64. I never quite figured out which one (very hard when you cannot get back to U-Boot to check).

Quoted 6 lines
Quoted 3 lines

There were quite a lot of problems, actually. There v2 series is at [7]

Only a C test can check what actually happens inside U-Boot.

Yes, I think now we get back to disagreeing on which symptoms lead to which code problems and then what to do about them.

OK

Quoted 14 lines
Quoted 7 lines
Quoted 6 lines

And you're not just coming up with a test, you're refactoring a bunch of code and introducing new subsystems in order to do that. When as I keep pointing out, we don't need that. We could easily extend the existing OS boot tests we have to script booting an ISO. And we only run those when say "ENABLE_SLOW_TESTS" is set, and only do that on tagged releases.

Quoted 6 lines

Yes of course we need to refactor to make tests work. This is not necessarily a bad thing, as it helps us break code down into testable chunks. We cannot rely only on large functional-tests, not that you are suggesting that. See [8], but they are too slow, too hard to debug when they fail. They also tend to devolve into chaos as people get lazy and stop writing unit/smaller tests.

Quoted 2 lines

I'll just note that I don't ever even think to use "make tests" or "qcheck" or any of the others since they never work for me.

Would you mind filing an issue on that? I use 'make pcheck' all the time.

Quoted 2 lines

With only a
little bit of wrappering I can however run pytest like in CI.

Yes, I use that too.

Regards,
Simon

#30 lore raw
Quoted 147 lines · Simon Glass

Hi Tom,

Quoted 136 lines · Tom Rini
Quoted 125 lines · Simon Glass

Hi Tom,

Quoted 122 lines · Tom Rini
Quoted 119 lines · Simon Glass

Hi Tom,

Quoted 103 lines · Tom Rini
Quoted 101 lines · Simon Glass

Hi Heinrich, Tom,

Quoted 80 lines · Heinrich Schuchardt
Quoted 69 lines · Tom Rini
Quoted 60 lines · Simon Glass

Hi Heinrich,

Quoted 22 lines · Heinrich Schuchardt
Quoted 20 lines · Simon Glass

Hi Heinrich,

Quoted 17 lines · Heinrich Schuchardt

On 06.01.25 15:47, Simon Glass wrote:
This test was hamstrung in code review so this series is an attempt to
complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still
uses the defunct board_quiesce_devices() so a nice cleanup would be to
call the bootm function instead, with suitable modifications. That would
allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so
far.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, it was rejected because a solution at the lib/log.c level would be
more generic.

As I mentioned, that idea isn't suitable for programmatic use.

What can be done with show_addr("mem", rec->memory); that log_debug() does not offer or which you could not do with a new log function in lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you propose to handle that? See [2] for my previous explanation, quoted here:

Quoted 3 lines

CONFIG_LOG with a bloblist option would be a great idea, but it's hard to programmatically scan text...plus only the external call sites are actually logged.

Also see the discussion on the original patch [3]. There was also your reply at [4], but I think you missed that this is intended for use in unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather than being EFI-loader-specific. I have no objection to that, but don't have a use case for it yet, so have deferred that to later. It's a fairly simple change, if/when needed. If the series was not NAKed, I'd be happy to do it now.

Quoted 8 lines
Quoted 8 lines
Quoted 4 lines

Tom suggested not to send patches that are for private enjoyment to the
mailing list.

My contributions to U-Boot are only ever about private enjoyment :-)

Do you have any comments on the patches?

Quoted 7 lines

Regards,
Simon

[1] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/
[2] https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/
[3] https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/
[4] https://lore.kernel.org/u-boot/[email protected]/

Quoted 8 lines

Looking at the logging portions of the original series again, especially if this was made generic, we probably don't want to print to actual console every time we're making a note of some memory allocation for example, that would be unreadable outside of a debug context. The point of this really seems to be "log things for verifying in tests later". Does that end up being useful? I don't know. Heinrich or Ilias, do the tests in [1] look generally useful?

Quoted 2 lines

The tests in [1] are not documented, not even in the commit message. So the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can add some.

Quoted 4 lines

At first sight the tests in [1] don't make much sense. E.g. that only a subset of memory types have been used does not tell that the right memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the memory types are sane, checks addresses are within DRAM, etc. With [5] it makes sure that devices are removed.

Quoted 3 lines

Implementing a specific tracing functionality for EFI is definitively the wrong way forward as it will lead to code duplication.

Quoted 8 lines
Quoted 1 line

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when everyone agrees it needs to be moved somewhere else. I mean [5] is a generic issue and test/py/tests/test_net_boot.py or some other test we already have which tests booting an OS should confirm that we've quiesced devices before moving on. And as a bonus it's in python where dealing with strings doesn't suck.

I really don't want to write C tests in Python. CI is slow enough as it is, something realy want to fix. I'm also not sure how you can tell if a device has been removed. Run 'dm tree' and look for the missing 'star' in the resulting 300 lines of text?

Quoted 8 lines
Quoted 4 lines

As I'm in a bisect-hell in our C tests you'll have to forgive me for not thinking the C tests are noticeably faster than python tests. Or that they aren't their own potential source of corner-case bugs. But I digress..

Welcome to my world. I bisected my lab devices so many times to try to isolate all the breakages that have crept in. What is the problem, maybe I can help?

Quoted 7 lines

Sure. test/cmd/hash.c::dm_test_cmd_hash_md5 fails randomly, in maybe 1 out of 100 runs, via pytest, in sandbox. Not via "./u-boot -T -c 'ut dm dm_test_cmd_hash_md5'" however (I stopped checking after 1000 iterations). I was iterating over "and built with clang" but I think it happens with gcc too, from the actual failures in CI. And you can use "-k ut" to limit to just what's matched there, so it's a quicker iteration.

Quoted 2 lines

Hmmm do you have a link? It's hard to imagine what it is, but perhaps a dependency on a previous test.

Sure:
https://source.denx.de/u-boot/u-boot/-/jobs/993200#L286

My current gut feeling is that we've got some section overlap issue somewhere. And, FWIW, if I turn off EFI_LOADER I still see it. And if you use the same binary it won't always fail.

Quoted 5 lines

At present 'ut all' fails so I am going to take a look at that. Quite a bit of clean-up needed in test system, though. Ideally we could run the tests in random order so we can find and fix the dependencies. For driver model we reinit as needed, but that's not the case for EFI, for example.

Personally, for making pytest faster I'd look at the general recommendations various blog posts about "make your pytest run faster" and then go from there.

Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 9 lines

And yes, taking a bunch of text and parsing it, is what python is fast at. And easier to write.

Quoted 2 lines

But actually [5] is not generic, since EFI uses its own code to remove devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being called in both cases are generic.

The code in EFI is:

if (!efi_st_keep_devices) {
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}

It does call somewhat the same functions, but is doing its own thing, not even using the arch-specific code. As I mentioned, a nice clean-up would be to make bootm_announce_and_cleanup() common.

Quoted 6 lines
Quoted 3 lines

Yes, we almost agree? Both the EFI code, and arch/$(ARCH)/lib/bootm.c have functions that make the above calls. A nice clean-up would be to have something common.

Yes indeed. It still does not provide a test for the EFI bootmeth, though, where I found half a dozen bugs.

Yes, the bootmeth code is it's own thing.

Quoted 74 lines
Quoted 7 lines
Quoted 2 lines

Actually, now that I see efi_st_keep_devices, I wonder why Heinrich didn't want my ANSI patch[6] which serves a similar function.

No? Your patch disables ANSI output in those tests, that variable is for making sure those tests can accomplish (if I skim things right) similar kinds of tests you've asked for before, but with an EFI app instead? But perhaps better to not start yet another tangent here...

I wouldn't know where to start, anyway...

Quoted 56 lines
Quoted 56 lines
Quoted 55 lines
Quoted 47 lines

If you want the logging to be renamed and placed centrally I don't mind doing it now. But note that only EFI will use it for now.

Quoted 35 lines
Quoted 35 lines
Quoted 9 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the format parameter and saves the binary data in an appropriate format for analysis by the unit tests:

Quoted 7 lines

* For %s the driver should save the string and not the address of the string.
* For %pD the driver should save the device path instead of the pointer.
* ...

Some changes to the log driver interface will be needed to pass the variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above suggestion is quite a complicated way of handling things. We have no way to decode printf() strings in this way. See log_dispatch() for how this is handled today. It uses sprintf(). Trying to test based on text output would be very clumsy (lots of regexes and sscan() calls?) and result in a huge amount of parsing code, highly dependent on the printf() format, etc.

I very-much doubt that would produce a useful implementation, but if you would like to try it out then I would be happy to look at it.

I mentioned this several times, but even if we did go that way, we only have logging on the external calls, so much of the EFI-memory allocation in U-Boot would not be logged.

Regards,
Simon

Quoted 8 lines
Quoted 1 line

[5] https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Yes, calling this a "log" when it's intended for capturing information for tests got some of this off on the wrong track. But that also helps explain now that this is still on the wrong track and should instead be following normal design practices for testing and expanding existing infrastructure and not inventing a new everything. So if you don't like Heinrich's suggestion, take a look at Caleb's suggestion.

Quoted 5 lines

I don't have the energy to port the tracing framework from Linux to U-Boot, although I agree it would be useful. Still, function tracing is quite fragile and confusing to work with when refactoring code. I don't like that idea much for this use case, although if function tracing did exist in U-Boot I would likely have used it.

I mean yes, it would be good if you went back and expanded on the trace functionality you did before.

Quoted 7 lines
Quoted 2 lines

I still don't believe it is the best solution and seems like yet another ocean I should avoid sticking my heater into.

I strongly disagree. If you go back to the trace code you brought in to start with and make it more useful / include newer features existing elsewhere you're not going to end up in conflict with everyone asking why you're doing something subsystem specific.

Quoted 4 lines

Perhaps someone else could do this? It would be a substantial amount of work to bring runtime tooling into U-Boot, bpf and the like. It would be quite a pain to use, I suspect, and certainly not possible to write a simple C test as I have done here.

I'm not sure where bpf and the like comes from in what I said here. But again, if you find that logging thing you wrote handy, keep it in a topic branch somewhere and then later on you can "Told You So" the rest of us later on.

Quoted 43 lines
Quoted 20 lines
Quoted 20 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch you can merge when you need to debug some problem that seemingly nothing else will catch.

Quoted 8 lines
Quoted 3 lines

Here we are over a year after I reported the bug and we still don't have a test to cover it. This series is better than the available alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a test for the underlying problem. We need more functional boot tests, but we need those to be in python too, and not more C code.

That is a nice improvement, but did not fix the underlying problem. The underlying problem was that EFI was calling exit-boot-services, causing U-Boot to free up data structures which were needed to boot. This was on x86_64. I never quite figured out which one (very hard when you cannot get back to U-Boot to check).

Quoted 6 lines
Quoted 3 lines

There were quite a lot of problems, actually. There v2 series is at [7]

Only a C test can check what actually happens inside U-Boot.

Yes, I think now we get back to disagreeing on which symptoms lead to which code problems and then what to do about them.

OK

Quoted 14 lines
Quoted 13 lines
Quoted 6 lines

And you're not just coming up with a test, you're refactoring a bunch of code and introducing new subsystems in order to do that. When as I keep pointing out, we don't need that. We could easily extend the existing OS boot tests we have to script booting an ISO. And we only run those when say "ENABLE_SLOW_TESTS" is set, and only do that on tagged releases.

Yes of course we need to refactor to make tests work. This is not necessarily a bad thing, as it helps us break code down into testable chunks. We cannot rely only on large functional-tests, not that you are suggesting that. See [8], but they are too slow, too hard to debug when they fail. They also tend to devolve into chaos as people get lazy and stop writing unit/smaller tests.

Quoted 4 lines
Quoted 2 lines

I'll just note that I don't ever even think to use "make tests" or "qcheck" or any of the others since they never work for me.

Would you mind filing an issue on that? I use 'make pcheck' all the time.

Done:
https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/33

I didn't file one for "qcheck" which fails differently in that same environment.

Signature · 1 line
Tom
#31 lore raw

Hi Tom,

Quoted 15 lines · Tom Rini
Quoted 13 lines · Simon Glass

Hi Tom,

Quoted 10 lines · Tom Rini
Quoted 8 lines · Simon Glass

Hi Tom,

Quoted 5 lines · Tom Rini
Quoted 3 lines · Simon Glass

Hi Tom,

On Wed, 8 Jan 2025 at 12:15, Tom Rini <[email protected]>

Quoted 5 lines · wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Simon Glass
Quoted 3 lines

Hi Heinrich, Tom,

On Tue, 7 Jan 2025 at 08:47, Heinrich Schuchardt <

Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines · Tom Rini
Quoted 1 line

On Tue, Jan 07, 2025 at 06:57:50AM -0700, Simon Glass

Quoted 3 lines · wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Hi Heinrich,

On Tue, 7 Jan 2025 at 06:11, Heinrich Schuchardt <

Quoted 5 lines · [email protected]> wrote:
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines · Simon Glass
Quoted 3 lines

Hi Heinrich,

On Mon, 6 Jan 2025 at 10:00, Heinrich Schuchardt <

Quoted 3 lines · [email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

On 06.01.25 15:47, Simon Glass wrote:
This test was hamstrung in code review so this

series is an attempt to

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA

devices

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

- Check that the bootflow is still present after

testapp finishes

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

The EFI functionality duplicates

bootm_announce_and_cleanup() and still

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

uses the defunct board_quiesce_devices() so a nice

cleanup would be to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

call the bootm function instead, with suitable

modifications. That would

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

allow bootstage to work too.

This series is based on sjg/master since the EFI

logging was rejected so

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

far.

Yes, it was rejected because a solution at the

lib/log.c level would be

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

more generic.

As I mentioned, that idea isn't suitable for

programmatic use.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

What can be done with show_addr("mem", rec->memory);

that log_debug()

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

does not offer or which you could not do with a new

log function in

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

lib/log.c that takes variadic arguments?

There are asserts in [1], for example. How do you

propose to handle

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

that? See [2] for my previous explanation, quoted here:

Quoted 1 line

CONFIG_LOG with a bloblist option would be a great

idea, but it's hard

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

to programmatically scan text...plus only the

external call sites are

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

actually logged.

Also see the discussion on the original patch [3].

There was also your

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

reply at [4], but I think you missed that this is

intended for use in

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

unit tests (i.e. with ut_assert()).

You also requested that this be generalised, rather

than being

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

EFI-loader-specific. I have no objection to that, but

don't have a use

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

case for it yet, so have deferred that to later. It's

a fairly simple

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

change, if/when needed. If the series was not NAKed,

I'd be happy to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

do it now.

Quoted 3 lines
Quoted 3 lines

Tom suggested not to send patches that are for

private enjoyment to the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

mailing list.

My contributions to U-Boot are only ever about

private enjoyment :-)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines

Do you have any comments on the patches?

Regards,
Simon

[1]

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[2]

https://lore.kernel.org/u-boot/CAFLszTjxOE_037+kR0jgdax80sBombYo_k0YgiuVnP=KZCOvuA@mail.gmail.com/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[3]

https://lore.kernel.org/u-boot/CAC_iWjKtaN54B98OKbkoXkC_GmKJ=x+M4=UY_O6roSOpZaDxag@mail.gmail.com/

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

[4]

https://lore.kernel.org/u-boot/[email protected]/

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Looking at the logging portions of the original series

again, especially

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

if this was made generic, we probably don't want to

print to actual

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

console every time we're making a note of some memory

allocation for

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

example, that would be unreadable outside of a debug

context. The point

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

of this really seems to be "log things for verifying in

tests later".

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Does that end up being useful? I don't know. Heinrich

or Ilias, do the

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

tests in [1] look generally useful?

The tests in [1] are not documented, not even in the

commit message. So

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

the reasoning behind the tests remains Simon's secret.

Are you asking for code comments in the test? If so, I can

add some.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

At first sight the tests in [1] don't make much sense.

E.g. that only a

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

subset of memory types have been used does not tell that

the right

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

memory type has been used for the right object.

It is a pretty good start, though. It makes sure that the

memory types

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

are sane, checks addresses are within DRAM, etc. With [5]

it makes

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

sure that devices are removed.

Quoted 2 lines

Implementing a specific tracing functionality for EFI is

definitively

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

the wrong way forward as it will lead to code duplication.

We can cross that bridge when we come to it.

Well, no. It's backwards to make a bridge in one place when

everyone

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

agrees it needs to be moved somewhere else. I mean [5] is a

generic

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

issue and test/py/tests/test_net_boot.py or some other test

we already

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

have which tests booting an OS should confirm that we've

quiesced

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

devices before moving on. And as a bonus it's in python where

dealing

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

with strings doesn't suck.

I really don't want to write C tests in Python. CI is slow

enough as

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

it is, something realy want to fix. I'm also not sure how you

can tell

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

if a device has been removed. Run 'dm tree' and look for the

missing

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

'star' in the resulting 300 lines of text?

As I'm in a bisect-hell in our C tests you'll have to forgive me

for not

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

thinking the C tests are noticeably faster than python tests. Or

that

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

they aren't their own potential source of corner-case bugs. But I digress..

Welcome to my world. I bisected my lab devices so many times to try

to

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

isolate all the breakages that have crept in. What is the problem, maybe I can help?

Sure. test/cmd/hash.c::dm_test_cmd_hash_md5 fails randomly, in maybe 1 out of 100 runs, via pytest, in sandbox. Not via "./u-boot -T -c 'ut

dm

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

dm_test_cmd_hash_md5'" however (I stopped checking after 1000 iterations). I was iterating over "and built with clang" but I think

it

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

happens with gcc too, from the actual failures in CI. And you can use "-k ut" to limit to just what's matched there, so it's a quicker iteration.

Hmmm do you have a link? It's hard to imagine what it is, but perhaps a dependency on a previous test.

Quoted 6 lines

Sure:
https://source.denx.de/u-boot/u-boot/-/jobs/993200#L286

My current gut feeling is that we've got some section overlap issue somewhere. And, FWIW, if I turn off EFI_LOADER I still see it. And if you use the same binary it won't always fail.

The only way I think the hash command can return CMD_RET_USAGE is if there are not enough arguments.

The only way that can happen with this code:

ut_assertok(run_command("hash md5 $loadaddr 0", 0));

is if loadaddr is undefined.

But (like you, I suspect) I cannot find how that could be.

In fact, I can't even build with clang:

$ buildman -O clang-17 --bo sandbox -w -o /tmp/b/sandbox-clang
Building current source for 1 boards (1 thread, 32 jobs per thread)
   sandbox:  +   sandbox
+/usr/bin/llvm-ar: error: arch/sandbox/cpu/built-in.o: Opaque pointers are
only supported in -opaque-pointers mode (Producer: 'LLVM17.0.6' Reader:
'LLVM 14.0.0')
+make[2]: *** [scripts/Makefile.build:333: arch/sandbox/cpu/built-in.o]
Error 1
+make[1]: *** [Makefile:1906: arch/sandbox/cpu] Error 2
+make: *** [Makefile:177: sub-make] Error 2
    0    0    1 /1              sandbox
Quoted 10 lines
Quoted 6 lines

At present 'ut all' fails so I am going to take a look at that. Quite a bit of clean-up needed in test system, though. Ideally we could run the tests in random order so we can find and fix the dependencies. For driver model we reinit as needed, but that's not the case for EFI, for example.

Personally, for making pytest faster I'd look at the general recommendations various blog posts about "make your pytest run faster" and then go from there.

I think the problem is that you are looking at the C tests through a Python lens, so everything seems a bit slow.

'ut all' takes about 18 seconds for me.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

And yes, taking a bunch of text and parsing it, is what python is

fast

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

at. And easier to write.

Quoted 1 line

But actually [5] is not generic, since EFI uses its own code to

remove

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

devices. This test is solely focussed on EFI.

Yes, you're testing the EFI version of the code in arch/$(ARCH)/lib/bootm.c. The remove devices functions being

called in

Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
Quoted 1 line

both cases are generic.

The code in EFI is:

if (!efi_st_keep_devices) {
bootm_disable_interrupts();
if (IS_ENABLED(CONFIG_USB_DEVICE))
udc_disconnect();
board_quiesce_devices();
dm_remove_devices_active();
}

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

It does call somewhat the same functions, but is doing its own

thing,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

not even using the arch-specific code. As I mentioned, a nice

clean-up

Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

would be to make bootm_announce_and_cleanup() common.

Yes, we almost agree? Both the EFI code, and arch/$(ARCH)/lib/bootm.c have functions that make the above calls. A nice clean-up would be to have something common.

Yes indeed. It still does not provide a test for the EFI bootmeth, though, where I found half a dozen bugs.

Yes, the bootmeth code is it's own thing.

No I mean there were bugs in the EFI implementation.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Actually, now that I see efi_st_keep_devices, I wonder why Heinrich didn't want my ANSI patch[6] which serves a similar function.

No? Your patch disables ANSI output in those tests, that variable is

for

Quoted 1 line
Quoted 1 line
Quoted 1 line

making sure those tests can accomplish (if I skim things right)

similar

Quoted 1 line
Quoted 1 line
Quoted 1 line

kinds of tests you've asked for before, but with an EFI app instead?

But

Quoted 5 lines
Quoted 5 lines
Quoted 1 line

perhaps better to not start yet another tangent here...

I wouldn't know where to start, anyway...

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

If you want the logging to be renamed and placed centrally I

don't

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

mind doing it now. But note that only EFI will use it for now.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

We already have function _log() which is variadic.

Simon could write a new log driver that parses the

format parameter

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

and saves the binary data in an appropriate format for

analysis by the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

unit tests:

* For %s the driver should save the string and not the

address of the

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

string.
* For %pD the driver should save the device path instead

of the pointer.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

* ...

Some changes to the log driver interface will be needed

to pass the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

variadic arguments instead of the formatted message.

Perhaps the word 'log' is confusing people. But the above

suggestion

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is quite a complicated way of handling things. We have no

way to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

decode printf() strings in this way. See log_dispatch() for

how this

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is handled today. It uses sprintf(). Trying to test based

on text

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

output would be very clumsy (lots of regexes and sscan()

calls?) and

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

result in a huge amount of parsing code, highly dependent

on the

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

printf() format, etc.

I very-much doubt that would produce a useful

implementation, but if

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

you would like to try it out then I would be happy to look

at it.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

I mentioned this several times, but even if we did go that

way, we

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

only have logging on the external calls, so much of the

EFI-memory

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

allocation in U-Boot would not be logged.

Regards,
Simon

[5]

https://patchwork.ozlabs.org/project/uboot/patch/[email protected]/

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Yes, calling this a "log" when it's intended for capturing

information

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

for tests got some of this off on the wrong track. But that

also helps

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

explain now that this is still on the wrong track and should

instead be

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

following normal design practices for testing and expanding

existing

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

infrastructure and not inventing a new everything. So if you

don't like

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

Heinrich's suggestion, take a look at Caleb's suggestion.

I don't have the energy to port the tracing framework from

Linux to

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

U-Boot, although I agree it would be useful. Still, function

tracing

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

is quite fragile and confusing to work with when refactoring

code. I

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

don't like that idea much for this use case, although if

function

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

tracing did exist in U-Boot I would likely have used it.

I mean yes, it would be good if you went back and expanded on the

trace

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

functionality you did before.

I still don't believe it is the best solution and seems like yet another ocean I should avoid sticking my heater into.

I strongly disagree. If you go back to the trace code you brought in

to

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

start with and make it more useful / include newer features existing elsewhere you're not going to end up in conflict with everyone asking why you're doing something subsystem specific.

Perhaps someone else could do this? It would be a substantial amount of work to bring runtime tooling into U-Boot, bpf and the like. It would be quite a pain to use, I suspect, and certainly not possible to write a simple C test as I have done here.

Quoted 4 lines

I'm not sure where bpf and the like comes from in what I said here. But again, if you find that logging thing you wrote handy, keep it in a topic branch somewhere and then later on you can "Told You So" the rest of us later on.

I'm not sure what you are suggesting re tracing, but I assumed it was that we patch the code at runtime and set tracepoints to check for particular calls in a test. I'm not sure how else we would get access to the function arguments. Then, presumably we need a bpf rule to collect the function args, etc.? It wasn't my idea, so perhaps we should let Caleb explain the intent.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

And if you
don't like Caleb's suggestion, go put this in a topic branch

you can

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

merge when you need to debug some problem that seemingly

nothing else

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

will catch.

Here we are over a year after I reported the bug and we still

don't

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

have a test to cover it. This series is better than the

available

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line

alternatives, IMO.

Well, no. We have commit dabaa4ae3206 ("dm: Add dm_remove_devices_active() for ordered device removal") we have a

test

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

for the underlying problem. We need more functional boot tests,

but we

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 1 line

need those to be in python too, and not more C code.

That is a nice improvement, but did not fix the underlying problem. The underlying problem was that EFI was calling exit-boot-services, causing U-Boot to free up data structures which were needed to boot. This was on x86_64. I never quite figured out which one (very hard when you cannot get back to U-Boot to check).

There were quite a lot of problems, actually. There v2 series is at

[7]

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

Only a C test can check what actually happens inside U-Boot.

Yes, I think now we get back to disagreeing on which symptoms lead to which code problems and then what to do about them.

OK

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

And you're not just coming up with a test, you're refactoring a

bunch of

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

code and introducing new subsystems in order to do that. When as

I keep

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

pointing out, we don't need that. We could easily extend the

existing OS

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

boot tests we have to script booting an ISO. And we only run

those when

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

say "ENABLE_SLOW_TESTS" is set, and only do that on tagged

releases.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

Yes of course we need to refactor to make tests work. This is not necessarily a bad thing, as it helps us break code down into

testable

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

chunks. We cannot rely only on large functional-tests, not that you are suggesting that. See [8], but they are too slow, too hard to

debug

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

when they fail. They also tend to devolve into chaos as people get lazy and stop writing unit/smaller tests.

I'll just note that I don't ever even think to use "make tests" or "qcheck" or any of the others since they never work for me.

Would you mind filing an issue on that? I use 'make pcheck' all the

time.

Quoted 6 lines

Done:
https://source.denx.de/u-boot/custodians/u-boot-dm/-/issues/33

I didn't file one for "qcheck" which fails differently in that same environment.

OK, I'll reply there, thanks.

Regards,
Simon

#32 lore raw
Quoted 5 lines · Simon Glass

Hi Tom,

Quoted 2 lines · Tom Rini

On Mon, Jan 13, 2025 at 12:01:36PM -0700, Simon Glass wrote:

[snip]

Quoted 41 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Sure. test/cmd/hash.c::dm_test_cmd_hash_md5 fails randomly, in maybe 1 out of 100 runs, via pytest, in sandbox. Not via "./u-boot -T -c 'ut

dm

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

dm_test_cmd_hash_md5'" however (I stopped checking after 1000 iterations). I was iterating over "and built with clang" but I think

it

Quoted 7 lines
Quoted 6 lines
Quoted 3 lines

happens with gcc too, from the actual failures in CI. And you can use "-k ut" to limit to just what's matched there, so it's a quicker iteration.

Hmmm do you have a link? It's hard to imagine what it is, but perhaps a dependency on a previous test.

Quoted 6 lines

Sure:
https://source.denx.de/u-boot/u-boot/-/jobs/993200#L286

My current gut feeling is that we've got some section overlap issue somewhere. And, FWIW, if I turn off EFI_LOADER I still see it. And if you use the same binary it won't always fail.

The only way I think the hash command can return CMD_RET_USAGE is if there are not enough arguments.

The only way that can happen with this code:

ut_assertok(run_command("hash md5 $loadaddr 0", 0));

is if loadaddr is undefined.

But (like you, I suspect) I cannot find how that could be.

In fact, I can't even build with clang:

$ buildman -O clang-17 --bo sandbox -w -o /tmp/b/sandbox-clang
Building current source for 1 boards (1 thread, 32 jobs per thread)
   sandbox:  +   sandbox
+/usr/bin/llvm-ar: error: arch/sandbox/cpu/built-in.o: Opaque pointers are
only supported in -opaque-pointers mode (Producer: 'LLVM17.0.6' Reader:
'LLVM 14.0.0')
+make[2]: *** [scripts/Makefile.build:333: arch/sandbox/cpu/built-in.o]
Error 1

Review

Quoted 3 lines
(quoted diff) +2 -0
+make[1]: *** [Makefile:1906: arch/sandbox/cpu] Error 2
+make: *** [Makefile:177: sub-make] Error 2
    0    0    1 /1              sandbox

This command works fine for me in the CI container, so I don't know what's going on with your local installation. I've also seen CI fail enough times now with just regular sandbox that I don't _think_ it's a compiler specific issue. Thanks for looking in to this more!

Signature · 1 line
Tom
#33 lore raw
In reply to Simon Glass

On Fri, Jan 17, 2025 at 08:35:42PM -0800, Simon Glass wrote:

[snip]

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

At present 'ut all' fails so I am going to take a look at that. Quite a bit of clean-up needed in test system, though. Ideally we could run the tests in random order so we can find and fix the dependencies. For driver model we reinit as needed, but that's not the case for EFI, for example.

Quoted 8 lines
Quoted 3 lines

Personally, for making pytest faster I'd look at the general recommendations various blog posts about "make your pytest run faster" and then go from there.

I think the problem is that you are looking at the C tests through a Python lens, so everything seems a bit slow.

'ut all' takes about 18 seconds for me.

Yes, and the "ut" tests just via pytest do take longer. And it would be good to have more testing in CI, and for tests to be as fast as possible.

Looking at the run I just did on HW:
====================== 202 passed, 426 skipped in 48.76s ======================= ================= 202 passed, 426 skipped in 80.04s (0:01:20) ================== ================= 206 passed, 422 skipped in 128.74s (0:02:08) ================= ================= 206 passed, 422 skipped in 118.15s (0:01:58) ================= ================= 206 passed, 422 skipped in 128.65s (0:02:08) ================= ================= 206 passed, 422 skipped in 123.76s (0:02:03) ================= ================= 205 passed, 423 skipped in 128.22s (0:02:08) ================= ================= 198 passed, 429 skipped in 106.92s (0:01:46) ================= ================= 192 passed, 431 skipped in 87.95s (0:01:27) ==================

That could be better, but it's not unreasonable and part of that is tftp'ing an 83MB kernel image.

I think if I had a point around here before, it was this. C is a terrible language for processing strings. Python is a reasonable language for processing strings. Neither of these statements should be controversial. The controversy is that I'm saying tests that parse output for results shouldn't be written in C.

Signature · 1 line
Tom
#34 lore raw
In reply to Simon Glass

-Ilias

Quoted 34 lines · Simon Glass

This test was hamstrung in code review so this series is an attempt to complete the intended functionality:

- Check memory allocations look correct
- Check that exit-boot-services removes active-DMA devices
- Check that the bootflow is still present after testapp finishes

The EFI functionality duplicates bootm_announce_and_cleanup() and still uses the defunct board_quiesce_devices() so a nice cleanup would be to call the bootm function instead, with suitable modifications. That would allow bootstage to work too.

This series is based on sjg/master since the EFI logging was rejected so far.

Simon Glass (8):
sandbox: Make USB controller as having active DMA
efi_loader: Fix display of addresses in log
efi_loader: Return the memory map in pointer format
efi_loader: Correct bounce-buffer setup
efi_loader: Check memory allocations in bootflow_efi test()
efi_loader: Update testapp to get memory map correctly
efi_loader: Check that the bootflow is not removed by app
efi_loader: Test that active-DMA devices are removed

 drivers/usb/host/usb-sandbox.c |  1 +
 lib/efi_loader/efi_log.c       |  5 +--
 lib/efi_loader/efi_memory.c    |  9 ++--
 lib/efi_loader/testapp.c       | 37 ++++++++++++++++
 test/boot/bootflow.c           | 78 +++++++++++++++++++++++++++++++++-
 5 files changed, 122 insertions(+), 8 deletions(-)
Quoted 3 lines

--
2.34.1

Series applied to sjg/master, thanks!