xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Dario Faggioli <dario.faggioli@citrix.com>
To: xen-devel@lists.xen.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH v2 5/5] xl: test script for the cpumap parser (for vCPU pinning)
Date: Fri, 06 Sep 2013 17:56:01 +0200	[thread overview]
Message-ID: <20130906155600.10218.27695.stgit@hit-nxdomain.opendns.com> (raw)
In-Reply-To: <20130906154725.10218.45008.stgit@hit-nxdomain.opendns.com>

This commit introduces "check-xl-vcpupin-parse" for helping
verifying and debugging the (v)CPU bitmap parsing code in xl.

The script runs "xl -N vcpu-pin 0 all <some strings>"
repeatedly, with various input strings, and checks that the
output is as expected.

This is an example run (on a 2 NUMA nodes and 16 vCPUs host):

# ./check-xl-vcpupin-parse
WARNING: some of these tests are topology based tests.
Expect failures if the topology is not detected correctly
detected topology:  16 CPUs,  2 nodes, 8 CPUs per node
test case foo...
Testing the 'all' syntax:
test case all...
test case nodes:all...
test case all,nodes:all...
test case all,^nodes:0,all...
Testing the empty cpumap case:
test case ^0...
A few attempts of pinning to just one random cpu:
test case 15...
test case 5...
test case 4...
test case 8...
A few attempts of pinning to all but one random cpu:
test case all,^5...
test case all,^1...
test case all,^9...
test case all,^8...
A few attempts of pinning to a random range of cpus:
test case 12-15...
test case 6-14...
test case 13-14...
test case 4-11...
A few attempts of pinning to just one random node:
test case nodes:0...
test case nodes:0...
test case nodes:0...
test case nodes:1...
A few attempts of pinning to all but one random node:
test case all,^nodes:1...
test case all,^nodes:0...
test case all,^nodes:1...
test case all,^nodes:1...
A few attempts of pinning to a random range of nodes:
test case nodes:0-1...
test case nodes:0-1...
test case nodes:0-1...
test case nodes:1-1...
A few attempts of pinning to a node but excluding one random cpu:
test case nodes:1,^11...
test case nodes:1,^15...
test case nodes:1,^8...
test case nodes:0,^2...
all ok.

Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com>
---
Changes from v1:
 * this was not there in v1, and adding it has been requested
   during review.
---
 tools/libxl/check-xl-vcpupin-parse |  229 ++++++++++++++++++++++++++++++++++++
 1 file changed, 229 insertions(+)
 create mode 100755 tools/libxl/check-xl-vcpupin-parse

diff --git a/tools/libxl/check-xl-vcpupin-parse b/tools/libxl/check-xl-vcpupin-parse
new file mode 100755
index 0000000..af9b8d8
--- /dev/null
+++ b/tools/libxl/check-xl-vcpupin-parse
@@ -0,0 +1,229 @@
+#!/bin/bash
+
+set -e
+
+if [ -x ./xl ] ; then
+    export LD_LIBRARY_PATH=.:../libxc:../xenstore:../blktap2/control
+    XL=./xl
+else
+    XL=xl
+fi
+
+fprefix=tmp.check-xl-vcpupin-parse
+
+expected () {
+    cat >$fprefix.expected
+}
+
+failures=0
+
+one () {
+    expected_rc=$1; shift
+    printf "test case %s...\n" "$*"
+    set +e
+    ${XL} -N vcpu-pin 0 all "$@" </dev/null >$fprefix.actual 2>/dev/null
+    actual_rc=$?
+    diff -u $fprefix.expected $fprefix.actual
+    diff_rc=$?
+    set -e
+    if [ $actual_rc != $expected_rc ] || [ $diff_rc != 0 ]; then
+        echo >&2 "test case \`$*' failed ($actual_rc $diff_rc)"
+        failures=$(( $failures + 1 ))
+    fi
+}
+
+complete () {
+    if [ "$failures" = 0 ]; then
+        echo all ok.; exit 0
+    else
+        echo "$failures tests failed."; exit 1
+    fi
+}
+
+e=255
+
+
+#---------- test data ----------
+#
+
+echo "WARNING: some of these tests are topology based tests."
+echo "Expect failures if the topology is not detected correctly"
+nr_cpus=`xl info | grep nr_cpus | cut -f2 -d':'`
+nr_nodes=`xl info | grep nr_nodes | cut -f2 -d':'`
+nr_cpus_per_node=`xl info -n | sed '/cpu:/,/numa_info/!d' | head -n -1 | \
+    awk '{print $4}' | uniq -c | tail -1 | awk '{print $1}'`
+echo "detected topology: $nr_cpus CPUs, $nr_nodes nodes, $nr_cpus_per_node CPUs per node"
+
+expected </dev/null
+one $e foo
+
+echo "Testing the 'all' syntax:"
+expected <<END
+cpumap: any cpu
+END
+one 0 all
+one 0 nodes:all
+one 0 all,nodes:all
+one 0 all,^nodes:0,all
+
+echo "Testing the empty cpumap case:"
+if [ $nr_cpus -gt 1 ]; then
+    expected <<END
+cpumap: none
+END
+    one 0 ^0
+fi
+
+echo "A few attempts of pinning to just one random cpu:"
+if [ $nr_cpus -gt 1 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        expected <<END
+cpumap: $cpu
+END
+        one 0 $cpu
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to all but one random cpu:"
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpu=$(($RANDOM % nr_cpus))
+        if [ $cpu -eq 0 ]; then
+            expected_range="1-$((nr_cpus - 1))"
+        elif [ $cpu -eq 1 ]; then
+            expected_range="0,2-$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 2)) ]; then
+            expected_range="0-$((cpu - 1)),$((nr_cpus - 1))"
+        elif [ $cpu -eq $((nr_cpus - 1)) ]; then
+            expected_range="0-$((nr_cpus - 2))"
+        else
+            expected_range="0-$((cpu - 1)),$((cpu + 1))-$((nr_cpus - 1))"
+        fi
+        expected <<END
+cpumap: $expected_range
+END
+        one 0 all,^$cpu
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to a random range of cpus:"
+if [ $nr_cpus -gt 2 ]; then
+    for i in `seq 0 3`; do
+        cpua=$(($RANDOM % nr_cpus))
+        range=$((nr_cpus - cpua))
+        cpub=$(($RANDOM % range))
+        cpubb=$((cpua + cpub))
+        if [ $cpua -eq $cpubb ]; then
+            expected_range="$cpua"
+        else
+            expected_range="$cpua-$cpubb"
+        fi
+        expected <<END
+cpumap: $expected_range
+END
+        one 0 $expected_range
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to just one random node:"
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        expected <<END
+cpumap: $((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1)-1))
+END
+        one 0 nodes:$node
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to all but one random node:"
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $node -eq 0 ]; then
+            expected_range="$nr_cpus_per_node-$((nr_cpus - 1))"
+        elif [ $node -eq $((nr_nodes - 1)) ]; then
+            expected_range="0-$((nr_cpus - nr_cpus_per_node - 1))"
+        else
+            expected_range="0-$((nr_cpus_per_node*node-1)),$((nr_cpus_per_node*(node+1)))-$nr_cpus"
+        fi
+        expected <<END
+cpumap: $expected_range
+END
+        one 0 all,^nodes:$node
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to a random range of nodes:"
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        nodea=$(($RANDOM % nr_nodes))
+        range=$((nr_nodes - nodea))
+        nodeb=$(($RANDOM % range))
+        nodebb=$((nodea + nodeb))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        if [ $nodea -eq 0 ] && [ $nodebb -eq $((nr_nodes - 1)) ]; then
+            expected_range="any cpu"
+#        elif [ $nodea -eq $nodebb ]; then
+#            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodea+1)-1))"
+        else
+            expected_range="$((nr_cpus_per_node*nodea))-$((nr_cpus_per_node*(nodebb+1) - 1))"
+        fi
+        expected <<END
+cpumap: $expected_range
+END
+        one 0 nodes:$nodea-$nodebb
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+echo "A few attempts of pinning to a node but excluding one random cpu:"
+if [ $nr_nodes -gt 1 ]; then
+    for i in `seq 0 3`; do
+        node=$(($RANDOM % nr_nodes))
+        # this assumes that the first $nr_cpus_per_node (from cpu
+        # 0 to cpu $nr_cpus_per_node-1) are assigned to the first node
+        # (node 0), the second $nr_cpus_per_node (from $nr_cpus_per_node
+        # to 2*$nr_cpus_per_node-1) are assigned to the second node (node
+        # 1), etc. Expect failures if that is not the case.
+        cpu=$(($RANDOM % nr_cpus_per_node + nr_cpus_per_node*node))
+        if [ $cpu -eq $((nr_cpus_per_node*node)) ]; then
+            expected_range="$((nr_cpus_per_node*node + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*node + 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node)),$((nr_cpus_per_node*node + 2))-$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 2)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 3)),$((nr_cpus_per_node*(node+1) - 1))"
+        elif [ $cpu -eq $((nr_cpus_per_node*(node+1) - 1)) ]; then
+            expected_range="$((nr_cpus_per_node*node))-$((nr_cpus_per_node*(node+1) - 2))"
+        else
+            expected_range="$((nr_cpus_per_node*node))-$((cpu - 1)),$((cpu + 1))-$((nr_cpus_per_node*(node+1) - 1))"
+        fi
+        expected <<END
+cpumap: $expected_range
+END
+        one 0 nodes:$node,^$cpu
+        sleep 1    # to trick $RANDOM
+    done
+fi
+
+complete

  parent reply	other threads:[~2013-09-06 15:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-06 15:55 [PATCH v2 0/5] xl: allow for node-wise specification of vcpu pinning Dario Faggioli
2013-09-06 15:55 ` [PATCH v2 1/5] xl: update the manpage about "cpus=" and NUMA node-affinity Dario Faggioli
2013-09-06 16:00   ` Ian Jackson
2013-09-06 15:55 ` [PATCH v2 2/5] libxl: introduce libxl_node_to_cpumap Dario Faggioli
2013-09-06 15:59   ` Ian Jackson
2013-09-06 15:55 ` [PATCH v2 3/5] xl: allow for node-wise specification of vcpu pinning Dario Faggioli
2013-09-06 16:37   ` Ian Jackson
2013-09-10 17:42     ` Dario Faggioli
2013-09-06 16:38   ` Ian Jackson
2013-09-10 17:38     ` Dario Faggioli
2013-09-06 15:55 ` [PATCH v2 4/5] xl: implement and enable dryrun mode for `xl vcpu-pin' Dario Faggioli
2013-09-08 22:28   ` Matt Wilson
2013-09-10 17:39     ` Dario Faggioli
2013-09-10 17:49   ` Ian Jackson
2013-09-06 15:56 ` Dario Faggioli [this message]
2013-09-10 17:52   ` [PATCH v2 5/5] xl: test script for the cpumap parser (for vCPU pinning) Ian Jackson
2013-09-11  8:31     ` Dario Faggioli
2013-09-11 10:49       ` Ian Jackson
2013-09-16 18:48         ` Dario Faggioli
2013-09-11  9:49     ` Ian Campbell
2013-09-16 18:50       ` Dario Faggioli
2013-09-06 16:12 ` [PATCH v2 0/5] xl: allow for node-wise specification of vcpu pinning Dario Faggioli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130906155600.10218.27695.stgit@hit-nxdomain.opendns.com \
    --to=dario.faggioli@citrix.com \
    --cc=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).