This patch modifies the test/ programs to use the libnuma that
uses variable size bit masks (struct bitmask).

Diffed against numactl-1.0.2

Signed-off-by: Cliff Wickman <cpw@sgi.com>
---
 test/distance.c        |    2 +-
 test/mbind_mig_pages.c |   23 ++++++++++++-----------
 test/migrate_pages.c   |   17 +++++++++--------
 test/nodemap.c         |   19 +++++++++++--------
 test/prefered.c        |   19 +++++++++++--------
 test/randmap.c         |   10 +++++-----
 test/tbitmap.c         |   40 +++++++++++++++++++++-------------------
 7 files changed, 70 insertions(+), 60 deletions(-)

Index: numactl-1.0.2/test/distance.c
===================================================================
--- numactl-1.0.2.orig/test/distance.c
+++ numactl-1.0.2/test/distance.c
@@ -11,7 +11,7 @@ int main(void)
 		exit(1);
 	}
 
-        numnodes = numa_max_node()+1;
+        numnodes = number_of_configured_nodes();
 	for (a = 0; a < numnodes; a++) { 
 		printf("%03d: ", a); 
 		if (numa_distance(a, a) != 10) { 
Index: numactl-1.0.2/test/nodemap.c
===================================================================
--- numactl-1.0.2.orig/test/nodemap.c
+++ numactl-1.0.2/test/nodemap.c
@@ -3,26 +3,29 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#define NCPUS 4096
 
 int main(void)
 {
-	int maxnode, i, k, w;
+	int i, k, w, ncpus;
+	struct bitmask *cpus;
+	int maxnode = number_of_configured_nodes()-1;
+
 	if (numa_available() < 0)  {
 		printf("no numa\n");
 		exit(1);
 	}
-	maxnode = numa_max_node();
+	cpus = allocate_cpumask();
+	ncpus = cpus->size;
+
 	for (i = 0; i <= maxnode ; i++) {
-		unsigned long cpus[NCPUS / sizeof(long)*8];
-		if (numa_node_to_cpus(i, cpus, sizeof(cpus)) < 0) {
+		if (numa_node_to_cpus(i, cpus) < 0) {
 			printf("node %d failed to convert\n",i); 
 		}		
 		printf("%d: ", i); 
 		w = 0;
-		for (k = 0; k < NCPUS; k++)
-			if (test_bit(k, cpus)) 
-				printf("%s%d", w>0?",":"", k); 
+		for (k = 0; k < ncpus; k++)
+			if (bitmask_isbitset(cpus, k))
+				printf(" %s%d", w>0?",":"", k);
 		putchar('\n');		
 	}
 	return 0;
Index: numactl-1.0.2/test/prefered.c
===================================================================
--- numactl-1.0.2.orig/test/prefered.c
+++ numactl-1.0.2/test/prefered.c
@@ -1,23 +1,25 @@
 /* Test prefer policy */
+#include "numa.h"
 #include "numaif.h"
 #include <sys/mman.h>
 #include <stdio.h>
 #include <assert.h>
 #include <unistd.h>
 #include <stdlib.h>
-#include <numa.h>
 
 #define err(x) perror(x),exit(1)
 
 int main(void)
 {
 	int max = numa_max_node();
-	nodemask_t nodes, mask;
+	struct bitmask *nodes, *mask;
 	int pagesize = getpagesize();
 	int i;
 	int pol;
 	int node;
 	int err = 0;
+	nodes = bitmask_alloc(max+1);
+	mask = bitmask_alloc(max+1);
 
 	for (i = max; i >= 0; --i) { 
 		char *mem = mmap(NULL, pagesize*(max+1), PROT_READ|PROT_WRITE, 
@@ -29,20 +31,21 @@ int main(void)
 
 		printf("%d offset %lx\n", i, (long)(adr - mem)); 
 
-		nodemask_zero(&nodes);
-		nodemask_zero(&mask);
-		nodemask_set(&mask, i);
+		bitmask_clearall(nodes);
+		bitmask_clearall(mask);
+		bitmask_setbit(mask, i);
 
-		if (mbind(adr,  pagesize, MPOL_PREFERRED, nodes.n, sizeof(nodemask_t)*8+1, 0) < 0) 
+		if (mbind(adr,  pagesize, MPOL_PREFERRED, nodes->maskp,
+							nodes->size, 0) < 0)
 			err("mbind");
 		
 		++*adr;
 			
-		if (get_mempolicy(&pol, mask.n, sizeof(nodemask_t)*8+1, adr, MPOL_F_ADDR) < 0) 
+		if (get_mempolicy(&pol, mask->maskp, mask->size, adr, MPOL_F_ADDR) < 0)
 			err("get_mempolicy");
 	
 		assert(pol == MPOL_PREFERRED);
-		assert(nodemask_isset(&mask, i));
+		assert(bitmask_isbitset(mask, i));
 
 		node = 0x123;
 		
Index: numactl-1.0.2/test/tbitmap.c
===================================================================
--- numactl-1.0.2.orig/test/tbitmap.c
+++ numactl-1.0.2/test/tbitmap.c
@@ -6,6 +6,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <ctype.h>
+#include "numa.h"
 
 #define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
 
@@ -33,14 +34,11 @@ typedef unsigned u32;
  * bitmap_scnprintf - convert bitmap to an ASCII hex string.
  * @buf: byte buffer into which string is placed
  * @buflen: reserved size of @buf, in bytes
- * @maskp: pointer to bitmap to convert
- * @nmaskbits: size of bitmap, in bits
+ * @mask: pointer to struct bitmask to convert
  *
- * Exactly @nmaskbits bits are displayed.  Hex digits are grouped into
- * comma-separated sets of eight digits per set.
+ * Hex digits are grouped into comma-separated sets of eight digits per set.
  */
-int bitmap_scnprintf(char *buf, unsigned int buflen,
-        const unsigned long *maskp, int nmaskbits)
+int bitmap_scnprintf(char *buf, unsigned int buflen, struct bitmask *mask)
 {
         int i, word, bit, len = 0;
         unsigned long val;
@@ -48,16 +46,16 @@ int bitmap_scnprintf(char *buf, unsigned
         int chunksz;
         u32 chunkmask;
 
-        chunksz = nmaskbits & (CHUNKSZ - 1);
+        chunksz = mask->size & (CHUNKSZ - 1);
         if (chunksz == 0)
                 chunksz = CHUNKSZ;
 
-        i = ALIGN(nmaskbits, CHUNKSZ) - CHUNKSZ;
+        i = ALIGN(mask->size, CHUNKSZ) - CHUNKSZ;
         for (; i >= 0; i -= CHUNKSZ) {
                 chunkmask = ((1ULL << chunksz) - 1);
                 word = i / BITS_PER_LONG;
                 bit = i % BITS_PER_LONG;
-                val = (maskp[word] >> bit) & chunkmask;
+                val = (mask->maskp[word] >> bit) & chunkmask;
                 len += snprintf(buf+len, buflen-len, "%s%0*lx", sep,
                         (chunksz+3)/4, val);
                 chunksz = CHUNKSZ;
@@ -66,24 +64,29 @@ int bitmap_scnprintf(char *buf, unsigned
         return len;
 }
 
-extern int numa_parse_bitmap(char  *buf,unsigned long *mask, unsigned bits);
+extern int numa_parse_bitmap(char  *buf, struct bitmask *mask);
+#define MASKSIZE 300
 
 int main(void)
 {
 	char buf[1024];
-	unsigned long mask[20], mask2[20];
+	struct bitmask *mask, *mask2;
 	int i;
+
+	mask  = bitmask_alloc(MASKSIZE);
+	mask2 = bitmask_alloc(MASKSIZE);
+
 	printf("Testing bitmap functions\n");
-	for (i = 0; i < 300; i++) {
-		memset(mask, 0, sizeof(mask));
-		memset(mask2, 0, sizeof(mask));
-		set_bit(i, mask);
-		bitmap_scnprintf(buf, sizeof(buf), mask, 300);
+	for (i = 0; i < MASKSIZE; i++) {
+		bitmask_clearall(mask);
+		bitmask_clearall(mask2);
+		bitmask_setbit(mask, i);
+		bitmap_scnprintf(buf, sizeof(buf), mask);
 		strcat(buf,"\n");
-		if (numa_parse_bitmap(buf, mask2, 300) < 0)
+		if (numa_parse_bitmap(buf, mask2) < 0)
 			assert(0);
 		if (memcmp(mask, mask2, sizeof(mask))) { 
-			bitmap_scnprintf(buf, sizeof(buf), mask2, 300);	
+			bitmap_scnprintf(buf, sizeof(buf), mask2);
 			printf("mask2 differs: %s\n", buf);
 			assert(0);
 		}
@@ -91,4 +94,3 @@ int main(void)
 	printf("Passed\n");
 	return 0;
 }
-
Index: numactl-1.0.2/test/randmap.c
===================================================================
--- numactl-1.0.2.orig/test/randmap.c
+++ numactl-1.0.2/test/randmap.c
@@ -1,5 +1,6 @@
 /* Randomly change policy */ 
 #include <stdio.h>
+#include "numa.h"
 #include "numaif.h"
 #include <sys/mman.h>
 #include <sys/shm.h>
@@ -31,7 +32,7 @@ void setpol(unsigned long offset, unsign
 
 	printf("off:%lx length:%lx policy:%d nodes:%lx\n",
 	       offset, length, policy, nodes);
-	
+
 	if (mbind(map + offset*pagesize, length*pagesize, policy,
 		  &nodes, 8, 0) < 0) {
 		printf("mbind: %s offset %lx length %lx policy %d nodes %lx\n", 
@@ -56,14 +57,13 @@ void setpol(unsigned long offset, unsign
 		int pol2;
 		unsigned long nodes2;
 		if (get_mempolicy(&pol2, &nodes2, sizeof(long)*8, map+i*pagesize, 
-				  MPOL_F_ADDR) < 0)
+				  			MPOL_F_ADDR) < 0)
 			err("get_mempolicy");
 		if (pol2 != pages[i].policy) { 
 			printf("%lx: got policy %d expected %d, nodes got %lx expected %lx\n",
-			       i,
-			       pol2, pages[i].policy, nodes2, pages[i].mask);
+				i, pol2, pages[i].policy, nodes2, pages[i].mask);
 		}
-		if (policy != MPOL_DEFAULT && nodes2 != pages[i].mask) { 
+		if (policy != MPOL_DEFAULT && nodes2 != pages[i].mask) {
 			printf("%lx: nodes %lx, expected %lx, policy %d\n",
 			       i, nodes2, pages[i].mask, policy);
 		}
Index: numactl-1.0.2/test/mbind_mig_pages.c
===================================================================
--- numactl-1.0.2.orig/test/mbind_mig_pages.c
+++ numactl-1.0.2/test/mbind_mig_pages.c
@@ -23,8 +23,8 @@ int *nodes;
 int errors;
 int nr_nodes;
 
-nodemask_t old_nodes;
-nodemask_t new_nodes;
+struct bitmask *old_nodes;
+struct bitmask *new_nodes;
 
 int main(int argc, char **argv)
 {
@@ -32,12 +32,13 @@ int main(int argc, char **argv)
 
 	pagesize = getpagesize();
 
-	nr_nodes = numa_max_node();
+	nr_nodes = numa_max_node()+1;
+
+	old_nodes = bitmask_alloc(nr_nodes);
+	new_nodes = bitmask_alloc(nr_nodes);
+	bitmask_setbit(old_nodes, 0);
+	bitmask_setbit(new_nodes, 1);
 
-	old_nodes = numa_no_nodes;
-	new_nodes = numa_no_nodes;
-	nodemask_set(&old_nodes, 0);
-	nodemask_set(&new_nodes, 1);
 	if (nr_nodes < 2) {
 		printf("A minimum of 2 nodes is required for this test.\n");
 		exit(1);
@@ -89,8 +90,8 @@ int main(int argc, char **argv)
 
 	/* Move to node zero */
 	printf("\nMoving pages via mbind to node 0 ...\n");
-	rc = mbind(pages, page_count * pagesize, MPOL_BIND, old_nodes.n,
-		numa_max_node(), MPOL_MF_MOVE | MPOL_MF_STRICT);
+	rc = mbind(pages, page_count * pagesize, MPOL_BIND, old_nodes->maskp,
+		old_nodes->size, MPOL_MF_MOVE | MPOL_MF_STRICT);
 	if (rc < 0) {
 		perror("mbind");
 		errors++;
@@ -98,8 +99,8 @@ int main(int argc, char **argv)
 
 
 	printf("\nMoving pages via mbind from node 0 to 1 ...\n");
-	rc = mbind(pages, page_count * pagesize, MPOL_BIND, new_nodes.n,
-		numa_max_node(), MPOL_MF_MOVE | MPOL_MF_STRICT);
+	rc = mbind(pages, page_count * pagesize, MPOL_BIND, new_nodes->maskp,
+		new_nodes->size, MPOL_MF_MOVE | MPOL_MF_STRICT);
 	if (rc < 0) {
 		perror("mbind");
 		errors++;
Index: numactl-1.0.2/test/migrate_pages.c
===================================================================
--- numactl-1.0.2.orig/test/migrate_pages.c
+++ numactl-1.0.2/test/migrate_pages.c
@@ -22,8 +22,8 @@ int *nodes;
 int errors;
 int nr_nodes;
 
-nodemask_t old_nodes;
-nodemask_t new_nodes;
+struct bitmask *old_nodes;
+struct bitmask *new_nodes;
 
 int main(int argc, char **argv)
 {
@@ -31,12 +31,13 @@ int main(int argc, char **argv)
 
 	pagesize = getpagesize();
 
-	nr_nodes = numa_max_node();
+	nr_nodes = numa_max_node()+1;
+
+	old_nodes = bitmask_alloc(nr_nodes);
+        new_nodes = bitmask_alloc(nr_nodes);
+        bitmask_setbit(old_nodes, 1);
+        bitmask_setbit(new_nodes, 0);
 
-	old_nodes = numa_no_nodes;
-	new_nodes = numa_no_nodes;
-	nodemask_set(&old_nodes, 1);
-	nodemask_set(&new_nodes, 0);
 	if (nr_nodes < 2) {
 		printf("A minimum of 2 nodes is required for this test.\n");
 		exit(1);
@@ -91,7 +92,7 @@ int main(int argc, char **argv)
 	numa_move_pages(0, page_count, addr, nodes, status, 0);
 
 	printf("\nMigrating the current processes pages ...\n");
-	rc = numa_migrate_pages(0, &old_nodes, &new_nodes);
+	rc = numa_migrate_pages(0, old_nodes, new_nodes);
 
 	if (rc < 0) {
 		perror("numa_migrate_pages failed");
