Add support for FreeRTOS and lwIP (#166)
Add support for FreeRTOS and lwIP Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
		
							parent
							
								
									dba4e6d391
								
							
						
					
					
						commit
						aa2715f4fe
					
				
					 67 changed files with 3691 additions and 200 deletions
				
			
		| 
						 | 
				
			
			@ -10,59 +10,63 @@
 | 
			
		|||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
#
 | 
			
		||||
include(CUnit)
 | 
			
		||||
include(GenerateDummyExportHeader)
 | 
			
		||||
 | 
			
		||||
set(sources
 | 
			
		||||
    "atomics.c"
 | 
			
		||||
    "environ.c"
 | 
			
		||||
    "heap.c"
 | 
			
		||||
    "ifaddrs.c"
 | 
			
		||||
    "sync.c"
 | 
			
		||||
    "strtoll.c"
 | 
			
		||||
    "thread.c"
 | 
			
		||||
    "thread_cleanup.c"
 | 
			
		||||
    "string.c"
 | 
			
		||||
    "log.c"
 | 
			
		||||
    "random.c"
 | 
			
		||||
    "strlcpy.c"
 | 
			
		||||
    "socket.c"
 | 
			
		||||
    "process.c"
 | 
			
		||||
    "select.c")
 | 
			
		||||
list(APPEND sources
 | 
			
		||||
  "atomics.c"
 | 
			
		||||
  "environ.c"
 | 
			
		||||
  "heap.c"
 | 
			
		||||
  "ifaddrs.c"
 | 
			
		||||
  "sync.c"
 | 
			
		||||
  "strtoll.c"
 | 
			
		||||
  "thread.c"
 | 
			
		||||
  "thread_cleanup.c"
 | 
			
		||||
  "string.c"
 | 
			
		||||
  "log.c"
 | 
			
		||||
  "random.c"
 | 
			
		||||
  "strlcpy.c"
 | 
			
		||||
  "socket.c"
 | 
			
		||||
  "select.c")
 | 
			
		||||
 | 
			
		||||
add_cunit_executable(cunit_ddsrt ${sources})
 | 
			
		||||
target_link_libraries(cunit_ddsrt PRIVATE ddsrt)
 | 
			
		||||
 | 
			
		||||
# Create a dummy export header. generate_export_header can only be used with
 | 
			
		||||
# library targets, but since the targets are linked statically,
 | 
			
		||||
# __declspec(dllimport) is not required anyway.
 | 
			
		||||
set(export_dir "${CMAKE_CURRENT_BINARY_DIR}/include/dds")
 | 
			
		||||
set(export_header "${export_dir}/export.h")
 | 
			
		||||
if(NOT EXISTS "${export_header}")
 | 
			
		||||
  file(MAKE_DIRECTORY "${export_dir}")
 | 
			
		||||
  file(WRITE "${export_header}" "#define DDS_EXPORT\n")
 | 
			
		||||
if(HAVE_MULTI_PROCESS)
 | 
			
		||||
  list(APPEND sources "process.c")
 | 
			
		||||
endif()
 | 
			
		||||
if(WITH_FREERTOS)
 | 
			
		||||
  list(APPEND sources "tasklist.c")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
add_cunit_executable(cunit_ddsrt ${sources})
 | 
			
		||||
target_link_libraries(
 | 
			
		||||
  cunit_ddsrt PRIVATE ddsrt)
 | 
			
		||||
target_include_directories(
 | 
			
		||||
  cunit_ddsrt PRIVATE "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
 | 
			
		||||
generate_dummy_export_header(
 | 
			
		||||
  cunit_ddsrt
 | 
			
		||||
  BASE_NAME dds
 | 
			
		||||
  EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/include/dds/export.h")
 | 
			
		||||
 | 
			
		||||
# Create a separate test application that will be used to
 | 
			
		||||
# test process management.
 | 
			
		||||
add_executable(process_app process_app.c)
 | 
			
		||||
target_link_libraries(process_app PRIVATE ddsrt)
 | 
			
		||||
target_include_directories(
 | 
			
		||||
        process_app
 | 
			
		||||
        PRIVATE
 | 
			
		||||
        "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
 | 
			
		||||
# Force the app to be at the same location, no matter what platform or build type.
 | 
			
		||||
set_target_properties(
 | 
			
		||||
        process_app
 | 
			
		||||
        PROPERTIES
 | 
			
		||||
        RUNTIME_OUTPUT_DIRECTORY                ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
        RUNTIME_OUTPUT_DIRECTORY_DEBUG          ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
        RUNTIME_OUTPUT_DIRECTORY_RELEASE        ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
        RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
        RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL     ${CMAKE_CURRENT_BINARY_DIR} )
 | 
			
		||||
# Let the cunit application know the location and name of the test application.
 | 
			
		||||
set(process_app_name "${CMAKE_CURRENT_BINARY_DIR}/process_app${CMAKE_EXECUTABLE_SUFFIX}")
 | 
			
		||||
configure_file(
 | 
			
		||||
        "process_test.h.in" "${CMAKE_CURRENT_BINARY_DIR}/include/process_test.h" @ONLY)
 | 
			
		||||
if(HAVE_MULTI_PROCESS)
 | 
			
		||||
  # A separate application is required to test process management.
 | 
			
		||||
  add_executable(process_app process_app.c)
 | 
			
		||||
  target_link_libraries(process_app PRIVATE ddsrt)
 | 
			
		||||
  target_include_directories(
 | 
			
		||||
    process_app
 | 
			
		||||
    PRIVATE
 | 
			
		||||
    "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>")
 | 
			
		||||
  # Force the app to be at the same location, no matter what platform or build type.
 | 
			
		||||
  # FIXME: What if custom targets are added?
 | 
			
		||||
  # FIXME: What debug and release builds are mixed on Windows and macOS?
 | 
			
		||||
  set_target_properties(
 | 
			
		||||
    process_app
 | 
			
		||||
    PROPERTIES
 | 
			
		||||
    RUNTIME_OUTPUT_DIRECTORY                ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
    RUNTIME_OUTPUT_DIRECTORY_DEBUG          ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
    RUNTIME_OUTPUT_DIRECTORY_RELEASE        ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
    RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_BINARY_DIR}
 | 
			
		||||
    RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL     ${CMAKE_CURRENT_BINARY_DIR} )
 | 
			
		||||
  # Let the cunit application know the location and name of the test application.
 | 
			
		||||
  set(process_app_name "${CMAKE_CURRENT_BINARY_DIR}/process_app${CMAKE_EXECUTABLE_SUFFIX}")
 | 
			
		||||
  configure_file(
 | 
			
		||||
    "process_test.h.in" "${CMAKE_CURRENT_BINARY_DIR}/include/process_test.h" @ONLY)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,10 +9,10 @@
 | 
			
		|||
 *
 | 
			
		||||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include "CUnit/Test.h"
 | 
			
		||||
#include "dds/ddsrt/cdtors.h"
 | 
			
		||||
#include "dds/ddsrt/ifaddrs.h"
 | 
			
		||||
#include "dds/ddsrt/retcode.h"
 | 
			
		||||
#include "CUnit/Test.h"
 | 
			
		||||
 | 
			
		||||
/* FIXME: It's not possible to predict what network interfaces are available
 | 
			
		||||
          on a given host. To properly test all combinations the abstracted
 | 
			
		||||
| 
						 | 
				
			
			@ -117,9 +117,9 @@ CU_Test(ddsrt_getifaddrs, empty_filter)
 | 
			
		|||
  ddsrt_freeifaddrs(ifa_root);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef DDSRT_HAVE_IPV6
 | 
			
		||||
CU_Test(ddsrt_getifaddrs, ipv6)
 | 
			
		||||
{
 | 
			
		||||
#ifdef DDSRT_HAVE_IPV6
 | 
			
		||||
  if (ipv6_enabled == 1) {
 | 
			
		||||
    dds_retcode_t ret;
 | 
			
		||||
    int have_ipv6 = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -149,12 +149,16 @@ CU_Test(ddsrt_getifaddrs, ipv6)
 | 
			
		|||
  } else {
 | 
			
		||||
    CU_PASS("IPv6 disabled in test environment");
 | 
			
		||||
  }
 | 
			
		||||
#else
 | 
			
		||||
  CU_PASS("IPv6 is not supported");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Assume at least one IPv4 and one IPv6 interface are available when IPv6 is
 | 
			
		||||
   available on the platform. */
 | 
			
		||||
CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6)
 | 
			
		||||
{
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
  if (ipv6_enabled == 1) {
 | 
			
		||||
    dds_retcode_t ret;
 | 
			
		||||
    int have_ipv4 = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -182,6 +186,8 @@ CU_Test(ddsrt_getifaddrs, ipv4_n_ipv6)
 | 
			
		|||
  } else {
 | 
			
		||||
    CU_PASS("IPv6 disabled in test environment");
 | 
			
		||||
  }
 | 
			
		||||
#else
 | 
			
		||||
  CU_PASS("IPv6 is not supported");
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -311,8 +311,8 @@ static ddsrt_mutex_t mutex;
 | 
			
		|||
struct arg {
 | 
			
		||||
  ddsrt_cond_t *cond;
 | 
			
		||||
  ddsrt_mutex_t *mutex;
 | 
			
		||||
  dds_time_t stamp;
 | 
			
		||||
  dds_duration_t pause;
 | 
			
		||||
  dds_time_t before;
 | 
			
		||||
  dds_time_t after;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void dummy(void *ptr, const dds_log_data_t *data)
 | 
			
		||||
| 
						 | 
				
			
			@ -326,10 +326,10 @@ static void block(void *ptr, const dds_log_data_t *data)
 | 
			
		|||
  (void)data;
 | 
			
		||||
  struct arg *arg = (struct arg *)ptr;
 | 
			
		||||
  ddsrt_mutex_lock(arg->mutex);
 | 
			
		||||
  arg->stamp = dds_time();
 | 
			
		||||
  arg->before = dds_time();
 | 
			
		||||
  ddsrt_cond_broadcast(arg->cond);
 | 
			
		||||
  ddsrt_mutex_unlock(arg->mutex);
 | 
			
		||||
  dds_sleepfor(arg->pause);
 | 
			
		||||
  arg->after = dds_time();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t run(void *ptr)
 | 
			
		||||
| 
						 | 
				
			
			@ -347,7 +347,6 @@ static uint32_t run(void *ptr)
 | 
			
		|||
CU_Test(dds_log, synchronous_sink_changes, .fini=reset)
 | 
			
		||||
{
 | 
			
		||||
  struct arg arg;
 | 
			
		||||
  dds_time_t diff, stamp;
 | 
			
		||||
  ddsrt_thread_t tid;
 | 
			
		||||
  ddsrt_threadattr_t tattr;
 | 
			
		||||
  dds_retcode_t ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -357,7 +356,6 @@ CU_Test(dds_log, synchronous_sink_changes, .fini=reset)
 | 
			
		|||
  (void)memset(&arg, 0, sizeof(arg));
 | 
			
		||||
  arg.mutex = &mutex;
 | 
			
		||||
  arg.cond = &cond;
 | 
			
		||||
  arg.pause = 1000000;
 | 
			
		||||
 | 
			
		||||
  ddsrt_mutex_lock(&mutex);
 | 
			
		||||
  dds_set_log_sink(&block, &arg);
 | 
			
		||||
| 
						 | 
				
			
			@ -366,9 +364,7 @@ CU_Test(dds_log, synchronous_sink_changes, .fini=reset)
 | 
			
		|||
  CU_ASSERT_EQUAL_FATAL(ret, DDS_RETCODE_OK);
 | 
			
		||||
  ddsrt_cond_wait(&cond, &mutex);
 | 
			
		||||
  dds_set_log_sink(dummy, NULL);
 | 
			
		||||
  stamp = dds_time();
 | 
			
		||||
 | 
			
		||||
  CU_ASSERT(arg.stamp < stamp);
 | 
			
		||||
  diff = stamp - arg.stamp;
 | 
			
		||||
  CU_ASSERT(arg.pause < diff);
 | 
			
		||||
  CU_ASSERT(arg.before < arg.after);
 | 
			
		||||
  CU_ASSERT(arg.after < dds_time());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,10 +9,10 @@
 | 
			
		|||
 *
 | 
			
		||||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
#include "dds/ddsrt/cdtors.h"
 | 
			
		||||
#include "dds/ddsrt/sockets_priv.h"
 | 
			
		||||
#include "dds/ddsrt/cdtors.h"
 | 
			
		||||
#include "dds/ddsrt/threads.h"
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
 | 
			
		||||
CU_Init(ddsrt_select)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -139,7 +139,7 @@ static const char mesg[] = "foobar";
 | 
			
		|||
 | 
			
		||||
static uint32_t select_timeout_routine(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
  int cnt = -1;
 | 
			
		||||
  int32_t cnt = -1;
 | 
			
		||||
  dds_retcode_t rc;
 | 
			
		||||
  dds_time_t before, after;
 | 
			
		||||
  dds_duration_t delay;
 | 
			
		||||
| 
						 | 
				
			
			@ -148,7 +148,13 @@ static uint32_t select_timeout_routine(void *ptr)
 | 
			
		|||
  uint32_t res = 0;
 | 
			
		||||
 | 
			
		||||
  FD_ZERO(&rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_OFF(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
  FD_SET(arg->sock, &rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_ON(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  before = dds_time();
 | 
			
		||||
  rc = ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &cnt);
 | 
			
		||||
| 
						 | 
				
			
			@ -157,11 +163,15 @@ static uint32_t select_timeout_routine(void *ptr)
 | 
			
		|||
 | 
			
		||||
  fprintf(stderr, "Waited for %"PRId64" (nanoseconds)\n", delay);
 | 
			
		||||
  fprintf(stderr, "Expected to wait %"PRId64" (nanoseconds)\n", arg->delay);
 | 
			
		||||
  fprintf(stderr, "ddsrt_select returned %d\n", rc);
 | 
			
		||||
  fprintf(stderr, "ddsrt_select reported %d ready\n", cnt);
 | 
			
		||||
  fprintf(stderr, "ddsrt_select returned %"PRId32"\n", rc);
 | 
			
		||||
  fprintf(stderr, "ddsrt_select reported %"PRId32" ready\n", cnt);
 | 
			
		||||
 | 
			
		||||
  if (rc == DDS_RETCODE_TIMEOUT) {
 | 
			
		||||
    res = (((after - delay) >= (arg->delay - arg->skew)) && (cnt == 0));
 | 
			
		||||
  /* Running in the FreeRTOS simulator causes some trouble as interrupts are
 | 
			
		||||
     simulated using signals causing the select call to be interrupted. */
 | 
			
		||||
  } else if (rc == DDS_RETCODE_INTERRUPTED) {
 | 
			
		||||
    res = (cnt == -1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return res;
 | 
			
		||||
| 
						 | 
				
			
			@ -207,13 +217,19 @@ static uint32_t recv_routine(void *ptr)
 | 
			
		|||
{
 | 
			
		||||
  thread_arg_t *arg = (thread_arg_t*)ptr;
 | 
			
		||||
 | 
			
		||||
  int nfds = 0;
 | 
			
		||||
  int32_t nfds = 0;
 | 
			
		||||
  fd_set rdset;
 | 
			
		||||
  ssize_t rcvd = -1;
 | 
			
		||||
  char buf[sizeof(mesg)];
 | 
			
		||||
 | 
			
		||||
  FD_ZERO(&rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_OFF(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
  FD_SET(arg->sock, &rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_ON(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  (void)ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &nfds);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +276,7 @@ static uint32_t recvmsg_routine(void *ptr)
 | 
			
		|||
{
 | 
			
		||||
  thread_arg_t *arg = (thread_arg_t*)ptr;
 | 
			
		||||
 | 
			
		||||
  int nfds = 0;
 | 
			
		||||
  int32_t nfds = 0;
 | 
			
		||||
  fd_set rdset;
 | 
			
		||||
  ssize_t rcvd = -1;
 | 
			
		||||
  char buf[sizeof(mesg)];
 | 
			
		||||
| 
						 | 
				
			
			@ -274,7 +290,13 @@ static uint32_t recvmsg_routine(void *ptr)
 | 
			
		|||
  msg.msg_iovlen = 1;
 | 
			
		||||
 | 
			
		||||
  FD_ZERO(&rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_OFF(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
  FD_SET(arg->sock, &rdset);
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  DDSRT_WARNING_GNUC_ON(sign-conversion)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  (void)ddsrt_select(arg->sock + 1, &rdset, NULL, NULL, arg->delay, &nfds);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,17 +9,17 @@
 | 
			
		|||
 *
 | 
			
		||||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <errno.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
#include "dds/ddsrt/sockets.h"
 | 
			
		||||
#include "dds/ddsrt/cdtors.h"
 | 
			
		||||
#include "dds/ddsrt/endian.h"
 | 
			
		||||
#include "dds/ddsrt/heap.h"
 | 
			
		||||
#include "dds/ddsrt/misc.h"
 | 
			
		||||
#include "dds/ddsrt/sockets.h"
 | 
			
		||||
#include "dds/ddsrt/string.h"
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
DDSRT_WARNING_MSVC_OFF(4305)
 | 
			
		||||
#if DDSRT_ENDIAN == DDSRT_BIG_ENDIAN
 | 
			
		||||
| 
						 | 
				
			
			@ -79,8 +79,8 @@ CU_Theory((char *str, int af, dds_retcode_t exp), ddsrt_sockaddrfromstr, ipv4, .
 | 
			
		|||
  sockaddrfromstr_test(str, af, exp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
CU_TheoryDataPoints(ddsrt_sockaddrfromstr, ipv6) = {
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
  CU_DataPoints(char *, "127.0.0.1", "::1",
 | 
			
		||||
                        "::1",       "::",
 | 
			
		||||
                        "nip"),
 | 
			
		||||
| 
						 | 
				
			
			@ -90,13 +90,20 @@ CU_TheoryDataPoints(ddsrt_sockaddrfromstr, ipv6) = {
 | 
			
		|||
  CU_DataPoints(dds_retcode_t, DDS_RETCODE_BAD_PARAMETER, DDS_RETCODE_OK,
 | 
			
		||||
                               DDS_RETCODE_BAD_PARAMETER, DDS_RETCODE_OK,
 | 
			
		||||
                               DDS_RETCODE_BAD_PARAMETER)
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
CU_Theory((char *str, int af, dds_retcode_t exp), ddsrt_sockaddrfromstr, ipv6, .init=setup, .fini=teardown)
 | 
			
		||||
{
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
  sockaddrfromstr_test(str, af, exp);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
  (void)str;
 | 
			
		||||
  (void)af;
 | 
			
		||||
  (void)exp;
 | 
			
		||||
  CU_PASS("IPV6 is not supported");
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sockaddrtostr, bad_sockaddr, .init=setup, .fini=teardown)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -128,16 +135,19 @@ CU_Test(ddsrt_sockaddrtostr, ipv4)
 | 
			
		|||
 | 
			
		||||
CU_Test(ddsrt_sockaddrtostr, ipv6)
 | 
			
		||||
{
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
  dds_retcode_t rc;
 | 
			
		||||
  char buf[128] = { 0 };
 | 
			
		||||
  rc = ddsrt_sockaddrtostr(&ipv6_loopback, buf, sizeof(buf));
 | 
			
		||||
  CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
 | 
			
		||||
  CU_ASSERT_STRING_EQUAL(buf, "::1");
 | 
			
		||||
#else
 | 
			
		||||
  CU_PASS("IPv6 is not supported");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sockets, gethostname)
 | 
			
		||||
{
 | 
			
		||||
  int ret;
 | 
			
		||||
  dds_retcode_t rc;
 | 
			
		||||
  char sysbuf[200], buf[200];
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -146,8 +156,12 @@ CU_Test(ddsrt_sockets, gethostname)
 | 
			
		|||
  CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
 | 
			
		||||
 | 
			
		||||
  sysbuf[0] = '\0';
 | 
			
		||||
  ret = gethostname(sysbuf, sizeof(sysbuf));
 | 
			
		||||
#if LWIP_SOCKET
 | 
			
		||||
  ddsrt_strlcpy(sysbuf, "localhost", sizeof(sysbuf));
 | 
			
		||||
#else
 | 
			
		||||
  int ret = gethostname(sysbuf, sizeof(sysbuf));
 | 
			
		||||
  CU_ASSERT_EQUAL(ret, 0);
 | 
			
		||||
#endif
 | 
			
		||||
  CU_ASSERT(strcmp(buf, sysbuf) == 0);
 | 
			
		||||
 | 
			
		||||
  rc = ddsrt_gethostname(buf, strlen(buf) - 1);
 | 
			
		||||
| 
						 | 
				
			
			@ -169,6 +183,7 @@ static void gethostbyname_test(char *name, int af, dds_retcode_t exp)
 | 
			
		|||
  }
 | 
			
		||||
  ddsrt_free(hent);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
CU_TheoryDataPoints(ddsrt_gethostbyname, ipv4) = {
 | 
			
		||||
  CU_DataPoints(char *,        "",                         "127.0.0.1",    "127.0.0.1"),
 | 
			
		||||
| 
						 | 
				
			
			@ -178,21 +193,34 @@ CU_TheoryDataPoints(ddsrt_gethostbyname, ipv4) = {
 | 
			
		|||
 | 
			
		||||
CU_Theory((char *name, int af, dds_retcode_t exp), ddsrt_gethostbyname, ipv4, .init=setup, .fini=teardown)
 | 
			
		||||
{
 | 
			
		||||
#if DDSRT_HAVE_DNS
 | 
			
		||||
  gethostbyname_test(name, af, exp);
 | 
			
		||||
#else
 | 
			
		||||
  (void)name;
 | 
			
		||||
  (void)af;
 | 
			
		||||
  (void)exp;
 | 
			
		||||
  CU_PASS("DNS is not supported");
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if DDSRT_HAVE_IPV6
 | 
			
		||||
/* Lookup of IPv4 address and specifying AF_INET6 is not invalid as it may
 | 
			
		||||
   return an IPV4-mapped IPv6 address. */
 | 
			
		||||
CU_TheoryDataPoints(ddsrt_gethostbyname, ipv6) = {
 | 
			
		||||
#if DDSRT_HAVE_IPV6 && DDSRT_HAVE_DNS
 | 
			
		||||
  CU_DataPoints(char *,        "::1",                      "::1",          "::1"),
 | 
			
		||||
  CU_DataPoints(int,           AF_INET,                    AF_INET6,       AF_UNSPEC),
 | 
			
		||||
  CU_DataPoints(dds_retcode_t, DDS_RETCODE_HOST_NOT_FOUND, DDS_RETCODE_OK, DDS_RETCODE_OK)
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
CU_Theory((char *name, int af, dds_retcode_t exp), ddsrt_gethostbyname, ipv6, .init=setup, .fini=teardown)
 | 
			
		||||
{
 | 
			
		||||
#if DDSRT_HAVE_IPV6 && DDSRT_HAVE_DNS
 | 
			
		||||
  gethostbyname_test(name, af, exp);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
  (void)name;
 | 
			
		||||
  (void)af;
 | 
			
		||||
  (void)exp;
 | 
			
		||||
  CU_PASS("DNS and IPv6 are not supported");
 | 
			
		||||
#endif /* DDSRT_HAVE_IPV6 */
 | 
			
		||||
#endif /* DDSRT_HAVE_DNS */
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -270,7 +270,7 @@ static uint32_t waitfor_routine(void *ptr)
 | 
			
		|||
  reltime = after - before;
 | 
			
		||||
  fprintf(stderr, "waited for %"PRId64" (nanoseconds)\n", reltime);
 | 
			
		||||
  fprintf(stderr, "expected to wait %"PRId64" (nanoseconds)\n", arg->reltime);
 | 
			
		||||
  fprintf(stderr, "woke up %u times\n", cnt);
 | 
			
		||||
  fprintf(stderr, "woke up %"PRIu32" times\n", cnt);
 | 
			
		||||
  ddsrt_mutex_unlock(&arg->lock);
 | 
			
		||||
  if (reltime >= arg->reltime) {
 | 
			
		||||
    /* Ensure that the condition variable at least waited for the amount of
 | 
			
		||||
| 
						 | 
				
			
			@ -322,7 +322,7 @@ static uint32_t waituntil_routine(void *ptr)
 | 
			
		|||
  ddsrt_mutex_unlock(&arg->lock);
 | 
			
		||||
  fprintf(stderr, "waited until %"PRId64" (nanoseconds)\n", after);
 | 
			
		||||
  fprintf(stderr, "expected to wait until %"PRId64" (nanoseconds)\n", arg->abstime);
 | 
			
		||||
  fprintf(stderr, "woke up %u times\n", cnt);
 | 
			
		||||
  fprintf(stderr, "woke up %"PRIu32" times\n", cnt);
 | 
			
		||||
  if (after > arg->abstime) {
 | 
			
		||||
    res = cnt < 3; /* An arbitrary number to ensure the implementation
 | 
			
		||||
                      did not just spin, aka is completely broken. */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										341
									
								
								src/ddsrt/tests/tasklist.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										341
									
								
								src/ddsrt/tests/tasklist.c
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,341 @@
 | 
			
		|||
/*
 | 
			
		||||
 * Copyright(c) 2006 to 2018 ADLINK Technology Limited and others
 | 
			
		||||
 *
 | 
			
		||||
 * This program and the accompanying materials are made available under the
 | 
			
		||||
 * terms of the Eclipse Public License v. 2.0 which is available at
 | 
			
		||||
 * http://www.eclipse.org/legal/epl-2.0, or the Eclipse Distribution License
 | 
			
		||||
 * v. 1.0 which is available at
 | 
			
		||||
 * http://www.eclipse.org/org/documents/edl-v10.php.
 | 
			
		||||
 *
 | 
			
		||||
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
 */
 | 
			
		||||
#include "dds/ddsrt/sync.h"
 | 
			
		||||
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
 | 
			
		||||
/* FreeRTOS specific! */
 | 
			
		||||
 | 
			
		||||
static void fill(ddsrt_tasklist_t *list)
 | 
			
		||||
{
 | 
			
		||||
  CU_ASSERT_PTR_NOT_NULL_FATAL(list);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
 | 
			
		||||
  for (size_t i = 1; i <= DDSRT_TASKLIST_INITIAL; i++) {
 | 
			
		||||
    ddsrt_tasklist_push(list, (TaskHandle_t)i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->cnt, i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->off, 0);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->end, i - 1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->cnt, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fill_wrapped(ddsrt_tasklist_t *list)
 | 
			
		||||
{
 | 
			
		||||
  size_t i;
 | 
			
		||||
 | 
			
		||||
  fill(list);
 | 
			
		||||
 | 
			
		||||
  for (i = 1; i <= DDSRT_TASKLIST_CHUNK; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(list, NULL);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->cnt, DDSRT_TASKLIST_INITIAL - i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->off, i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (i = (DDSRT_TASKLIST_INITIAL+1); i <= (DDSRT_TASKLIST_INITIAL+DDSRT_TASKLIST_CHUNK); i++) {
 | 
			
		||||
    ddsrt_tasklist_push(list, (TaskHandle_t)i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->cnt, i - DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(list->end, (i - 1) - DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->cnt, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(list->end, DDSRT_TASKLIST_CHUNK - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef void(*fill_t)(ddsrt_tasklist_t *);
 | 
			
		||||
 | 
			
		||||
CU_TheoryDataPoints(ddsrt_sync, tasklist_pop_all) = {
 | 
			
		||||
  CU_DataPoints(fill_t, &fill, &fill_wrapped),
 | 
			
		||||
  CU_DataPoints(size_t, 1, DDSRT_TASKLIST_CHUNK + 1),
 | 
			
		||||
  CU_DataPoints(size_t, DDSRT_TASKLIST_INITIAL, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Most basic test to verify behavior is correct for simple use case. */
 | 
			
		||||
CU_Theory((fill_t func, size_t first, size_t last), ddsrt_sync, tasklist_pop_all)
 | 
			
		||||
{
 | 
			
		||||
  TaskHandle_t task;
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  func(&list);
 | 
			
		||||
 | 
			
		||||
  task = ddsrt_tasklist_pop(&list, NULL);
 | 
			
		||||
  CU_ASSERT_PTR_EQUAL(task, (TaskHandle_t)first);
 | 
			
		||||
 | 
			
		||||
  for (size_t i = first + 1; i < last; i++) {
 | 
			
		||||
    task = ddsrt_tasklist_pop(&list, NULL);
 | 
			
		||||
    CU_ASSERT_PTR_EQUAL(task, (TaskHandle_t)i);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, 1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, ((DDSRT_TASKLIST_INITIAL*2) - last) - 1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, ((DDSRT_TASKLIST_INITIAL*2) - last) - 1);
 | 
			
		||||
  task = ddsrt_tasklist_pop(&list, NULL);
 | 
			
		||||
  CU_ASSERT_PTR_EQUAL(task, (TaskHandle_t)last);
 | 
			
		||||
  task = ddsrt_tasklist_pop(&list, NULL);
 | 
			
		||||
  CU_ASSERT_PTR_NULL(task);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, 0);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_TheoryDataPoints(ddsrt_sync, tasklist_pop_n_push) = {
 | 
			
		||||
  CU_DataPoints(fill_t,
 | 
			
		||||
    &fill, &fill, &fill, &fill,
 | 
			
		||||
    &fill_wrapped, &fill_wrapped, &fill_wrapped, &fill_wrapped, &fill_wrapped),
 | 
			
		||||
  CU_DataPoints(TaskHandle_t, /* Task to pop. */
 | 
			
		||||
    (TaskHandle_t)NULL,
 | 
			
		||||
    (TaskHandle_t)1,
 | 
			
		||||
    (TaskHandle_t)DDSRT_TASKLIST_CHUNK,
 | 
			
		||||
    (TaskHandle_t)DDSRT_TASKLIST_INITIAL,
 | 
			
		||||
    (TaskHandle_t)NULL,
 | 
			
		||||
    (TaskHandle_t)(DDSRT_TASKLIST_CHUNK + 1),
 | 
			
		||||
    (TaskHandle_t)DDSRT_TASKLIST_INITIAL,
 | 
			
		||||
    (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + 1),
 | 
			
		||||
    (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK)),
 | 
			
		||||
  CU_DataPoints(size_t, /* Expected position to clear. */
 | 
			
		||||
    0, 0, DDSRT_TASKLIST_CHUNK - 1, DDSRT_TASKLIST_INITIAL - 1,
 | 
			
		||||
    DDSRT_TASKLIST_CHUNK, DDSRT_TASKLIST_CHUNK, DDSRT_TASKLIST_INITIAL - 1, 0, DDSRT_TASKLIST_CHUNK - 1),
 | 
			
		||||
  CU_DataPoints(size_t, /* Expected position of pushed task. */
 | 
			
		||||
    0, 0, DDSRT_TASKLIST_INITIAL - 1, DDSRT_TASKLIST_INITIAL - 1,
 | 
			
		||||
    DDSRT_TASKLIST_CHUNK, DDSRT_TASKLIST_CHUNK, DDSRT_TASKLIST_CHUNK, DDSRT_TASKLIST_CHUNK - 1, DDSRT_TASKLIST_CHUNK - 1)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Test to verify tasklist is correctly updated (trimmed and packed) when the
 | 
			
		||||
   tasklist is sparse. */
 | 
			
		||||
CU_Theory((fill_t func, TaskHandle_t task, size_t pos, size_t end), ddsrt_sync, tasklist_pop_n_push)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  func(&list);
 | 
			
		||||
 | 
			
		||||
  if (task == NULL) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, NULL);
 | 
			
		||||
  } else {
 | 
			
		||||
    CU_ASSERT_PTR_EQUAL(ddsrt_tasklist_pop(&list, task), task);
 | 
			
		||||
    CU_ASSERT_PTR_NULL(ddsrt_tasklist_pop(&list, task));
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_PTR_EQUAL(list.tasks[pos], NULL);
 | 
			
		||||
  task = (TaskHandle_t)(DDSRT_TASKLIST_INITIAL*2);
 | 
			
		||||
  CU_ASSERT_NOT_EQUAL_FATAL(ddsrt_tasklist_push(&list, task), -1);
 | 
			
		||||
  CU_ASSERT_PTR_EQUAL(list.tasks[end], task);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_ltrim)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill(&list);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)2);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)3);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - 2);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, 9);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - 3);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 3);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, 9);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_rtrim)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill(&list);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL - 1));
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL - 2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - 2);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - 3);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 4);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_wrapped_ltrim)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill_wrapped(&list);
 | 
			
		||||
 | 
			
		||||
  for (size_t i = DDSRT_TASKLIST_CHUNK+2; i < DDSRT_TASKLIST_INITIAL; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)i);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - (DDSRT_TASKLIST_CHUNK - 2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_CHUNK - 1);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_CHUNK+1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - (DDSRT_TASKLIST_CHUNK - 1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_CHUNK - 1);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL+1));
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, DDSRT_TASKLIST_INITIAL - (DDSRT_TASKLIST_CHUNK + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_CHUNK - 1);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_wrapped_rtrim)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
  size_t last = DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill_wrapped(&list);
 | 
			
		||||
 | 
			
		||||
  for (size_t i = last - 1; i > DDSRT_TASKLIST_INITIAL + 1; i--) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)i);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) + 2);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_CHUNK - 1);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) + 1);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, 0);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL - 1));
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL - 2));
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) - 2);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.cnt, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) - 3);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 4);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_resize)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
  int ret;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill(&list);
 | 
			
		||||
 | 
			
		||||
  /* Grow one past initial. Buffer should increase by chunk. */
 | 
			
		||||
  ret = ddsrt_tasklist_push(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  /* Grow one past initial+chunk. Buffer should increase by chunk again. */
 | 
			
		||||
  for (size_t i = 2; i <= DDSRT_TASKLIST_CHUNK + 1; i++) {
 | 
			
		||||
    ret = ddsrt_tasklist_push(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + i));
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + (DDSRT_TASKLIST_CHUNK*2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
 | 
			
		||||
  /* Shrink one past initial+chunk. Buffer should not decrease by chunk. */
 | 
			
		||||
  for (size_t i = 1; i <= DDSRT_TASKLIST_CHUNK; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)i);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + (DDSRT_TASKLIST_CHUNK*2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
 | 
			
		||||
  /* Shrink to initial. Buffer should decrease by chunk. */
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_CHUNK + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
 | 
			
		||||
  /* Shrink to initial-chunk. Buffer should decrease by chunk. */
 | 
			
		||||
  for (size_t i = DDSRT_TASKLIST_CHUNK+1; i <= (DDSRT_TASKLIST_CHUNK*2)+1; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)i);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) - 1);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CU_Test(ddsrt_sync, tasklist_wrapped_resize)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_tasklist_t list;
 | 
			
		||||
  int ret;
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_init(&list);
 | 
			
		||||
  fill_wrapped(&list);
 | 
			
		||||
 | 
			
		||||
  /* Grow one past initial. Buffer should increase by chunk. */
 | 
			
		||||
  ret = ddsrt_tasklist_push(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  /* Grow one past initial+chunk. Buffer should increase by chunk again. */
 | 
			
		||||
  for (size_t i = 2; i <= (DDSRT_TASKLIST_CHUNK + 1); i++) {
 | 
			
		||||
    ret = ddsrt_tasklist_push(&list, (TaskHandle_t)(DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK + i));
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, 0);
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + (DDSRT_TASKLIST_CHUNK*2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
 | 
			
		||||
  /* Shrink one past initial+chunk. Buffer should not decrease by chunk. */
 | 
			
		||||
  for (size_t i = 1; i <= DDSRT_TASKLIST_CHUNK; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)(DDSRT_TASKLIST_CHUNK + i));
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + (DDSRT_TASKLIST_CHUNK*2));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
 | 
			
		||||
  /* Shrink to initial. Buffer should decrease by chunk. */
 | 
			
		||||
  ddsrt_tasklist_pop(&list, (TaskHandle_t)((DDSRT_TASKLIST_CHUNK*2) + 1));
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL + DDSRT_TASKLIST_CHUNK);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, DDSRT_TASKLIST_INITIAL - 1);
 | 
			
		||||
 | 
			
		||||
  /* Shrink to initial-chunk. Buffer should decrease by chunk. */
 | 
			
		||||
  for (size_t i = 2; i <= DDSRT_TASKLIST_CHUNK + 1; i++) {
 | 
			
		||||
    ddsrt_tasklist_pop(&list, (TaskHandle_t)((DDSRT_TASKLIST_CHUNK*2) + i));
 | 
			
		||||
  }
 | 
			
		||||
  CU_ASSERT_EQUAL(list.len, DDSRT_TASKLIST_INITIAL);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.off, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(list.end, (DDSRT_TASKLIST_INITIAL - DDSRT_TASKLIST_CHUNK) - 1);
 | 
			
		||||
 | 
			
		||||
  ddsrt_tasklist_fini(&list);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -11,9 +11,12 @@
 | 
			
		|||
 */
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#if !defined(_WIN32)
 | 
			
		||||
#include <sched.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
# include <FreeRTOS.h>
 | 
			
		||||
# include <task.h>
 | 
			
		||||
#elif !defined(_WIN32)
 | 
			
		||||
# include <sched.h>
 | 
			
		||||
# include <unistd.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "CUnit/Theory.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +33,10 @@ static int32_t min_other_prio = 250;
 | 
			
		|||
CU_Init(ddsrt_thread)
 | 
			
		||||
{
 | 
			
		||||
  ddsrt_init();
 | 
			
		||||
#if defined(WIN32)
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
  max_other_prio = max_fifo_prio = configMAX_PRIORITIES - 1;
 | 
			
		||||
  min_other_prio = min_fifo_prio = tskIDLE_PRIORITY + 1;
 | 
			
		||||
#elif defined(WIN32)
 | 
			
		||||
  max_fifo_prio = THREAD_PRIORITY_HIGHEST;
 | 
			
		||||
  min_fifo_prio = THREAD_PRIORITY_LOWEST;
 | 
			
		||||
  max_other_prio = THREAD_PRIORITY_HIGHEST;
 | 
			
		||||
| 
						 | 
				
			
			@ -68,7 +74,12 @@ uint32_t thread_main(void *ptr)
 | 
			
		|||
 | 
			
		||||
  attr = arg->attr;
 | 
			
		||||
 | 
			
		||||
#if _WIN32
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
  int prio = (int)uxTaskPriorityGet(NULL);
 | 
			
		||||
  if (prio == attr->schedPriority) {
 | 
			
		||||
    arg->res = 1;
 | 
			
		||||
  }
 | 
			
		||||
#elif _WIN32
 | 
			
		||||
  int prio = GetThreadPriority(GetCurrentThread());
 | 
			
		||||
  if (prio == THREAD_PRIORITY_ERROR_RETURN)
 | 
			
		||||
    abort();
 | 
			
		||||
| 
						 | 
				
			
			@ -113,7 +124,12 @@ CU_Theory((ddsrt_sched_t sched, int32_t *prio, uint32_t exp), ddsrt_thread, crea
 | 
			
		|||
  ddsrt_threadattr_t attr;
 | 
			
		||||
  thread_arg_t arg;
 | 
			
		||||
 | 
			
		||||
#if defined(__VXWORKS__)
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
  if (sched == DDSRT_SCHED_TIMESHARE) {
 | 
			
		||||
    skip = 1;
 | 
			
		||||
    CU_PASS("FreeRTOS only support SCHED_FIFO");
 | 
			
		||||
  }
 | 
			
		||||
#elif defined(__VXWORKS__)
 | 
			
		||||
# if defined(_WRS_KERNEL)
 | 
			
		||||
  if (sched == DDSRT_SCHED_TIMESHARE) {
 | 
			
		||||
    skip = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +166,9 @@ CU_Test(ddsrt_thread, thread_id)
 | 
			
		|||
{
 | 
			
		||||
  int eq = 0;
 | 
			
		||||
  ddsrt_thread_t thr;
 | 
			
		||||
#if defined(_WIN32)
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
  TaskHandle_t task;
 | 
			
		||||
#elif defined(_WIN32)
 | 
			
		||||
  DWORD _tid;
 | 
			
		||||
#else
 | 
			
		||||
  pthread_t _thr;
 | 
			
		||||
| 
						 | 
				
			
			@ -158,7 +176,10 @@ CU_Test(ddsrt_thread, thread_id)
 | 
			
		|||
 | 
			
		||||
  thr = ddsrt_thread_self();
 | 
			
		||||
 | 
			
		||||
#if defined(_WIN32)
 | 
			
		||||
#if DDSRT_WITH_FREERTOS
 | 
			
		||||
  task = xTaskGetCurrentTaskHandle();
 | 
			
		||||
  eq = (thr.task == task);
 | 
			
		||||
#elif defined(_WIN32)
 | 
			
		||||
  _tid = GetCurrentThreadId();
 | 
			
		||||
  eq = (thr.tid == _tid);
 | 
			
		||||
#else
 | 
			
		||||
| 
						 | 
				
			
			@ -230,4 +251,3 @@ CU_Test(ddsrt_thread, attribute)
 | 
			
		|||
  CU_ASSERT_EQUAL(attr.schedPriority, 0);
 | 
			
		||||
  CU_ASSERT_EQUAL(attr.stackSize, 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue