Skip to content

Commit

Permalink
No more sleeps in test code.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelkgutierrez committed May 10, 2018
1 parent f9e4203 commit f86811b
Showing 1 changed file with 65 additions and 40 deletions.
105 changes: 65 additions & 40 deletions tests/trivial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include "mpi.h"

static int nkeys = 21;

#define ABORT(id, rc) \
do { \
abort_job(__LINE__, id, rc); \
Expand All @@ -35,6 +37,51 @@ abort_job(
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

static void
do_puts(
sdsdkv_context dkvc,
int rank
) {
for (int i = 0; i < nkeys; ++i) {
uint64_t key = i + rank;
uint64_t value = key + 1;
int erc = sdsdkv_put(
dkvc,
(const void *)&key,
sizeof(key),
(const void *)&value,
sizeof(value)
);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
}
}

static void
do_gets(
sdsdkv_context dkvc,
int rank
) {
for (int i = 0; i < nkeys; ++i) {
uint64_t key = i + rank;
uint64_t value = -1;
uint64_t value_size = sizeof(value);
int erc = sdsdkv_get(
dkvc,
(const void *)&key,
sizeof(key),
&value,
&value_size
);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
if (value != key + 1) ABORT(rank, -1);
if (sizeof(value) != value_size) ABORT(rank, -2);
printf(
"rank=%d (key=%" PRIu64 ", val=%" PRIu64 ")\n",
rank, key, value
);
}
}

int
main(int argc, char **argv)
{
Expand All @@ -51,14 +98,21 @@ main(int argc, char **argv)

char *db_prefix = getenv("PWD");
if (!db_prefix) db_prefix = (char *)"/tmp";

std::string db_name = std::string(db_prefix) + "/TEST-DB";

auto personality = (
(rank % 2 == 0) ? SDSDKV_PERSONALITY_SERVER : SDSDKV_PERSONALITY_CLIENT
);

MPI_Comm pcomm;
erc = MPI_Comm_split(MPI_COMM_WORLD, personality, rank, &pcomm);
if (erc != MPI_SUCCESS) ABORT(rank, erc);

sdsdkv_config dkv_config = {
/* .init_comm = */
MPI_COMM_WORLD,
/* .personality = */
(rank % 2 == 0) ? SDSDKV_PERSONALITY_SERVER : SDSDKV_PERSONALITY_CLIENT,
personality,
/* .hash_be = */
SDSDKV_HASHING_CH_PLACEMENT,
/* .db_type = */
Expand All @@ -78,49 +132,20 @@ main(int argc, char **argv)
//
erc = sdsdkv_open(dkvc);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
static int nkeys = 20;
//
if (dkv_config.personality == SDSDKV_PERSONALITY_CLIENT) {
for (int i = 0; i < nkeys; ++i) {
uint64_t key = i + rank;
uint64_t value = key + 1;
erc = sdsdkv_put(
dkvc,
(const void *)&key,
sizeof(key),
(const void *)&value,
sizeof(value)
);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
}
}
sleep(3);
if (dkv_config.personality == SDSDKV_PERSONALITY_CLIENT) {
for (int i = 0; i < nkeys; ++i) {
uint64_t key = i + rank;
uint64_t value = -1;
uint64_t value_size = sizeof(value);
erc = sdsdkv_get(
dkvc,
(const void *)&key,
sizeof(key),
&value,
&value_size
);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
if (value != key + 1) ABORT(rank, -1);
if (sizeof(value) != value_size) ABORT(rank, -2);
printf(
"rank=%d (key=%" PRIu64 ", val=%" PRIu64 ")\n",
rank, key, value
);
}

if (personality == SDSDKV_PERSONALITY_CLIENT) {
do_puts(dkvc, rank);
MPI_Barrier(pcomm);
do_gets(dkvc, rank);
MPI_Barrier(pcomm);
}
sleep(3);
//
erc = sdsdkv_destroy(dkvc);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
//
erc = MPI_Comm_free(&pcomm);
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
//
erc = MPI_Finalize();
if (erc != SDSDKV_SUCCESS) ABORT(rank, erc);
//
Expand Down

0 comments on commit f86811b

Please sign in to comment.