Rearrange and fixup abstraction layer

- Replace os_result by dds_retcode_t and move DDS return code defines down.
  Eliminates the need to convert between different return code types.

- Move dds_time_t down and remove os_time.
  Eliminates the need to convert between different time representations and
  reduces code duplication.

- Remove use of Microsoft source-code annotation language (SAL).
  SAL annotations are Microsoft specific and not very well documented. This
  makes it very difficult for contributers to write.

- Rearrange the abstraction layer to be feature-based. The previous layout
  falsely assumed that the operating system dictates which implementation is
  best suited. For general purpose operating systems this is mostly true, but
  embedded targets require a slightly different approach and may not even offer
  all features. The new layout makes it possible to mix-and-match feature
  implementations and allows for features to not be implemented at all.

- Replace the os prefix by ddsrt to avoid name collisions.

- Remove various portions of unused and unwanted code.

- Export thread names on all supported platforms.

- Return native thread identifier on POSIX compatible platforms.

- Add timed wait for condition variables that takes an absolute time.

- Remove system abstraction for errno. The os_getErrno and os_setErrno were
  incorrect. Functions that might fail now simply return a DDS return code
  instead.

- Remove thread-specific memory abstraction. os_threadMemGet and accompanying
  functions were a mess and their use has been eliminated by other changes in
  this commit.

- Replace attribute (re)defines by ddsrt_ prefixed equivalents to avoid name
  collisions and problems with faulty __nonnull__ attributes.

Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
Jeroen Koekkoek 2019-01-18 14:10:19 +01:00
parent 318968f40f
commit cd6742ee12
439 changed files with 22117 additions and 28782 deletions

98
src/ddsrt/tests/environ.c Normal file
View file

@ -0,0 +1,98 @@
/*
* 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 <stdlib.h>
#include "CUnit/Theory.h"
#include "dds/ddsrt/environ.h"
#include "dds/ddsrt/misc.h"
CU_TheoryDataPoints(ddsrt_environ, bad_name) = {
CU_DataPoints(const char *, "", "foo=")
};
CU_Theory((const char *name), ddsrt_environ, bad_name)
{
dds_retcode_t rc;
static const char value[] = "bar";
static char dummy[] = "foobar";
char *ptr;
rc = ddsrt_setenv(name, value);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER);
rc = ddsrt_unsetenv(name);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER);
ptr = dummy;
rc = ddsrt_getenv(name, &ptr);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_BAD_PARAMETER);
CU_ASSERT_PTR_EQUAL(ptr, dummy);
}
DDSRT_WARNING_MSVC_OFF(4996)
CU_Test(ddsrt_environ, setenv)
{
dds_retcode_t rc;
static const char name[] = "foo";
static char value[] = "bar";
char *ptr;
rc = ddsrt_setenv(name, value);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
ptr = getenv(name);
CU_ASSERT_PTR_NOT_NULL(ptr);
CU_ASSERT_STRING_EQUAL(ptr, "bar");
/* Ensure value is copied into the environment. */
value[2] = 'z';
ptr = getenv(name);
CU_ASSERT_PTR_NOT_NULL(ptr);
CU_ASSERT_STRING_EQUAL(ptr, "bar");
rc = ddsrt_setenv(name, "");
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
ptr = getenv(name);
CU_ASSERT_PTR_NULL(ptr);
}
DDSRT_WARNING_MSVC_ON(4996)
CU_Test(ddsrt_environ, getenv)
{
dds_retcode_t rc;
static const char name[] = "foo";
static const char value[] = "bar";
static char dummy[] = "foobar";
char *ptr;
/* Ensure "not found" is returned. */
rc = ddsrt_unsetenv(name);
CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK);
ptr = dummy;
rc = ddsrt_getenv(name, &ptr);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_NOT_FOUND);
CU_ASSERT_PTR_EQUAL(ptr, dummy);
/* Ensure "ok" is returned and value is what it should be. */
rc = ddsrt_setenv(name, value);
CU_ASSERT_EQUAL_FATAL(rc, DDS_RETCODE_OK);
ptr = dummy;
rc = ddsrt_getenv(name, &ptr);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
CU_ASSERT_PTR_NOT_EQUAL(ptr, dummy);
CU_ASSERT_PTR_NOT_EQUAL(ptr, NULL);
if (ptr != NULL) {
CU_ASSERT_STRING_EQUAL(ptr, "bar");
}
/* Ensure environement is as it was. */
rc = ddsrt_unsetenv(name);
CU_ASSERT_EQUAL(rc, DDS_RETCODE_OK);
}