Blame SOURCES/0339-test-add-a-simple-sanity-check-for-systems-without-N.patch

df9c27
From 8239ecf0b4b8bbe5b3c17964d230d13cee4d900a Mon Sep 17 00:00:00 2001
df9c27
From: Frantisek Sumsal <frantisek@sumsal.cz>
df9c27
Date: Mon, 5 Aug 2019 14:38:45 +0200
df9c27
Subject: [PATCH 339/341] test: add a simple sanity check for systems without
df9c27
 NUMA support
df9c27
df9c27
(cherry picked from commit 92f8e978923f962a57d744c5f358520ac06f7892)
df9c27
df9c27
Related: #1808940
df9c27
---
df9c27
 test/TEST-36-NUMAPOLICY/testsuite.sh | 350 ++++++++++++++-------------
df9c27
 1 file changed, 180 insertions(+), 170 deletions(-)
df9c27
df9c27
diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
index 1c8cf7e6b6..a5ac788178 100755
df9c27
--- a/test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
+++ b/test/TEST-36-NUMAPOLICY/testsuite.sh
df9c27
@@ -50,11 +50,12 @@ startJournalctl() {
df9c27
 }
df9c27
 
df9c27
 stopJournalctl() {
df9c27
+    local unit="${1:-init.scope}"
df9c27
     # 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
-    journalctl -u init.scope --cursor-file="$journalCursorFile" > "$journalLog"
df9c27
+    journalctl -u $unit --cursor-file="$journalCursorFile" > "$journalLog"
df9c27
 }
df9c27
 
df9c27
 checkNUMA() {
df9c27
@@ -125,181 +126,190 @@ systemctlCheckNUMAProperties() {
df9c27
     fi
df9c27
 }
df9c27
 
df9c27
-if ! checkNUMA; then
df9c27
-    echo >&2 "NUMA is not supported on this machine, skipping the test"
df9c27
-
df9c27
-    # FIXME: add some sanity checks to verify systemd behaves correctly with
df9c27
-    #        NUMA disabled together with NUMAPolicy= and NUMAMask=
df9c27
-
df9c27
-    systemd-analyze log-level info
df9c27
-    echo OK > /testok
df9c27
-
df9c27
-    exit 0
df9c27
-fi
df9c27
-
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
-# The unpatched versions of strace don't recognize the MPOL_LOCAL constant and
df9c27
-# return a numerical constant instead (with a comment):
df9c27
-#   set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0
df9c27
-# Let's cover this scenario as well
df9c27
-grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog
df9c27
-
df9c27
-echo "PID1 NUMAPolicy support - Local policy w/ mask"
df9c27
-writePID1NUMAPolicy "local" "0"
df9c27
-pid1ReloadWithStrace
df9c27
-grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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 -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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 -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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
+if ! checkNUMA; then
df9c27
+    echo >&2 "NUMA is not supported on this machine, switching to a simple sanity check"
df9c27
+
df9c27
+    echo "PID1 NUMAPolicy=default && NUMAMask=0 check without NUMA support"
df9c27
+    writePID1NUMAPolicy "default" "0"
df9c27
+    startJournalctl
df9c27
+    systemctl daemon-reload
df9c27
+    stopJournalctl
df9c27
+    grep "NUMA support not available, ignoring" "$journalLog"
df9c27
+
df9c27
+    echo "systemd-run NUMAPolicy=default && NUMAMask=0 check without NUMA support"
df9c27
+    runUnit='numa-systemd-run-test.service'
df9c27
+    startJournalctl
df9c27
+    systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000
df9c27
+    sleep $sleepAfterStart
df9c27
+    pid1StopUnit $runUnit
df9c27
+    stopJournalctl $runUnit
df9c27
+    grep "NUMA support not available, ignoring" "$journalLog"
df9c27
+
df9c27
+else
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
+    # The unpatched versions of strace don't recognize the MPOL_LOCAL constant and
df9c27
+    # return a numerical constant instead (with a comment):
df9c27
+    #   set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0
df9c27
+    # Let's cover this scenario as well
df9c27
+    grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog
df9c27
+
df9c27
+    echo "PID1 NUMAPolicy support - Local policy w/ mask"
df9c27
+    writePID1NUMAPolicy "local" "0"
df9c27
+    pid1ReloadWithStrace
df9c27
+    grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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 -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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 -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), 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
+fi
df9c27
 
df9c27
 # Cleanup
df9c27
 rm -rf $testDir
df9c27
-- 
df9c27
2.21.1
df9c27