mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-07-05 11:20:00 +08:00

libuv: CC: pthread/pthread_mutexattr_setrobust.c libuv/src/unix/thread.c: In function ‘uv_thread_create_ex’: libuv/src/unix/thread.c:174:24: error: storage size of ‘param’ isn’t known 174 | struct sched_param param; | ^~~~~ btsak_main: In file included from btsak_main.c:39: btsak.h:149:1: error: unknown type name ‘bool’ 149 | bool btsak_str2bool(FAR const char *str); pipe_main.c: CC: sim/sim_registerdump.c pipe_main.c:44:30: error: unknown type name ‘pthread_addr_t’ 44 | static void *open_write_only(pthread_addr_t pvarg) | ^~~~~~~~~~~~~~ pipe_main.c: In function ‘pipe_main’: pipe_main.c:81:3: error: unknown type name ‘pthread_t’ 81 | pthread_t writeonly; redirect_test.c: In function ‘redirection_test’: redirect_test.c:205:3: error: unknown type name ‘pthread_t’ 205 | pthread_t readerid; | ^~~~~~~~~ redirect_test.c:206:3: error: unknown type name ‘pthread_t’ 206 | pthread_t writerid; | ^~~~~~~~~ drivertest_posix_timer.c:48:29: error: ‘optarg’ undeclared (first use in this function) 48 | value = (type)strtoul(optarg, &ptr, base); \ drivertest_posix_timer.c:208:3: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration] 208 | sleep(SLEEPSECONDS); | ^~~~~ drivertest_uart.c:92:13: warning: implicit declaration of function ‘read’; did you mean ‘fread’? [-Wimplicit-function-declaration] 92 | len = read(fd, &tmp_char, 1); | ^~~~ | fread drivertest_uart.c:323:44: error: ‘optopt’ undeclared (first use in this function) 323 | printf("Unknown option: %c\n", optopt); kernel/fs/cases/fs_getfilep_test.c:71:9: warning: implicit declaration of function ‘fs_getfilep’ [-Wimplicit-function-declaration] 71 | ret = fs_getfilep(fileno(fp), &filep); | ^~~~~~~~~~~ kernel/mm/cases/mm_test_008.c:148:9: warning: implicit declaration of function ‘task_create’; did you mean ‘timer_create’? [-Wimplicit-function-declaration] 148 | pid = task_create("TestNuttx08_routine_1", | ^~~~~~~~~~~ | timer_create /home/ajh/work/nuttxwork/apps/testing/cmocka/cmocka_main.c:171:11: warning: implicit declaration of function ‘setenv’ [-Wimplicit-function-declaration] 171 | setenv("CMOCKA_XML_FILE", xml_path, 1); | ^~~~~~ drivertest_pm_runtime.c:123:7: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration] 123 | usleep(210 * 1000); | ^~~~~~ Signed-off-by: anjiahao <anjiahao@xiaomi.com>
294 lines
7.3 KiB
C
294 lines
7.3 KiB
C
/****************************************************************************
|
|
* apps/examples/pipe/pipe_main.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 <sys/stat.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <sched.h>
|
|
#include <fcntl.h>
|
|
#include <errno.h>
|
|
#include <pthread.h>
|
|
|
|
#include "pipe.h"
|
|
|
|
/****************************************************************************
|
|
* Private Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: open_write_only
|
|
****************************************************************************/
|
|
|
|
static void *open_write_only(pthread_addr_t pvarg)
|
|
{
|
|
void *fd_addr = (void *)pvarg;
|
|
|
|
fprintf(stderr, "open_write_only: Opening FIFO for write access\n");
|
|
((int *)fd_addr)[1] = open(FIFO_PATH1, O_WRONLY);
|
|
if (((int *)fd_addr)[1] < 0)
|
|
{
|
|
fprintf(stderr, \
|
|
"open_write_only: Failed to open FIFO %s for writing,"
|
|
"errno=%d\n", FIFO_PATH1, errno);
|
|
return (void *)(uintptr_t)1;
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
/****************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
/****************************************************************************
|
|
* Name: pipe_main
|
|
****************************************************************************/
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
{
|
|
#if CONFIG_DEV_FIFO_SIZE > 0 || CONFIG_DEV_PIPE_SIZE > 0
|
|
int fd[2];
|
|
int ret;
|
|
#endif
|
|
|
|
#if CONFIG_DEV_FIFO_SIZE > 0
|
|
/* Test FIFO logic */
|
|
|
|
fprintf(stderr, "\npipe_main: Performing FIFO test\n");
|
|
|
|
pthread_t writeonly;
|
|
void *status;
|
|
|
|
/* Open one end of the FIFO for reading and the other end for writing.
|
|
* NOTE: This test's result is expected to be the same on any other
|
|
* POSIX-compliant system. NuttX FIFOs block for write-only and
|
|
* read-only (see interlock_test()).
|
|
*/
|
|
|
|
ret = mkfifo(FIFO_PATH1, 0666);
|
|
if (ret < 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: mkfifo failed with errno=%d\n", errno);
|
|
return 1;
|
|
}
|
|
|
|
ret = pthread_create(&writeonly, NULL, open_write_only, &fd);
|
|
|
|
if (ret < 0)
|
|
{
|
|
fprintf(stderr, "redirection_test: "
|
|
"Failed to create open_write_only task: %d\n", ret);
|
|
return 2;
|
|
}
|
|
|
|
fd[0] = open(FIFO_PATH1, O_RDONLY);
|
|
if (fd[0] < 0)
|
|
{
|
|
fprintf(stderr,
|
|
"pipe_main: Failed to open FIFO %s for reading, errno=%d\n",
|
|
FIFO_PATH1, errno);
|
|
if (close(fd[1]) != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
}
|
|
|
|
return 3;
|
|
}
|
|
|
|
/* Wait for open_write_only thread to complete */
|
|
|
|
fprintf(stderr, "open_write_only: Waiting for open_write_only thread\n");
|
|
ret = pthread_join(writeonly, &status);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: pthread_join failed, error=%d\n", ret);
|
|
return 4;
|
|
}
|
|
else
|
|
{
|
|
fprintf(stderr, "pipe_main: open_write_only returned %p\n", status);
|
|
if (status != NULL)
|
|
{
|
|
return 5;
|
|
}
|
|
}
|
|
|
|
/* Then perform the test using those file descriptors */
|
|
|
|
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)
|
|
{
|
|
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
}
|
|
|
|
if (close(fd[1]) != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
}
|
|
|
|
/* unlink(FIFO_PATH1); fails */
|
|
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: FIFO test FAILED (%d)\n", ret);
|
|
return 6;
|
|
}
|
|
|
|
ret = remove(FIFO_PATH1);
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: remove failed with errno=%d\n", errno);
|
|
}
|
|
|
|
/* Perform the FIFO interlock test */
|
|
|
|
fprintf(stderr, "\npipe_main: Performing pipe interlock test\n");
|
|
ret = interlock_test();
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: FIFO interlock test FAILED (%d)\n", ret);
|
|
return 7;
|
|
}
|
|
|
|
fprintf(stderr, "pipe_main: FIFO interlock test PASSED\n");
|
|
|
|
fprintf(stderr, "pipe_main: FIFO test PASSED\n");
|
|
|
|
#else
|
|
fprintf(stderr, "\npipe_main: Skipping FIFO test\n");
|
|
|
|
#endif /* CONFIG_DEV_FIFO_SIZE > 0 */
|
|
|
|
#if CONFIG_DEV_PIPE_SIZE > 0
|
|
/* Test PIPE logic */
|
|
|
|
fprintf(stderr, "\npipe_main: Performing pipe test\n");
|
|
|
|
ret = pipe(fd);
|
|
if (ret < 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: pipe failed with errno=%d\n", errno);
|
|
return 8;
|
|
}
|
|
|
|
/* Then perform the test using those file descriptors */
|
|
|
|
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)
|
|
{
|
|
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
}
|
|
|
|
if (close(fd[1]) != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: close failed: %d\n", errno);
|
|
}
|
|
|
|
/* Perform the pipe redirection test */
|
|
|
|
fprintf(stderr, "\npipe_main: Performing redirection test\n");
|
|
ret = redirection_test();
|
|
if (ret != 0)
|
|
{
|
|
fprintf(stderr, "pipe_main: PIPE redirection test FAILED (%d)\n", ret);
|
|
return 10;
|
|
}
|
|
|
|
fprintf(stderr, "pipe_main: PIPE redirection test PASSED\n");
|
|
|
|
fprintf(stderr, "pipe_main: PIPE test PASSED\n");
|
|
|
|
#else
|
|
fprintf(stderr, "\npipe_main: Skipping pipe test\n");
|
|
|
|
#endif /* CONFIG_DEV_PIPE_SIZE > 0 */
|
|
|
|
fflush(stderr);
|
|
return 0;
|
|
}
|