[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH v2 5/5] xl: test script for the cpumap parser (for vCPU pinning)



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@xxxxxxxxxx>
---
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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.