Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: mbox_api: testcase test_mbox_data_get_null has some bugs. #33114

Closed
IRISZZW opened this issue Mar 8, 2021 · 1 comment · Fixed by #33121
Closed

tests: mbox_api: testcase test_mbox_data_get_null has some bugs. #33114

IRISZZW opened this issue Mar 8, 2021 · 1 comment · Fixed by #33121
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@IRISZZW
Copy link
Contributor

IRISZZW commented Mar 8, 2021

relative pull request: #31012

we can't k_mbox_data_get from a _syncing_thread who didn't send a msg.

sending_thread->base.swap_data not initialized.

zephyr/kernel/mailbox.c

Lines 189 to 191 in 1ce264e

sending_thread = rx_msg->_syncing_thread;
rx_msg->_syncing_thread = NULL;
tx_msg = (struct k_mbox_msg *)sending_thread->base.swap_data;

static void thread_mbox_data_get_null(void *p1, void *p2, void *p3)
{
	struct k_mbox_msg get_msg = {0};
	char str_data[] = "it string for get msg test";

	get_msg.size = 16;
	get_msg.rx_source_thread = K_ANY;
	get_msg.tx_block.data = str_data;
	get_msg._syncing_thread = receiver_tid;

	k_mbox_data_get(&get_msg, NULL);

	get_msg._syncing_thread = NULL;
	k_mbox_data_get(&get_msg, NULL);
	k_sem_give(&end_sema);
}

relative codes

void test_mbox_data_get_null(void)
{
k_sem_reset(&end_sema);
receiver_tid = k_thread_create(&tdata, tstack, STACK_SIZE,
thread_mbox_data_get_null,
NULL, NULL, NULL,
K_PRIO_PREEMPT(0), 0,
K_NO_WAIT);
k_sem_take(&end_sema, K_FOREVER);
/*test case teardown*/
k_thread_abort(receiver_tid);
}

K_MBOX_DEFINE(send_mbox);
static void thread_mbox_data_get_null(void *p1, void *p2, void *p3)
{
struct k_mbox_msg get_msg = {0};
char str_data[] = "it string for get msg test";
get_msg.size = 16;
get_msg.rx_source_thread = K_ANY;
get_msg.tx_block.data = str_data;
get_msg._syncing_thread = receiver_tid;
k_mbox_data_get(&get_msg, NULL);
get_msg._syncing_thread = NULL;
k_mbox_data_get(&get_msg, NULL);
k_sem_give(&end_sema);
}

zephyr/kernel/mailbox.c

Lines 336 to 350 in 1ce264e

void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer)
{
/* handle case where data is to be discarded */
if (buffer == NULL) {
rx_msg->size = 0;
mbox_message_dispose(rx_msg);
return;
}
/* copy message data to buffer, then dispose of message */
if ((rx_msg->tx_data != NULL) && (rx_msg->size > 0)) {
(void)memcpy(buffer, rx_msg->tx_data, rx_msg->size);
}
mbox_message_dispose(rx_msg);
}

zephyr/kernel/mailbox.c

Lines 174 to 194 in 1ce264e

static void mbox_message_dispose(struct k_mbox_msg *rx_msg)
{
struct k_thread *sending_thread;
struct k_mbox_msg *tx_msg;
/* do nothing if message was disposed of when it was received */
if (rx_msg->_syncing_thread == NULL) {
return;
}
if (rx_msg->tx_block.data != NULL) {
rx_msg->tx_block.data = NULL;
}
/* recover sender info */
sending_thread = rx_msg->_syncing_thread;
rx_msg->_syncing_thread = NULL;
tx_msg = (struct k_mbox_msg *)sending_thread->base.swap_data;
/* update data size field for sender */
tx_msg->size = rx_msg->size;

@IRISZZW IRISZZW added the bug The issue is a bug, or the PR is fixing a bug label Mar 8, 2021
@IRISZZW
Copy link
Contributor Author

IRISZZW commented Mar 8, 2021

this testcase will fail in nsim_em:

START - test_mbox_data_get_null
E: ***** Exception vector: 0x6, cause code: 0x2, parameter 0x2
E: Address 0x80000824
E: EV_ProtV
E: Memory write protection violation (stack checking scheme)
E:  r0: 0x80000168  r1: 0x00000000  r2: 0x80000820  r3: 0x00000000
E:  r4: 0xffffffff  r5: 0x00000000  r6: 0x00000000  r7: 0x00000000
E:  r8: 0x00000000  r9: 0x00000000 r10: 0x00000000 r11: 0x00000000
E: r12: 0x00000000 r13: 0x00000033  pc: 0x0000360e
E:  blink: 0x00000a12 status32: 0x80084406
E: lp_end: 0x00000000 lp_start: 0x00000000 lp_count: 0x00000000
E: >>> ZEPHYR FATAL ERROR 2: Stack overflow on CPU 0
E: Current thread: 0x80000168 (unknown)
E: Halting system

how to reproduce:

  1. west build -b nsim_em -d build tests/kernel/mbox/mbox_api/
  2. west flash

@nashif nashif added the priority: medium Medium impact/importance bug label Mar 8, 2021
KangJianX added a commit to KangJianX/zephyr that referenced this issue Mar 16, 2021
Fix issue zephyrproject-rtos#33114 zephyrproject-rtos#33120. Modify the testcase that run failed on iotdk
and nsim. This testing do not need receive thread ID when invoke
k_mbox_data_get() with NULL param. The testcase purpose is invoke
this API with NULL buffer and NULL receive_id. It will cause fatal
error if use a uninitialize receive id.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
galak pushed a commit that referenced this issue Mar 16, 2021
Fix issue #33114 #33120. Modify the testcase that run failed on iotdk
and nsim. This testing do not need receive thread ID when invoke
k_mbox_data_get() with NULL param. The testcase purpose is invoke
this API with NULL buffer and NULL receive_id. It will cause fatal
error if use a uninitialize receive id.

Signed-off-by: Jian Kang <jianx.kang@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants