Skip to content

Commit 057e4cb

Browse files
pabigotnashif
authored andcommitted
tests: kernel: work_queue: remove unpassable tests
The original implementation of resubmitting a delayed work item removed the item not only from the schedule, but also from the work queue if it was already in the work queue. This is not the semantics of the new implementation, which will leave the work item in the queue if the previous deadline had elapsed and the work item was submitted. The new semantics is preferred, as it improves consistency with SMP targets where once an item has been submitted to a queue it can be run at any time, and scheduling it again doesn't magically reverse the submission. The original test would never have passed on an SMP target, and passes now on qemu_x86 only because the timing granularity prevents the work item from being both scheduled and queued at the same time. The problematic test application is the one developed for the original implementation. Correct functioning of the new implementation is fully verified by the sibling work test. That the legacy API does not precisely preserve the original behavior where it was not consistent between SMP and uniprocessor targets is regrettable, but unavoidable. Remove the tests that cannot pass reliably. Also fix a missing reset() after a test. Signed-off-by: Peter Bigot <[email protected]>
1 parent 0bcb008 commit 057e4cb

File tree

1 file changed

+1
-89
lines changed
  • tests/kernel/workq/work_queue/src

1 file changed

+1
-89
lines changed

tests/kernel/workq/work_queue/src/main.c

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static void test_delayed_cancel(void)
314314

315315
TC_PRINT(" - Checking results\n");
316316
check_results(0);
317+
reset_results();
317318
}
318319

319320
static void test_delayed_pending(void)
@@ -347,93 +348,6 @@ static void test_delayed_pending(void)
347348
reset_results();
348349
}
349350

350-
static void delayed_resubmit_work_handler(struct k_work *work)
351-
{
352-
struct delayed_test_item *ti =
353-
CONTAINER_OF(work, struct delayed_test_item, work);
354-
355-
results[num_results++] = ti->key;
356-
357-
if (ti->key < NUM_TEST_ITEMS) {
358-
ti->key++;
359-
TC_PRINT(" - Resubmitting delayed work\n");
360-
k_delayed_work_submit(&ti->work, K_MSEC(WORK_ITEM_WAIT));
361-
}
362-
}
363-
364-
/**
365-
* @brief Test delayed resubmission of work queue item
366-
*
367-
* @ingroup kernel_workqueue_tests
368-
*
369-
* @see k_delayed_work_init(), k_delayed_work_submit()
370-
*/
371-
static void test_delayed_resubmit(void)
372-
{
373-
TC_PRINT("Starting delayed resubmit test\n");
374-
375-
delayed_tests[0].key = 1;
376-
k_delayed_work_init(&delayed_tests[0].work,
377-
delayed_resubmit_work_handler);
378-
379-
TC_PRINT(" - Submitting delayed work\n");
380-
k_delayed_work_submit(&delayed_tests[0].work, K_MSEC(WORK_ITEM_WAIT));
381-
382-
TC_PRINT(" - Waiting for work to finish\n");
383-
k_msleep(CHECK_WAIT);
384-
385-
TC_PRINT(" - Checking results\n");
386-
check_results(NUM_TEST_ITEMS);
387-
reset_results();
388-
}
389-
390-
static void coop_delayed_work_resubmit(void)
391-
{
392-
int i;
393-
394-
for (i = 0; i < NUM_TEST_ITEMS; i++) {
395-
TC_PRINT(" - Resubmitting delayed work with 1 ms\n");
396-
k_delayed_work_submit(&delayed_tests[0].work, K_MSEC(1));
397-
398-
/* Busy wait 1 ms to force a clash with workqueue */
399-
#if defined(CONFIG_ARCH_POSIX)
400-
k_busy_wait(1000);
401-
#else
402-
volatile uint32_t uptime;
403-
uptime = k_uptime_get_32();
404-
while (k_uptime_get_32() == uptime) {
405-
}
406-
#endif
407-
}
408-
}
409-
410-
411-
/**
412-
* @brief Test delayed resubmission of work queue thread
413-
*
414-
* @ingroup kernel_workqueue_tests
415-
*
416-
* @see k_delayed_work_init()
417-
*/
418-
static void test_delayed_resubmit_thread(void)
419-
{
420-
TC_PRINT("Starting delayed resubmit from coop thread test\n");
421-
422-
delayed_tests[0].key = 1;
423-
k_delayed_work_init(&delayed_tests[0].work, delayed_work_handler);
424-
425-
k_thread_create(&co_op_data, co_op_stack, STACK_SIZE,
426-
(k_thread_entry_t)coop_delayed_work_resubmit,
427-
NULL, NULL, NULL, K_PRIO_COOP(10), 0, K_NO_WAIT);
428-
429-
TC_PRINT(" - Waiting for work to finish\n");
430-
k_msleep(WORK_ITEM_WAIT_ALIGNED);
431-
432-
TC_PRINT(" - Checking results\n");
433-
check_results(1);
434-
reset_results();
435-
}
436-
437351
/**
438352
* @brief Test delayed work items
439353
*
@@ -807,8 +721,6 @@ void test_main(void)
807721
ztest_1cpu_unit_test(test_sequence),
808722
ztest_1cpu_unit_test(test_resubmit),
809723
ztest_1cpu_unit_test(test_delayed),
810-
ztest_1cpu_unit_test(test_delayed_resubmit),
811-
ztest_1cpu_unit_test(test_delayed_resubmit_thread),
812724
ztest_1cpu_unit_test(test_delayed_cancel),
813725
ztest_1cpu_unit_test(test_delayed_pending),
814726
ztest_1cpu_unit_test(test_triggered),

0 commit comments

Comments
 (0)