/** * * @brief Test some context routines from a preemptible thread * * This routines tests the k_current_get() and * k_is_in_isr() routines from both a preemtible thread and an ISR (that * interrupted a preemtible thread). Checking those routines with cooperative * threads are done elsewhere. * * @return TC_PASS on success * @return TC_FAIL on failure */ static int test_kernel_ctx_task(void) { k_tid_t self_thread_id; TC_PRINT("Testing k_current_get() from an ISR and task\n"); self_thread_id = k_current_get(); isr_info.command = THREAD_SELF_CMD; isr_info.error = 0; /* isr_info is modified by the isr_handler routine */ isr_handler_trigger(); if (isr_info.error || isr_info.data != (void *)self_thread_id) { /* * Either the ISR detected an error, or the ISR context ID * does not match the interrupted task's thread ID. */ return TC_FAIL; } TC_PRINT("Testing k_is_in_isr() from an ISR\n"); isr_info.command = EXEC_CTX_TYPE_CMD; isr_info.error = 0; isr_handler_trigger(); if (isr_info.error || isr_info.value != K_ISR) { return TC_FAIL; } TC_PRINT("Testing k_is_in_isr() from a preemtible thread\n"); if (k_is_in_isr() || _current->base.prio < 0) { return TC_FAIL; } return TC_PASS; }
/** * * @brief Test some context routines from a preemptible thread * * This routines tests the k_current_get() and * k_is_in_isr() routines from both a preemtible thread and an ISR (that * interrupted a preemtible thread). Checking those routines with cooperative * threads are done elsewhere. * * @return TC_PASS on success * @return TC_FAIL on failure */ static int test_kernel_ctx_task(void) { k_tid_t self_thread_id; TC_PRINT("Testing k_current_get() from an ISR and task\n"); self_thread_id = k_current_get(); isr_info.command = THREAD_SELF_CMD; isr_info.error = 0; /* isr_info is modified by the isr_handler routine */ isr_handler_trigger(); if (isr_info.error) { TC_ERROR("ISR detected an error\n"); return TC_FAIL; } if (isr_info.data != (void *)self_thread_id) { TC_ERROR("ISR context ID mismatch\n"); return TC_FAIL; } TC_PRINT("Testing k_is_in_isr() from an ISR\n"); isr_info.command = EXEC_CTX_TYPE_CMD; isr_info.error = 0; isr_handler_trigger(); if (isr_info.error) { TC_ERROR("ISR detected an error\n"); return TC_FAIL; } if (isr_info.value != K_ISR) { TC_ERROR("isr_info.value was not K_ISR\n"); return TC_FAIL; } TC_PRINT("Testing k_is_in_isr() from a preemptible thread\n"); if (k_is_in_isr()) { TC_ERROR("Should not be in ISR context\n"); return TC_FAIL; } if (_current->base.prio < 0) { TC_ERROR("Current thread should have preemptible priority\n"); return TC_FAIL; } return TC_PASS; }
/** * * @brief Test the various context/thread routines from a cooperative thread * * This routines tests the k_current_get and * k_is_in_isr() routines from both a thread and an ISR (that interrupted a * cooperative thread). Checking those routines with preemptible threads are * done elsewhere. * * This routine may set <thread_detected_error> to the following values: * 1 - if thread ID matches that of the task * 2 - if thread ID taken during ISR does not match that of the thread * 3 - k_is_in_isr() when called from an ISR is false * 4 - k_is_in_isr() when called from a thread is true * 5 - if thread is not a cooperative thread * * @return TC_PASS on success * @return TC_FAIL on failure */ static int test_kernel_thread(k_tid_t task_thread_id) { k_tid_t self_thread_id; self_thread_id = k_current_get(); if (self_thread_id == task_thread_id) { thread_detected_error = 1; return TC_FAIL; } isr_info.command = THREAD_SELF_CMD; isr_info.error = 0; isr_handler_trigger(); if (isr_info.error || isr_info.data != (void *)self_thread_id) { /* * Either the ISR detected an error, or the ISR context ID * does not match the interrupted thread's thread ID. */ thread_detected_error = 2; return TC_FAIL; } isr_info.command = EXEC_CTX_TYPE_CMD; isr_info.error = 0; isr_handler_trigger(); if (isr_info.error || (isr_info.value != K_ISR)) { thread_detected_error = 3; return TC_FAIL; } if (k_is_in_isr()) { thread_detected_error = 4; return TC_FAIL; } if (_current->base.prio >= 0) { thread_detected_error = 5; return TC_FAIL; } return TC_PASS; }