pointer-type args: cast appropriately to be 64-bit compatible

Using void pointers as universal arguments is widely used. However, when
compiling a 64-bit target, the compiler doesn't like when an int is
converted to a pointer and vice versa despite the presence of a cast.
This is due to a width mismatch between ints (32 bits) and pointers
(64 bits). The trick is to cast to a widening integer type such as
intptr_t and then cast to
void*.

When appropriate, the INT_TO_POINTER macro is used instead of this
double cast to make things clearer. The converse with POINTER_TO_INT
is also done which also serves as good code annotations.

While at it, remove unneeded casts to specific pointer types from void*
in the vicinity, and move to typed variable upon function entry to make
the code cleaner.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
This commit is contained in:
Nicolas Pitre 2019-05-21 15:48:45 -04:00 committed by Andrew Boie
commit 6311766d9a
24 changed files with 120 additions and 112 deletions

View file

@ -145,7 +145,7 @@ void philosopher(void *id, void *unused1, void *unused2)
fork_t fork1;
fork_t fork2;
int my_id = (int)id;
int my_id = POINTER_TO_INT(id);
/* Djkstra's solution: always pick up the lowest numbered fork first */
if (is_last_philosopher(my_id)) {
@ -217,8 +217,8 @@ static void start_threads(void)
int prio = new_prio(i);
k_thread_create(&threads[i], &stacks[i][0], STACK_SIZE,
philosopher, (void *)i, NULL, NULL, prio,
K_USER, K_FOREVER);
philosopher, INT_TO_POINTER(i), NULL, NULL,
prio, K_USER, K_FOREVER);
k_object_access_grant(fork(i), &threads[i]);
k_object_access_grant(fork((i + 1) % NUM_PHIL), &threads[i]);

View file

@ -135,7 +135,7 @@ void philosopher(void const *id)
fork_t fork1;
fork_t fork2;
int my_id = (int)id;
int my_id = POINTER_TO_INT(id);
/* Djkstra's solution: always pick up the lowest numbered fork first */
if (is_last_philosopher(my_id)) {
@ -186,7 +186,7 @@ static void start_threads(void)
for (int i = 0; i < NUM_PHIL; i++) {
int prio = new_prio(i);
id = osThreadCreate(osThread(philosopher), (void *)i);
id = osThreadCreate(osThread(philosopher), INT_TO_POINTER(i));
osThreadSetPriority(id, prio);
}
}

View file

@ -171,7 +171,7 @@ void philosopher(void *id)
fork_t fork1;
fork_t fork2;
int my_id = (int)id;
int my_id = POINTER_TO_INT(id);
/* Djkstra's solution: always pick up the lowest numbered fork first */
if (is_last_philosopher(my_id)) {
@ -226,7 +226,7 @@ static void start_threads(void)
for (int i = 0; i < NUM_PHIL; i++) {
int prio = new_prio(i);
thread_attr[i].priority = prio;
osThreadNew(philosopher, (void *)i, &thread_attr[i]);
osThreadNew(philosopher, INT_TO_POINTER(i), &thread_attr[i]);
}
}

View file

@ -1156,9 +1156,9 @@ static void kill_handler(const struct shell *shell)
void shell_thread(void *shell_handle, void *arg_log_backend,
void *arg_log_level)
{
struct shell *shell = (struct shell *)shell_handle;
struct shell *shell = shell_handle;
bool log_backend = (bool)arg_log_backend;
u32_t log_level = (u32_t)arg_log_level;
u32_t log_level = POINTER_TO_UINT(arg_log_level);
int err;
err = shell->iface->api->enable(shell->iface, false);
@ -1220,7 +1220,7 @@ int shell_init(const struct shell *shell, const void *transport_config,
k_tid_t tid = k_thread_create(shell->thread,
shell->stack, CONFIG_SHELL_STACK_SIZE,
shell_thread, (void *)shell, (void *)log_backend,
(void *)init_log_level,
UINT_TO_POINTER(init_log_level),
K_LOWEST_APPLICATION_THREAD_PRIO, 0, K_NO_WAIT);
shell->ctx->tid = tid;

View file

@ -42,7 +42,7 @@ void lifo_thread1(void *par1, void *par2, void *par3)
int element_a[2];
int element_b[2];
int *pelement;
int num_loops = (int) par2;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par1);
@ -82,8 +82,8 @@ void lifo_thread2(void *par1, void *par2, void *par3)
int i;
int element[2];
int *pelement;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
for (i = 0; i < num_loops; i++) {
element[1] = i;
@ -114,8 +114,8 @@ void lifo_thread3(void *par1, void *par2, void *par3)
int i;
int element[2];
int *pelement;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
for (i = 0; i < num_loops; i++) {
element[1] = i;
@ -163,11 +163,11 @@ int lifo_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, lifo_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, lifo_thread2,
(void *) &i, (void *) number_of_loops, NULL,
&i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -197,11 +197,11 @@ int lifo_test(void)
i = 0;
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, lifo_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, lifo_thread3,
(void *) &i, (void *) number_of_loops, NULL,
&i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -229,7 +229,7 @@ int lifo_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, lifo_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
for (i = 0; i < number_of_loops / 2U; i++) {
int element[2];

View file

@ -43,7 +43,7 @@ void fifo_thread1(void *par1, void *par2, void *par3)
int i;
int element[2];
int *pelement;
int num_loops = (int) par2;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par1);
ARG_UNUSED(par3);
@ -76,8 +76,8 @@ void fifo_thread2(void *par1, void *par2, void *par3)
int i;
int element[2];
int *pelement;
int *pcounter = (int *) par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -111,8 +111,8 @@ void fifo_thread3(void *par1, void *par2, void *par3)
int i;
int element[2];
int *pelement;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -163,10 +163,10 @@ int fifo_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, fifo_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, fifo_thread2,
(void *) &i, (void *) number_of_loops, NULL,
&i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -195,10 +195,10 @@ int fifo_test(void)
i = 0;
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, fifo_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, fifo_thread3,
(void *) &i, (void *) number_of_loops, NULL,
&i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -226,10 +226,10 @@ int fifo_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, fifo_thread1,
NULL, (void *) (number_of_loops / 2U), NULL,
NULL, INT_TO_POINTER(number_of_loops / 2U), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, fifo_thread1,
NULL, (void *) (number_of_loops / 2U), NULL,
NULL, INT_TO_POINTER(number_of_loops / 2U), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
for (i = 0; i < number_of_loops / 2U; i++) {
int element[2];

View file

@ -37,7 +37,7 @@ void sema_test_init(void)
void sema_thread1(void *par1, void *par2, void *par3)
{
int i;
int num_loops = (int) par2;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par1);
ARG_UNUSED(par3);
@ -63,7 +63,7 @@ void sema_thread2(void *par1, void *par2, void *par3)
{
int i;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -88,7 +88,7 @@ void sema_thread3(void *par1, void *par2, void *par3)
{
int i;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -127,10 +127,10 @@ int sema_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, sema_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, sema_thread2,
(void *) &i, (void *) number_of_loops, NULL,
(void *) &i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -152,10 +152,10 @@ int sema_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, sema_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, sema_thread3,
(void *) &i, (void *) number_of_loops, NULL,
(void *) &i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -177,7 +177,7 @@ int sema_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, sema_thread1,
NULL, (void *) number_of_loops, NULL,
NULL, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
for (i = 0; i < number_of_loops; i++) {
k_sem_give(&sem1);

View file

@ -41,7 +41,7 @@ void stack_test_init(void)
*/
void stack_thread1(void *par1, void *par2, void *par3)
{
int num_loops = ((int) par2 / 2);
int num_loops = POINTER_TO_INT(par2) / 2;
int i;
u32_t data;
@ -80,8 +80,8 @@ void stack_thread2(void *par1, void *par2, void *par3)
{
int i;
u32_t data;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -112,8 +112,8 @@ void stack_thread3(void *par1, void *par2, void *par3)
{
int i;
u32_t data;
int *pcounter = (int *)par1;
int num_loops = (int) par2;
int *pcounter = par1;
int num_loops = POINTER_TO_INT(par2);
ARG_UNUSED(par3);
@ -161,10 +161,10 @@ int stack_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, stack_thread1,
0, (void *) number_of_loops, NULL,
0, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, stack_thread2,
(void *) &i, (void *) number_of_loops, NULL,
(void *) &i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -188,10 +188,10 @@ int stack_test(void)
i = 0;
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, stack_thread1,
0, (void *) number_of_loops, NULL,
0, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
k_thread_create(&thread_data2, thread_stack2, STACK_SIZE, stack_thread3,
(void *) &i, (void *) number_of_loops, NULL,
(void *) &i, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
t = TIME_STAMP_DELTA_GET(t);
@ -216,7 +216,7 @@ int stack_test(void)
t = BENCH_START();
k_thread_create(&thread_data1, thread_stack1, STACK_SIZE, stack_thread1,
0, (void *) number_of_loops, NULL,
0, INT_TO_POINTER(number_of_loops), NULL,
K_PRIO_COOP(3), 0, K_NO_WAIT);
for (i = 0; i < number_of_loops / 2U; i++) {

View file

@ -39,8 +39,11 @@ struct result result[N_THREADS];
struct k_fifo fifo;
static void errno_thread(int n, int my_errno)
static void errno_thread(void *_n, void *_my_errno, void *_unused)
{
int n = POINTER_TO_INT(_n);
int my_errno = POINTER_TO_INT(_my_errno);
errno = my_errno;
k_sleep(30 - (n * 10));
@ -77,8 +80,8 @@ void test_thread_context(void)
/**TESTPOINT: thread- threads stacks are separate */
for (int ii = 0; ii < N_THREADS; ii++) {
k_thread_create(&threads[ii], stacks[ii], STACK_SIZE,
(k_thread_entry_t) errno_thread,
(void *) ii, (void *) errno_values[ii], NULL,
errno_thread, INT_TO_POINTER(ii),
INT_TO_POINTER(errno_values[ii]), NULL,
K_PRIO_PREEMPT(ii + 5), 0, K_NO_WAIT);
}

View file

@ -22,7 +22,7 @@ volatile u32_t sentinel;
static void offload_function(void *param)
{
u32_t x = (u32_t)param;
u32_t x = POINTER_TO_INT(param);
/* Make sure we're in IRQ context */
zassert_true(z_is_in_isr(), "Not in IRQ context!");

View file

@ -55,7 +55,8 @@ void test_timeout_order(void)
for (ii = 0; ii < NUM_TIMEOUTS; ii++) {
(void)k_thread_create(&threads[ii], stacks[ii], STACKSIZE,
thread, (void *)ii, 0, 0, prio, 0, 0);
thread, INT_TO_POINTER(ii), 0, 0,
prio, 0, 0);
k_timer_init(&timer[ii], 0, 0);
k_sem_init(&sem[ii], 0, 1);
results[ii] = -1;

View file

@ -663,7 +663,7 @@ static void busy_wait_thread(void *mseconds, void *arg2, void *arg3)
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
usecs = (int)mseconds * 1000;
usecs = POINTER_TO_INT(mseconds) * 1000;
TC_PRINT("Thread busy waiting for %d usecs\n", usecs);
k_busy_wait(usecs);
@ -689,7 +689,7 @@ static void busy_wait_thread(void *mseconds, void *arg2, void *arg3)
static void thread_sleep(void *delta, void *arg2, void *arg3)
{
s64_t timestamp;
int timeout = (int)delta;
int timeout = POINTER_TO_INT(delta);
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
@ -711,7 +711,7 @@ static void thread_sleep(void *delta, void *arg2, void *arg3)
/* a thread is started with a delay, then it reports that it ran via a fifo */
static void delayed_thread(void *num, void *arg2, void *arg3)
{
struct timeout_order *timeout = &timeouts[(int)num];
struct timeout_order *timeout = &timeouts[POINTER_TO_INT(num)];
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
@ -738,7 +738,7 @@ static void test_busy_wait(void)
k_thread_create(&timeout_threads[0], timeout_stacks[0],
THREAD_STACKSIZE2, busy_wait_thread,
(void *)(intptr_t) timeout, NULL,
INT_TO_POINTER(timeout), NULL,
NULL, K_PRIO_COOP(THREAD_PRIORITY), 0, 0);
rv = k_sem_take(&reply_timeout, timeout * 2);
@ -765,7 +765,7 @@ static void test_k_sleep(void)
k_thread_create(&timeout_threads[0], timeout_stacks[0],
THREAD_STACKSIZE2, thread_sleep,
(void *)(intptr_t) timeout, NULL,
INT_TO_POINTER(timeout), NULL,
NULL, K_PRIO_COOP(THREAD_PRIORITY), 0, 0);
rv = k_sem_take(&reply_timeout, timeout * 2);
@ -779,8 +779,7 @@ static void test_k_sleep(void)
k_thread_create(&timeout_threads[i], timeout_stacks[i],
THREAD_STACKSIZE2,
delayed_thread,
(void *)i,
NULL, NULL,
INT_TO_POINTER(i), NULL, NULL,
K_PRIO_COOP(5), 0, timeouts[i].timeout);
}
for (i = 0; i < NUM_TIMEOUT_THREADS; i++) {
@ -815,7 +814,7 @@ static void test_k_sleep(void)
id = k_thread_create(&timeout_threads[i], timeout_stacks[i],
THREAD_STACKSIZE2, delayed_thread,
(void *)i, NULL, NULL,
INT_TO_POINTER(i), NULL, NULL,
K_PRIO_COOP(5), 0, timeouts[i].timeout);
delayed_threads[i] = id;

View file

@ -494,7 +494,7 @@ static void test_timeout_threads_pend_fail_on_fifo(void)
*/
static void test_timeout_setup(void)
{
s32_t ii;
intptr_t ii;
/* Init kernel objects */
k_fifo_init(&fifo_timeout[0]);

View file

@ -429,7 +429,7 @@ static void test_timeout_threads_pend_on_lifo(void)
*/
static void test_para_init(void)
{
s32_t ii;
intptr_t ii;
/* Init kernel objects*/
k_lifo_init(&lifo_timeout[0]);

View file

@ -68,11 +68,13 @@ static void async_put_sema_give(void *p1, void *p2, void *p3)
}
static void mbox_get_waiting_thread(void *thread_number, void *pmbox, void *p3)
static void mbox_get_waiting_thread(void *p1, void *p2, void *p3)
{
int thread_number = POINTER_TO_INT(p1);
struct k_mbox *pmbox = p2;
struct k_mbox_msg mmsg = {0};
switch ((int) thread_number) {
switch (thread_number) {
case 0:
mmsg.rx_source_thread = K_ANY;
break;
@ -98,8 +100,7 @@ static void mbox_get_waiting_thread(void *thread_number, void *pmbox, void *p3)
}
mmsg.size = 0;
zassert_true(k_mbox_get((struct k_mbox *)pmbox,
&mmsg, NULL, K_FOREVER) == 0,
zassert_true(k_mbox_get(pmbox, &mmsg, NULL, K_FOREVER) == 0,
"Failure at thread number %d", thread_number);
}
@ -501,7 +502,7 @@ static void tmbox_get(struct k_mbox *pmbox)
waiting_get_stack[i],
STACK_SIZE,
mbox_get_waiting_thread,
(void *)i, pmbox, NULL,
INT_TO_POINTER(i), pmbox, NULL,
K_PRIO_PREEMPT(0), 0, K_NO_WAIT);
}
/* Create a new thread to trigger the semaphore needed for the

View file

@ -23,7 +23,7 @@ int exec_order[NUM_THREADS];
void worker(void *p1, void *p2, void *p3)
{
int tidx = (int) p1;
int tidx = POINTER_TO_INT(p1);
ARG_UNUSED(p2);
ARG_UNUSED(p3);
@ -54,7 +54,7 @@ void test_deadline(void)
for (i = 0; i < NUM_THREADS; i++) {
k_thread_create(&worker_threads[i],
worker_stacks[i], STACK_SIZE,
worker, (void *)i, NULL, NULL,
worker, INT_TO_POINTER(i), NULL, NULL,
K_LOWEST_APPLICATION_THREAD_PRIO,
0, 0);

View file

@ -236,7 +236,7 @@ void validate_wakeup(int src, int target, k_tid_t last_thread)
void worker(void *p1, void *p2, void *p3)
{
int id = (int)p1;
int id = POINTER_TO_INT(p1);
k_tid_t curr = &worker_threads[id], prev;
ARG_UNUSED(p2);
@ -329,7 +329,7 @@ void test_preempt(void)
k_thread_create(&worker_threads[i],
worker_stacks[i], STACK_SIZE,
worker, (void *)i, NULL, NULL,
worker, INT_TO_POINTER(i), NULL, NULL,
priority, 0, 0);
}

View file

@ -33,15 +33,17 @@ static struct k_thread t[NUM_THREAD];
/* Application thread */
static void thread_tslice(void *p1, void *p2, void *p3)
{
int idx = POINTER_TO_INT(p1);
/* Print New line for last thread */
int thread_parameter = ((int)p1 == (NUM_THREAD - 1)) ? '\n' :
((int)p1 + 'A');
int thread_parameter = (idx == (NUM_THREAD - 1)) ? '\n' :
(idx + 'A');
while (1) {
/* Prining alphabet corresponding to thread*/
TC_PRINT("%c", thread_parameter);
/* Testing if threads are execueted as per priority*/
zassert_true(((int)p1 == thread_idx), NULL);
zassert_true((idx == thread_idx), NULL);
thread_idx = (thread_idx + 1) % (NUM_THREAD);
/* Realease CPU and give chance to Ztest thread to run*/
@ -77,7 +79,7 @@ void test_priority_scheduling(void)
/* Create Threads with different Priority*/
for (int i = 0; i < NUM_THREAD; i++) {
tid[i] = k_thread_create(&t[i], tstacks[i], STACK_SIZE,
thread_tslice, (void *)(intptr_t) i, NULL, NULL,
thread_tslice, INT_TO_POINTER(i), NULL, NULL,
K_PRIO_PREEMPT(BASE_PRIORITY + i), 0, 0);
}

View file

@ -22,13 +22,13 @@ struct k_timer timer;
static void thread_entry(void *p1, void *p2, void *p3)
{
int sleep_ms = (int)p2;
int sleep_ms = POINTER_TO_INT(p2);
if (sleep_ms > 0) {
k_sleep(sleep_ms);
}
int tnum = (int)p1;
int tnum = POINTER_TO_INT(p1);
tdata[tnum].executed = 1;
}
@ -57,7 +57,8 @@ static void spawn_threads(int sleep_sec)
for (int i = 0; i < THREADS_NUM; i++) {
tdata[i].tid = k_thread_create(&tthread[i], tstacks[i],
STACK_SIZE, thread_entry,
(void *)i, (void *)sleep_sec,
INT_TO_POINTER(i),
INT_TO_POINTER(sleep_sec),
NULL, tdata[i].priority, 0, 0);
}
}

View file

@ -35,9 +35,11 @@ static int thread_idx;
static void thread_tslice(void *p1, void *p2, void *p3)
{
int idx = POINTER_TO_INT(p1);
/*Print New line for last thread*/
int thread_parameter = ((int)p1 == (NUM_THREAD - 1)) ? '\n' :
((int)p1 + 'A');
int thread_parameter = (idx == (NUM_THREAD - 1)) ? '\n' :
(idx + 'A');
s64_t expected_slice_min = __ticks_to_ms(z_ms_to_ticks(SLICE_SIZE));
s64_t expected_slice_max = __ticks_to_ms(z_ms_to_ticks(SLICE_SIZE) + 1);
@ -50,7 +52,7 @@ static void thread_tslice(void *p1, void *p2, void *p3)
*/
zassert_true(((tdelta >= expected_slice_min) &&
(tdelta <= expected_slice_max) &&
((int)p1 == thread_idx)), NULL);
(idx == thread_idx)), NULL);
thread_idx = (thread_idx + 1) % (NUM_THREAD);
/* Keep the current thread busy for more than one slice,
@ -89,7 +91,8 @@ void test_slice_scheduling(void)
/* create threads with equal preemptive priority*/
for (int i = 0; i < NUM_THREAD; i++) {
tid[i] = k_thread_create(&t[i], tstacks[i], STACK_SIZE,
thread_tslice, (void *)(intptr_t) i, NULL, NULL,
thread_tslice,
INT_TO_POINTER(i), NULL, NULL,
K_PRIO_PREEMPT(BASE_PRIORITY), 0, 0);
}

View file

@ -619,20 +619,19 @@ void test_sem_measure_timeout_from_thread(void)
}
void test_sem_multiple_take_and_timeouts_helper(void *timeout,
void *p2,
void *p3)
void test_sem_multiple_take_and_timeouts_helper(void *p1, void *p2, void *p3)
{
int timeout = POINTER_TO_INT(p1);
u32_t start_ticks, end_ticks;
size_t bytes_written;
start_ticks = k_uptime_get();
k_sem_take(&simple_sem, (int)timeout);
k_sem_take(&simple_sem, timeout);
end_ticks = k_uptime_get();
zassert_true((end_ticks - start_ticks >= (int)timeout),
zassert_true((end_ticks - start_ticks >= timeout),
"time missmatch. expected less than %d ,got %d\n",
timeout, end_ticks - start_ticks);
@ -661,7 +660,7 @@ void test_sem_multiple_take_and_timeouts(void)
k_thread_create(&multiple_tid[i],
multiple_stack[i], STACK_SIZE,
test_sem_multiple_take_and_timeouts_helper,
(void *)K_SECONDS(i + 1), NULL, NULL,
INT_TO_POINTER(K_SECONDS(i + 1)), NULL, NULL,
K_PRIO_PREEMPT(1), 0, K_NO_WAIT);
}
@ -679,25 +678,25 @@ void test_sem_multiple_take_and_timeouts(void)
}
void test_sem_multi_take_timeout_diff_sem_helper(void *timeout,
void *sema,
void *p3)
void test_sem_multi_take_timeout_diff_sem_helper(void *p1, void *p2, void *p3)
{
int timeout = POINTER_TO_INT(p1);
struct k_sem *sema = p2;
u32_t start_ticks, end_ticks;
s32_t ret_value;
size_t bytes_written;
struct timeout_info info = {
.timeout = (u32_t) timeout,
.sema = (struct k_sem *)sema
.timeout = timeout,
.sema = sema
};
start_ticks = k_uptime_get();
ret_value = k_sem_take((struct k_sem *)sema, (int)timeout);
ret_value = k_sem_take(sema, timeout);
end_ticks = k_uptime_get();
zassert_true((end_ticks - start_ticks >= (int)timeout),
zassert_true((end_ticks - start_ticks >= timeout),
"time missmatch. expected less than %d, got %d\n",
timeout, end_ticks - start_ticks);
@ -736,9 +735,8 @@ void test_sem_multi_take_timeout_diff_sem(void)
k_thread_create(&multiple_tid[i],
multiple_stack[i], STACK_SIZE,
test_sem_multi_take_timeout_diff_sem_helper,
(void *)seq_info[i].timeout,
(void *)seq_info[i].sema,
NULL,
INT_TO_POINTER(seq_info[i].timeout),
seq_info[i].sema, NULL,
K_PRIO_PREEMPT(1), 0, K_NO_WAIT);
}

View file

@ -76,7 +76,7 @@ static void thread_name_entry(void)
static void customdata_entry(void *p1, void *p2, void *p3)
{
u32_t data = 1U;
long data = 1U;
zassert_is_null(k_thread_custom_data_get(), NULL);
while (1) {
@ -84,7 +84,7 @@ static void customdata_entry(void *p1, void *p2, void *p3)
/* relinguish cpu for a while */
k_sleep(50);
/** TESTPOINT: custom data comparison */
zassert_equal(data, (u32_t)k_thread_custom_data_get(), NULL);
zassert_equal(data, (long)k_thread_custom_data_get(), NULL);
data++;
}
}

View file

@ -19,9 +19,9 @@ static ZTEST_BMEM int spawn_prio;
static void thread_entry_params(void *p1, void *p2, void *p3)
{
/* checkpoint: check parameter 1, 2, 3 */
zassert_equal((char *)p1, tp1, NULL);
zassert_equal((int)p2, tp2, NULL);
zassert_equal((struct k_sema *)p3, tp3, NULL);
zassert_equal(p1, tp1, NULL);
zassert_equal(POINTER_TO_INT(p2), tp2, NULL);
zassert_equal(p3, tp3, NULL);
}
static void thread_entry_priority(void *p1, void *p2, void *p3)
@ -50,7 +50,7 @@ static void thread_entry_delay(void *p1, void *p2, void *p3)
void test_threads_spawn_params(void)
{
k_thread_create(&tdata, tstack, STACK_SIZE, thread_entry_params,
(void *)tp1, (void *)tp2, (void *)tp3, 0,
tp1, INT_TO_POINTER(tp2), tp3, 0,
K_USER, 0);
k_sleep(100);
}

View file

@ -129,7 +129,7 @@ static struct {
/*entry of contexts*/
static void tringbuf_put(void *p)
{
int index = (int)p;
int index = POINTER_TO_INT(p);
/**TESTPOINT: ring buffer put*/
int ret = ring_buf_item_put(pbuf, data[index].type, data[index].value,
data[index].buffer, data[index].length);
@ -142,7 +142,7 @@ static void tringbuf_get(void *p)
u16_t type;
u8_t value, size32 = DATA_MAX_SIZE;
u32_t rx_data[DATA_MAX_SIZE];
int ret, index = (int)p;
int ret, index = POINTER_TO_INT(p);
/**TESTPOINT: ring buffer get*/
ret = ring_buf_item_get(pbuf, &type, &value, rx_data, &size32);