diff --git a/testing/ostest/ostest_main.c b/testing/ostest/ostest_main.c index 26f6f7d7c..c0f37dbc9 100644 --- a/testing/ostest/ostest_main.c +++ b/testing/ostest/ostest_main.c @@ -371,7 +371,7 @@ static int user_main(int argc, char *argv[]) #endif #if !defined(CONFIG_DISABLE_PTHREAD) && defined(__KERNEL__) && \ - (defined(CONFIG_SCHED_LPWORK) || defined(CONFIG_SCHED_HPWORK)) + defined(CONFIG_SCHED_WORKQUEUE) /* Check work queues */ printf("\nuser_main: wqueue test\n"); diff --git a/testing/ostest/wqueue.c b/testing/ostest/wqueue.c index 06f8b369e..f8b68dd13 100644 --- a/testing/ostest/wqueue.c +++ b/testing/ostest/wqueue.c @@ -33,7 +33,7 @@ #include -#if defined(CONFIG_SCHED_LPWORK) || defined(CONFIG_SCHED_HPWORK) +#ifdef CONFIG_SCHED_WORKQUEUE /**************************************************************************** * Pre-processor Definitions @@ -74,16 +74,25 @@ static void count_worker(FAR void *arg) static FAR void *tester(FAR void *arg) { - int interval = (intptr_t)arg; - int i; + FAR void **val = arg; struct work_s work; + int i; memset(&work, 0, sizeof(work)); for (i = 0; i < TEST_COUNT; i++) { - work_queue(TEST_QUEUE, &work, empty_worker, NULL, 0); - work_cancel(TEST_QUEUE, &work); - usleep(interval); + if (val[1] != NULL) + { + work_queue_wq(val[1], &work, empty_worker, NULL, 0); + work_cancel_wq(val[1], &work); + } + else + { + work_queue((int)(uintptr_t)val[0], &work, empty_worker, NULL, 0); + work_cancel((int)(uintptr_t)val[0], &work); + } + + usleep((int)(uintptr_t)val[2]); } usleep(SLEEP_TIME); /* Wait for workers to run. */ @@ -92,6 +101,7 @@ static FAR void *tester(FAR void *arg) static FAR void *verifier(FAR void *arg) { + FAR void **val = arg; sem_t sem; sem_t call_sem; int call_count; @@ -104,13 +114,28 @@ static FAR void *verifier(FAR void *arg) /* Queue sleep worker. */ - work_queue(TEST_QUEUE, &work[0], sleep_worker, &sem, 0); + if (val[1] != NULL) + { + work_queue_wq(val[1], &work[0], sleep_worker, &sem, 0); + } + else + { + work_queue((int)(uintptr_t)val[0], &work[0], sleep_worker, &sem, 0); + } - /* Queue count workers when TEST_QUEUE is busy. */ + /* Queue count workers when qid is busy. */ for (i = 1; i <= VERIFY_COUNT; i++) { - work_queue(TEST_QUEUE, &work[i], count_worker, &call_sem, 0); + if (val[1] != NULL) + { + work_queue_wq(val[1], &work[i], count_worker, &call_sem, 0); + } + else + { + work_queue((int)(uintptr_t)val[0], &work[i], + count_worker, &call_sem, 0); + } } /* Wait for sleep worker to run. */ @@ -138,12 +163,14 @@ static FAR void *verifier(FAR void *arg) return NULL; } -static void run_once(int interval, int priority_test, int priority_verify) +static void run_once(int qid, FAR void *wq, int interval, + int priority_test, int priority_verify) { pthread_t thread; pthread_attr_t attr; struct sched_param sparam; int status; + FAR void *val[3]; status = pthread_attr_init(&attr); if (status != 0) @@ -163,8 +190,10 @@ static void run_once(int interval, int priority_test, int priority_verify) "status=%d\n", status); } - status = pthread_create(&thread, &attr, tester, - (FAR void *)(intptr_t)interval); + val[0] = (FAR void *)(uintptr_t)qid; + val[1] = wq; + val[2] = (FAR void *)(uintptr_t)interval; + status = pthread_create(&thread, &attr, tester, val); if (status != 0) { printf("wqueue_test: pthread_create failed for tester, " @@ -196,7 +225,9 @@ static void run_once(int interval, int priority_test, int priority_verify) "status=%d\n", status); } - status = pthread_create(&thread, &attr, verifier, NULL); + val[0] = (FAR void *)(uintptr_t)qid; + val[1] = wq; + status = pthread_create(&thread, &attr, verifier, val); if (status != 0) { printf("wqueue_test: pthread_create failed for verifier, " @@ -211,11 +242,7 @@ static void run_once(int interval, int priority_test, int priority_verify) } } -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -void wqueue_test(void) +void wqueue_priority_test(int qid, FAR void *wq, int prio) { int interval; int priority_test; @@ -223,18 +250,50 @@ void wqueue_test(void) for (interval = 0; interval <= 1; interval++) { - for (priority_test = TEST_QUEUE_PRIORITY - 1; - priority_test <= TEST_QUEUE_PRIORITY + 1; + for (priority_test = prio - 1; + priority_test <= prio + 1; priority_test++) { - for (priority_verify = TEST_QUEUE_PRIORITY - 1; - priority_verify <= TEST_QUEUE_PRIORITY + 1; + for (priority_verify = prio - 1; + priority_verify <= prio + 1; priority_verify++) { - run_once(interval, priority_test, priority_verify); + run_once(qid, wq, interval, priority_test, priority_verify); } } } } -#endif /* CONFIG_SCHED_LPWORK || CONFIG_SCHED_HPWORK */ +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void wqueue_test(void) +{ + FAR void *wq; + int i; + +#ifdef CONFIG_SCHED_HPWORK + printf("wqueue_test: HPWORK\n"); + wqueue_priority_test(HPWORK, NULL, CONFIG_SCHED_HPWORKPRIORITY); + printf("wqueue_test: HPWORK done\n"); +#endif + +#ifdef CONFIG_SCHED_LPWORK + printf("wqueue_test: LPWORK\n"); + wqueue_priority_test(LPWORK, NULL, CONFIG_SCHED_LPWORKPRIORITY); + printf("wqueue_test: HPWORK done\n"); +#endif + + for (i = 1; i < 3; i++) + { + printf("wqueue_test: test %d\n", i); + wq = work_queue_create("test", 100, 2048, i); + DEBUGASSERT(wq != NULL); + wqueue_priority_test(0, wq, 100); + work_queue_free(wq); + printf("wqueue_test: test %d done\n", i); + } +} + +#endif /* CONFIG_SCHED_WORKQUEUE */