testing/rpmsgdev: Add option for rpmsgdev_export()

And fix errors for other platform

Test

  Server (NuttX)

    testdev -d 0 -r "/dev/testrpmsgdev"
    testdev -d 2 -c "CLIENT" -l "/dev/testrpmsgdev"

  Client (Other)

    testdev -l /dev/testrpmsgdev -t 1
    testdev -l /dev/testrpmsgdev -t 2
    testdev -l /dev/testrpmsgdev -t 3
    testdev -l /dev/testrpmsgdev -t 5
    testdev -l /dev/testrpmsgdev -t 6
    testdev -l /dev/testrpmsgdev -t 7
    testdev -l /dev/testrpmsgdev -t 8

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
This commit is contained in:
wangjianyu3
2024-06-13 19:22:22 +08:00
committed by Xiang Xiao
parent 047f881673
commit 366865723b
2 changed files with 54 additions and 17 deletions

View File

@@ -22,11 +22,11 @@
if(CONFIG_RPMSGDEV_TEST) if(CONFIG_RPMSGDEV_TEST)
nuttx_add_application( nuttx_add_application(
NAME NAME
rpmsgdev testdev
PRIORITY PRIORITY
${CONFIG_TESTING_TESTCASES_PRIORITY} ${SCHED_PRIORITY_DEFAULT}
STACKSIZE STACKSIZE
${CONFIG_TESTING_TESTCASES_STACKSIZE} ${CONFIG_DEFAULT_TASK_STACKSIZE}
SRCS SRCS
testdev.c) testdev.c)
endif() endif()

View File

@@ -22,8 +22,6 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/fs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/select.h> #include <sys/select.h>
@@ -32,12 +30,13 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <syslog.h> #include <syslog.h>
#include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <poll.h> #include <poll.h>
#ifdef CONFIG_DEV_RPMSG #if defined(__NuttX__) && (defined(CONFIG_DEV_RPMSG) || defined(CONFIG_DEV_RPMSG_SERVER))
#include <nuttx/drivers/rpmsgdev.h> #include <nuttx/drivers/rpmsgdev.h>
#endif #endif
@@ -45,20 +44,27 @@
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
#ifdef __ANDROID__
#define syslog(l,...) printf(__VA_ARGS__)
#endif
/* set a random open flag to check whether the open api behave correctly */ /* set a random open flag to check whether the open api behave correctly */
#define OPEN_FLAG O_RDWR #define OPEN_FLAG O_RDWR
#define RET 114514 #define RET ENOENT
#define OFFSET 1234l #define OFFSET 1234l
#define WHENCE SEEK_SET #define WHENCE SEEK_SET
#ifdef __NuttX__
#define IOCTL FIONSPACE #define IOCTL FIONSPACE
#define IOCTL_ARG 0x55AA #define IOCTL_ARG 0x55AA
#endif
static int hour __attribute__((unused)); static int hour __attribute__((unused));
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
#ifdef __NuttX__
static int testdev_open(FAR struct file *filep); static int testdev_open(FAR struct file *filep);
static int testdev_close(FAR struct file *filep); static int testdev_close(FAR struct file *filep);
static ssize_t testdev_read(FAR struct file *filep, FAR char *buffer, static ssize_t testdev_read(FAR struct file *filep, FAR char *buffer,
@@ -97,7 +103,8 @@ static const struct file_operations g_testdev_ops =
static int testdev_open(FAR struct file *filep) static int testdev_open(FAR struct file *filep)
{ {
if (filep->f_oflags == (OPEN_FLAG | O_NONBLOCK)) if ((filep->f_oflags & (OPEN_FLAG | O_NONBLOCK)) ==
(OPEN_FLAG | O_NONBLOCK))
{ {
filep->f_pos = 0; filep->f_pos = 0;
syslog(LOG_INFO, "test open success\n"); syslog(LOG_INFO, "test open success\n");
@@ -110,7 +117,8 @@ static int testdev_open(FAR struct file *filep)
static int testdev_close(FAR struct file *filep) static int testdev_close(FAR struct file *filep)
{ {
if (filep->f_oflags == (OPEN_FLAG | O_NONBLOCK)) if ((filep->f_oflags & (OPEN_FLAG | O_NONBLOCK)) ==
(OPEN_FLAG | O_NONBLOCK))
{ {
syslog(LOG_INFO, "test close success\n"); syslog(LOG_INFO, "test close success\n");
return 0; return 0;
@@ -233,7 +241,7 @@ static int testdev_poll(FAR struct file *filep, FAR struct pollfd *fds,
static void _register_driver(int mode, char *cpu, char *remotepath, static void _register_driver(int mode, char *cpu, char *remotepath,
char *localpath) char *localpath)
{ {
int ret; int ret = -EINVAL;
switch (mode) switch (mode)
{ {
@@ -257,8 +265,21 @@ static void _register_driver(int mode, char *cpu, char *remotepath,
ret = rpmsgdev_register(cpu, remotepath, localpath, 0); ret = rpmsgdev_register(cpu, remotepath, localpath, 0);
break; break;
#endif #endif
case 2:
#ifdef CONFIG_DEV_RPMSG_SERVER
if (cpu == NULL || localpath == NULL)
{
syslog(LOG_ERR, "please set -c, -l\n");
exit(1);
}
ret = rpmsgdev_export(cpu, localpath);
#else
syslog(LOG_WARNING, "feature of case %d not enabled\n", mode);
#endif
break;
default: default:
syslog(LOG_ERR, "-r must between 0 and 1\n"); syslog(LOG_ERR, "-d must between 0 and 2\n");
exit(1); exit(1);
break; break;
} }
@@ -272,8 +293,9 @@ static void _register_driver(int mode, char *cpu, char *remotepath,
syslog(LOG_INFO, "register driver success\n"); syslog(LOG_INFO, "register driver success\n");
} }
#endif
#ifdef CONFIG_DEV_RPMSG #if defined(CONFIG_DEV_RPMSG) || defined(TEST_RPMSGDEV)
static int test_open(char *path, int flags) static int test_open(char *path, int flags)
{ {
int fd; int fd;
@@ -337,7 +359,8 @@ static int test_read(int fd, size_t len)
{ {
if (buf[ret] != 'r') if (buf[ret] != 'r')
{ {
syslog(LOG_ERR, "check data error, ret %d, except 'a'", buf[ret]); syslog(LOG_ERR, "check data error, ret[%d] %d, except 'r'\n",
ret, buf[ret]);
free(buf); free(buf);
return -1; return -1;
} }
@@ -401,6 +424,7 @@ static off_t test_seek(int fd, off_t offset, int whence)
return ret; return ret;
} }
#ifdef __NuttX__
static int test_ioctl(int fd, unsigned long request, unsigned long arg) static int test_ioctl(int fd, unsigned long request, unsigned long arg)
{ {
int ret; int ret;
@@ -414,6 +438,7 @@ static int test_ioctl(int fd, unsigned long request, unsigned long arg)
syslog(LOG_INFO, "test ioctl return %d\n", ret); syslog(LOG_INFO, "test ioctl return %d\n", ret);
return ret; return ret;
} }
#endif
static int test_poll(int fd, int event, int timeout) static int test_poll(int fd, int event, int timeout)
{ {
@@ -445,7 +470,7 @@ static int testcase_1(char *path)
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd != -1 || errno != RET) if (fd != -1 || errno != RET)
{ {
syslog(LOG_ERR, "open test fail, fs %d (expect -1), " syslog(LOG_ERR, "open test fail, fd %d (expect -1), "
"errno %d (expect %d)\n", fd, errno, RET); "errno %d (expect %d)\n", fd, errno, RET);
return -1; return -1;
} }
@@ -510,6 +535,7 @@ static int testcase_3(char *path)
return test_close(fd); return test_close(fd);
} }
#ifdef __NuttX__
/* open -> ioctl fail -> ioctl success -> close */ /* open -> ioctl fail -> ioctl success -> close */
static int testcase_4(char *path) static int testcase_4(char *path)
@@ -547,6 +573,7 @@ static int testcase_4(char *path)
syslog(LOG_INFO, "ioctl2 success\n"); syslog(LOG_INFO, "ioctl2 success\n");
return test_close(fd); return test_close(fd);
} }
#endif
/* open -> poll -> close */ /* open -> poll -> close */
@@ -565,7 +592,7 @@ static int testcase_5(char *path)
ret = test_poll(fd, POLLIN, 200); ret = test_poll(fd, POLLIN, 200);
if (ret != 1) if (ret != 1)
{ {
syslog(LOG_ERR, "poll test1 fail, ret %d, expect 0\n", ret); syslog(LOG_ERR, "poll test1 fail, ret %d, expect 1\n", ret);
return -1; return -1;
} }
@@ -580,6 +607,7 @@ static int testcase_5(char *path)
syslog(LOG_INFO, "poll2 success\n"); syslog(LOG_INFO, "poll2 success\n");
#if 0
ret = test_poll(fd, POLLOUT, 0); ret = test_poll(fd, POLLOUT, 0);
if (ret != 1) if (ret != 1)
{ {
@@ -588,6 +616,8 @@ static int testcase_5(char *path)
} }
syslog(LOG_INFO, "poll3 success\n"); syslog(LOG_INFO, "poll3 success\n");
#endif
return test_close(fd); return test_close(fd);
} }
@@ -687,7 +717,10 @@ static void show_usage(void)
syslog(LOG_WARNING, syslog(LOG_WARNING,
"Usage: CMD [-d <regist driver>] [-c <remote cpu>] " "Usage: CMD [-d <regist driver>] [-c <remote cpu>] "
"[-l <localpath>] [-r <remotepath>] [-h <hour>] [-t <test>]\n" "[-l <localpath>] [-r <remotepath>] [-h <hour>] [-t <test>]\n"
"\t\t-d: regist driver, 0 for test driver, 1 for rpmsgdev\n" "\t\t-d: regist driver\n"
"\t\t\t 0 for test driver\n"
"\t\t\t 1 for rpmsgdev(client register)\n"
"\t\t\t 2 for rpmsgdev(server export)\n"
"\t\t-c: remote cpu which regists test driver\n" "\t\t-c: remote cpu which regists test driver\n"
"\t\t-l: localpath, which means rpmsgdev's name\n" "\t\t-l: localpath, which means rpmsgdev's name\n"
"\t\t-r: remotepath, which means test driver's name\n" "\t\t-r: remotepath, which means test driver's name\n"
@@ -757,10 +790,12 @@ int main(int argc, char *argv[])
if (mode >= 0) if (mode >= 0)
{ {
#ifdef __NuttX__
_register_driver(mode, cpu, remotepath, localpath); _register_driver(mode, cpu, remotepath, localpath);
#endif
} }
#ifdef CONFIG_DEV_RPMSG #if defined(CONFIG_DEV_RPMSG) || defined(TEST_RPMSGDEV)
if (test >= 0) if (test >= 0)
{ {
if (localpath == NULL) if (localpath == NULL)
@@ -780,9 +815,11 @@ int main(int argc, char *argv[])
case 3: case 3:
ret = testcase_3(localpath); ret = testcase_3(localpath);
break; break;
#ifdef __NuttX__
case 4: case 4:
ret = testcase_4(localpath); ret = testcase_4(localpath);
break; break;
#endif
case 5: case 5:
ret = testcase_5(localpath); ret = testcase_5(localpath);
break; break;