xref: /linux/tools/testing/selftests/damon/_debugfs_common.sh (revision 7f71507851fc7764b36a3221839607d3a45c2025)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4test_write_result() {
5	file=$1
6	content=$2
7	orig_content=$3
8	expect_reason=$4
9	expected=$5
10
11	if [ "$expected" = "0" ]
12	then
13		echo "$content" > "$file"
14	else
15		echo "$content" > "$file" 2> /dev/null
16	fi
17	if [ $? -ne "$expected" ]
18	then
19		echo "writing $content to $file doesn't return $expected"
20		echo "expected because: $expect_reason"
21		echo "$orig_content" > "$file"
22		exit 1
23	fi
24}
25
26test_write_succ() {
27	test_write_result "$1" "$2" "$3" "$4" 0
28}
29
30test_write_fail() {
31	test_write_result "$1" "$2" "$3" "$4" 1
32}
33
34test_content() {
35	file=$1
36	orig_content=$2
37	expected=$3
38	expect_reason=$4
39
40	content=$(cat "$file")
41	if [ "$content" != "$expected" ]
42	then
43		echo "reading $file expected $expected but $content"
44		echo "expected because: $expect_reason"
45		echo "$orig_content" > "$file"
46		exit 1
47	fi
48}
49
50source ./_chk_dependency.sh
51
52damon_onoff="$DBGFS/monitor_on"
53if [ -f "$DBGFS/monitor_on_DEPRECATED" ]
54then
55	damon_onoff="$DBGFS/monitor_on_DEPRECATED"
56else
57	damon_onoff="$DBGFS/monitor_on"
58fi
59
60if [ $(cat "$damon_onoff") = "on" ]
61then
62	echo "monitoring is on"
63	exit $ksft_skip
64fi
65