summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/damon/_debugfs_common.sh
blob: 54d45791b0d9cb8875956bb0aa89471244e40686 (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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

test_write_result() {
	file=$1
	content=$2
	orig_content=$3
	expect_reason=$4
	expected=$5

	if [ "$expected" = "0" ]
	then
		echo "$content" > "$file"
	else
		echo "$content" > "$file" 2> /dev/null
	fi
	if [ $? -ne "$expected" ]
	then
		echo "writing $content to $file doesn't return $expected"
		echo "expected because: $expect_reason"
		echo "$orig_content" > "$file"
		exit 1
	fi
}

test_write_succ() {
	test_write_result "$1" "$2" "$3" "$4" 0
}

test_write_fail() {
	test_write_result "$1" "$2" "$3" "$4" 1
}

test_content() {
	file=$1
	orig_content=$2
	expected=$3
	expect_reason=$4

	content=$(cat "$file")
	if [ "$content" != "$expected" ]
	then
		echo "reading $file expected $expected but $content"
		echo "expected because: $expect_reason"
		echo "$orig_content" > "$file"
		exit 1
	fi
}

source ./_chk_dependency.sh

damon_onoff="$DBGFS/monitor_on"
if [ -f "$DBGFS/monitor_on_DEPRECATED" ]
then
	damon_onoff="$DBGFS/monitor_on_DEPRECATED"
else
	damon_onoff="$DBGFS/monitor_on"
fi

if [ $(cat "$damon_onoff") = "on" ]
then
	echo "monitoring is on"
	exit $ksft_skip
fi