tools/testing/selftests/sysctl: Add pre-check to the value of writes_strict
authorOrson Zhai <orson.zhai@linaro.org>
Tue, 27 Jun 2017 00:52:09 +0000 (08:52 +0800)
committerShuah Khan <shuahkh@osg.samsung.com>
Wed, 28 Jun 2017 00:57:02 +0000 (18:57 -0600)
Sysctl test will fail in some items if the value of /proc/sys/kernel
/sysctrl_writes_strict is 0 as the default value in kernel older than v4.5.

Make this test more robus and compatible with older kernel by checking and
update writes_strict value and restore it when test is done.

Signed-off-by: Orson Zhai <orson.zhai@linaro.org>
Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org>
Tested-by: Sumit Semwal <sumit.semwal@linaro.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
tools/testing/selftests/sysctl/common_tests
tools/testing/selftests/sysctl/run_numerictests
tools/testing/selftests/sysctl/run_stringtests

index 17d534b1b7b4abfc0b4c3564875d9c0e114831ed..b6862322962ff3b1463ab0f23726cfd74ba45bf1 100644 (file)
@@ -24,6 +24,14 @@ verify()
        return 0
 }
 
+exit_test()
+{
+       if [ ! -z ${old_strict} ]; then
+               echo ${old_strict} > ${WRITES_STRICT}
+       fi
+       exit $rc
+}
+
 trap 'set_orig; rm -f "${TEST_FILE}"' EXIT
 
 rc=0
@@ -63,6 +71,20 @@ else
        echo "ok"
 fi
 
+echo -n "Checking write strict setting ... "
+WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict"
+if [ ! -e ${WRITES_STRICT} ]; then
+       echo "FAIL, but skip in case of old kernel" >&2
+else
+       old_strict=$(cat ${WRITES_STRICT})
+       if [ "$old_strict" = "1" ]; then
+               echo "ok"
+       else
+               echo "FAIL, strict value is 0 but force to 1 to continue" >&2
+               echo "1" > ${WRITES_STRICT}
+       fi
+fi
+
 # Now that we've validated the sanity of "set_test" and "set_orig",
 # we can use those functions to set starting states before running
 # specific behavioral tests.
index 8510f93f2d149ebb7ec199eab7be8d09bddc3bbf..e6e76c93d94873ec39c49519da05cb11bec5189d 100755 (executable)
@@ -7,4 +7,4 @@ TEST_STR=$(( $ORIG + 1 ))
 
 . ./common_tests
 
-exit $rc
+exit_test
index 90a9293d520cbb624c80a3e3b36e7dc3c1cfac38..857ec667fb02c9138d6ac3f157529a8f2b0d4662 100755 (executable)
@@ -74,4 +74,4 @@ else
        echo "ok"
 fi
 
-exit $rc
+exit_test