naccyde / rpms / systemd

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