From daab168357b9f57d7c9e76345a28143a7170c090 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 10:48:08 +0200 Subject: [PATCH 1/9] Drive-by fix: return 0 in case of success --- tests/plt_405.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/plt_405.c b/tests/plt_405.c index 95bf6427a..bf4682a89 100644 --- a/tests/plt_405.c +++ b/tests/plt_405.c @@ -13,5 +13,5 @@ int main (int argc, char *argv[]) { vmem_write(vmem_plt_405.vaddr, test_vector, sizeof(test_vector)); vmem_read(buf, vmem_plt_405.vaddr, sizeof(test_vector)); assert(0 == memcmp(buf, test_vector, sizeof(test_vector))); - return 1; + return 0; } \ No newline at end of file From 7de1e6aac53b89d1620088da9ab84e398759b8b8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 10:48:37 +0200 Subject: [PATCH 2/9] Add test for param_list_clear() --- tests/meson.build | 4 +++- tests/plt_406.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 tests/plt_406.c diff --git a/tests/meson.build b/tests/meson.build index d90c77523..f1903452f 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,2 +1,4 @@ plt_405_exe = executable('plt_405', 'plt_405.c', dependencies: [param_dep, csp_dep]) -test('plt_405', plt_405_exe) \ No newline at end of file +test('plt_405', plt_405_exe) +plt_406_exe = executable('plt_406', 'plt_406.c', dependencies: [param_dep, csp_dep], link_args : ['-Wl,-Map=plt_406.map']) +test('plt_406', plt_406_exe) \ No newline at end of file diff --git a/tests/plt_406.c b/tests/plt_406.c new file mode 100644 index 000000000..4264d3fc6 --- /dev/null +++ b/tests/plt_406.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include + +static int32_t _plt_406; + +PARAM_DEFINE_STATIC_RAM(1, plt_406, PARAM_TYPE_INT32, 0, 1, PM_READONLY, NULL, "-", &_plt_406, "PLT 406 test parameter"); + +int main (int argc, char *argv[]) { + (void)argc; + (void)argv; + /* Make sure our own param (id = 1) is in the list */ + const param_t * p = param_list_find_id(0, 1); + if(NULL == p) { + /* libparam is probably built as a shared library -> need to explicitly add our own parameters*/ + param_list_add((param_t *)&plt_406); + } + p = param_list_find_id(0, 1); + assert(p); + + /* Add a remote parameter with node = 0 */ + param_t *remote = param_list_create_remote(128, 0, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); + param_list_add(remote); + p = param_list_find_id(0, 128); + assert(p); + + /* Add a remote parameter with node != 0 */ + remote = param_list_create_remote(128, 400, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); + param_list_add(remote); + p = param_list_find_id(400, 128); + assert(p); + + /* Clear the list */ + param_list_clear(); + + /* Can you we still find our own added remote parameter with node = 0 ? */ + p = param_list_find_id(0, 128); + assert(p); + + /* Did we remove the remote parameter (node != 0) from the list ? */ + p = param_list_find_id(400, 128); + assert(NULL == p); + + /* Explicitly remove our own remote parameter with node = 0 ? */ + p = param_list_find_id(0, 128); + param_list_remove_specific(p, 0, 1); + p = param_list_find_id(0, 128); + assert(NULL == p); + + /* Can we still find our local parameter ? */ + p = param_list_find_id(0, 1); + assert(p); + return 0; +} \ No newline at end of file From ac68da4b71bc9b97eb677d015c29213de84a2fd1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 10:49:12 +0200 Subject: [PATCH 3/9] Skip parameters with node == 0 when clearing list --- src/param/list/param_list.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/param/list/param_list.c b/src/param/list/param_list.c index b6d2b6220..b586c9e85 100644 --- a/src/param/list/param_list.c +++ b/src/param/list/param_list.c @@ -413,10 +413,12 @@ static void param_list_destroy_impl(const param_t * param) { #ifdef PARAM_LIST_DYNAMIC void param_list_clear(void) { - while (!SLIST_EMPTY(¶m_list_head)) { - struct param_s *param = SLIST_FIRST(¶m_list_head); - SLIST_REMOVE_HEAD(¶m_list_head, next); - param_list_destroy(param); + struct param_s *iter = 0; + SLIST_FOREACH(iter, ¶m_list_head, next) { + if(*iter->node != 0) { + SLIST_REMOVE(¶m_list_head, iter, param_s, next); + param_list_destroy(iter); + } } } From 981528e55ea077a94ec85f0f2a955c90eee947a0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 10:50:32 +0200 Subject: [PATCH 4/9] Drive-by fix: don't treat static and shared builds differently --- meson.build | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/meson.build b/meson.build index fb5bf0303..9ff91d935 100644 --- a/meson.build +++ b/meson.build @@ -80,11 +80,7 @@ if get_option('collector') == true endif param_inc = include_directories('.', 'include') -if get_option('default_library') == 'static' - deps = [clib_dep, bsd_dep, csp_dep.partial_dependency(includes:true)] -else - deps = [clib_dep, bsd_dep, csp_dep] -endif +deps = [clib_dep, bsd_dep, csp_dep] param_lib = library('param', sources: [param_src, libparam_h], include_directories : param_inc, From b67e465d7d0616718ab4e8832e9ef4c9a99cbddc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 11:39:31 +0200 Subject: [PATCH 5/9] Take a copy of iterator before destroying it --- src/param/list/param_list.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/param/list/param_list.c b/src/param/list/param_list.c index b586c9e85..cfea85391 100644 --- a/src/param/list/param_list.c +++ b/src/param/list/param_list.c @@ -417,7 +417,8 @@ void param_list_clear(void) { SLIST_FOREACH(iter, ¶m_list_head, next) { if(*iter->node != 0) { SLIST_REMOVE(¶m_list_head, iter, param_s, next); - param_list_destroy(iter); + struct param_s to_be_destroyed = *iter; + param_list_destroy(&to_be_destroyed); } } } From 12679d16d7eb12f667be6521206bd64c3972d736 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 11:41:04 +0200 Subject: [PATCH 6/9] Update test code after review --- tests/plt_406.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/plt_406.c b/tests/plt_406.c index 4264d3fc6..cb18ae64a 100644 --- a/tests/plt_406.c +++ b/tests/plt_406.c @@ -21,12 +21,14 @@ int main (int argc, char *argv[]) { /* Add a remote parameter with node = 0 */ param_t *remote = param_list_create_remote(128, 0, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); + assert(p); param_list_add(remote); p = param_list_find_id(0, 128); assert(p); /* Add a remote parameter with node != 0 */ remote = param_list_create_remote(128, 400, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); + assert(remote); param_list_add(remote); p = param_list_find_id(400, 128); assert(p); @@ -34,7 +36,7 @@ int main (int argc, char *argv[]) { /* Clear the list */ param_list_clear(); - /* Can you we still find our own added remote parameter with node = 0 ? */ + /* Can we still find our own added remote parameter with node = 0 ? */ p = param_list_find_id(0, 128); assert(p); @@ -44,6 +46,7 @@ int main (int argc, char *argv[]) { /* Explicitly remove our own remote parameter with node = 0 ? */ p = param_list_find_id(0, 128); + assert(p); param_list_remove_specific(p, 0, 1); p = param_list_find_id(0, 128); assert(NULL == p); From 21f3af9a0bb30e809778bc5ecdd64900d9ff0148 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 15:00:21 +0200 Subject: [PATCH 7/9] Implement safe iteration in param_list_clear, skipping the RO and local parameters --- src/param/list/param_list.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/param/list/param_list.c b/src/param/list/param_list.c index cfea85391..789527cd6 100644 --- a/src/param/list/param_list.c +++ b/src/param/list/param_list.c @@ -413,13 +413,16 @@ static void param_list_destroy_impl(const param_t * param) { #ifdef PARAM_LIST_DYNAMIC void param_list_clear(void) { - struct param_s *iter = 0; - SLIST_FOREACH(iter, ¶m_list_head, next) { - if(*iter->node != 0) { - SLIST_REMOVE(¶m_list_head, iter, param_s, next); - struct param_s to_be_destroyed = *iter; - param_list_destroy(&to_be_destroyed); + param_list_iterator i = {0}; + const param_t * iter_param = param_list_iterate(&i); + + while (iter_param) { + const param_t * param = iter_param; + if (i.phase != 0 && (i.element && *(i.element->node) != 0)) { + SLIST_REMOVE(¶m_list_head, param, param_s, next); + param_list_destroy(param); } + iter_param = param_list_iterate(&i); } } From 0ea449c96b2331d80b8a7ace87a7f503791c4aa9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 15:01:52 +0200 Subject: [PATCH 8/9] Improve tests a bit after review --- tests/plt_406.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/plt_406.c b/tests/plt_406.c index cb18ae64a..776556664 100644 --- a/tests/plt_406.c +++ b/tests/plt_406.c @@ -14,20 +14,22 @@ int main (int argc, char *argv[]) { const param_t * p = param_list_find_id(0, 1); if(NULL == p) { /* libparam is probably built as a shared library -> need to explicitly add our own parameters*/ - param_list_add((param_t *)&plt_406); + param_t *local = param_list_create_remote(1, 0, PARAM_TYPE_INT32, PM_READONLY, 1, "plt_406", "-", "PLT 406 test parameter", -1); + assert(local); + param_list_add(local); } p = param_list_find_id(0, 1); assert(p); - /* Add a remote parameter with node = 0 */ + /* Add a "fake" remote parameter with node = 0 */ param_t *remote = param_list_create_remote(128, 0, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); - assert(p); + assert(remote); param_list_add(remote); p = param_list_find_id(0, 128); assert(p); /* Add a remote parameter with node != 0 */ - remote = param_list_create_remote(128, 400, PARAM_TYPE_UINT16, PM_DEBUG, 0, "remote", NULL, NULL, -1); + remote = param_list_create_remote(128, 400, PARAM_TYPE_UINT16, PM_REMOTE, 0, "remote", NULL, NULL, -1); assert(remote); param_list_add(remote); p = param_list_find_id(400, 128); From 5b8b9d077295ec89e08efcd96c05bd2beb380233 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Lab Date: Fri, 24 Jul 2026 15:03:02 +0200 Subject: [PATCH 9/9] Add linker script that explicitly creates an enumerable "param" ELF section and use it in test --- tests/linux.ld | 11 +++++++++++ tests/meson.build | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 tests/linux.ld diff --git a/tests/linux.ld b/tests/linux.ld new file mode 100644 index 000000000..6a6d12913 --- /dev/null +++ b/tests/linux.ld @@ -0,0 +1,11 @@ +SECTIONS +{ + .param ALIGN(8) : + { + PROVIDE(__start_param = .); + KEEP(*(SORT_BY_NAME(param*))) + . = ALIGN(8); + PROVIDE(__stop_param = .); + } +} +INSERT AFTER .rodata; \ No newline at end of file diff --git a/tests/meson.build b/tests/meson.build index f1903452f..408b0a6e3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,4 +1,6 @@ +linker_script = meson.current_source_dir() / 'linux.ld' + plt_405_exe = executable('plt_405', 'plt_405.c', dependencies: [param_dep, csp_dep]) test('plt_405', plt_405_exe) -plt_406_exe = executable('plt_406', 'plt_406.c', dependencies: [param_dep, csp_dep], link_args : ['-Wl,-Map=plt_406.map']) -test('plt_406', plt_406_exe) \ No newline at end of file +plt_406_exe = executable('plt_406', 'plt_406.c', dependencies: [param_dep, csp_dep], link_args : ['-Wl,--script=' + linker_script]) +test('plt_406', plt_406_exe)