Skip to content

Commit

Permalink
Test sample ranks also when skipping some samples
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Boasson <eb@ilities.com>
  • Loading branch information
eboasson committed Jul 20, 2023
1 parent 0495bf2 commit 9d2deac
Showing 1 changed file with 79 additions and 47 deletions.
126 changes: 79 additions & 47 deletions src/core/ddsc/tests/reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ CU_Test(ddsc_reader_create, topic_lifespan)
CU_ASSERT_FATAL (tp > 0);
dds_entity_t rd = dds_create_reader (pp, tp, NULL, NULL);
CU_ASSERT_FATAL (rd > 0);

// need to look at the QoS object as it is actually stored: we don't want to
// overlook the LIFESPAN making it into the reader and then not observing it
// because get_qos does something funny
Expand Down Expand Up @@ -3213,7 +3213,13 @@ CU_Test(ddsc_take_mask_wl, combination_of_states, .init=reader_init, .fini=reade
}
/*************************************************************************************************/

static void do_readtake_sample_rank (dds_return_t (*op) (dds_entity_t reader_or_condition, void **buf, dds_sample_info_t *si, size_t bufsz, uint32_t maxs))
static bool test_even_long_2 (const void *vsample)
{
const Space_Type1 *sample = vsample;
return (sample->long_2 % 2) == 0;
}

static void do_readtake_sample_rank (dds_return_t (*op) (dds_entity_t reader_or_condition, void **buf, dds_sample_info_t *si, size_t bufsz, uint32_t maxs, uint32_t mask))
{
const dds_entity_t dp = dds_create_participant (0, NULL, NULL);
CU_ASSERT_FATAL (dp > 0);
Expand Down Expand Up @@ -3243,58 +3249,84 @@ static void do_readtake_sample_rank (dds_return_t (*op) (dds_entity_t reader_or_
printf ("\n");
fflush (stdout);

for (int nrd = 1; nrd < totsamp + 1; nrd++)
for (int drop_even_long_2 = 0; drop_even_long_2 <= 1; drop_even_long_2++)
{
const dds_entity_t rd = dds_create_reader (dp, tp, NULL, NULL);
CU_ASSERT_FATAL (rd > 0);
const dds_entity_t wr = dds_create_writer (dp, tp, NULL, NULL);
CU_ASSERT_FATAL (wr > 0);

// write as many samples as planned for each instance,
// add an invalid one iff # == 4
for (int i = 0; nsamp[i] > 0; i++) {
for (int s = 0; s < nsamp[i]; s++) {
rc = ((s < 4) ? dds_write : dds_dispose) (wr, &(Space_Type1){ .long_1 = i, .long_2 = s, 0 });
CU_ASSERT_FATAL (rc == 0);
}
//printf (" drop_even_long_2 %d", drop_even_long_2);
int totsamp_after_maybe_dropping_even = 0;
if (!drop_even_long_2)
totsamp_after_maybe_dropping_even = totsamp;
else
{
for (int i = 0; nsamp[i] > 0; i++)
totsamp_after_maybe_dropping_even += nsamp[i] / 2;
}

assert (nrd < (int) (sizeof (xs) / sizeof (xs[0])));
int n = (int) op (rd, buf, si, (size_t) nrd, (uint32_t) nrd);
CU_ASSERT_FATAL (n == ((nrd <= totsamp) ? nrd : totsamp));
//printf (" -- read %d ranks", n);
//for (int i = 0; i < n; i++)
// printf (" %"PRIu32, si[i].sample_rank);
//printf ("\n");


for (int nrd = 1; nrd < totsamp + 1; nrd++)
{
int i = 0;
while (i < n)
const dds_entity_t rd = dds_create_reader (dp, tp, NULL, NULL);
CU_ASSERT_FATAL (rd > 0);
const dds_entity_t wr = dds_create_writer (dp, tp, NULL, NULL);
CU_ASSERT_FATAL (wr > 0);

// write as many samples as planned for each instance,
// add an invalid one iff # == 4
for (int i = 0; nsamp[i] > 0; i++) {
for (int s = 0; s < nsamp[i]; s++) {
rc = ((s < 4) ? dds_write : dds_dispose) (wr, &(Space_Type1){ .long_1 = i, .long_2 = s, 0 });
CU_ASSERT_FATAL (rc == 0);
}
}

if (drop_even_long_2)
{
CU_ASSERT_FATAL (0 <= xs[i].long_1 && xs[i].long_1 <= 2);
const int nsamp_of_inst = (i + nsamp[xs[i].long_1] < n) ? nsamp[xs[i].long_1] : n - i;
//printf ("i = %d nsamp_of_inst = %d\n", i, nsamp_of_inst);
assert (nsamp_of_inst > 0);
CU_ASSERT_FATAL (si[i].sample_rank == (uint32_t) (nsamp_of_inst - 1));
CU_ASSERT_FATAL (xs[i].long_3 == 0);
CU_ASSERT_FATAL ((int) si[i].sample_rank < nsamp_of_inst);
const int first_of_inst = i;
for (int j = 0; j < nsamp_of_inst; j++)
const dds_entity_t qc = dds_create_querycondition (rd, 0, test_even_long_2);
rc = dds_read (qc, buf, si, sizeof (xs) / sizeof (xs[0]), (uint32_t) (sizeof (xs) / sizeof (xs[0])));
CU_ASSERT_FATAL (rc >= 0);
for (int i = 0; i < rc; i++)
CU_ASSERT_FATAL ((xs[i].long_2 % 2) == 0);
rc = dds_delete (qc);
CU_ASSERT_FATAL (rc == 0);
}

assert (nrd < (int) (sizeof (xs) / sizeof (xs[0])));
int n = (int) op (rd, buf, si, (size_t) nrd, (uint32_t) nrd, (drop_even_long_2 ? DDS_NOT_READ_SAMPLE_STATE : 0));
CU_ASSERT_FATAL (n == ((nrd <= totsamp_after_maybe_dropping_even) ? nrd : totsamp_after_maybe_dropping_even));
//printf (" -- read %d ranks", n);
//for (int i = 0; i < n; i++)
// printf (" %"PRIu32, si[i].sample_rank);
//printf ("\n");

{
int i = 0;
while (i < n)
{
CU_ASSERT_FATAL (si[i + j].instance_handle == si[first_of_inst].instance_handle);
CU_ASSERT_FATAL (si[i + j].sample_rank == (uint32_t) (nsamp_of_inst - j - 1));
CU_ASSERT_FATAL (xs[i + j].long_2 == j);
CU_ASSERT_FATAL (0 <= xs[i].long_1 && xs[i].long_1 <= 2);
CU_ASSERT_FATAL (!drop_even_long_2 || (xs[i].long_2 % 2) != 0);
const int nsamp_after_maybe_dropping_even = drop_even_long_2 ? nsamp[xs[i].long_1] / 2 : nsamp[xs[i].long_1];
const int nsamp_of_inst = (i + nsamp_after_maybe_dropping_even < n) ? nsamp_after_maybe_dropping_even : n - i;
//printf ("i = %d nsamp_of_inst = %d\n", i, nsamp_of_inst);
assert (nsamp_of_inst > 0);
CU_ASSERT_FATAL (si[i].sample_rank == (uint32_t) (nsamp_of_inst - 1));
CU_ASSERT_FATAL (xs[i].long_3 == 0);
CU_ASSERT_FATAL ((int) si[i].sample_rank < nsamp_of_inst);
const int first_of_inst = i;
for (int j = 0; j < nsamp_of_inst; j++)
{
CU_ASSERT_FATAL (si[i + j].instance_handle == si[first_of_inst].instance_handle);
CU_ASSERT_FATAL (si[i + j].sample_rank == (uint32_t) (nsamp_of_inst - j - 1));
CU_ASSERT_FATAL (xs[i + j].long_2 == (drop_even_long_2) ? 2*j+1 : j);
}
i += nsamp_of_inst;
}
i += nsamp_of_inst;
}
}

rc = dds_delete (rd);
CU_ASSERT_FATAL (rc == 0);
rc = dds_delete (wr);
CU_ASSERT_FATAL (rc == 0);
rc = dds_delete (rd);
CU_ASSERT_FATAL (rc == 0);
rc = dds_delete (wr);
CU_ASSERT_FATAL (rc == 0);
}
}

// increment # samples per instance
{ int i = 0; while (++nsamp[i] == 5) nsamp[i++] = 1; }
}
Expand All @@ -3305,10 +3337,10 @@ static void do_readtake_sample_rank (dds_return_t (*op) (dds_entity_t reader_or_

CU_Test (ddsc_read, sample_rank)
{
do_readtake_sample_rank (dds_read);
do_readtake_sample_rank (dds_read_mask);
}

CU_Test (ddsc_take, sample_rank)
{
do_readtake_sample_rank (dds_take);
do_readtake_sample_rank (dds_take_mask);
}

0 comments on commit 9d2deac

Please sign in to comment.