Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package socket_wrapper for openSUSE:Factory checked in at 2023-06-29 17:27:34 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/socket_wrapper (Old) and /work/SRC/openSUSE:Factory/.socket_wrapper.new.13546 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "socket_wrapper" Thu Jun 29 17:27:34 2023 rev:22 rq:1095788 version:1.4.1 Changes: -------- --- /work/SRC/openSUSE:Factory/socket_wrapper/socket_wrapper.changes 2023-02-25 19:54:38.815094718 +0100 +++ /work/SRC/openSUSE:Factory/.socket_wrapper.new.13546/socket_wrapper.changes 2023-06-29 17:27:44.714054368 +0200 @@ -1,0 +2,8 @@ +Wed Jun 21 10:45:26 UTC 2023 - Andreas Schneider <[email protected]> + +- Update to version 1.4.1 + * Fixed issue with fnctl() on 32bit + * Added openat64() to detect stale fds +- Remove socket_wrapper-fix-cmocka-1.1.6+-support.patch + +------------------------------------------------------------------- Old: ---- socket_wrapper-1.4.0.tar.gz socket_wrapper-1.4.0.tar.gz.asc socket_wrapper-fix-cmocka-1.1.6+-support.patch New: ---- socket_wrapper-1.4.1.tar.gz socket_wrapper-1.4.1.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ socket_wrapper.spec ++++++ --- /var/tmp/diff_new_pack.sSV3rk/_old 2023-06-29 17:27:47.302069528 +0200 +++ /var/tmp/diff_new_pack.sSV3rk/_new 2023-06-29 17:27:47.306069552 +0200 @@ -24,7 +24,7 @@ ############################# NOTE ################################## Name: socket_wrapper -Version: 1.4.0 +Version: 1.4.1 Release: 0 Summary: A library passing all socket communications through Unix sockets License: BSD-3-Clause @@ -35,7 +35,6 @@ Source1: https://ftp.samba.org/pub/cwrap/%{name}-%{version}.tar.gz.asc Source2: socket_wrapper.keyring Source3: %{name}-rpmlintrc -Patch0: socket_wrapper-fix-cmocka-1.1.6+-support.patch # BuildRequires: cmake BuildRequires: libcmocka-devel ++++++ socket_wrapper-1.4.0.tar.gz -> socket_wrapper-1.4.1.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/.gitlab-ci.yml new/socket_wrapper-1.4.1/.gitlab-ci.yml --- old/socket_wrapper-1.4.0/.gitlab-ci.yml 2022-11-04 15:45:56.000000000 +0100 +++ new/socket_wrapper-1.4.1/.gitlab-ci.yml 2023-06-21 12:27:11.000000000 +0200 @@ -224,6 +224,26 @@ paths: - obj/ +tumbleweed/x86/gcc: + stage: test + image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD + script: + - mkdir -p obj && cd obj && cmake + -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-m32.cmake + -DCMAKE_BUILD_TYPE=RelWithDebInfo + -DPICKY_DEVELOPER=ON + -DUNIT_TESTING=ON .. && + make -j$(nproc) && ctest --output-on-failure + tags: + - shared + except: + - tags + artifacts: + expire_in: 1 week + when: on_failure + paths: + - obj/ + tumbleweed/static-analysis: stage: analysis image: $CI_REGISTRY/$BUILD_IMAGES_PROJECT:$TUMBLEWEED_BUILD diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/0001-cmake-Fix-cmocka-1.1.6-find_package-in-CONFIG-mode.patch new/socket_wrapper-1.4.1/0001-cmake-Fix-cmocka-1.1.6-find_package-in-CONFIG-mode.patch --- old/socket_wrapper-1.4.0/0001-cmake-Fix-cmocka-1.1.6-find_package-in-CONFIG-mode.patch 1970-01-01 01:00:00.000000000 +0100 +++ new/socket_wrapper-1.4.1/0001-cmake-Fix-cmocka-1.1.6-find_package-in-CONFIG-mode.patch 2023-02-17 17:52:50.000000000 +0100 @@ -0,0 +1,29 @@ +From 34743b8f54d2ecb420c53845a7b7b93122be94a8 Mon Sep 17 00:00:00 2001 +From: Andreas Schneider <[email protected]> +Date: Fri, 17 Feb 2023 17:51:27 +0100 +Subject: [PATCH] cmake: Fix cmocka >= 1.1.6 find_package() in CONFIG mode + +Signed-off-by: Andreas Schneider <[email protected]> +--- + tests/CMakeLists.txt | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt +index 6c3aae9..3748461 100644 +--- a/tests/CMakeLists.txt ++++ b/tests/CMakeLists.txt +@@ -7,6 +7,11 @@ include_directories( + ${CMOCKA_INCLUDE_DIR} + ) + ++# Required for cmocka >= 1.1.6 ++if (TARGET cmocka::cmocka) ++ set(CMOCKA_LIBRARY cmocka::cmocka) ++endif() ++ + set(TORTURE_LIBRARY torture) + + # RFC862 echo server +-- +2.39.2 + diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/CHANGELOG new/socket_wrapper-1.4.1/CHANGELOG --- old/socket_wrapper-1.4.0/CHANGELOG 2023-01-17 19:35:18.000000000 +0100 +++ new/socket_wrapper-1.4.1/CHANGELOG 2023-06-21 12:27:11.000000000 +0200 @@ -1,6 +1,10 @@ CHANGELOG ========= +version 1.4.1 (released 2023-06-21) + * Fixed issue with fnctl() on 32bit + * Added openat64() to detect stale fds + version 1.4.0 (released 2023-01-18) * Added support for sendmmsg()/recvmmsg() * Added support for handling close, recvmmsg and sendmmsg syscalls diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/CMakeLists.txt new/socket_wrapper-1.4.1/CMakeLists.txt --- old/socket_wrapper-1.4.0/CMakeLists.txt 2023-01-17 19:35:32.000000000 +0100 +++ new/socket_wrapper-1.4.1/CMakeLists.txt 2023-06-21 12:27:11.000000000 +0200 @@ -11,7 +11,7 @@ include(DefineCMakeDefaults) include(DefineCompilerFlags) -project(socket_wrapper VERSION 1.4.0 LANGUAGES C) +project(socket_wrapper VERSION 1.4.1 LANGUAGES C) # global needed variables set(APPLICATION_NAME ${PROJECT_NAME}) @@ -25,7 +25,7 @@ # Increment PATCH. set(LIBRARY_VERSION_MAJOR 0) set(LIBRARY_VERSION_MINOR 4) -set(LIBRARY_VERSION_PATCH 0) +set(LIBRARY_VERSION_PATCH 1) set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR}) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/ConfigureChecks.cmake new/socket_wrapper-1.4.1/ConfigureChecks.cmake --- old/socket_wrapper-1.4.0/ConfigureChecks.cmake 2023-01-17 19:32:07.000000000 +0100 +++ new/socket_wrapper-1.4.1/ConfigureChecks.cmake 2023-06-21 12:27:11.000000000 +0200 @@ -70,6 +70,7 @@ check_function_exists(bindresvport HAVE_BINDRESVPORT) check_function_exists(accept4 HAVE_ACCEPT4) check_function_exists(open64 HAVE_OPEN64) +check_function_exists(openat64 HAVE_OPENAT64) check_function_exists(fopen64 HAVE_FOPEN64) check_function_exists(getprogname HAVE_GETPROGNAME) check_function_exists(getexecname HAVE_GETEXECNAME) @@ -80,6 +81,7 @@ check_function_exists(recvmmsg HAVE_RECVMMSG) check_function_exists(sendmmsg HAVE_SENDMMSG) check_function_exists(syscall HAVE_SYSCALL) +check_function_exists(fcntl64 HAVE_FCNTL64) if (UNIX) find_library(DLFCN_LIBRARY dl) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/cmake/Toolchain-cross-m32.cmake new/socket_wrapper-1.4.1/cmake/Toolchain-cross-m32.cmake --- old/socket_wrapper-1.4.0/cmake/Toolchain-cross-m32.cmake 1970-01-01 01:00:00.000000000 +0100 +++ new/socket_wrapper-1.4.1/cmake/Toolchain-cross-m32.cmake 2023-06-21 12:27:11.000000000 +0200 @@ -0,0 +1,23 @@ +set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags" FORCE) +set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE) + +set(LIB32 /usr/lib) # Fedora + +if(EXISTS /usr/lib32) + set(LIB32 /usr/lib32) # Arch, Solus +endif() + +set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) +set(CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) + +# this is probably unlikely to be needed, but just in case +set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) +set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) + +# on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have +# to include the regular system .pc files as well (at the end), because some +# are not always present in the 32 bit directory +if(EXISTS ${LIB32}/pkgconfig) + set(ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) +endiF() diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/config.h.cmake new/socket_wrapper-1.4.1/config.h.cmake --- old/socket_wrapper-1.4.0/config.h.cmake 2023-01-17 19:32:07.000000000 +0100 +++ new/socket_wrapper-1.4.1/config.h.cmake 2023-06-21 12:27:11.000000000 +0200 @@ -43,6 +43,7 @@ #cmakedefine HAVE_BINDRESVPORT 1 #cmakedefine HAVE_ACCEPT4 1 #cmakedefine HAVE_OPEN64 1 +#cmakedefine HAVE_OPENAT64 1 #cmakedefine HAVE_FOPEN64 1 #cmakedefine HAVE_GETPROGNAME 1 #cmakedefine HAVE_GETEXECNAME 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/src/CMakeLists.txt new/socket_wrapper-1.4.1/src/CMakeLists.txt --- old/socket_wrapper-1.4.0/src/CMakeLists.txt 2022-11-04 15:45:56.000000000 +0100 +++ new/socket_wrapper-1.4.1/src/CMakeLists.txt 2023-06-21 12:27:11.000000000 +0200 @@ -8,6 +8,12 @@ PRIVATE ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE) +if (CMAKE_SIZEOF_VOID_P EQUAL 4) + target_compile_options(socket_wrapper + PRIVATE + -D_LARGEFILE64_SOURCE) +endif() + target_link_libraries(socket_wrapper PRIVATE ${SWRAP_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/src/socket_wrapper.c new/socket_wrapper-1.4.1/src/socket_wrapper.c --- old/socket_wrapper-1.4.0/src/socket_wrapper.c 2023-01-17 19:32:07.000000000 +0100 +++ new/socket_wrapper-1.4.1/src/socket_wrapper.c 2023-06-21 12:27:11.000000000 +0200 @@ -531,6 +531,9 @@ #ifdef HAVE_OPEN64 typedef int (*__libc_open64)(const char *pathname, int flags, ...); #endif /* HAVE_OPEN64 */ +#ifdef HAVE_OPENAT64 +typedef int (*__libc_openat64)(int dirfd, const char *pathname, int flags, ...); +#endif /* HAVE_OPENAT64 */ typedef int (*__libc_openat)(int dirfd, const char *path, int flags, ...); typedef int (*__libc_pipe)(int pipefd[2]); typedef int (*__libc_read)(int fd, void *buf, size_t count); @@ -611,7 +614,11 @@ SWRAP_SYMBOL_ENTRY(connect); SWRAP_SYMBOL_ENTRY(dup); SWRAP_SYMBOL_ENTRY(dup2); +#ifdef HAVE_FCNTL64 + SWRAP_SYMBOL_ENTRY(fcntl64); +#else SWRAP_SYMBOL_ENTRY(fcntl); +#endif SWRAP_SYMBOL_ENTRY(fopen); #ifdef HAVE_FOPEN64 SWRAP_SYMBOL_ENTRY(fopen64); @@ -628,6 +635,9 @@ #ifdef HAVE_OPEN64 SWRAP_SYMBOL_ENTRY(open64); #endif +#ifdef HAVE_OPENAT64 + SWRAP_SYMBOL_ENTRY(openat64); +#endif SWRAP_SYMBOL_ENTRY(openat); SWRAP_SYMBOL_ENTRY(pipe); SWRAP_SYMBOL_ENTRY(read); @@ -978,7 +988,24 @@ arg = va_arg(ap, void *); + /* + * If fcntl64 exists then this is a system were fcntl is + * renamed (including when building this file), and so we must + * assume that the binary under test was built with + * -D_FILE_OFFSET_BITS=64 and pass on to fcntl64. + * + * If we are wrong, then fcntl is unwrapped, but while that is + * not ideal, is is also unlikely. + * + * In any case, it is always wrong to map fcntl64() to fcntl() + * as this will cause a thunk from struct flock -> flock64 + * that the caller had already prepared for. + */ +#ifdef HAVE_FCNTL64 + rc = swrap.libc.symbols._libc_fcntl64.f(fd, cmd, arg); +#else rc = swrap.libc.symbols._libc_fcntl.f(fd, cmd, arg); +#endif return rc; } @@ -1115,6 +1142,29 @@ } #endif /* HAVE_OPEN64 */ +#ifdef HAVE_OPENAT64 +static int +libc_vopenat64(int dirfd, const char *pathname, int flags, va_list ap) +{ + int mode = 0; + int fd; + + swrap_bind_symbol_all(); + + swrap_inject_o_largefile(&flags); + + if (flags & O_CREAT) { + mode = va_arg(ap, int); + } + fd = swrap.libc.symbols._libc_openat64.f(dirfd, + pathname, + flags, + (mode_t)mode); + + return fd; +} +#endif /* HAVE_OPENAT64 */ + static int libc_vopenat(int dirfd, const char *path, int flags, va_list ap) { int mode = 0; @@ -1400,7 +1450,11 @@ swrap_bind_symbol_libsocket(connect); swrap_bind_symbol_libc(dup); swrap_bind_symbol_libc(dup2); +#ifdef HAVE_FCNTL64 + swrap_bind_symbol_libc(fcntl64); +#else swrap_bind_symbol_libc(fcntl); +#endif swrap_bind_symbol_libc(fopen); #ifdef HAVE_FOPEN64 swrap_bind_symbol_libc(fopen64); @@ -1417,6 +1471,9 @@ #ifdef HAVE_OPEN64 swrap_bind_symbol_libc(open64); #endif +#ifdef HAVE_OPENAT64 + swrap_bind_symbol_libc(openat64); +#endif swrap_bind_symbol_libc(openat); swrap_bind_symbol_libsocket(pipe); swrap_bind_symbol_libc(read); @@ -4667,6 +4724,42 @@ #endif /* HAVE_OPEN64 */ /**************************************************************************** + * OPENAT64 + ***************************************************************************/ + +#ifdef HAVE_OPENAT64 +static int +swrap_vopenat64(int dirfd, const char *pathname, int flags, va_list ap) +{ + int ret; + + ret = libc_vopenat64(dirfd, pathname, flags, ap); + if (ret != -1) { + /* + * There are methods for closing descriptors (libc-internal code + * paths, direct syscalls) which close descriptors in ways that + * we can't intercept, so try to recover when we notice that + * that's happened + */ + swrap_remove_stale(ret); + } + return ret; +} + +int openat64(int dirfd, const char *pathname, int flags, ...) +{ + va_list ap; + int fd; + + va_start(ap, flags); + fd = swrap_vopenat64(dirfd, pathname, flags, ap); + va_end(ap); + + return fd; +} +#endif /* HAVE_OPENAT64 */ + +/**************************************************************************** * OPENAT ***************************************************************************/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/tests/CMakeLists.txt new/socket_wrapper-1.4.1/tests/CMakeLists.txt --- old/socket_wrapper-1.4.0/tests/CMakeLists.txt 2023-01-17 19:32:07.000000000 +0100 +++ new/socket_wrapper-1.4.1/tests/CMakeLists.txt 2023-06-21 12:27:11.000000000 +0200 @@ -7,6 +7,11 @@ ${CMOCKA_INCLUDE_DIR} ) +# Required for cmocka >= 1.1.6 +if (TARGET cmocka::cmocka) + set(CMOCKA_LIBRARY cmocka::cmocka) +endif() + set(TORTURE_LIBRARY torture) # RFC862 echo server @@ -53,12 +58,14 @@ test_tcp_listen test_tcp_dup2 test_fcntl + test_fcntl_lock test_echo_tcp_connect test_echo_tcp_bind test_echo_tcp_socket_options test_echo_tcp_sendmsg_recvmsg test_echo_tcp_sendmmsg_recvmmsg test_echo_tcp_write_read + test_echo_tcp_poll test_echo_tcp_writev_readv test_echo_tcp_get_peer_sock_name test_echo_udp_sendto_recvfrom @@ -120,10 +127,15 @@ ENVIRONMENT "${TORTURE_ENVIRONMENT}") endfunction() +if (CMAKE_SIZEOF_VOID_P EQUAL 4) + message(STATUS "Enabling large file support for tests") + set(LFS_CFLAGS "-D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64") +endif() + foreach(_SWRAP_TEST ${SWRAP_TESTS}) add_cmocka_test(${_SWRAP_TEST} SOURCES ${_SWRAP_TEST}.c - COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE + COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} -D_GNU_SOURCE ${LFS_CFLAGS} LINK_LIBRARIES ${TORTURE_LIBRARY} socket_wrapper_noop LINK_OPTIONS ${DEFAULT_LINK_FLAGS}) add_cmocka_test_environment(${_SWRAP_TEST}) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/tests/test_echo_tcp_poll.c new/socket_wrapper-1.4.1/tests/test_echo_tcp_poll.c --- old/socket_wrapper-1.4.0/tests/test_echo_tcp_poll.c 1970-01-01 01:00:00.000000000 +0100 +++ new/socket_wrapper-1.4.1/tests/test_echo_tcp_poll.c 2023-05-05 07:11:57.000000000 +0200 @@ -0,0 +1,226 @@ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include "config.h" +#include "torture.h" + +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <stdlib.h> +#include <stdio.h> +#include <unistd.h> +#include <poll.h> + +static int setup_echo_srv_tcp_ipv4(void **state) +{ + torture_setup_echo_srv_tcp_ipv4(state); + + return 0; +} + +#ifdef HAVE_IPV6 +static int setup_echo_srv_tcp_ipv6(void **state) +{ + torture_setup_echo_srv_tcp_ipv6(state); + + return 0; +} +#endif + +static int teardown(void **state) +{ + torture_teardown_echo_srv(state); + + return 0; +} + +static void handle_poll_loop(size_t size, int s) +{ + char send_buf[size]; + char recv_buf[size]; + int nfds, num_open_fds; + struct pollfd pfds[1]; + size_t nread = 0, nwrote = 0; + ssize_t ret; + int i; + + num_open_fds = nfds = 1; + pfds[0].fd = s; + pfds[0].events = POLLIN | POLLOUT; + + i = 0; + memset(send_buf, 0, sizeof(send_buf)); + + while (num_open_fds > 0 && i < 10) { + int ready; + + printf("About to poll()\n"); + ready = poll(pfds, nfds, -1); + assert_int_not_equal(ready, -1); + + printf("Ready: %d\n", ready); + + /* Deal with array returned by poll(). */ + for (int j = 0; j < nfds; j++) { + if (pfds[j].revents != 0) { + printf(" fd=%d; events: %s%s%s%s\n", pfds[j].fd, + (pfds[j].revents & POLLIN) ? "POLLIN " : "", + (pfds[j].revents & POLLOUT) ? "POLLOUT " : "", + (pfds[j].revents & POLLHUP) ? "POLLHUP " : "", + (pfds[j].revents & POLLERR) ? "POLLERR " : ""); + } + + if (pfds[j].revents & POLLIN) { + ret = read(s, + recv_buf + nread, + sizeof(recv_buf) - nread); + printf(" fd=%d: read=%zd\n", pfds[j].fd, ret); + assert_int_not_equal(ret, -1); + nread += ret; + /* try to delay */ + sleep(5); + } + if (pfds[j].revents & POLLOUT) { + snprintf(send_buf, sizeof(send_buf), + "packet.%d", i); + ret = write(s, + send_buf + nwrote, + sizeof(send_buf) - nwrote); + printf(" fd=%d: wrote=%zd\n", pfds[j].fd, ret); + assert_int_not_equal(ret, -1); + nwrote += ret; + if (nwrote == sizeof(send_buf)) { + /* no more to write */ + pfds[j].events &= ~POLLOUT; + } + } + if (pfds[j].revents & (POLLERR | POLLHUP)) { + printf(" closing fd %d\n", pfds[j].fd); + close(pfds[j].fd); + num_open_fds--; + } + + /* verify the data */ + if (nwrote == sizeof(send_buf) && nread == nwrote) { + assert_memory_equal(send_buf, recv_buf, + sizeof(send_buf)); + i++; + nwrote = 0; + nread = 0; + /* new packet to write */ + pfds[j].events |= POLLOUT; + printf("== Next packet %d\n", i); + } + } + } + + printf("All file descriptors closed; bye\n"); +} + +static void test_write_read_ipv4_size(void **state, size_t size) +{ + struct torture_address addr = { + .sa_socklen = sizeof(struct sockaddr_in), + }; + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + assert_int_not_equal(s, -1); + + addr.sa.in.sin_family = AF_INET; + addr.sa.in.sin_port = htons(torture_server_port()); + + rc = inet_pton(addr.sa.in.sin_family, + torture_server_address(AF_INET), + &addr.sa.in.sin_addr); + assert_int_equal(rc, 1); + + rc = connect(s, &addr.sa.s, addr.sa_socklen); + assert_int_equal(rc, 0); + + /* closes the socket too */ + handle_poll_loop(size, s); +} + +static void test_write_read_ipv4(void **state) +{ + test_write_read_ipv4_size(state, 64); +} + +static void test_write_read_ipv4_large(void **state) +{ + test_write_read_ipv4_size(state, 2000); +} + +#ifdef HAVE_IPV6 +static void test_write_read_ipv6_size(void **state, size_t size) +{ + struct torture_address addr = { + .sa_socklen = sizeof(struct sockaddr_in6), + }; + int rc; + int s; + + (void) state; /* unused */ + + s = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP); + assert_int_not_equal(s, -1); + + addr.sa.in6.sin6_family = AF_INET6; + addr.sa.in6.sin6_port = htons(torture_server_port()); + + rc = inet_pton(AF_INET6, + torture_server_address(AF_INET6), + &addr.sa.in6.sin6_addr); + assert_int_equal(rc, 1); + + rc = connect(s, &addr.sa.s, addr.sa_socklen); + assert_int_equal(rc, 0); + + /* closes the socket too */ + handle_poll_loop(size, s); +} + +static void test_write_read_ipv6(void **state) +{ + test_write_read_ipv6_size(state, 64); +} + +static void test_write_read_ipv6_large(void **state) +{ + test_write_read_ipv6_size(state, 2000); +} +#endif + +int main(void) { + int rc; + + const struct CMUnitTest tcp_write_tests[] = { + cmocka_unit_test_setup_teardown(test_write_read_ipv4, + setup_echo_srv_tcp_ipv4, + teardown), + cmocka_unit_test_setup_teardown(test_write_read_ipv4_large, + setup_echo_srv_tcp_ipv4, + teardown), +#ifdef HAVE_IPV6 + cmocka_unit_test_setup_teardown(test_write_read_ipv6, + setup_echo_srv_tcp_ipv6, + teardown), + cmocka_unit_test_setup_teardown(test_write_read_ipv6_large, + setup_echo_srv_tcp_ipv6, + teardown), +#endif + }; + + rc = cmocka_run_group_tests(tcp_write_tests, NULL, NULL); + + return rc; +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/tests/test_echo_tcp_write_read.c new/socket_wrapper-1.4.1/tests/test_echo_tcp_write_read.c --- old/socket_wrapper-1.4.0/tests/test_echo_tcp_write_read.c 2018-11-13 17:47:01.000000000 +0100 +++ new/socket_wrapper-1.4.1/tests/test_echo_tcp_write_read.c 2023-05-05 07:11:57.000000000 +0200 @@ -38,11 +38,13 @@ return 0; } -static void test_write_read_ipv4(void **state) +static void test_write_read_ipv4_size(void **state, size_t size) { struct torture_address addr = { .sa_socklen = sizeof(struct sockaddr_in), }; + char send_buf[size]; + char recv_buf[size]; ssize_t ret; int rc; int i; @@ -64,34 +66,49 @@ rc = connect(s, &addr.sa.s, addr.sa_socklen); assert_int_equal(rc, 0); + memset(send_buf, 0, sizeof(send_buf)); for (i = 0; i < 10; i++) { - char send_buf[64] = {0}; - char recv_buf[64] = {0}; - + size_t nread = 0, nwrote = 0; snprintf(send_buf, sizeof(send_buf), "packet.%d", i); - ret = write(s, - send_buf, - sizeof(send_buf)); - assert_int_not_equal(ret, -1); - - ret = read(s, - recv_buf, - sizeof(recv_buf)); - assert_int_not_equal(ret, -1); + do { + ret = write(s, + send_buf + nwrote, + sizeof(send_buf) - nwrote); + assert_int_not_equal(ret, -1); + nwrote += ret; + + ret = read(s, + recv_buf + nread, + sizeof(recv_buf) - nread); + assert_int_not_equal(ret, -1); + nread += ret; + } while (nread < sizeof(recv_buf) && nwrote < sizeof(send_buf)); + assert_int_equal(nread, sizeof(send_buf)); assert_memory_equal(send_buf, recv_buf, sizeof(send_buf)); } close(s); } +static void test_write_read_ipv4(void **state) +{ + test_write_read_ipv4_size(state, 64); +} + +static void test_write_read_ipv4_large(void **state) +{ + test_write_read_ipv4_size(state, 2000); +} #ifdef HAVE_IPV6 -static void test_write_read_ipv6(void **state) +static void test_write_read_ipv6_size(void **state, size_t size) { struct torture_address addr = { .sa_socklen = sizeof(struct sockaddr_in6), }; + char send_buf[size]; + char recv_buf[size]; ssize_t ret; int rc; int i; @@ -113,27 +130,41 @@ rc = connect(s, &addr.sa.s, addr.sa_socklen); assert_int_equal(rc, 0); + memset(send_buf, 0, sizeof(send_buf)); for (i = 0; i < 10; i++) { - char send_buf[64] = {0}; - char recv_buf[64] = {0}; - + size_t nread = 0, nwrote = 0; snprintf(send_buf, sizeof(send_buf), "packet.%d", i); - ret = write(s, - send_buf, - sizeof(send_buf)); - assert_int_not_equal(ret, -1); - - ret = read(s, - recv_buf, - sizeof(recv_buf)); - assert_int_not_equal(ret, -1); + do { + ret = write(s, + send_buf + nwrote, + sizeof(send_buf) - nwrote); + assert_int_not_equal(ret, -1); + nwrote += ret; + + ret = read(s, + recv_buf + nread, + sizeof(recv_buf) - nread); + assert_int_not_equal(ret, -1); + nread += ret; + } while (nread < sizeof(recv_buf) && nwrote < sizeof(send_buf)); + assert_int_equal(nread, sizeof(send_buf)); assert_memory_equal(send_buf, recv_buf, sizeof(send_buf)); } close(s); } + +static void test_write_read_ipv6(void **state) +{ + test_write_read_ipv6_size(state, 64); +} + +static void test_write_read_ipv6_large(void **state) +{ + test_write_read_ipv6_size(state, 2000); +} #endif int main(void) { @@ -143,10 +174,16 @@ cmocka_unit_test_setup_teardown(test_write_read_ipv4, setup_echo_srv_tcp_ipv4, teardown), + cmocka_unit_test_setup_teardown(test_write_read_ipv4_large, + setup_echo_srv_tcp_ipv4, + teardown), #ifdef HAVE_IPV6 cmocka_unit_test_setup_teardown(test_write_read_ipv6, setup_echo_srv_tcp_ipv6, teardown), + cmocka_unit_test_setup_teardown(test_write_read_ipv6_large, + setup_echo_srv_tcp_ipv6, + teardown), #endif }; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.4.0/tests/test_fcntl_lock.c new/socket_wrapper-1.4.1/tests/test_fcntl_lock.c --- old/socket_wrapper-1.4.0/tests/test_fcntl_lock.c 1970-01-01 01:00:00.000000000 +0100 +++ new/socket_wrapper-1.4.1/tests/test_fcntl_lock.c 2023-06-21 12:27:11.000000000 +0200 @@ -0,0 +1,93 @@ +#include "torture.h" + +#include <cmocka.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <limits.h> +#include <unistd.h> +#include <fcntl.h> +#include <errno.h> + +static int setup(void **state) +{ + char test_tmpdir[256]; + const char *p; + + (void) state; /* unused */ + + snprintf(test_tmpdir, sizeof(test_tmpdir), "/tmp/test_socket_wrapper_XXXXXX"); + + p = mkdtemp(test_tmpdir); + assert_non_null(p); + + *state = strdup(p); + return 0; +} + +static int teardown(void **state) +{ + char remove_cmd[PATH_MAX] = {0}; + char *s = (char *)*state; + int rc; + + if (s == NULL) { + return -1; + } + + snprintf(remove_cmd, sizeof(remove_cmd), "rm -rf %s", s); + free(s); + + rc = system(remove_cmd); + if (rc < 0) { + fprintf(stderr, "%s failed: %s", remove_cmd, strerror(errno)); + } + + return rc; +} + +static void test_fcntl_lock(void **state) +{ + char file[PATH_MAX]; + int fd, rc; + struct flock lock; + char *s = (char *)*state; + int cmd = F_SETLK; +#ifdef F_SETLK64 + cmd = F_SETLK64; +#endif +#ifdef F_OFD_SETLK + cmd = F_OFD_SETLK; +#endif + + rc = snprintf(file, sizeof(file), "%s/file", s); + assert_in_range(rc, 0, PATH_MAX); + + fd = open(file, O_CREAT, 0600); + assert_return_code(fd, errno); + + lock.l_type = F_RDLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 4; + lock.l_pid = 0; + + rc = fcntl(fd, cmd, &lock); + assert_return_code(rc, errno); + + rc = unlink(file); + assert_return_code(rc, errno); +} + + +int main(void) { + int rc; + + const struct CMUnitTest tcp_fcntl_lock_tests[] = { + cmocka_unit_test(test_fcntl_lock), + }; + + rc = cmocka_run_group_tests(tcp_fcntl_lock_tests, setup, teardown); + + return rc; +}
