#!/bin/sh
#-*-sh-*-

#
# Copyright © 2009 CNRS
# Copyright © 2009-2011 INRIA.  All rights reserved.
# Copyright © 2009, 2011 Université Bordeaux 1
# See COPYING in top-level directory.
#

: ${TMPDIR=/tmp}
{
  tmp=`
    (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
  ` &&
  test -n "$tmp" && test -d "$tmp"
} || {
  tmp=$TMPDIR/foo$$-$RANDOM
  (umask 077 && mkdir "$tmp")
} || exit $?
file="$tmp/test-hwloc-distrib.output"

set -e
(
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" root
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" all --taskset
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" 0xf
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" 0xf ~0x3 0xff0 '^0xf0'
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:0 pu:15 ~pu:0 '^pu:2'
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:even
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" node:2-
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:12-
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:62:10
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:all.pu:1:2
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:odd.pu:0
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:6:2 core:3-4.pu:1-3 node:2.pu:14:2 node:3.core:3.pu:3
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" root --number-of node
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" node:2 -N core
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" node:2 -N 3
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" root --intersect Machine
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:4-7 -I NUMANode
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" core:10-15 -I 1
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:2-3 --hierarchical node.pu
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:3-6 -H node.core
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:3-6 -H core.pu
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:11:4 -H node.core.pu
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:12-37 --largest
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --largest
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --single
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:22-47 --single --pulist
  echo
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:33-37 --pulist --po
  ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4" pu:30-37 --nodelist --po
  echo
  ./hwloc-calc --if synthetic --input "group:2 cache:2 pu:1" group:0 cache:3
  ./hwloc-calc --if synthetic --input "group:2 group:2 cache:2 cache:2 pu:1" Group2:1 Group1:0
  ./hwloc-calc --if synthetic --input "group:2 group:2 cache:2 cache:2 pu:1" l2:0-2 L1cache:13:3
  echo
  cat << EOF | ./hwloc-calc --if synthetic --input "node:4 core:4 pu:4"
pu:0
core:0 core:15
node:0 node:3
0x0001 0x00002 0x000004 0x000000000008
0x0000000000000000000000000000000000000000000000000000000000000000000000000000001
0x1,0x0,0x0
root
EOF
) > "$file"
diff @HWLOC_DIFF_U@ $srcdir/test-hwloc-calc.output "$file"
rm -rf "$tmp"
