@@ -33,6 +33,10 @@ static struct k_thread test_thread;
3333static struct k_thread test_loprio_thread ;
3434K_THREAD_STACK_DEFINE (test_stack , STACK_SIZE );
3535K_THREAD_STACK_DEFINE (test_loprio_stack , STACK_SIZE );
36+ K_MSGQ_DEFINE (msgq_high_prio_thread , sizeof (unsigned int ), 4 , 4 );
37+ static K_THREAD_STACK_DEFINE (high_prio_stack_area , 4096 ) ;
38+ static struct k_thread high_prio_data ;
39+ static volatile bool wake_up_by_poll = true;
3640
3741/**
3842 * @brief Test cases to verify poll
@@ -779,6 +783,40 @@ void poll_test_grant_access(void)
779783 & test_stack , & multi_sem , & multi_reply );
780784}
781785
786+
787+ static void high_prio_main (void * param1 , void * param2 , void * param3 )
788+ {
789+ static struct k_poll_event poll_events [1 ];
790+
791+ /* Setup wake-up for message queue */
792+ k_poll_event_init (& poll_events [0 ], K_POLL_TYPE_MSGQ_DATA_AVAILABLE , K_POLL_MODE_NOTIFY_ONLY ,
793+ & msgq_high_prio_thread );
794+ (void )k_poll (poll_events , 1 , K_FOREVER );
795+
796+ zassert_equal (poll_events [0 ].state , K_POLL_STATE_MSGQ_DATA_AVAILABLE );
797+ zassert_equal (wake_up_by_poll , true);
798+ }
799+
800+ ZTEST (poll_api_1cpu , test_poll_msgq )
801+ {
802+ int low_prio_thread_priority = 1 ;
803+ int high_prio_thread_priority = -2 ;
804+ unsigned int data_to_high_prio = 0x1234 ;
805+
806+ k_thread_priority_set (k_current_get (), low_prio_thread_priority );
807+
808+ /* Create high priority thread */
809+ (void )k_thread_create (& high_prio_data , high_prio_stack_area ,
810+ K_THREAD_STACK_SIZEOF (high_prio_stack_area ), high_prio_main , NULL ,
811+ NULL , NULL , high_prio_thread_priority , 0 , K_NO_WAIT );
812+ k_sleep (K_MSEC (1 ));
813+ /* Send message to high-priority thread */
814+ (void )k_msgq_put (& msgq_high_prio_thread , & data_to_high_prio , K_NO_WAIT );
815+
816+ /* low priority thread should not execute here before wake up high priority task */
817+ wake_up_by_poll = false;
818+ }
819+
782820ZTEST (poll_api_1cpu , test_poll_zero_events )
783821{
784822 struct k_poll_event event ;
0 commit comments