Commit 3bfbd0c6 authored by Jonathan Jenkins's avatar Jonathan Jenkins

more testing

parent 3e632f0b
......@@ -8,45 +8,68 @@
#include "codes/codes-jobmap.h"
const int N = 10;
int main(int argc, char *argv[])
{
struct codes_jobmap_ctx *c;
struct codes_jobmap_params_dummy p;
p.num_jobs = N;
#define ERR(str, ...) \
do { \
fprintf(stderr, "ERROR: " str "\n", ##__VA_ARGS__); \
fprintf(stderr, "ERROR at %s:%d: " str "\n", __FILE__, __LINE__, ##__VA_ARGS__); \
return 1; \
} while(0)
static int test_jobmap_dummy(int num_jobs)
{
struct codes_jobmap_ctx *c;
struct codes_jobmap_params_dummy p;
p.num_jobs = num_jobs;
/* initialize */
c = codes_jobmap_configure(CODES_JOBMAP_DUMMY, &p);
if (!c) ERR("jobmap configure failure");
/* successful lookups */
struct codes_jobmap_id id;
for (int i = 0; i < N; i++) {
id = codes_jobmap_to_local_id(i, c);
if (id.job != i || id.rank != 0)
struct codes_jobmap_id lid;
/* successful local lookups */
for (int i = 0; i < num_jobs; i++) {
lid = codes_jobmap_to_local_id(i, c);
if (lid.job != i || lid.rank != 0)
ERR("lookup failure for %d: expected (%d,%d), got (%d,%d)",
i, i, 0, id.job, id.rank);
i, i, 0, lid.job, lid.rank);
else {
id.job = -1;
id.rank = -1;
lid.job = -1;
lid.rank = -1;
}
}
/* bad lookup */
id = codes_jobmap_to_local_id(10, c);
if (id.job != -1 || id.rank != -1)
ERR("lookup expected failure for 10: expected (%d,%d), got (%d,%d)",
-1,-1, id.job,id.rank);
/* bad local lookup */
lid = codes_jobmap_to_local_id(num_jobs, c);
if (lid.job != -1 || lid.rank != -1)
ERR("lookup expected failure for %d: expected (%d,%d), got (%d,%d)",
num_jobs, -1,-1, lid.job,lid.rank);
/* successful global lookups */
int gid;
lid.rank = 0;
for (lid.job = 0; lid.job < num_jobs; lid.job++) {
gid = codes_jobmap_to_global_id(lid, c);
if (gid != lid.job)
ERR("lookup failure for (%d,%d): expected %d, got %d",
lid.job, lid.rank, lid.job, gid);
}
/* bad global lookup */
lid.job = num_jobs;
gid = codes_jobmap_to_global_id(lid, c);
if (gid != -1)
ERR("lookup expected failure for (%d,0): expected -1, got %d",
num_jobs, gid);
/* cleanup */
codes_jobmap_destroy(c);
#undef ERR
return 0;
}
int main(int argc, char *argv[])
{
int rc;
rc = test_jobmap_dummy(10);
if (rc) return rc;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment