Skip to content

Commit

Permalink
test/prefered: add test cases for new 'preferred-many' policy
Browse files Browse the repository at this point in the history
Signed-off-by: Feng Tang <feng.tang@intel.com>
  • Loading branch information
ftang1 authored and andikleen committed Dec 9, 2021
1 parent 91a3fd4 commit bf0a0af
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/prefered.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#define err(x) perror(x),exit(1)

extern void printmask(char *name, struct bitmask *mask);

void usage(void)
{
}
Expand All @@ -27,6 +29,8 @@ int main(void)
nodes = numa_bitmask_alloc(maxmask);
mask = numa_bitmask_alloc(maxmask);

/* Step 1. test 'preferred' policy */
printf("\nTesting MPOL_PREFERRED policy:\n\n");
for (i = max; i >= 0; --i) {
char *mem = mmap(NULL, pagesize*(max+1), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
Expand Down Expand Up @@ -63,5 +67,51 @@ int main(void)
if (node != i)
err = 1;
}


/* Step 2. test 'preferred-many' policy */
if (max < 1)
return err;

printf("\nTesting MPOL_PREFERRED_MANY policy:\n\n");
for (i = max; i >= 1; --i) {
char *mem = mmap(NULL, pagesize*(max+1), PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
char *adr = mem;

if (mem == (char *)-1)
err("mmap");

numa_bitmask_clearall(nodes);
numa_bitmask_clearall(mask);
/* Set 2 nodes */
numa_bitmask_setbit(nodes, i);
numa_bitmask_setbit(nodes, i - 1);

if (mbind(adr, pagesize, MPOL_PREFERRED_MANY, nodes->maskp,
nodes->size, 0) < 0)
err("mbind");

++*adr;
if (get_mempolicy(&pol, mask->maskp, mask->size, adr, MPOL_F_ADDR) < 0)
err("get_mempolicy");

assert(pol == MPOL_PREFERRED_MANY);
printmask("Got nodes", mask);
printmask("Expected nodes", nodes);
if (!numa_bitmask_equal(mask, nodes))
err = 1;

node = 0x123;
if (get_mempolicy(&node, NULL, 0, adr, MPOL_F_ADDR|MPOL_F_NODE) < 0)
err("get_mempolicy2");

printf("Got node: %d ", node);
printmask("Expected nodes", nodes);

if (!numa_bitmask_isbitset(nodes, node))
err = 1;
}

return err;
}

0 comments on commit bf0a0af

Please sign in to comment.