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, diff --git a/src/param/list/param_list.c b/src/param/list/param_list.c index b6d2b6220..789527cd6 100644 --- a/src/param/list/param_list.c +++ b/src/param/list/param_list.c @@ -413,10 +413,16 @@ 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); + 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); } } 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 d90c77523..408b0a6e3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,2 +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) \ 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,--script=' + linker_script]) +test('plt_406', plt_406_exe) 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 diff --git a/tests/plt_406.c b/tests/plt_406.c new file mode 100644 index 000000000..776556664 --- /dev/null +++ b/tests/plt_406.c @@ -0,0 +1,60 @@ +#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_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 "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(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_REMOTE, 0, "remote", NULL, NULL, -1); + assert(remote); + param_list_add(remote); + p = param_list_find_id(400, 128); + assert(p); + + /* Clear the list */ + param_list_clear(); + + /* Can 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); + assert(p); + 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