Add domain creation torture test.

Signed-off-by: Martin Bremmer <martin.bremmer@adlinktech.com>

Disabled domain_torture_imlicit test.

Signed-off-by: Martin Bremmer <martin.bremmer@adlinktech.com>
This commit is contained in:
Martin Bremmer 2019-11-06 11:05:33 +01:00 committed by eboasson
parent fc8b8fef3a
commit b6b0c25355
5 changed files with 122 additions and 10 deletions

View file

@ -252,7 +252,7 @@ dds_entity_t dds_create_domain (const dds_domainid_t domain, const char *config)
dds_domain *dom; dds_domain *dom;
dds_entity_t ret; dds_entity_t ret;
if (domain > 230) if (domain == DDS_DOMAIN_DEFAULT)
return DDS_RETCODE_BAD_PARAMETER; return DDS_RETCODE_BAD_PARAMETER;
if (config == NULL) if (config == NULL)

View file

@ -126,9 +126,9 @@ dds_entity_t dds_create_participant (const dds_domainid_t domain, const dds_qos_
pp->m_builtin_subscriber = 0; pp->m_builtin_subscriber = 0;
/* Add participant to extent */ /* Add participant to extent */
ddsrt_mutex_lock (&dds_global.m_entity.m_mutex); ddsrt_mutex_lock (&dom->m_entity.m_mutex);
dds_entity_register_child (&dom->m_entity, &pp->m_entity); dds_entity_register_child (&dom->m_entity, &pp->m_entity);
ddsrt_mutex_unlock (&dds_global.m_entity.m_mutex); ddsrt_mutex_unlock (&dom->m_entity.m_mutex);
dds_entity_init_complete (&pp->m_entity); dds_entity_init_complete (&pp->m_entity);
/* drop temporary extra ref to domain, dds_init */ /* drop temporary extra ref to domain, dds_init */

View file

@ -21,6 +21,7 @@ set(ddsc_test_sources
"config.c" "config.c"
"dispose.c" "dispose.c"
"domain.c" "domain.c"
"domain_torture.c"
"entity_api.c" "entity_api.c"
"entity_hierarchy.c" "entity_hierarchy.c"
"entity_status.c" "entity_status.c"

View file

@ -287,10 +287,3 @@ CU_Test(ddsc_domain_create, invalid_xml)
domain = dds_create_domain(1, "<CycloneDDS incorrect XML"); domain = dds_create_domain(1, "<CycloneDDS incorrect XML");
CU_ASSERT_FATAL(domain == DDS_RETCODE_ERROR); CU_ASSERT_FATAL(domain == DDS_RETCODE_ERROR);
} }
CU_Test(ddsc_domain_create, invalid_id)
{
dds_entity_t domain;
domain = dds_create_domain(321, "<"DDS_PROJECT_NAME"><Domain><Id>any</Id></Domain></"DDS_PROJECT_NAME">");
CU_ASSERT_FATAL(domain == DDS_RETCODE_BAD_PARAMETER);
}

View file

@ -0,0 +1,118 @@
/*
* Copyright(c) 2019 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 <assert.h>
#include <limits.h>
#include "dds/dds.h"
#include "CUnit/Theory.h"
#include "RoundTrip.h"
#include "dds/ddsrt/threads.h"
#include "dds/ddsrt/atomics.h"
#include "dds/ddsrt/time.h"
#define N_THREADS (10)
static const dds_duration_t TEST_DURATION = DDS_SECS(3);
static ddsrt_atomic_uint32_t terminate;
static uint32_t create_participants_thread (void *varg)
{
(void) varg;
while (!ddsrt_atomic_ld32 (&terminate))
{
dds_entity_t par = dds_create_participant (DDS_DOMAIN_DEFAULT, NULL, NULL);
if (par < 0)
{
fprintf (stderr, "dds_create_participant failed: %s\n", dds_strretcode (par));
ddsrt_atomic_st32 (&terminate, 1);
return 1;
}
dds_return_t ret = dds_delete(par);
if (ret != DDS_RETCODE_OK)
{
fprintf (stderr, "dds_delete failed: %s\n", dds_strretcode (ret));
ddsrt_atomic_st32 (&terminate, 1);
return 1;
}
}
return 0;
}
static void participant_creation_torture()
{
dds_return_t rc;
ddsrt_thread_t tids[N_THREADS];
ddsrt_threadattr_t tattr;
ddsrt_threadattr_init (&tattr);
/* Start threads. */
for (size_t i = 0; i < sizeof(tids) / sizeof(*tids); i++)
{
rc = ddsrt_thread_create (&tids[i], "domain_torture_explicit", &tattr, create_participants_thread, 0);
CU_ASSERT_FATAL (rc == DDS_RETCODE_OK);
}
/* Let the threads do the torturing for a while. */
dds_sleepfor(TEST_DURATION);
/* Stop and check threads results. */
ddsrt_atomic_st32 (&terminate, 1);
for (size_t i = 0; i < sizeof (tids) / sizeof (tids[0]); i++)
{
uint32_t retval;
rc = ddsrt_thread_join (tids[i], &retval);
CU_ASSERT_FATAL (rc == DDS_RETCODE_OK);
CU_ASSERT (retval == 0);
}
}
/*
* There are some issues when completely init/deinit the
* library in a torturing way. We really just want to
* check the domain creation/deletion. So, disable this
* test for now.
*/
CU_Test (ddsc_domain, torture_implicit, .disabled=true)
{
/* No explicit domain creation, just start creating and
* deleting participants (that'll create and delete the
* domain implicitly) in a torturing manner. */
participant_creation_torture();
}
CU_Test (ddsc_domain, torture_explicit)
{
dds_return_t rc;
dds_entity_t domain;
/* Create domain explicitly. */
domain = dds_create_domain(1, "");
CU_ASSERT_FATAL (domain > 0);
/* Start creating and deleting participants on the
* explicit domain in a torturing manner. */
participant_creation_torture();
/* Delete domain. */
rc = dds_delete(domain);
CU_ASSERT_FATAL (rc == DDS_RETCODE_OK);
rc = dds_delete(domain);
CU_ASSERT_FATAL (rc != DDS_RETCODE_OK);
}