wengzhe commented on code in PR #1665: URL: https://github.com/apache/nuttx-apps/pull/1665#discussion_r1143012482
########## testing/ostest/wqueue.c: ########## @@ -0,0 +1,188 @@ +/**************************************************************************** + * apps/testing/ostest/wqueue.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <assert.h> +#include <pthread.h> +#include <sched.h> +#include <semaphore.h> +#include <stdio.h> +#include <unistd.h> + +#include <nuttx/wqueue.h> + +#if defined(CONFIG_SCHED_LPWORK) || defined(CONFIG_SCHED_HPWORK) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define SLEEP_TIME (100 * 1000) +#define TEST_COUNT (1000) +#define VERIFY_COUNT (100) + +#ifdef CONFIG_SCHED_LPWORK +# define TEST_QUEUE LPWORK +# define TEST_QUEUE_PRIORITY CONFIG_SCHED_LPWORKPRIORITY +#else +# define TEST_QUEUE HPWORK +# define TEST_QUEUE_PRIORITY CONFIG_SCHED_HPWORKPRIORITY +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static void empty_worker(FAR void *arg) +{ +} + +static void sleep_worker(FAR void *arg) +{ + FAR sem_t *sem = arg; + usleep(SLEEP_TIME); + sem_post(sem); +} + +static void count_worker(FAR void *arg) +{ + FAR sem_t *sem = arg; + sem_post(sem); +} + +static FAR void *tester(FAR void *arg) +{ + int interval = (intptr_t)arg; + int i; + struct work_s work; + + 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); + } + + usleep(SLEEP_TIME); /* Wait for workers to run. */ + return NULL; +} + +static FAR void *verifier(FAR void *arg) +{ + sem_t sem; + sem_t call_sem; + int call_count; + int i; + struct work_s work[VERIFY_COUNT + 1]; + + sem_init(&sem, 0, 0); + sem_init(&call_sem, 0, 0); + memset(&work, 0, sizeof(work)); + + /* Queue sleep worker. */ + + work_queue(TEST_QUEUE, &work[0], sleep_worker, &sem, 0); + + /* Queue count workers when TEST_QUEUE is busy. */ + + for (i = 1; i <= VERIFY_COUNT; i++) + { + work_queue(TEST_QUEUE, &work[i], count_worker, &call_sem, 0); + } + + /* Wait for sleep worker to run. */ + + sem_wait(&sem); + + /* Wait for count workers to run. */ + + usleep(SLEEP_TIME); + + sem_getvalue(&call_sem, &call_count); + printf("wqueue_test: call = %d, expect = %d\n", call_count, VERIFY_COUNT); + + for (i = 0; i < VERIFY_COUNT; i++) + { + ASSERT(work[i].worker == NULL); + } + + ASSERT(call_count == VERIFY_COUNT); + return NULL; +} + +static void run_once(int interval, int priority_test, int priority_verify) +{ + pthread_t thread; + pthread_attr_t attr; + struct sched_param sparam; + + pthread_attr_init(&attr); + memset(&sparam, 0, sizeof(sparam)); Review Comment: It seems that we cannot get param before we have a pid. Every code I see that calls `pthread_attr_setschedparam` uses a `struct sched_param sparam` in stack without calling any init function, just set the field to change. I just want to make sure it's all zero (as stack var) so add this `memset`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org