Skip to content

Commit

Permalink
ztests: Enable native specific functionality with embedded libCs
Browse files Browse the repository at this point in the history
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 <alberto.escolar.piedras@nordicsemi.no>
  • Loading branch information
aescolar committed Jul 6, 2023
1 parent 5f75f41 commit ed2de80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion subsys/testsuite/ztest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions subsys/testsuite/ztest/src/ztest_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "cmdline.h" /* native_posix command line options header */
#include "soc.h"
#include <zephyr/tc_util.h>
#include <zephyr/ztest_test_new.h>
#include "nsi_host_trampolines.h"

static const char *test_args;
static bool list_tests;
Expand Down Expand Up @@ -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 '/' */
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit ed2de80

Please sign in to comment.