From ed2de802c311a72e8955bfe19288226625f64253 Mon Sep 17 00:00:00 2001 From: Alberto Escolar Piedras Date: Thu, 6 Jul 2023 10:16:05 +0200 Subject: [PATCH] ztests: Enable native specific functionality with embedded libCs When building with the native simulator instead of attempting to call directly to the host libC, use the trampolines provided by the runner. In this way we can build this code even if we are building Zephyr with an embedded C library. Signed-off-by: Alberto Escolar Piedras --- subsys/testsuite/ztest/CMakeLists.txt | 2 +- subsys/testsuite/ztest/src/ztest_posix.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/subsys/testsuite/ztest/CMakeLists.txt b/subsys/testsuite/ztest/CMakeLists.txt index a0cf1615159980c..c9c9332898581f7 100644 --- a/subsys/testsuite/ztest/CMakeLists.txt +++ b/subsys/testsuite/ztest/CMakeLists.txt @@ -24,7 +24,7 @@ zephyr_library_sources_ifdef(CONFIG_ZTEST_MOCKING src/ztest_mock.c) zephyr_library_sources_ifdef(CONFIG_ZTRESS src/ztress.c) -if(CONFIG_ARCH_POSIX AND CONFIG_EXTERNAL_LIBC) +if(CONFIG_ARCH_POSIX) zephyr_library_sources_ifdef(CONFIG_ZTEST_NEW_API src/ztest_posix.c) else() zephyr_library_sources_ifdef(CONFIG_ZTEST_NEW_API src/ztest_defaults.c) diff --git a/subsys/testsuite/ztest/src/ztest_posix.c b/subsys/testsuite/ztest/src/ztest_posix.c index fd8789a89c749a8..fbfb3ed41377105 100644 --- a/subsys/testsuite/ztest/src/ztest_posix.c +++ b/subsys/testsuite/ztest/src/ztest_posix.c @@ -6,11 +6,11 @@ #include #include -#include #include "cmdline.h" /* native_posix command line options header */ #include "soc.h" #include #include +#include "nsi_host_trampolines.h" static const char *test_args; static bool list_tests; @@ -57,7 +57,7 @@ const char *ztest_relative_filename(const char *file) const char *cwd; char buf[200]; - cwd = getcwd(buf, sizeof(buf)); + cwd = nsi_host_getcwd(buf, sizeof(buf)); if (cwd && strlen(file) > strlen(cwd) && !strncmp(file, cwd, strlen(cwd))) { return file + strlen(cwd) + 1; /* move past the trailing '/' */ } @@ -146,7 +146,7 @@ void z_ztest_run_all(const void *state) static bool z_ztest_testargs_contains(const char *suite_name, const char *test_name) { bool found = false; - char *test_args_local = strdup(test_args); + char *test_args_local = nsi_host_strdup(test_args); char *suite_test_pair; char *last_suite_test_pair; char *suite_arg; @@ -168,7 +168,7 @@ static bool z_ztest_testargs_contains(const char *suite_name, const char *test_n suite_test_pair = strtok_r(NULL, ",", &last_suite_test_pair); } - free(test_args_local); + nsi_host_free(test_args_local); return found; }