mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-09-02 15:13:03 +00:00
examples/pipe: Enhance test by different r/w thread priority
By arranging and combining the priorities of read and write threads to cover more usage scenarios. Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
parent
0b8a52379c
commit
648e25bac1
3 changed files with 92 additions and 13 deletions
|
|
@ -48,7 +48,8 @@
|
|||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
extern int transfer_test(int fdin, int fdout);
|
||||
extern int transfer_test(int fdin, int fdout,
|
||||
int boost_reader, int boost_writer);
|
||||
extern int interlock_test(void);
|
||||
extern int redirection_test(void);
|
||||
|
||||
|
|
|
|||
|
|
@ -137,7 +137,37 @@ int main(int argc, FAR char *argv[])
|
|||
|
||||
/* Then perform the test using those file descriptors */
|
||||
|
||||
ret = transfer_test(fd[0], fd[1]);
|
||||
ret = transfer_test(fd[0], fd[1], 0, 0);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: FIFO test FAILED (00) (%d)\n", ret);
|
||||
return 6;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 1, 0);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: FIFO test FAILED (10) (%d)\n", ret);
|
||||
return 6;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 0, 1);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: FIFO test FAILED (01)(%d)\n", ret);
|
||||
return 6;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 1, 1);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: FIFO test FAILED (11) (%d)\n", ret);
|
||||
return 6;
|
||||
}
|
||||
|
||||
if (close(fd[0]) != 0)
|
||||
{
|
||||
|
|
@ -196,7 +226,37 @@ int main(int argc, FAR char *argv[])
|
|||
|
||||
/* Then perform the test using those file descriptors */
|
||||
|
||||
ret = transfer_test(fd[0], fd[1]);
|
||||
ret = transfer_test(fd[0], fd[1], 0, 0);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (00) (%d)\n", ret);
|
||||
return 9;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 1, 0);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (10) (%d)\n", ret);
|
||||
return 9;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 0, 1);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (01) (%d)\n", ret);
|
||||
return 9;
|
||||
}
|
||||
|
||||
ret = transfer_test(fd[0], fd[1], 1, 1);
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (11) (%d)\n", ret);
|
||||
return 9;
|
||||
}
|
||||
|
||||
if (close(fd[0]) != 0)
|
||||
{
|
||||
|
|
@ -208,12 +268,6 @@ int main(int argc, FAR char *argv[])
|
|||
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
||||
}
|
||||
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, "pipe_main: PIPE test FAILED (%d)\n", ret);
|
||||
return 9;
|
||||
}
|
||||
|
||||
/* Perform the pipe redirection test */
|
||||
|
||||
fprintf(stderr, "\npipe_main: Performing redirection test\n");
|
||||
|
|
|
|||
|
|
@ -176,21 +176,34 @@ static void *transfer_writer(pthread_addr_t pvarg)
|
|||
* Name: transfer_test
|
||||
****************************************************************************/
|
||||
|
||||
int transfer_test(int fdin, int fdout)
|
||||
int transfer_test(int fdin, int fdout, int boost_reader, int boost_writer)
|
||||
{
|
||||
pthread_t readerid;
|
||||
pthread_t writerid;
|
||||
pthread_attr_t rattr;
|
||||
pthread_attr_t wattr;
|
||||
void *value;
|
||||
int tmp;
|
||||
int ret;
|
||||
|
||||
printf("transfer_test: fdin=%d fdout=%d\n", fdin, fdout);
|
||||
|
||||
/* Boost the priority of reader or writer on need */
|
||||
|
||||
pthread_attr_init(&rattr);
|
||||
if (boost_reader)
|
||||
{
|
||||
rattr.priority += 1;
|
||||
printf("transfer_test: Boost priority of transfer_reader"
|
||||
"thread to %d\n", rattr.priority);
|
||||
}
|
||||
|
||||
/* Start transfer_reader thread */
|
||||
|
||||
printf("transfer_test: Starting transfer_reader thread\n");
|
||||
ret = pthread_create(&readerid, NULL, \
|
||||
ret = pthread_create(&readerid, &rattr,
|
||||
transfer_reader, (void *)(intptr_t)fdin);
|
||||
pthread_attr_destroy(&rattr);
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, \
|
||||
|
|
@ -199,11 +212,22 @@ int transfer_test(int fdin, int fdout)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* Boost the priority of reader or writer on need */
|
||||
|
||||
pthread_attr_init(&wattr);
|
||||
if (boost_writer)
|
||||
{
|
||||
wattr.priority += 1;
|
||||
printf("transfer_test: Boost priority of transfer_writer"
|
||||
"thread to %d\n", wattr.priority);
|
||||
}
|
||||
|
||||
/* Start transfer_writer thread */
|
||||
|
||||
printf("transfer_test: Starting transfer_writer thread\n");
|
||||
ret = pthread_create(&writerid, \
|
||||
NULL, transfer_writer, (void *)(intptr_t)fdout);
|
||||
ret = pthread_create(&writerid, &wattr,
|
||||
transfer_writer, (void *)(intptr_t)fdout);
|
||||
pthread_attr_destroy(&wattr);
|
||||
if (ret != 0)
|
||||
{
|
||||
fprintf(stderr, \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue