Skip to content

Commit 913920a

Browse files
aescolarnashif
authored andcommitted
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 <[email protected]>
1 parent 9aeb497 commit 913920a

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

subsys/testsuite/ztest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ zephyr_library_sources_ifdef(CONFIG_ZTEST_MOCKING src/ztest_mock.c)
2424
zephyr_library_sources_ifdef(CONFIG_ZTRESS src/ztress.c)
2525

2626

27-
if(CONFIG_ARCH_POSIX AND CONFIG_EXTERNAL_LIBC)
27+
if(CONFIG_ARCH_POSIX)
2828
zephyr_library_sources_ifdef(CONFIG_ZTEST_NEW_API src/ztest_posix.c)
2929
else()
3030
zephyr_library_sources_ifdef(CONFIG_ZTEST_NEW_API src/ztest_defaults.c)

subsys/testsuite/ztest/src/ztest_posix.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
#include <stdio.h>
88
#include <stdlib.h>
9-
#include <unistd.h>
109
#include "cmdline.h" /* native_posix command line options header */
1110
#include "soc.h"
1211
#include <zephyr/tc_util.h>
1312
#include <zephyr/ztest_test_new.h>
13+
#include "nsi_host_trampolines.h"
1414

1515
static const char *test_args;
1616
static bool list_tests;
@@ -57,7 +57,7 @@ const char *ztest_relative_filename(const char *file)
5757
const char *cwd;
5858
char buf[200];
5959

60-
cwd = getcwd(buf, sizeof(buf));
60+
cwd = nsi_host_getcwd(buf, sizeof(buf));
6161
if (cwd && strlen(file) > strlen(cwd) && !strncmp(file, cwd, strlen(cwd))) {
6262
return file + strlen(cwd) + 1; /* move past the trailing '/' */
6363
}
@@ -146,7 +146,7 @@ void z_ztest_run_all(const void *state)
146146
static bool z_ztest_testargs_contains(const char *suite_name, const char *test_name)
147147
{
148148
bool found = false;
149-
char *test_args_local = strdup(test_args);
149+
char *test_args_local = nsi_host_strdup(test_args);
150150
char *suite_test_pair;
151151
char *last_suite_test_pair;
152152
char *suite_arg;
@@ -168,7 +168,7 @@ static bool z_ztest_testargs_contains(const char *suite_name, const char *test_n
168168
suite_test_pair = strtok_r(NULL, ",", &last_suite_test_pair);
169169
}
170170

171-
free(test_args_local);
171+
nsi_host_free(test_args_local);
172172
return found;
173173
}
174174

0 commit comments

Comments
 (0)