File: Memory_safety_-_Watchfd.test

package info (click to toggle)
pv 1.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,076 kB
  • sloc: ansic: 8,421; sh: 6,426; makefile: 131; sed: 16
file content (107 lines) | stat: -rwxr-xr-x 2,760 bytes parent folder | download
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
#!/bin/sh
#
# Run valgrind's memory checker against a process using the --watchfd
# option.

# Allow all tests to be skipped, e.g. during a release build
test "${SKIP_ALL_TESTS}" = "1" && exit 77

true "${sourcePath:?not set - call this from 'make check'}"
true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
true "${workFile2:?not set - call this from 'make check'}"
true "${workFile3:?not set - call this from 'make check'}"
true "${workFile4:?not set - call this from 'make check'}"

# Load the valgrind function.
. "${sourcePath}/tests/run-valgrind.sh"

# Skip the test if "-d" is not available.
if ! "${testSubject}" -h | grep -Fq ' -d'; then
	echo "no \`--watchfd' / \`-d' option on this platform"
	exit 77
fi

# Skip the test if "-d" does not work.
sleep 2 &
pid=$!
sleep 0.1
"${testSubject}" -d "${pid}" -f -i 0.5 >/dev/null 2>"${workFile1}"
if grep -Fq ' -d: not available' "${workFile1}"; then
	echo "no \`--watchfd' / \`-d' option on this platform"
	exit 77
fi

# Check "--watchfd PID:FD".
# See the "Watchfd" tests for more detail.
seq 1 100 > "${workFile1}"
true > "${workFile3}"
# shellcheck disable=SC2030
(while test -e "${workFile3}" && ! test -s "${workFile3}"; do sleep 0.1; done; sleep 1; read -r line; sleep 1; read -r line; sleep 1) <"${workFile1}" &
pid=$!
sleep 0.1
{ runWithValgrind -P "${workFile3}" -d "${pid}:0" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1

# Check "--watchfd PID".
seq 1 100 > "${workFile1}"
seq 1 300 > "${workFile2}"
true > "${workFile3}"
# shellcheck disable=SC2030
(
while test -e "${workFile3}" && ! test -s "${workFile3}"; do sleep 0.1; done
sleep 1
read -r line
exec 9<"${workFile2}"
sleep 1
exec 8<"${workFile1}"
exec 7</dev/null
sleep 1
exec 9<&-
# shellcheck disable=SC2034
read -r line
sleep 1
) <"${workFile1}" &
pid=$!
sleep 0.1
{ runWithValgrind -P "${workFile3}" -d "${pid}" -f -i 0.5 >/dev/null 2>&1; } 4>&1 || exit 1

# Check "--watchfd PID1 PID2".
seq 1 100 > "${workFile1}"
seq 1 300 > "${workFile2}"
true > "${workFile3}"
# shellcheck disable=SC2030
(
while test -e "${workFile3}" && ! test -s "${workFile3}"; do sleep 0.1; done
sleep 1
read -r line
exec 9<"${workFile2}"
sleep 1
exec 8<"${workFile1}"
exec 7</dev/null
sleep 1
exec 9<&-
# shellcheck disable=SC2034
read -r line
sleep 1
) <"${workFile1}" &
pid1=$!
# shellcheck disable=SC2030
(
while test -e "${workFile3}" && ! test -s "${workFile3}"; do sleep 0.1; done
sleep 1
read -r line
exec 9<"${workFile2}"
sleep 1
exec 8<"${workFile1}"
exec 7</dev/null
sleep 1
exec 9<&-
# shellcheck disable=SC2034
read -r line
sleep 1
) <"${workFile1}" &
pid2=$!
sleep 0.1
{ runWithValgrind -P "${workFile3}" -f -i 0.5 -d "${pid1}" "${pid2}" >/dev/null 2>&1; } 4>&1 || exit 1

exit 0