]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add test for cpu affinity
authorMatthijs Mekking <matthijs@isc.org>
Thu, 10 Dec 2020 10:57:23 +0000 (11:57 +0100)
committerMark Andrews <marka@isc.org>
Tue, 22 Dec 2020 22:25:48 +0000 (09:25 +1100)
Add a test to check BIND 9 honors CPU affinity mask. This requires
some changes to the start script, to construct the named command.

(cherry picked from commit f1a097964c52b1d765248fd10fb98837174a5077)

bin/tests/system/conf.sh.in
bin/tests/system/cpu/clean.sh [new file with mode: 0644]
bin/tests/system/cpu/ns1/named.conf.in [new file with mode: 0644]
bin/tests/system/cpu/prereq.sh [new file with mode: 0644]
bin/tests/system/cpu/setup.sh [new file with mode: 0644]
bin/tests/system/cpu/tests.sh [new file with mode: 0644]
bin/tests/system/start.pl
util/copyrights

index 5967425c8b65d61c578fb971b560a07cfa3a420b..4e87585eefe8440b0b50cbf7033edbd9c801c5c1 100644 (file)
@@ -83,7 +83,7 @@ KRB5_CONFIG=/dev/null
 SEQUENTIAL_UNIX="@PKCS11_TEST@"
 SEQUENTIALDIRS="$SEQUENTIAL_COMMON $SEQUENTIAL_UNIX"
 
-PARALLEL_UNIX="@CHECKDS@ @COVERAGE@ @DNSTAP@ @KEYMGR@ cookie logfileconfig"
+PARALLEL_UNIX="@CHECKDS@ @COVERAGE@ @DNSTAP@ @KEYMGR@ cookie cpu logfileconfig"
 PARALLELDIRS="$PARALLEL_COMMON $PARALLEL_UNIX"
 
 SUBDIRS="$SEQUENTIALDIRS $PARALLELDIRS"
diff --git a/bin/tests/system/cpu/clean.sh b/bin/tests/system/cpu/clean.sh
new file mode 100644 (file)
index 0000000..0a6c10b
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+#
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+set -e
+
+rm -f ps.out
+rm -f ns1/named.conf ns1/managed-keys.* ns1/named.run ns1/named.memstats
diff --git a/bin/tests/system/cpu/ns1/named.conf.in b/bin/tests/system/cpu/ns1/named.conf.in
new file mode 100644 (file)
index 0000000..d152b27
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * See the COPYRIGHT file distributed with this work for additional
+ * information regarding copyright ownership.
+ */
+
+options {
+       query-source address 10.53.0.1;
+       port @PORT@;
+       pid-file "named.pid";
+       listen-on { 10.53.0.1; };
+       listen-on-v6 { none; };
+};
diff --git a/bin/tests/system/cpu/prereq.sh b/bin/tests/system/cpu/prereq.sh
new file mode 100644 (file)
index 0000000..8b0cd6e
--- /dev/null
@@ -0,0 +1,30 @@
+#!/bin/sh -e
+#
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+set -e
+
+# shellcheck source=conf.sh
+. ../conf.sh
+
+case $(uname) in
+       Linux*)
+               ;;
+       *)
+               echo_i "cpu test only runs on Linux, skipping test"
+               exit 255
+               ;;
+esac
+
+# TASKSET will be an empty string if no taskset program was found.
+TASKSET=$(command -v "taskset" || true)
+if ! test -x "$TASKSET" ; then
+       exit 255
+fi
diff --git a/bin/tests/system/cpu/setup.sh b/bin/tests/system/cpu/setup.sh
new file mode 100644 (file)
index 0000000..5d42868
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh -e
+#
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# shellcheck source=conf.sh
+. ../conf.sh
+
+set -e
+
+$SHELL clean.sh
+
+copy_setports ns1/named.conf.in ns1/named.conf
diff --git a/bin/tests/system/cpu/tests.sh b/bin/tests/system/cpu/tests.sh
new file mode 100644 (file)
index 0000000..54cdb0a
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/sh
+#
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+# shellcheck source=conf.sh
+. ../conf.sh
+
+status=0
+n=0
+
+n=$((n+1))
+echo_i "stop server ($n)"
+ret=0
+$PERL ../stop.pl cpu ns1 || ret=1
+test "$ret" -eq 0 || echo_i "failed"
+status=$((status+ret))
+
+n=$((n+1))
+echo_i "start server with taskset ($n)"
+ret=0
+start_server --noclean --taskset fff0 --restart --port "${PORT}" cpu ns1 || ret=1
+test "$ret" -eq 0 || echo_i "failed"
+status=$((status+ret))
+
+n=$((n+1))
+echo_i "check ps output ($n)"
+ret=0
+ps -T -o pid,psr,time,comm -e > ps.out
+pid=$(cat ns1/named.pid)
+echo_i "pid=$pid"
+psr=$(awk -v pid="$pid" '$1 == pid && $4 == "isc-net-0000" {print $2}' < ps.out)
+echo_i "psr=$psr"
+# The next available cpu relative to the existing affinity mask is 4.
+test "$psr" -eq 4 || ret=1
+test "$ret" -eq 0 || echo_i "failed"
+status=$((status+ret))
+
+echo_i "exit status: $status"
+[ $status -eq 0 ] || exit 1
index ae81503872ae16c3834d4d7131e12da700c628ba..9e3518585c8d31268d3067d8dfb376fb1d3e5c79 100755 (executable)
@@ -23,7 +23,7 @@ use Getopt::Long;
 use Time::HiRes 'sleep'; # allows sleeping fractional seconds
 
 # Usage:
-#   perl start.pl [--noclean] [--restart] [--port port] test [server [options]]
+#   perl start.pl [--noclean] [--restart] [--port port] [--taskset cpus] test [server [options]]
 #
 #   --noclean       Do not cleanup files in server directory.
 #
@@ -38,6 +38,10 @@ use Time::HiRes 'sleep'; # allows sleeping fractional seconds
 #                   of the file "named.port" in the server directory containing
 #                   the number of the query port.)
 #
+#   --taskset cpus  Use taskset to signal which cpus can be used. For example
+#                   cpus=fff0 means all cpus aexcept for 0, 1, 2, and 3 are
+#                   eligible.
+#
 #   test            Name of the test directory.
 #
 #   server          Name of the server directory.  This will be of the form
@@ -57,15 +61,17 @@ use Time::HiRes 'sleep'; # allows sleeping fractional seconds
 #                   the file is ignored). If "options" is already set, then
 #                   "named.args" is ignored.
 
-my $usage = "usage: $0 [--noclean] [--restart] [--port <port>] test-directory [server-directory [server-options]]";
+my $usage = "usage: $0 [--noclean] [--restart] [--port <port>] [--taskset <cpus>] test-directory [server-directory [server-options]]";
 my $clean = 1;
 my $restart = 0;
 my $queryport = 5300;
+my $taskset = "";
 
 GetOptions(
-       'clean!'   => \$clean,
-       'restart!' => \$restart,
-       'port=i'   => \$queryport,
+       'clean!'    => \$clean,
+       'restart!'  => \$restart,
+       'port=i'    => \$queryport,
+       'taskset=s' => \$taskset,
 ) or die "$usage\n";
 
 my( $test, $server_arg, $options_arg ) = @ARGV;
@@ -231,7 +237,11 @@ sub construct_ns_command {
 
                $command .= "$NAMED -m none -M external ";
        } else {
-               $command = "$NAMED ";
+               if ($taskset) {
+                       $command = "taskset $taskset $NAMED ";
+               } else {
+                       $command = "$NAMED ";
+               }
        }
 
        my $args_file = $testdir . "/" . $server . "/" . "named.args";
index c1092e2b455e6c9bce370ac056d00fce851a9139..b64f71f1aedd11241c6cc627706b778ef1f1e1a3 100644 (file)
 ./bin/tests/system/coverage/clean.sh           SH      2013,2014,2016,2018,2019,2020
 ./bin/tests/system/coverage/setup.sh           SH      2013,2014,2016,2017,2018,2019,2020
 ./bin/tests/system/coverage/tests.sh           SH      2013,2014,2016,2018,2019,2020
+./bin/tests/system/cpu/clean.sh                        SH      2020
+./bin/tests/system/cpu/prereq.sh               SH      2020
+./bin/tests/system/cpu/setup.sh                        SH      2020
+./bin/tests/system/cpu/tests.sh                        SH      2020
 ./bin/tests/system/database/clean.sh           SH      2011,2012,2014,2016,2018,2019,2020
 ./bin/tests/system/database/setup.sh           SH      2011,2012,2016,2018,2019,2020
 ./bin/tests/system/database/tests.sh           SH      2011,2012,2016,2018,2019,2020