native_simulator: Get latest from upstream

Align with native_simulator's upstream main
3eae4374db5984a5defcefdeda254b37e72e2ca8

Which includes:
* 3eae437 cmdline parsing: Allow providing more arguments progammatically
* d148a28 Host trampolines: Add realloc

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2024-01-16 15:42:05 +01:00 committed by Carles Cufí
parent 6a1f48bd4e
commit 5a2641b1d7
4 changed files with 36 additions and 0 deletions

View file

@ -18,6 +18,7 @@ extern "C" {
#endif
void nsi_handle_cmd_line(int argc, char *argv[]);
void nsi_register_extra_args(int argc, char *argv[]);
#ifdef __cplusplus
}

View file

@ -33,6 +33,7 @@ int nsi_host_open(const char *pathname, int flags);
/* int nsi_host_printf (const char *fmt, ...); Use the nsi_tracing.h equivalents */
long nsi_host_random(void);
long nsi_host_read(int fd, void *buffer, unsigned long size);
void *nsi_host_realloc(void *ptr, unsigned long size);
void nsi_host_srandom(unsigned int seed);
char *nsi_host_strdup(const char *s);
long nsi_host_write(int fd, void *buffer, unsigned long size);

View file

@ -56,6 +56,11 @@ long nsi_host_read(int fd, void *buffer, unsigned long size)
return read(fd, buffer, size);
}
void *nsi_host_realloc(void *ptr, unsigned long size)
{
return realloc(ptr, size);
}
void nsi_host_srandom(unsigned int seed)
{
srandom(seed);

View file

@ -18,6 +18,10 @@
static int s_argc, test_argc;
static char **s_argv, **test_argv;
/* Extra "command line options" provided programmatically: */
static int extra_argc;
static char **extra_argv;
static struct args_struct_t *args_struct;
static int used_args;
static int args_aval;
@ -119,6 +123,13 @@ void nsi_handle_cmd_line(int argc, char *argv[])
nsi_cmd_args_set_defaults(args_struct);
for (int i = 0; i < extra_argc; i++) {
if (!nsi_cmd_parse_one_arg(extra_argv[i], args_struct)) {
nsi_cmd_print_switches_help(args_struct);
print_invalid_opt_error(extra_argv[i]);
}
}
for (i = 1; i < argc; i++) {
if ((nsi_cmd_is_option(argv[i], "testargs", 0))) {
@ -134,6 +145,24 @@ void nsi_handle_cmd_line(int argc, char *argv[])
}
}
void nsi_register_extra_args(int argc, char *argv[])
{
int new_size = extra_argc + argc;
extra_argv = realloc(extra_argv, new_size*sizeof(char *));
for (int i = 0; i < argc; i++) {
memcpy(&extra_argv[extra_argc], argv, argc*sizeof(char *));
}
extra_argc += argc;
}
static void clear_extra_args(void)
{
free(extra_argv);
}
NSI_TASK(clear_extra_args, ON_EXIT_PRE, 100);
/**
* The application/test can use this function to inspect all the command line
* arguments