test/common: Don't take randomize_va_space default setting for granted

Currently, kill_stub() doesn't gracefully handle this particular sysctl
since it overwrites it with assumed default that doesn't necessarily
have to be a part of kernel's config on a given system.

Don't presume what the setting should be, instead, read and save the
current value and try to restore it whenever kill_stub() is called.

Change-Id: I1f1ee85c29d5e2ec2f442a54f700e3bc45ee2437
Signed-off-by: Michal Berger <michallinuxstuff@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/482652
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Michal Berger 2020-01-23 00:22:05 +01:00 committed by Ben Walker
parent b41f404d9f
commit 4b1dbc948b

View File

@ -578,7 +578,9 @@ function rbd_cleanup() {
function start_stub() {
# Disable ASLR for multi-process testing. SPDK does support using DPDK multi-process,
# but ASLR can still be unreliable in some cases.
# We will reenable it again after multi-process testing is complete in kill_stub()
# We will reenable it again after multi-process testing is complete in kill_stub().
# Save current setting so it can be restored upon calling kill_stub().
_randomize_va_space=$(</proc/sys/kernel/randomize_va_space)
echo 0 > /proc/sys/kernel/randomize_va_space
$rootdir/test/app/stub/stub $1 &
stubpid=$!
@ -596,7 +598,7 @@ function kill_stub() {
# Re-enable ASLR now that we are done with multi-process testing
# Note: "1" enables ASLR w/o randomizing data segments, "2" adds data segment
# randomizing and is the default on all recent Linux kernels
echo 2 > /proc/sys/kernel/randomize_va_space
echo "${_randomize_va_space:-2}" > /proc/sys/kernel/randomize_va_space
}
function run_test() {