linux/tools/testing/selftests/damon/_chk_dependency.sh
Gautam 43fe0cc46b kselftests/damon: add support for cases where debugfs cannot be read
The kernel is in lockdown mode when secureboot is enabled and hence
debugfs cannot be used. Add support for this and other general cases
where debugfs cannot be read and communicate the same to the user before
running tests.

Signed-off-by: Gautam <gautammenghani201@gmail.com>
Reviewed-by: SeongJae Park <sj@kernel.org>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
2022-06-27 14:14:41 -06:00

39 lines
672 B
Bash

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
# Kselftest framework requirement - SKIP code is 4.
ksft_skip=4
DBGFS=/sys/kernel/debug/damon
if [ $EUID -ne 0 ];
then
echo "Run as root"
exit $ksft_skip
fi
if [ ! -d "$DBGFS" ]
then
echo "$DBGFS not found"
exit $ksft_skip
fi
for f in attrs target_ids monitor_on
do
if [ ! -f "$DBGFS/$f" ]
then
echo "$f not found"
exit 1
fi
done
permission_error="Operation not permitted"
for f in attrs target_ids monitor_on
do
status=$( cat "$DBGFS/$f" 2>&1 )
if [ "${status#*$permission_error}" != "$status" ]; then
echo "Permission for reading $DBGFS/$f denied; maybe secureboot enabled?"
exit $ksft_skip
fi
done