blob: b6862322962ff3b1463ab0f23726cfd74ba45bf1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
#!/bin/sh
TEST_FILE=$(mktemp)
echo "== Testing sysctl behavior against ${TARGET} =="
set_orig()
{
echo "${ORIG}" > "${TARGET}"
}
set_test()
{
echo "${TEST_STR}" > "${TARGET}"
}
verify()
{
local seen
seen=$(cat "$1")
if [ "${seen}" != "${TEST_STR}" ]; then
return 1
fi
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
echo -n "Writing test file ... "
echo "${TEST_STR}" > "${TEST_FILE}"
if ! verify "${TEST_FILE}"; then
echo "FAIL" >&2
exit 1
else
echo "ok"
fi
echo -n "Checking sysctl is not set to test value ... "
if verify "${TARGET}"; then
echo "FAIL" >&2
exit 1
else
echo "ok"
fi
echo -n "Writing sysctl from shell ... "
set_test
if ! verify "${TARGET}"; then
echo "FAIL" >&2
exit 1
else
echo "ok"
fi
echo -n "Resetting sysctl to original value ... "
set_orig
if verify "${TARGET}"; then
echo "FAIL" >&2
exit 1
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.
echo -n "Writing entire sysctl in single write ... "
set_orig
dd if="${TEST_FILE}" of="${TARGET}" bs=4096 2>/dev/null
if ! verify "${TARGET}"; then
echo "FAIL" >&2
rc=1
else
echo "ok"
fi
echo -n "Writing middle of sysctl after synchronized seek ... "
set_test
dd if="${TEST_FILE}" of="${TARGET}" bs=1 seek=1 skip=1 2>/dev/null
if ! verify "${TARGET}"; then
echo "FAIL" >&2
rc=1
else
echo "ok"
fi
echo -n "Writing beyond end of sysctl ... "
set_orig
dd if="${TEST_FILE}" of="${TARGET}" bs=20 seek=2 2>/dev/null
if verify "${TARGET}"; then
echo "FAIL" >&2
rc=1
else
echo "ok"
fi
echo -n "Writing sysctl with multiple long writes ... "
set_orig
(perl -e 'print "A" x 50;'; echo "${TEST_STR}") | \
dd of="${TARGET}" bs=50 2>/dev/null
if verify "${TARGET}"; then
echo "FAIL" >&2
rc=1
else
echo "ok"
fi
|