Blame SOURCES/0333-test-introduce-TEST-36-NUMAPOLICY.patch

df9c27
From 90dda340e4adeb1126639a849d4f31ae327fdc4b Mon Sep 17 00:00:00 2001
df9c27
From: Frantisek Sumsal <frantisek@sumsal.cz>
df9c27
Date: Tue, 25 Jun 2019 23:01:40 +0200
df9c27
Subject: [PATCH 333/341] test: introduce TEST-36-NUMAPOLICY
df9c27
df9c27
(cherry picked from commit 8f65e26508969610ac934d1aadbade8223bfcaac)
df9c27
df9c27
Related: #1808940
df9c27
---
df9c27
 test/TEST-36-NUMAPOLICY/Makefile     |   1 +
df9c27
 test/TEST-36-NUMAPOLICY/test.sh      |  51 +++++
df9c27
 test/TEST-36-NUMAPOLICY/testsuite.sh | 292 +++++++++++++++++++++++++++
df9c27
 3 files changed, 344 insertions(+)
df9c27
 create mode 120000 test/TEST-36-NUMAPOLICY/Makefile
df9c27
 create mode 100755 test/TEST-36-NUMAPOLICY/test.sh
df9c27
 create mode 100755 test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
df9c27
diff --git a/test/TEST-36-NUMAPOLICY/Makefile b/test/TEST-36-NUMAPOLICY/Makefile
df9c27
new file mode 120000
df9c27
index 0000000000..e9f93b1104
df9c27
--- /dev/null
df9c27
+++ b/test/TEST-36-NUMAPOLICY/Makefile
df9c27
@@ -0,0 +1 @@
df9c27
+../TEST-01-BASIC/Makefile
df9c27
\ No newline at end of file
df9c27
diff --git a/test/TEST-36-NUMAPOLICY/test.sh b/test/TEST-36-NUMAPOLICY/test.sh
df9c27
new file mode 100755
df9c27
index 0000000000..a0d8623e8e
df9c27
--- /dev/null
df9c27
+++ b/test/TEST-36-NUMAPOLICY/test.sh
df9c27
@@ -0,0 +1,51 @@
df9c27
+#!/bin/bash
df9c27
+set -e
df9c27
+TEST_DESCRIPTION="test MUMAPolicy= and NUMAMask= options"
df9c27
+TEST_NO_NSPAWN=1
df9c27
+QEMU_OPTIONS="-numa node,nodeid=0"
df9c27
+
df9c27
+. $TEST_BASE_DIR/test-functions
df9c27
+
df9c27
+test_setup() {
df9c27
+    create_empty_image
df9c27
+    mkdir -p $TESTDIR/root
df9c27
+    mount ${LOOPDEV}p1 $TESTDIR/root
df9c27
+
df9c27
+    (
df9c27
+        LOG_LEVEL=5
df9c27
+        eval $(udevadm info --export --query=env --name=${LOOPDEV}p2)
df9c27
+
df9c27
+        setup_basic_environment
df9c27
+        inst_binary mktemp
df9c27
+
df9c27
+        # mask some services that we do not want to run in these tests
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service
df9c27
+        ln -fs /dev/null $initdir/etc/systemd/system/systemd-machined.service
df9c27
+
df9c27
+        # setup the testsuite service
df9c27
+        cat >$initdir/etc/systemd/system/testsuite.service <
df9c27
+[Unit]
df9c27
+Description=Testsuite service
df9c27
+
df9c27
+[Service]
df9c27
+ExecStart=/bin/bash -x /testsuite.sh
df9c27
+Type=oneshot
df9c27
+StandardOutput=tty
df9c27
+StandardError=tty
df9c27
+NotifyAccess=all
df9c27
+EOF
df9c27
+        cp testsuite.sh $initdir/
df9c27
+
df9c27
+        setup_testsuite
df9c27
+    ) || return 1
df9c27
+    setup_nspawn_root
df9c27
+
df9c27
+    ddebug "umount $TESTDIR/root"
df9c27
+    umount $TESTDIR/root
df9c27
+}
df9c27
+
df9c27
+do_test "$@"
df9c27
diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
new file mode 100755
df9c27
index 0000000000..e15087b137
df9c27
--- /dev/null
df9c27
+++ b/test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
@@ -0,0 +1,292 @@
df9c27
+#!/bin/bash
df9c27
+set -ex
df9c27
+set -o pipefail
df9c27
+
df9c27
+at_exit() {
df9c27
+    if [ $? -ne 0 ]; then
df9c27
+        # We're exiting with a non-zero EC, let's dump test artifacts
df9c27
+        # for easier debugging
df9c27
+        [ -f "$straceLog" ] && cat "$straceLog"
df9c27
+        [ -f "$journalLog" ] && cat "$journalLog"
df9c27
+    fi
df9c27
+}
df9c27
+
df9c27
+trap at_exit EXIT
df9c27
+
df9c27
+systemd-analyze log-level debug
df9c27
+systemd-analyze log-target journal
df9c27
+
df9c27
+# Log files
df9c27
+straceLog='strace.log'
df9c27
+journalLog='journal.log'
df9c27
+
df9c27
+# Systemd config files
df9c27
+testUnit='numa-test.service'
df9c27
+testUnitFile="/etc/systemd/system/$testUnit"
df9c27
+testUnitNUMAConf="$testUnitFile.d/numa.conf"
df9c27
+
df9c27
+# Sleep constants (we should probably figure out something better but nothing comes to mind)
df9c27
+journalSleep=5
df9c27
+sleepAfterStart=1
df9c27
+
df9c27
+startStrace() {
df9c27
+    coproc strace -qq -p 1 -o $straceLog -e set_mempolicy -s 1024 $1
df9c27
+}
df9c27
+
df9c27
+stopStrace() {
df9c27
+    kill -s TERM $COPROC_PID
df9c27
+}
df9c27
+
df9c27
+startJournalctl() {
df9c27
+    coproc journalctl -u init.scope -f > $journalLog
df9c27
+}
df9c27
+
df9c27
+stopJournalctl() {
df9c27
+    # Wait a few seconds until the messages get properly queued...
df9c27
+    sleep $journalSleep
df9c27
+    # ...and then force journald to write them to the backing storage
df9c27
+    # Also, using journalctl --sync should be better than using SIGRTMIN+1, as
df9c27
+    # the --sync wait until the synchronization is complete
df9c27
+    echo "Force journald to write all queued messages"
df9c27
+    journalctl --sync
df9c27
+    kill -s TERM $COPROC_PID
df9c27
+}
df9c27
+
df9c27
+checkNUMA() {
df9c27
+    # NUMA enabled system should have at least NUMA node0
df9c27
+    test -e /sys/devices/system/node/node0
df9c27
+}
df9c27
+
df9c27
+writePID1NUMAPolicy() {
df9c27
+    echo [Manager] > $confDir/numa.conf
df9c27
+    echo NUMAPolicy=$1 >> $confDir/numa.conf
df9c27
+    echo NUMAMask=$2>> $confDir/numa.conf
df9c27
+}
df9c27
+
df9c27
+writeTestUnit() {
df9c27
+    echo [Service] > $testUnitFile
df9c27
+    echo ExecStart=/bin/sleep 3600 >> $testUnitFile
df9c27
+    mkdir -p $testUnitFile.d/
df9c27
+}
df9c27
+
df9c27
+writeTestUnitNUMAPolicy() {
df9c27
+    echo [Service] > $testUnitNUMAConf
df9c27
+    echo NUMAPolicy=$1 >> $testUnitNUMAConf
df9c27
+    echo NUMAMask=$2>> $testUnitNUMAConf
df9c27
+    systemctl daemon-reload
df9c27
+}
df9c27
+
df9c27
+pid1ReloadWithStrace() {
df9c27
+    startStrace
df9c27
+    systemctl daemon-reload
df9c27
+    stopStrace
df9c27
+}
df9c27
+
df9c27
+pid1ReloadWithJournal() {
df9c27
+    startJournalctl
df9c27
+    systemctl daemon-reload
df9c27
+    stopJournalctl
df9c27
+}
df9c27
+
df9c27
+pid1StartUnitWithStrace() {
df9c27
+    startStrace '-f'
df9c27
+    systemctl start $1
df9c27
+    sleep $sleepAfterStart
df9c27
+    stopStrace
df9c27
+}
df9c27
+
df9c27
+pid1StartUnitWithJournal() {
df9c27
+    startJournalctl
df9c27
+    systemctl start $1
df9c27
+    sleep $sleepAfterStart
df9c27
+    stopJournalctl
df9c27
+}
df9c27
+
df9c27
+pid1StopUnit() {
df9c27
+    systemctl stop $1
df9c27
+}
df9c27
+
df9c27
+systemctlCheckNUMAProperties() {
df9c27
+    local LOGFILE="$(mktemp)"
df9c27
+    systemctl show -p NUMAPolicy $1 > "$LOGFILE"
df9c27
+    grep "NUMAPolicy=$2" "$LOGFILE"
df9c27
+
df9c27
+    > "$LOGFILE"
df9c27
+
df9c27
+    if [ -n $3 ]; then
df9c27
+        systemctl show -p NUMAMask $1 > "$LOGFILE"
df9c27
+        grep "NUMAMask=$3" "$LOGFILE"
df9c27
+    fi
df9c27
+}
df9c27
+
df9c27
+checkNUMA
df9c27
+writeTestUnit
df9c27
+
df9c27
+# Create systemd config drop-in directory
df9c27
+confDir="/etc/systemd/system.conf.d/"
df9c27
+mkdir -p "$confDir"
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Default policy w/o mask"
df9c27
+writePID1NUMAPolicy "default"
df9c27
+pid1ReloadWithStrace
df9c27
+# Kernel requires that nodemask argument is set to NULL when setting default policy
df9c27
+grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Default policy w/ mask"
df9c27
+writePID1NUMAPolicy "default" "0"
df9c27
+pid1ReloadWithStrace
df9c27
+grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Bind policy w/o mask"
df9c27
+writePID1NUMAPolicy "bind"
df9c27
+pid1ReloadWithJournal
df9c27
+grep "Failed to set NUMA memory policy: Invalid argument" $journalLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Bind policy w/ mask"
df9c27
+writePID1NUMAPolicy "bind" "0"
df9c27
+pid1ReloadWithStrace
df9c27
+grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Interleave policy w/o mask"
df9c27
+writePID1NUMAPolicy "interleave"
df9c27
+pid1ReloadWithJournal
df9c27
+grep "Failed to set NUMA memory policy: Invalid argument" $journalLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Interleave policy w/ mask"
df9c27
+writePID1NUMAPolicy "interleave" "0"
df9c27
+pid1ReloadWithStrace
df9c27
+grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Preferred policy w/o mask"
df9c27
+writePID1NUMAPolicy "preferred"
df9c27
+pid1ReloadWithJournal
df9c27
+# Preferred policy with empty node mask is actually allowed and should reset allocation policy to default
df9c27
+! grep "Failed to set NUMA memory policy: Invalid argument" $journalLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Preferred policy w/ mask"
df9c27
+writePID1NUMAPolicy "preferred" "0"
df9c27
+pid1ReloadWithStrace
df9c27
+grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Local policy w/o mask"
df9c27
+writePID1NUMAPolicy "local"
df9c27
+pid1ReloadWithStrace
df9c27
+# Kernel requires that nodemask argument is set to NULL when setting default policy
df9c27
+grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog
df9c27
+
df9c27
+echo "PID1 NUMAPolicy support - Local policy w/ mask"
df9c27
+writePID1NUMAPolicy "local" "0"
df9c27
+pid1ReloadWithStrace
df9c27
+grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Default policy w/o mask"
df9c27
+writeTestUnitNUMAPolicy "default"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "default"
df9c27
+pid1StopUnit $testUnit
df9c27
+grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Default policy w/ mask"
df9c27
+writeTestUnitNUMAPolicy "default" "0"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "default" "0"
df9c27
+pid1StopUnit $testUnit
df9c27
+# Maks must be ignored
df9c27
+grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Bind policy w/o mask"
df9c27
+writeTestUnitNUMAPolicy "bind"
df9c27
+pid1StartUnitWithJournal $testUnit
df9c27
+pid1StopUnit $testUnit
df9c27
+grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Bind policy w/ mask"
df9c27
+writeTestUnitNUMAPolicy "bind" "0"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "bind" "0"
df9c27
+pid1StopUnit $testUnit
df9c27
+grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Interleave policy w/o mask"
df9c27
+writeTestUnitNUMAPolicy "interleave"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+pid1StopUnit $testUnit
df9c27
+grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Interleave policy w/ mask"
df9c27
+writeTestUnitNUMAPolicy "interleave" "0"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "interleave" "0"
df9c27
+pid1StopUnit $testUnit
df9c27
+grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Preferred policy w/o mask"
df9c27
+writeTestUnitNUMAPolicy "preferred"
df9c27
+pid1StartUnitWithJournal $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "preferred"
df9c27
+pid1StopUnit $testUnit
df9c27
+! grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Preferred policy w/ mask"
df9c27
+writeTestUnitNUMAPolicy "preferred" "0"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "preferred" "0"
df9c27
+pid1StopUnit $testUnit
df9c27
+grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Local policy w/o mask"
df9c27
+writeTestUnitNUMAPolicy "local"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "local"
df9c27
+pid1StopUnit $testUnit
df9c27
+grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog
df9c27
+
df9c27
+echo "Unit file NUMAPolicy support - Local policy w/ mask"
df9c27
+writeTestUnitNUMAPolicy "local" "0"
df9c27
+pid1StartUnitWithStrace $testUnit
df9c27
+systemctlCheckNUMAProperties $testUnit "local" "0"
df9c27
+pid1StopUnit $testUnit
df9c27
+# Maks must be ignored
df9c27
+grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog
df9c27
+
df9c27
+echo "systemd-run NUMAPolicy support"
df9c27
+runUnit='numa-systemd-run-test.service'
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=default --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "default"
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "default" ""
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "bind" "0"
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "interleave" "0"
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "preferred" "0"
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=local --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "local"
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+systemctlCheckNUMAProperties $runUnit "local" ""
df9c27
+pid1StopUnit $runUnit
df9c27
+
df9c27
+# Cleanup
df9c27
+rm -rf $testDir
df9c27
+rm -rf $confDir
df9c27
+systemctl daemon-reload
df9c27
+
df9c27
+systemd-analyze log-level info
df9c27
+
df9c27
+echo OK > /testok
df9c27
+
df9c27
+exit 0
df9c27
-- 
df9c27
2.21.1
df9c27