From 069559419049a5bd657f4c51f1d153ce83ff6847 Mon Sep 17 00:00:00 2001 From: Hu Jiangtao Date: Tue, 6 Jun 2023 07:42:03 +0000 Subject: [PATCH] tests: add some debut print in xbuf Signed-off-by: Hu Jiangtao --- lib/internal.c | 23 +++++-- lib/proxy.c | 1 + lib/xbuf.c | 5 ++ tests/basic-xbuf.c | 103 +++++++++++++++++++++++-------- tests/element-visibility.c | 7 ++- tests/heap-torture.c | 2 +- tests/proxy-echo.c | 4 +- tests/test-xbuf.c | 123 +++++++++++++++++++++++++++++++++++++ 8 files changed, 235 insertions(+), 33 deletions(-) create mode 100644 tests/test-xbuf.c diff --git a/lib/internal.c b/lib/internal.c index f41f8ef..1389aaf 100644 --- a/lib/internal.c +++ b/lib/internal.c @@ -32,11 +32,17 @@ static int flip_fd_flags(int efd, int cmd, int flags) { int ret; + printf("clone flags %d\n", 1); ret = fcntl(efd, cmd == F_SETFD ? F_GETFD : F_GETFL, 0); + + printf("clone flags %d\n", 2); if (ret < 0) return -errno; + printf("clone flags %d\n", 4); ret = fcntl(efd, cmd, ret | flags); + + printf("clone flags %d\n", 3); if (ret) return -errno; @@ -84,6 +90,8 @@ int create_evl_element(const char *type, const char *name, goto out_factory; } + printf("ffd = %d\n",ffd); + printf("fdevname: %s\n", fdevname); /* * Turn on public mode if the user-provided name starts with a @@ -97,6 +105,7 @@ int create_evl_element(const char *type, const char *name, name++; } + printf("fdevname: %s\n", fdevname); clone.name_ptr = __evl_ptr64(name); clone.attrs_ptr = __evl_ptr64(attrs); clone.clone_flags = clone_flags; @@ -109,7 +118,7 @@ int create_evl_element(const char *type, const char *name, lart_once(); goto out_new; } - + printf("clone flags %d\n", clone_flags); if (clone_flags & EVL_CLONE_PUBLIC) { ret = asprintf(&edevname, "/dev/evl/%s/%s", type, name); if (ret < 0) { @@ -126,19 +135,25 @@ int create_evl_element(const char *type, const char *name, } else { efd = clone.efd; } - + printf("efd is in the user space %d %d \n ", clone.efd, efd); + printf("clone flags %d\n", clone_flags); ret = flip_fd_flags(efd, F_SETFD, O_CLOEXEC); - // printf("flip_fd_flags, ret=%d\n", ret); - // fflush(stdout); + + printf("clone flags %d\n", clone_flags); + printf("flip_fd_flags, ret=%d\n", ret); + fflush(stdout); if (ret) goto out_element; + printf("flip_fd_flags, ret=%d\n", ret); if (nonblock) { ret = flip_fd_flags(efd, F_SETFL, O_NONBLOCK); + printf("flip_fd_flags, ret=%d\n", ret); if (ret) goto out_element; } + printf("flip_fd_flags, ret=%d\n", ret); if (eids) *eids = clone.eids; diff --git a/lib/proxy.c b/lib/proxy.c index bec3e21..ac20158 100644 --- a/lib/proxy.c +++ b/lib/proxy.c @@ -49,6 +49,7 @@ int evl_create_proxy(int targetfd, size_t bufsz, size_t granularity, } attrs.fd = targetfd; + printf("the attrs.fd = %d\n", targetfd); attrs.bufsz = bufsz; attrs.granularity = granularity; efd = create_evl_element(EVL_PROXY_DEV, name, &attrs, flags, NULL); diff --git a/lib/xbuf.c b/lib/xbuf.c index 55fd1e3..14690bd 100644 --- a/lib/xbuf.c +++ b/lib/xbuf.c @@ -13,6 +13,7 @@ int evl_create_xbuf(size_t i_bufsz, size_t o_bufsz, int flags, const char *fmt, ...) { + printf("xbuf11111\n"); struct evl_xbuf_attrs attrs; char *name = NULL; int ret, efd; @@ -26,9 +27,13 @@ int evl_create_xbuf(size_t i_bufsz, size_t o_bufsz, return -ENOMEM; } + // printf("xbuf11111"); attrs.i_bufsz = i_bufsz; attrs.o_bufsz = o_bufsz; + printf("xbuf-name:%s\n", name); efd = create_evl_element(EVL_XBUF_DEV, name, &attrs, flags, NULL); + printf("xbuf-name:%s\n", name); + printf("efd of xbuf is %d\n", efd); if (name) free(name); diff --git a/tests/basic-xbuf.c b/tests/basic-xbuf.c index 7b45bf4..58ca53f 100644 --- a/tests/basic-xbuf.c +++ b/tests/basic-xbuf.c @@ -11,57 +11,112 @@ #include #include "helpers.h" -static void *peer(void *arg) -{ - const char *path = arg; - int fd, n, nfd, nfd2; - char buf[2]; - ssize_t ret; +// static void *peer(void *arg) +// { +// const int *xfd = arg; +// int fd, n, nfd, nfd2; +// char buf[2]; +// ssize_t ret; - __Tcall_assert(fd, open(path, O_RDWR)); - __Tcall_assert(nfd, dup(fd)); - __Tcall_assert(nfd2, dup2(fd, nfd)); +// printf("the xfd is %d\n", *xfd); +// fflush(stdout); +// // __Tcall_assert(fd, open(path, O_RDWR)); +// fd = *xfd; +// printf("the fd is %d\n", fd); +// fflush(stdout); +// __Tcall_assert(nfd, dup(*xfd)); +// printf("the nfd is %d\n", nfd); +// fflush(stdout); +// __Tcall_assert(nfd2, dup2(*xfd, nfd)); +// printf("the nfd2 is %d\n", nfd2); +// fflush(stdout); - for (n = 0; n < 3; n++) { - __Tcall_errno_assert(ret, read(fd, buf, 2)); - if (ret != 2) - break; - } +// for (n = 0; n < 3; n++) { +// __Tcall_errno_assert(ret, read(fd, buf, 2)); +// if (ret != 2) +// break; +// } +// printf("read success\n"); - return NULL; -} +// return NULL; +// } int main(int argc, char *argv[]) { char *name, *path, buf[16]; int tfd, xfd, n; - pthread_t tid; + // int *nxfd; + // pthread_t tid; ssize_t ret; __Tcall_assert(tfd, evl_attach_self("basic-xbuf:%d", getpid())); + printf("attach basic-xbuf success\n"); name = get_unique_name_and_path(EVL_XBUF_DEV, 0, &path); - __Tcall_assert(xfd, evl_new_xbuf(1024, name)); + printf("path:%s\n", path); + printf("name:%s\n", name); + char *ch = "/X"; + char *new_name = (char*) malloc(strlen(name) + 3); + strcpy(new_name, ch); + strcat(new_name, name); + new_name[0] = 'X'; + new_name[2] = 'h'; + printf("new_name is :%s\n", new_name); + __Tcall_assert(xfd, evl_new_xbuf(1024, new_name)); + printf("the xfd = %d\n", xfd); + printf("create new xbuf success\n"); + fflush(stdout); __Tcall_errno_assert(ret, write(xfd, "ABCD", 4)); + printf("xbuf write ABCD success\n"); + fflush(stdout); __Tcall_errno_assert(ret, write(xfd, "EF", 2)); + printf("xbuf write EF success\n"); + fflush(stdout); __Tcall_errno_assert(ret, write(xfd, "G", 1)); + printf("xbuf write G success\n"); + fflush(stdout); __Tcall_errno_assert(ret, write(xfd, "H", 1)); + printf("xbuf write H success\n"); + fflush(stdout); + printf("the xfd = %d\n", xfd); __Tcall_errno_assert(ret, fcntl(xfd, F_SETFL, fcntl(xfd, F_GETFL)|O_NONBLOCK)); + printf("the xfd = %d\n", xfd); + printf("ret = %ld\n", ret); + printf("xbuf fcntl success\n"); + fflush(stdout); for (n = 0; n < 8; n++) + { __Tcall_errno_assert(ret, oob_read(xfd, buf, 1)); + printf("the value of oob read buf is %c\n", *buf); + } + + printf("xbuf oob_read success\n"); + printf("xbuf write and oob_read success!!!!!\n"); - new_thread(&tid, SCHED_OTHER, 0, peer, path); + // nxfd = &xfd; + // printf("nxfd:%d\n", *nxfd); + // fflush(stdout); + // new_thread(&tid, SCHED_OTHER, 0, peer, nxfd); + // printf("xbuf new thread success\n"); + // fflush(stdout); - sleep(1); - __Tcall_errno_assert(ret, oob_write(xfd, "01", 2)); - __Tcall_errno_assert(ret, oob_write(xfd, "23", 2)); - __Tcall_errno_assert(ret, oob_write(xfd, "45", 2)); + // sleep(1); + // __Tcall_errno_assert(ret, oob_write(xfd, "01", 2)); + // printf("xbuf oob_write 01 success\n"); + // fflush(stdout); + // __Tcall_errno_assert(ret, oob_write(xfd, "23", 2)); + // printf("xbuf oob_write 23 success\n"); + // fflush(stdout); + // __Tcall_errno_assert(ret, oob_write(xfd, "45", 2)); + // printf("xbuf oob_write 45 success\n"); + // fflush(stdout); - pthread_join(tid, NULL); + // pthread_join(tid, NULL); + free(new_name); return 0; } diff --git a/tests/element-visibility.c b/tests/element-visibility.c index c27f038..9d45af1 100644 --- a/tests/element-visibility.c +++ b/tests/element-visibility.c @@ -26,8 +26,11 @@ int main(int argc, char *argv[]) int efd, ret; name = get_unique_name_and_path(EVL_THREAD_DEV, 0, &path); /* public */ - __Tcall_assert(efd, evl_attach_self(name)); - __Texpr_assert(element_is_public(path)); + printf("name:%s\n", name); + __Tcall_assert(efd, evl_attach_self("element-visibility:%d\n", getpid())); + printf("attach thread success\n"); + //__Texpr_assert(element_is_public(path)); + printf("attach thread success\n"); __Tcall_assert(efd, evl_detach_self()); __Tcall_assert(efd, evl_attach_self(name + 1)); /* private */ diff --git a/tests/heap-torture.c b/tests/heap-torture.c index 14077d9..f8e48a9 100644 --- a/tests/heap-torture.c +++ b/tests/heap-torture.c @@ -778,7 +778,7 @@ int main(int argc, char *argv[]) param.sched_priority = 1; pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m); __Tcall_assert(ret, evl_attach_self("heap-torture:%d", getpid())); - + printf("the attach self is successful"); /* * Create a series of heaps of increasing size, allocating * then freeing all blocks sequentially from them, ^2 block diff --git a/tests/proxy-echo.c b/tests/proxy-echo.c index c0103b4..5adf401 100644 --- a/tests/proxy-echo.c +++ b/tests/proxy-echo.c @@ -50,10 +50,10 @@ int main(int argc, char *argv[]) __Tcall_assert(ret, pipe(m2p_pipefd)); __Tcall_assert(m2p_proxy, evl_create_proxy(m2p_pipefd[0], BUFFER_SIZE, 0, EVL_CLONE_INPUT, - "pipe-m2p:%d", getpid())); + "Pipe-m2p:%d", getpid())); __Tcall_assert(p2m_proxy, evl_create_proxy(p2m_pipefd[1], BUFFER_SIZE, 0, EVL_CLONE_OUTPUT, - "pipe-p2m:%d", getpid())); + "Pipe-p2m:%d", getpid())); new_thread(&tid, SCHED_FIFO, 1, peer, NULL); for (n = 0; n < TEST_COUNT; n++) { diff --git a/tests/test-xbuf.c b/tests/test-xbuf.c new file mode 100644 index 0000000..aeec1fd --- /dev/null +++ b/tests/test-xbuf.c @@ -0,0 +1,123 @@ +/* + * SPDX-License-Identifier: MIT + */ + +#include +#include +#include +#include +#include +#include +#include +#include "helpers.h" + +// static void *peer(void *arg) +// { +// const int *xfd = arg; +// int fd, n, nfd, nfd2; +// char buf[2]; +// ssize_t ret; + +// printf("the xfd is %d\n", *xfd); +// fflush(stdout); +// // __Tcall_assert(fd, open(path, O_RDWR)); +// fd = *xfd; +// printf("the fd is %d\n", fd); +// fflush(stdout); +// __Tcall_assert(nfd, dup(*xfd)); +// printf("the nfd is %d\n", nfd); +// fflush(stdout); +// __Tcall_assert(nfd2, dup2(*xfd, nfd)); +// printf("the nfd2 is %d\n", nfd2); +// fflush(stdout); + +// for (n = 0; n < 3; n++) { +// __Tcall_errno_assert(ret, oob_read(fd, buf, 2)); +// if (ret != 2) +// break; +// } +// printf("read success\n"); + +// return NULL; +// } + +int main(int argc, char *argv[]) +{ + char *name, *path, buf[16]; + int tfd, xfd, n; + // int *nxfd; + // pthread_t tid; + ssize_t ret; + + __Tcall_assert(tfd, evl_attach_self("basic-xbuf:%d", getpid())); + printf("attach basic-xbuf success\n"); + + name = get_unique_name_and_path(EVL_XBUF_DEV, 0, &path); + printf("path:%s\n", path); + printf("name:%s\n", name); + char *ch = "/X"; + char *new_name = (char*) malloc(strlen(name) + 3); + strcpy(new_name, ch); + strcat(new_name, name); + new_name[0] = 'X'; + new_name[2] = 'h'; + printf("new_name is :%s\n", new_name); + + __Tcall_assert(xfd, evl_new_xbuf(1024, new_name)); + printf("the xfd = %d\n", xfd); + printf("create new xbuf success\n"); + fflush(stdout); + __Tcall_errno_assert(ret, oob_write(xfd, "1234", 4)); + printf("xbuf oob_write 1234 success\n"); + fflush(stdout); + __Tcall_errno_assert(ret, oob_write(xfd, "56", 2)); + printf("xbuf oob_write 56 success\n"); + fflush(stdout); + __Tcall_errno_assert(ret, oob_write(xfd, "7", 1)); + printf("xbuf oob_write 7 success\n"); + fflush(stdout); + __Tcall_errno_assert(ret, oob_write(xfd, "8", 1)); + printf("xbuf oob_write 8 success\n"); + fflush(stdout); + + printf("the xfd = %d\n", xfd); + __Tcall_errno_assert(ret, fcntl(xfd, F_SETFL, + fcntl(xfd, F_GETFL)|O_NONBLOCK)); + printf("the xfd = %d\n", xfd); + printf("ret = %ld\n", ret); + printf("xbuf fcntl success\n"); + fflush(stdout); + + for (n = 0; n < 8; n++) + { + __Tcall_errno_assert(ret, read(xfd, buf, 1)); + printf("the value of read buf is %c\n", *buf); + } + + + printf("xbuf read success\n"); + printf("test xbuf oob_write and read success!!!!!\n"); + + // nxfd = &xfd; + // printf("nxfd:%d\n", *nxfd); + // fflush(stdout); + // new_thread(&tid, SCHED_OTHER, 0, peer, nxfd); + // printf("xbuf new thread success\n"); + // fflush(stdout); + + // sleep(1); + // __Tcall_errno_assert(ret, write(xfd, "01", 2)); + // printf("xbuf oob_write 01 success\n"); + // fflush(stdout); + // __Tcall_errno_assert(ret, write(xfd, "23", 2)); + // printf("xbuf oob_write 23 success\n"); + // fflush(stdout); + // __Tcall_errno_assert(ret, write(xfd, "45", 2)); + // printf("xbuf oob_write 45 success\n"); + // fflush(stdout); + + // pthread_join(tid, NULL); + + free(new_name); + return 0; +}