]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - tools/testing/selftests/sysctl/common_tests
scsi: qedf: Fix a potential NULL pointer dereference
[mirror_ubuntu-artful-kernel.git] / tools / testing / selftests / sysctl / common_tests
1 #!/bin/sh
2
3 TEST_FILE=$(mktemp)
4
5 echo "== Testing sysctl behavior against ${TARGET} =="
6
7 set_orig()
8 {
9 echo "${ORIG}" > "${TARGET}"
10 }
11
12 set_test()
13 {
14 echo "${TEST_STR}" > "${TARGET}"
15 }
16
17 verify()
18 {
19 local seen
20 seen=$(cat "$1")
21 if [ "${seen}" != "${TEST_STR}" ]; then
22 return 1
23 fi
24 return 0
25 }
26
27 exit_test()
28 {
29 if [ ! -z ${old_strict} ]; then
30 echo ${old_strict} > ${WRITES_STRICT}
31 fi
32 exit $rc
33 }
34
35 trap 'set_orig; rm -f "${TEST_FILE}"' EXIT
36
37 rc=0
38
39 echo -n "Writing test file ... "
40 echo "${TEST_STR}" > "${TEST_FILE}"
41 if ! verify "${TEST_FILE}"; then
42 echo "FAIL" >&2
43 exit 1
44 else
45 echo "ok"
46 fi
47
48 echo -n "Checking sysctl is not set to test value ... "
49 if verify "${TARGET}"; then
50 echo "FAIL" >&2
51 exit 1
52 else
53 echo "ok"
54 fi
55
56 echo -n "Writing sysctl from shell ... "
57 set_test
58 if ! verify "${TARGET}"; then
59 echo "FAIL" >&2
60 exit 1
61 else
62 echo "ok"
63 fi
64
65 echo -n "Resetting sysctl to original value ... "
66 set_orig
67 if verify "${TARGET}"; then
68 echo "FAIL" >&2
69 exit 1
70 else
71 echo "ok"
72 fi
73
74 echo -n "Checking write strict setting ... "
75 WRITES_STRICT="${SYSCTL}/kernel/sysctl_writes_strict"
76 if [ ! -e ${WRITES_STRICT} ]; then
77 echo "FAIL, but skip in case of old kernel" >&2
78 else
79 old_strict=$(cat ${WRITES_STRICT})
80 if [ "$old_strict" = "1" ]; then
81 echo "ok"
82 else
83 echo "FAIL, strict value is 0 but force to 1 to continue" >&2
84 echo "1" > ${WRITES_STRICT}
85 fi
86 fi
87
88 # Now that we've validated the sanity of "set_test" and "set_orig",
89 # we can use those functions to set starting states before running
90 # specific behavioral tests.
91
92 echo -n "Writing entire sysctl in single write ... "
93 set_orig
94 dd if="${TEST_FILE}" of="${TARGET}" bs=4096 2>/dev/null
95 if ! verify "${TARGET}"; then
96 echo "FAIL" >&2
97 rc=1
98 else
99 echo "ok"
100 fi
101
102 echo -n "Writing middle of sysctl after synchronized seek ... "
103 set_test
104 dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 skip=1 2>/dev/null
105 if ! verify "${TARGET}"; then
106 echo "FAIL" >&2
107 rc=1
108 else
109 echo "ok"
110 fi
111
112 echo -n "Writing beyond end of sysctl ... "
113 set_orig
114 dd if="${TEST_FILE}" of="${TARGET}" bs=20 seek=2 2>/dev/null
115 if verify "${TARGET}"; then
116 echo "FAIL" >&2
117 rc=1
118 else
119 echo "ok"
120 fi
121
122 echo -n "Writing sysctl with multiple long writes ... "
123 set_orig
124 (perl -e 'print "A" x 50;'; echo "${TEST_STR}") | \
125 dd of="${TARGET}" bs=50 2>/dev/null
126 if verify "${TARGET}"; then
127 echo "FAIL" >&2
128 rc=1
129 else
130 echo "ok"
131 fi