File: test.sh

package info (click to toggle)
damo 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,504 kB
  • sloc: python: 14,399; sh: 958; makefile: 30; ansic: 13
file content (218 lines) | stat: -rwxr-xr-x 4,306 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

bindir=$(dirname "$0")
cd "$bindir"

damo="../../damo"

cmd_log=$(mktemp damo_test_cmd_log_XXX)

cleanup_files()
{
	files_to_remove="./damon.data ./damon.data.perf.data ./damon.data.old"
	for file in $files_to_remove
	do
		if [ -f "$file" ]
		then
			if ! sudo rm "$file"
			then
				echo "removing $file failed"
				exit 1
			fi
		fi
	done
}

test_record_permission()
{
	sudo "$damo" record "sleep 5" --timeout 5 --output_permission 611 \
		&> "$cmd_log"
	if [ ! "$(stat -c %a damon.data)" = "611" ]
	then
		echo "FAIL record-permission"
		cat "$cmd_log"
		exit 1
	fi
	cleanup_files

	echo "PASS record-permission"
}

test_record_validate_noexit()
{
	if [ $# -ne 4 ]
	then
		echo "Usage: $0 <target> <timeout> <region> \\"
		echo "		<damon interface to use>"
		return 1
	fi

	target=$1
	timeout=$2
	regions_boundary=$3
	damon_interface=$4

	testname="record-validate \"$target\" $timeout $regions_boundary"
	testname+=" $damon_interface"

	if [ "$target" = "paddr" ] && ! sudo "$damo" features \
		--damon_interface_DEPRECATED "$damon_interface" supported \
		2> /dev/null | \
		grep -w paddr &> /dev/null
	then
		echo "SKIP record-validate $target $timeout (paddr unsupported)"
		return 2
	fi

	if [ "$regions_boundary" = "none" ]
	then
		sudo "$damo" record "$target" --timeout "$timeout" \
			--damon_interface_DEPRECATED "$damon_interface" \
			&> "$cmd_log"
	else
		sudo "$damo" record "$target" --timeout "$timeout" \
			--regions "$regions_boundary" \
			--damon_interface_DEPRECATED "$damon_interface" \
			&> "$cmd_log"
	fi

	rc=$?
	if [ $rc -ne 0 ]
	then
		echo "FAIL $testname"
		echo "(damo-record command failed with value $rc)"
		cat "$cmd_log"
		return 3
	fi

	if [ "$regions_boundary" = "none" ]
	then
		if ! sudo "$damo" validate &> "$cmd_log"
		then
			echo "FAIL $testname (record file is not valid)"
			cat "$cmd_log"
			return 4
		fi
	else
		if ! sudo "$damo" validate \
			--regions_boundary "$regions_boundary" &> "$cmd_log"
		then
			echo "FAIL $testname (record file is not valid)"
			cat "$cmd_log"
			return 5
		fi
	fi

	if [ -f ./damon.data.perf.data ]
	then
		echo "FAIL $testname (perf.data is not removed)"
		cat "$cmd_log"
		return 6
	fi

	permission=$(stat -c %a damon.data)
	if [ ! "$permission" = "600" ]
	then
		echo "FAIL $testname (out file permission $permission)"
		cat "$cmd_log"
		return 7
	fi

	cleanup_files

	echo "PASS $testname"
	return 0
}

test_record_validate()
{
	if [ $# -ne 4 ]
	then
		echo "Usage: $0 <target> <timeout> <region> \\"
		echo "		<damon interface to use>"
		exit 1
	fi

	local output=$(test_record_validate_noexit "$1" "$2" "$3" "$4")
	local rc=$?
	echo "$output"
	if [ "$rc" = "0" ]
	then
		return
	fi
	exit 1
}

test_sleep_record_validate()
{
	if [ $# -ne 4 ]
	then
		echo "Usage: $0 <min timeout> <max timeout> <region> \\"
		echo "		<damon interface to use>"
		exit 1
	fi

	local min_timeout=$1
	local max_timeout=$2
	local region_boundasry=$3
	local damon_interface=$4

	# for short runtime, damo gets no sufficient time to collect record.
	# Gradually increase the timeout and retry until success, or reaching
	# the maximum timeout.
	for ((runtime = min_timeout ; runtime < max_timeout ; \
		runtime += min_timeout))
	do
		output=$(test_record_validate_noexit "sleep $runtime" \
			"$runtime" "$region_boundasry" "$damon_interface")
		local rc=$?
		if echo "$output" | grep --quiet "target snapshots is zero"
		then
			echo "no snapshot failure with runtime $runtime; retry"
			continue
		fi
		echo "$output"
		if [ "$rc" -ne "0" ]
		then
			exit 1
		fi
		return
	done
}

damon_interfaces=""
if [ -d "/sys/kernel/debug/damon" ]
then
	damon_interfaces+="debugfs "
fi

if [ -d "/sys/kernel/mm/damon" ]
then
	damon_interfaces+="sysfs "
fi

if [ "$damon_interfaces" = "" ]
then
	echo "SKIP $(basename $(pwd)) (DAMON interface not found)"
	exit 0
fi

for damon_interface in $damon_interfaces
do
	test_sleep_record_validate 5 16 "none" "$damon_interface"
	test_record_validate "paddr" 3 "none" "$damon_interface"
done

if sudo "$damo" features \
	--damon_interface_DEPRECATED "$damon_interface" supported \
	2> /dev/null | \
	grep -w fvaddr &> /dev/null
then
	test_sleep_record_validate 5 16 "4096-81920" "sysfs"
fi

test_record_permission

rm -f "$cmd_log"
echo "PASS $(basename $(pwd))"