From 761ce2a4ba8843ba7015e279e9c9444cbe63a680 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 25 Jun 2019 22:45:15 +0200 Subject: [PATCH 01/10] test: allow overriding QEMU_OPTIONS from the outside --- test/test-functions | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-functions b/test/test-functions index 37bdfd58dc..6523db01b9 100644 --- a/test/test-functions +++ b/test/test-functions @@ -209,6 +209,7 @@ $KERNEL_APPEND \ -nographic \ -kernel $KERNEL_BIN \ -drive format=raw,cache=unsafe,file=${TESTDIR}/rootdisk.img \ +$QEMU_OPTIONS \ " if [[ "$INITRD" && "$SKIP_INITRD" != "yes" ]]; then From 8f65e26508969610ac934d1aadbade8223bfcaac Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 25 Jun 2019 23:01:40 +0200 Subject: [PATCH 02/10] test: introduce TEST-36-NUMAPOLICY --- test/TEST-36-NUMAPOLICY/Makefile | 1 + test/TEST-36-NUMAPOLICY/test.sh | 51 +++++ test/TEST-36-NUMAPOLICY/testsuite.sh | 292 +++++++++++++++++++++++++++ 3 files changed, 344 insertions(+) create mode 120000 test/TEST-36-NUMAPOLICY/Makefile create mode 100755 test/TEST-36-NUMAPOLICY/test.sh create mode 100755 test/TEST-36-NUMAPOLICY/testsuite.sh diff --git a/test/TEST-36-NUMAPOLICY/Makefile b/test/TEST-36-NUMAPOLICY/Makefile new file mode 120000 index 0000000000..e9f93b1104 --- /dev/null +++ b/test/TEST-36-NUMAPOLICY/Makefile @@ -0,0 +1 @@ +../TEST-01-BASIC/Makefile \ No newline at end of file diff --git a/test/TEST-36-NUMAPOLICY/test.sh b/test/TEST-36-NUMAPOLICY/test.sh new file mode 100755 index 0000000000..a0d8623e8e --- /dev/null +++ b/test/TEST-36-NUMAPOLICY/test.sh @@ -0,0 +1,51 @@ +#!/bin/bash +set -e +TEST_DESCRIPTION="test MUMAPolicy= and NUMAMask= options" +TEST_NO_NSPAWN=1 +QEMU_OPTIONS="-numa node,nodeid=0" + +. $TEST_BASE_DIR/test-functions + +test_setup() { + create_empty_image + mkdir -p $TESTDIR/root + mount ${LOOPDEV}p1 $TESTDIR/root + + ( + LOG_LEVEL=5 + eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) + + setup_basic_environment + inst_binary mktemp + + # mask some services that we do not want to run in these tests + ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service + ln -fs /dev/null $initdir/etc/systemd/system/systemd-journal-catalog-update.service + ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.service + ln -fs /dev/null $initdir/etc/systemd/system/systemd-networkd.socket + ln -fs /dev/null $initdir/etc/systemd/system/systemd-resolved.service + ln -fs /dev/null $initdir/etc/systemd/system/systemd-machined.service + + # setup the testsuite service + cat >$initdir/etc/systemd/system/testsuite.service < $journalLog +} + +stopJournalctl() { + # Wait a few seconds until the messages get properly queued... + sleep $journalSleep + # ...and then force journald to write them to the backing storage + # Also, using journalctl --sync should be better than using SIGRTMIN+1, as + # the --sync wait until the synchronization is complete + echo "Force journald to write all queued messages" + journalctl --sync + kill -s TERM $COPROC_PID +} + +checkNUMA() { + # NUMA enabled system should have at least NUMA node0 + test -e /sys/devices/system/node/node0 +} + +writePID1NUMAPolicy() { + echo [Manager] > $confDir/numa.conf + echo NUMAPolicy=$1 >> $confDir/numa.conf + echo NUMAMask=$2>> $confDir/numa.conf +} + +writeTestUnit() { + echo [Service] > $testUnitFile + echo ExecStart=/bin/sleep 3600 >> $testUnitFile + mkdir -p $testUnitFile.d/ +} + +writeTestUnitNUMAPolicy() { + echo [Service] > $testUnitNUMAConf + echo NUMAPolicy=$1 >> $testUnitNUMAConf + echo NUMAMask=$2>> $testUnitNUMAConf + systemctl daemon-reload +} + +pid1ReloadWithStrace() { + startStrace + systemctl daemon-reload + stopStrace +} + +pid1ReloadWithJournal() { + startJournalctl + systemctl daemon-reload + stopJournalctl +} + +pid1StartUnitWithStrace() { + startStrace '-f' + systemctl start $1 + sleep $sleepAfterStart + stopStrace +} + +pid1StartUnitWithJournal() { + startJournalctl + systemctl start $1 + sleep $sleepAfterStart + stopJournalctl +} + +pid1StopUnit() { + systemctl stop $1 +} + +systemctlCheckNUMAProperties() { + local LOGFILE="$(mktemp)" + systemctl show -p NUMAPolicy $1 > "$LOGFILE" + grep "NUMAPolicy=$2" "$LOGFILE" + + > "$LOGFILE" + + if [ -n $3 ]; then + systemctl show -p NUMAMask $1 > "$LOGFILE" + grep "NUMAMask=$3" "$LOGFILE" + fi +} + +checkNUMA +writeTestUnit + +# Create systemd config drop-in directory +confDir="/etc/systemd/system.conf.d/" +mkdir -p "$confDir" + +echo "PID1 NUMAPolicy support - Default policy w/o mask" +writePID1NUMAPolicy "default" +pid1ReloadWithStrace +# Kernel requires that nodemask argument is set to NULL when setting default policy +grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + +echo "PID1 NUMAPolicy support - Default policy w/ mask" +writePID1NUMAPolicy "default" "0" +pid1ReloadWithStrace +grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + +echo "PID1 NUMAPolicy support - Bind policy w/o mask" +writePID1NUMAPolicy "bind" +pid1ReloadWithJournal +grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + +echo "PID1 NUMAPolicy support - Bind policy w/ mask" +writePID1NUMAPolicy "bind" "0" +pid1ReloadWithStrace +grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog + +echo "PID1 NUMAPolicy support - Interleave policy w/o mask" +writePID1NUMAPolicy "interleave" +pid1ReloadWithJournal +grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + +echo "PID1 NUMAPolicy support - Interleave policy w/ mask" +writePID1NUMAPolicy "interleave" "0" +pid1ReloadWithStrace +grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + +echo "PID1 NUMAPolicy support - Preferred policy w/o mask" +writePID1NUMAPolicy "preferred" +pid1ReloadWithJournal +# Preferred policy with empty node mask is actually allowed and should reset allocation policy to default +! grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + +echo "PID1 NUMAPolicy support - Preferred policy w/ mask" +writePID1NUMAPolicy "preferred" "0" +pid1ReloadWithStrace +grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + +echo "PID1 NUMAPolicy support - Local policy w/o mask" +writePID1NUMAPolicy "local" +pid1ReloadWithStrace +# Kernel requires that nodemask argument is set to NULL when setting default policy +grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog + +echo "PID1 NUMAPolicy support - Local policy w/ mask" +writePID1NUMAPolicy "local" "0" +pid1ReloadWithStrace +grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog + +echo "Unit file NUMAPolicy support - Default policy w/o mask" +writeTestUnitNUMAPolicy "default" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "default" +pid1StopUnit $testUnit +grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + +echo "Unit file NUMAPolicy support - Default policy w/ mask" +writeTestUnitNUMAPolicy "default" "0" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "default" "0" +pid1StopUnit $testUnit +# Maks must be ignored +grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + +echo "Unit file NUMAPolicy support - Bind policy w/o mask" +writeTestUnitNUMAPolicy "bind" +pid1StartUnitWithJournal $testUnit +pid1StopUnit $testUnit +grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + +echo "Unit file NUMAPolicy support - Bind policy w/ mask" +writeTestUnitNUMAPolicy "bind" "0" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "bind" "0" +pid1StopUnit $testUnit +grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog + +echo "Unit file NUMAPolicy support - Interleave policy w/o mask" +writeTestUnitNUMAPolicy "interleave" +pid1StartUnitWithStrace $testUnit +pid1StopUnit $testUnit +grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + +echo "Unit file NUMAPolicy support - Interleave policy w/ mask" +writeTestUnitNUMAPolicy "interleave" "0" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "interleave" "0" +pid1StopUnit $testUnit +grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + +echo "Unit file NUMAPolicy support - Preferred policy w/o mask" +writeTestUnitNUMAPolicy "preferred" +pid1StartUnitWithJournal $testUnit +systemctlCheckNUMAProperties $testUnit "preferred" +pid1StopUnit $testUnit +! grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + +echo "Unit file NUMAPolicy support - Preferred policy w/ mask" +writeTestUnitNUMAPolicy "preferred" "0" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "preferred" "0" +pid1StopUnit $testUnit +grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + +echo "Unit file NUMAPolicy support - Local policy w/o mask" +writeTestUnitNUMAPolicy "local" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "local" +pid1StopUnit $testUnit +grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog + +echo "Unit file NUMAPolicy support - Local policy w/ mask" +writeTestUnitNUMAPolicy "local" "0" +pid1StartUnitWithStrace $testUnit +systemctlCheckNUMAProperties $testUnit "local" "0" +pid1StopUnit $testUnit +# Maks must be ignored +grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog + +echo "systemd-run NUMAPolicy support" +runUnit='numa-systemd-run-test.service' + +systemd-run -p NUMAPolicy=default --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "default" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "default" "" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "bind" "0" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "interleave" "0" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "preferred" "0" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=local --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "local" +pid1StopUnit $runUnit + +systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit $runUnit sleep 1000 +systemctlCheckNUMAProperties $runUnit "local" "" +pid1StopUnit $runUnit + +# Cleanup +rm -rf $testDir +rm -rf $confDir +systemctl daemon-reload + +systemd-analyze log-level info + +echo OK > /testok + +exit 0 From d0b2178f3e79f302702bd7140766eee03643f734 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 1 Jul 2019 09:27:59 +0200 Subject: [PATCH 03/10] test: replace `tail -f` with journal cursor which should be... more reliable --- test/TEST-36-NUMAPOLICY/testsuite.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index e15087b137..306a96b517 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -29,6 +29,9 @@ testUnitNUMAConf="$testUnitFile.d/numa.conf" journalSleep=5 sleepAfterStart=1 +# Journal cursor for easier navigation +journalCursorFile="jounalCursorFile" + startStrace() { coproc strace -qq -p 1 -o $straceLog -e set_mempolicy -s 1024 $1 } @@ -38,18 +41,16 @@ stopStrace() { } startJournalctl() { - coproc journalctl -u init.scope -f > $journalLog + # Save journal's cursor for later navigation + journalctl --no-pager --cursor-file="$journalCursorFile" -n0 -ocat } stopJournalctl() { - # Wait a few seconds until the messages get properly queued... - sleep $journalSleep - # ...and then force journald to write them to the backing storage - # Also, using journalctl --sync should be better than using SIGRTMIN+1, as + # Using journalctl --sync should be better than using SIGRTMIN+1, as # the --sync wait until the synchronization is complete echo "Force journald to write all queued messages" journalctl --sync - kill -s TERM $COPROC_PID + journalctl -u init.scope --cursor-file="$journalCursorFile" > "$journalLog" } checkNUMA() { From ac14396d027023e1be910327989cb422cb2f6724 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 1 Jul 2019 13:08:26 +0200 Subject: [PATCH 04/10] test: support MPOL_LOCAL matching in unpatched strace versions The MPOL_LOCAL constant is not recognized in current strace versions. Let's match at least the numerical value of this constant until the strace patch is approved & merged. --- test/TEST-36-NUMAPOLICY/testsuite.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index 306a96b517..a4134bdeca 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -173,12 +173,16 @@ echo "PID1 NUMAPolicy support - Local policy w/o mask" writePID1NUMAPolicy "local" pid1ReloadWithStrace # Kernel requires that nodemask argument is set to NULL when setting default policy -grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog +# The unpatched versions of strace don't recognize the MPOL_LOCAL constant and +# return a numerical constant instead (with a comment): +# set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0 +# Let's cover this scenario as well +grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog echo "PID1 NUMAPolicy support - Local policy w/ mask" writePID1NUMAPolicy "local" "0" pid1ReloadWithStrace -grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog +grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog echo "Unit file NUMAPolicy support - Default policy w/o mask" writeTestUnitNUMAPolicy "default" @@ -240,7 +244,7 @@ writeTestUnitNUMAPolicy "local" pid1StartUnitWithStrace $testUnit systemctlCheckNUMAProperties $testUnit "local" pid1StopUnit $testUnit -grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog +grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog echo "Unit file NUMAPolicy support - Local policy w/ mask" writeTestUnitNUMAPolicy "local" "0" @@ -248,7 +252,7 @@ pid1StartUnitWithStrace $testUnit systemctlCheckNUMAProperties $testUnit "local" "0" pid1StopUnit $testUnit # Maks must be ignored -grep "set_mempolicy(MPOL_LOCAL, NULL" $straceLog +grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog echo "systemd-run NUMAPolicy support" runUnit='numa-systemd-run-test.service' From 56425e54a2140f47b4560b51c5db08aa2de199a6 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 1 Jul 2019 19:53:45 +0200 Subject: [PATCH 05/10] test: make sure the strace process is indeed dead It may take a few moments for the strace process to properly terminate and write all logs to the backing storage --- test/TEST-36-NUMAPOLICY/test.sh | 2 +- test/TEST-36-NUMAPOLICY/testsuite.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/TEST-36-NUMAPOLICY/test.sh b/test/TEST-36-NUMAPOLICY/test.sh index a0d8623e8e..f0a321e7a1 100755 --- a/test/TEST-36-NUMAPOLICY/test.sh +++ b/test/TEST-36-NUMAPOLICY/test.sh @@ -16,7 +16,7 @@ test_setup() { eval $(udevadm info --export --query=env --name=${LOOPDEV}p2) setup_basic_environment - inst_binary mktemp + dracut_install mktemp # mask some services that we do not want to run in these tests ln -fs /dev/null $initdir/etc/systemd/system/systemd-hwdb-update.service diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index a4134bdeca..daed8fcc1c 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -38,6 +38,8 @@ startStrace() { stopStrace() { kill -s TERM $COPROC_PID + # Make sure the strace process is indeed dead + while kill -0 $COPROC_PID 2>/dev/null; do sleep 0.1; done } startJournalctl() { @@ -80,6 +82,7 @@ writeTestUnitNUMAPolicy() { pid1ReloadWithStrace() { startStrace systemctl daemon-reload + sleep $sleepAfterStart stopStrace } From b030847163e9bd63d3dd6eec6ac7f336411faba6 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 2 Jul 2019 09:52:45 +0200 Subject: [PATCH 06/10] test: skip the test on systems without NUMA support --- test/TEST-36-NUMAPOLICY/testsuite.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index daed8fcc1c..4b715d305a 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -123,7 +123,18 @@ systemctlCheckNUMAProperties() { fi } -checkNUMA +if ! checkNUMA; then + echo >&2 "NUMA is not supported on this machine, skipping the test" + + # FIXME: add some sanity checks to verify systemd behaves correctly with + # NUMA disabled together with NUMAPolicy= and NUMAMask= + + systemd-analyze log-level info + echo OK > /testok + + exit 0 +fi + writeTestUnit # Create systemd config drop-in directory From c7367d7cfdfdcec98f8659f0ed3f1d7b77123903 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Tue, 23 Jul 2019 00:56:04 +0200 Subject: [PATCH 07/10] test: give strace some time to initialize The `coproc` implementation seems to be a little bit different in older bash versions, so the `strace` is sometimes started AFTER `systemctl daemon-reload`, which causes unexpected fails. Let's help it a little by sleeping for a bit. --- test/TEST-36-NUMAPOLICY/testsuite.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index 4b715d305a..1c8cf7e6b6 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -34,6 +34,8 @@ journalCursorFile="jounalCursorFile" startStrace() { coproc strace -qq -p 1 -o $straceLog -e set_mempolicy -s 1024 $1 + # Wait for strace to properly "initialize" + sleep $sleepAfterStart } stopStrace() { From 92f8e978923f962a57d744c5f358520ac06f7892 Mon Sep 17 00:00:00 2001 From: Frantisek Sumsal Date: Mon, 5 Aug 2019 14:38:45 +0200 Subject: [PATCH 08/10] test: add a simple sanity check for systems without NUMA support --- test/TEST-36-NUMAPOLICY/testsuite.sh | 296 ++++++++++++++------------- 1 file changed, 153 insertions(+), 143 deletions(-) diff --git a/test/TEST-36-NUMAPOLICY/testsuite.sh b/test/TEST-36-NUMAPOLICY/testsuite.sh index 1c8cf7e6b6..a5ac788178 100755 --- a/test/TEST-36-NUMAPOLICY/testsuite.sh +++ b/test/TEST-36-NUMAPOLICY/testsuite.sh @@ -50,11 +50,12 @@ startJournalctl() { } stopJournalctl() { + local unit="${1:-init.scope}" # Using journalctl --sync should be better than using SIGRTMIN+1, as # the --sync wait until the synchronization is complete echo "Force journald to write all queued messages" journalctl --sync - journalctl -u init.scope --cursor-file="$journalCursorFile" > "$journalLog" + journalctl -u $unit --cursor-file="$journalCursorFile" > "$journalLog" } checkNUMA() { @@ -125,181 +126,190 @@ systemctlCheckNUMAProperties() { fi } -if ! checkNUMA; then - echo >&2 "NUMA is not supported on this machine, skipping the test" - - # FIXME: add some sanity checks to verify systemd behaves correctly with - # NUMA disabled together with NUMAPolicy= and NUMAMask= - - systemd-analyze log-level info - echo OK > /testok - - exit 0 -fi - writeTestUnit # Create systemd config drop-in directory confDir="/etc/systemd/system.conf.d/" mkdir -p "$confDir" -echo "PID1 NUMAPolicy support - Default policy w/o mask" -writePID1NUMAPolicy "default" -pid1ReloadWithStrace -# Kernel requires that nodemask argument is set to NULL when setting default policy -grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog +if ! checkNUMA; then + echo >&2 "NUMA is not supported on this machine, switching to a simple sanity check" -echo "PID1 NUMAPolicy support - Default policy w/ mask" -writePID1NUMAPolicy "default" "0" -pid1ReloadWithStrace -grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + echo "PID1 NUMAPolicy=default && NUMAMask=0 check without NUMA support" + writePID1NUMAPolicy "default" "0" + startJournalctl + systemctl daemon-reload + stopJournalctl + grep "NUMA support not available, ignoring" "$journalLog" -echo "PID1 NUMAPolicy support - Bind policy w/o mask" -writePID1NUMAPolicy "bind" -pid1ReloadWithJournal -grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + echo "systemd-run NUMAPolicy=default && NUMAMask=0 check without NUMA support" + runUnit='numa-systemd-run-test.service' + startJournalctl + systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 + sleep $sleepAfterStart + pid1StopUnit $runUnit + stopJournalctl $runUnit + grep "NUMA support not available, ignoring" "$journalLog" -echo "PID1 NUMAPolicy support - Bind policy w/ mask" -writePID1NUMAPolicy "bind" "0" -pid1ReloadWithStrace -grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog +else + echo "PID1 NUMAPolicy support - Default policy w/o mask" + writePID1NUMAPolicy "default" + pid1ReloadWithStrace + # Kernel requires that nodemask argument is set to NULL when setting default policy + grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog -echo "PID1 NUMAPolicy support - Interleave policy w/o mask" -writePID1NUMAPolicy "interleave" -pid1ReloadWithJournal -grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + echo "PID1 NUMAPolicy support - Default policy w/ mask" + writePID1NUMAPolicy "default" "0" + pid1ReloadWithStrace + grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog -echo "PID1 NUMAPolicy support - Interleave policy w/ mask" -writePID1NUMAPolicy "interleave" "0" -pid1ReloadWithStrace -grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + echo "PID1 NUMAPolicy support - Bind policy w/o mask" + writePID1NUMAPolicy "bind" + pid1ReloadWithJournal + grep "Failed to set NUMA memory policy: Invalid argument" $journalLog -echo "PID1 NUMAPolicy support - Preferred policy w/o mask" -writePID1NUMAPolicy "preferred" -pid1ReloadWithJournal -# Preferred policy with empty node mask is actually allowed and should reset allocation policy to default -! grep "Failed to set NUMA memory policy: Invalid argument" $journalLog + echo "PID1 NUMAPolicy support - Bind policy w/ mask" + writePID1NUMAPolicy "bind" "0" + pid1ReloadWithStrace + grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog -echo "PID1 NUMAPolicy support - Preferred policy w/ mask" -writePID1NUMAPolicy "preferred" "0" -pid1ReloadWithStrace -grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + echo "PID1 NUMAPolicy support - Interleave policy w/o mask" + writePID1NUMAPolicy "interleave" + pid1ReloadWithJournal + grep "Failed to set NUMA memory policy: Invalid argument" $journalLog -echo "PID1 NUMAPolicy support - Local policy w/o mask" -writePID1NUMAPolicy "local" -pid1ReloadWithStrace -# Kernel requires that nodemask argument is set to NULL when setting default policy -# The unpatched versions of strace don't recognize the MPOL_LOCAL constant and -# return a numerical constant instead (with a comment): -# set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0 -# Let's cover this scenario as well -grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + echo "PID1 NUMAPolicy support - Interleave policy w/ mask" + writePID1NUMAPolicy "interleave" "0" + pid1ReloadWithStrace + grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog -echo "PID1 NUMAPolicy support - Local policy w/ mask" -writePID1NUMAPolicy "local" "0" -pid1ReloadWithStrace -grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + echo "PID1 NUMAPolicy support - Preferred policy w/o mask" + writePID1NUMAPolicy "preferred" + pid1ReloadWithJournal + # Preferred policy with empty node mask is actually allowed and should reset allocation policy to default + ! grep "Failed to set NUMA memory policy: Invalid argument" $journalLog -echo "Unit file NUMAPolicy support - Default policy w/o mask" -writeTestUnitNUMAPolicy "default" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "default" -pid1StopUnit $testUnit -grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + echo "PID1 NUMAPolicy support - Preferred policy w/ mask" + writePID1NUMAPolicy "preferred" "0" + pid1ReloadWithStrace + grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog -echo "Unit file NUMAPolicy support - Default policy w/ mask" -writeTestUnitNUMAPolicy "default" "0" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "default" "0" -pid1StopUnit $testUnit -# Maks must be ignored -grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog + echo "PID1 NUMAPolicy support - Local policy w/o mask" + writePID1NUMAPolicy "local" + pid1ReloadWithStrace + # Kernel requires that nodemask argument is set to NULL when setting default policy + # The unpatched versions of strace don't recognize the MPOL_LOCAL constant and + # return a numerical constant instead (with a comment): + # set_mempolicy(0x4 /* MPOL_??? */, NULL, 0) = 0 + # Let's cover this scenario as well + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog -echo "Unit file NUMAPolicy support - Bind policy w/o mask" -writeTestUnitNUMAPolicy "bind" -pid1StartUnitWithJournal $testUnit -pid1StopUnit $testUnit -grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + echo "PID1 NUMAPolicy support - Local policy w/ mask" + writePID1NUMAPolicy "local" "0" + pid1ReloadWithStrace + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog -echo "Unit file NUMAPolicy support - Bind policy w/ mask" -writeTestUnitNUMAPolicy "bind" "0" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "bind" "0" -pid1StopUnit $testUnit -grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog + echo "Unit file NUMAPolicy support - Default policy w/o mask" + writeTestUnitNUMAPolicy "default" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "default" + pid1StopUnit $testUnit + grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog -echo "Unit file NUMAPolicy support - Interleave policy w/o mask" -writeTestUnitNUMAPolicy "interleave" -pid1StartUnitWithStrace $testUnit -pid1StopUnit $testUnit -grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + echo "Unit file NUMAPolicy support - Default policy w/ mask" + writeTestUnitNUMAPolicy "default" "0" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "default" "0" + pid1StopUnit $testUnit + # Maks must be ignored + grep "set_mempolicy(MPOL_DEFAULT, NULL" $straceLog -echo "Unit file NUMAPolicy support - Interleave policy w/ mask" -writeTestUnitNUMAPolicy "interleave" "0" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "interleave" "0" -pid1StopUnit $testUnit -grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog + echo "Unit file NUMAPolicy support - Bind policy w/o mask" + writeTestUnitNUMAPolicy "bind" + pid1StartUnitWithJournal $testUnit + pid1StopUnit $testUnit + grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog -echo "Unit file NUMAPolicy support - Preferred policy w/o mask" -writeTestUnitNUMAPolicy "preferred" -pid1StartUnitWithJournal $testUnit -systemctlCheckNUMAProperties $testUnit "preferred" -pid1StopUnit $testUnit -! grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog + echo "Unit file NUMAPolicy support - Bind policy w/ mask" + writeTestUnitNUMAPolicy "bind" "0" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "bind" "0" + pid1StopUnit $testUnit + grep -P "set_mempolicy\(MPOL_BIND, \[0x0*1\]" $straceLog -echo "Unit file NUMAPolicy support - Preferred policy w/ mask" -writeTestUnitNUMAPolicy "preferred" "0" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "preferred" "0" -pid1StopUnit $testUnit -grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog + echo "Unit file NUMAPolicy support - Interleave policy w/o mask" + writeTestUnitNUMAPolicy "interleave" + pid1StartUnitWithStrace $testUnit + pid1StopUnit $testUnit + grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog -echo "Unit file NUMAPolicy support - Local policy w/o mask" -writeTestUnitNUMAPolicy "local" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "local" -pid1StopUnit $testUnit -grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + echo "Unit file NUMAPolicy support - Interleave policy w/ mask" + writeTestUnitNUMAPolicy "interleave" "0" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "interleave" "0" + pid1StopUnit $testUnit + grep -P "set_mempolicy\(MPOL_INTERLEAVE, \[0x0*1\]" $straceLog -echo "Unit file NUMAPolicy support - Local policy w/ mask" -writeTestUnitNUMAPolicy "local" "0" -pid1StartUnitWithStrace $testUnit -systemctlCheckNUMAProperties $testUnit "local" "0" -pid1StopUnit $testUnit -# Maks must be ignored -grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog + echo "Unit file NUMAPolicy support - Preferred policy w/o mask" + writeTestUnitNUMAPolicy "preferred" + pid1StartUnitWithJournal $testUnit + systemctlCheckNUMAProperties $testUnit "preferred" + pid1StopUnit $testUnit + ! grep "numa-test.service: Main process exited, code=exited, status=242/NUMA" $journalLog -echo "systemd-run NUMAPolicy support" -runUnit='numa-systemd-run-test.service' + echo "Unit file NUMAPolicy support - Preferred policy w/ mask" + writeTestUnitNUMAPolicy "preferred" "0" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "preferred" "0" + pid1StopUnit $testUnit + grep -P "set_mempolicy\(MPOL_PREFERRED, \[0x0*1\]" $straceLog -systemd-run -p NUMAPolicy=default --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "default" -pid1StopUnit $runUnit + echo "Unit file NUMAPolicy support - Local policy w/o mask" + writeTestUnitNUMAPolicy "local" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "local" + pid1StopUnit $testUnit + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog -systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "default" "" -pid1StopUnit $runUnit + echo "Unit file NUMAPolicy support - Local policy w/ mask" + writeTestUnitNUMAPolicy "local" "0" + pid1StartUnitWithStrace $testUnit + systemctlCheckNUMAProperties $testUnit "local" "0" + pid1StopUnit $testUnit + # Maks must be ignored + grep -E "set_mempolicy\((MPOL_LOCAL|0x4 [^,]*), NULL" $straceLog -systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "bind" "0" -pid1StopUnit $runUnit + echo "systemd-run NUMAPolicy support" + runUnit='numa-systemd-run-test.service' -systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "interleave" "0" -pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=default --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "default" + pid1StopUnit $runUnit -systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "preferred" "0" -pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=default -p NUMAMask=0 --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "default" "" + pid1StopUnit $runUnit -systemd-run -p NUMAPolicy=local --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "local" -pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=bind -p NUMAMask=0 --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "bind" "0" + pid1StopUnit $runUnit -systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit $runUnit sleep 1000 -systemctlCheckNUMAProperties $runUnit "local" "" -pid1StopUnit $runUnit + systemd-run -p NUMAPolicy=interleave -p NUMAMask=0 --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "interleave" "0" + pid1StopUnit $runUnit + + systemd-run -p NUMAPolicy=preferred -p NUMAMask=0 --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "preferred" "0" + pid1StopUnit $runUnit + + systemd-run -p NUMAPolicy=local --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "local" + pid1StopUnit $runUnit + + systemd-run -p NUMAPolicy=local -p NUMAMask=0 --unit $runUnit sleep 1000 + systemctlCheckNUMAProperties $runUnit "local" "" + pid1StopUnit $runUnit +fi # Cleanup rm -rf $testDir From 00d27e5dd74a6c67759def1e958a71aae0650976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 5 Aug 2019 16:36:45 +0200 Subject: [PATCH 09/10] shared/exit-status: fix lookup FLAGS_SET() is the wrong operator here, because we want to see if *any* bits are set. Add test. https://github.com/systemd/systemd/pull/12884#issuecomment-518238410 --- src/shared/exit-status.c | 2 +- src/test/test-exit-status.c | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 44b1c9b749..3704f5d481 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -99,7 +99,7 @@ const ExitStatusMapping exit_status_mappings[256] = { const char* exit_status_to_string(int code, ExitStatusClass class) { if (code < 0 || (size_t) code >= ELEMENTSOF(exit_status_mappings)) return NULL; - return FLAGS_SET(exit_status_mappings[code].class, class) ? exit_status_mappings[code].name : NULL; + return class & exit_status_mappings[code].class ? exit_status_mappings[code].name : NULL; } const char* exit_status_class(int code) { diff --git a/src/test/test-exit-status.c b/src/test/test-exit-status.c index 3bcebd06a4..a007bda5c4 100644 --- a/src/test/test-exit-status.c +++ b/src/test/test-exit-status.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "exit-status.h" +#include "string-util.h" #include "tests.h" static void test_exit_status_to_string(void) { @@ -31,11 +32,21 @@ static void test_exit_status_from_string(void) { assert_se(exit_status_from_string("FAILURE") == 1); } +static void test_exit_status_NUMA_POLICY(void) { + log_info("/* %s */", __func__); + + assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_FULL), "NUMA_POLICY")); + assert_se(streq(exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_SYSTEMD), "NUMA_POLICY")); + assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_BSD)); + assert_se(!exit_status_to_string(EXIT_NUMA_POLICY, EXIT_STATUS_LSB)); +} + int main(int argc, char *argv[]) { test_setup_logging(LOG_DEBUG); test_exit_status_to_string(); test_exit_status_from_string(); + test_exit_status_NUMA_POLICY(); return 0; } From aa39b24a863d76e77f4f8d6e3b62a49a12e2869c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 5 Aug 2019 16:37:53 +0200 Subject: [PATCH 10/10] shared/exit-status: fix off-by-one in comment --- src/shared/exit-status.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 3704f5d481..82b1422b2d 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -18,8 +18,8 @@ const ExitStatusMapping exit_status_mappings[256] = { * 8…63 │ (Currently unmapped) * 64…78 │ BSD defined exit codes * 79…199 │ (Currently unmapped) - * 200…241 │ systemd's private error codes (might be extended to 254 in future development) - * 242…254 │ (Currently unmapped, but see above) + * 200…242 │ systemd's private error codes (might be extended to 254 in future development) + * 243…254 │ (Currently unmapped, but see above) * * 255 │ EXIT_EXCEPTION (We use this to propagate exit-by-signal events. It's frequently used by others apps (like bash) * │ to indicate exit reason that cannot really be expressed in a single exit status value — such as a propagated