#!/bin/bash
# check if affinity works

BASE=`pwd`/..
export LD_LIBRARY_PATH=$BASE
export PATH=$BASE:$PATH

S=`numactl --show | grep nodebind:`
NODES=`echo $S | sed -e "s/nodebind://"`

S=`numactl --show | grep physcpubind:`
CPUS=`echo $S | sed -e "s/physcpubind://"`

for i in $CPUS ; do
    if [ "$(numactl --physcpubind=$i ./printcpu)" != "$i" ] ; then
       echo "--physcpubind for $i doesn't work"
       exit 1
    fi
    if [ "$(numactl --physcpubind=$i numactl --show | awk '/^physcpubind/ { print $2 }' )" != "$i" ] ; then
	echo "--show doesn't agree with physcpubind for cpu $i"
	exit 1
    fi
done

for i in $NODES ; do
    if [ $(numactl --cpunodebind=$i numactl --show | awk '/nodebind/ { print $2 }' ) != $i ] ; then
	echo "--show doesn't agree with cpunodebind for node $i"
	exit 1
    fi
done
