1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0-or-later 3# Copyright (C) 2017 Red Hat, Inc. 4# 5# Test functionality of dynamic debug feature by enabling 6# and disabling traces with available flags. Check that these 7# settings don't cause issues by searching dmesg. 8# 9# This test handles changes of dynamic debug interface from 10# commits 5ca7d2a6 (dynamic_debug: describe_flags with 11# '=[pmflt_]*') and 8ba6ebf5 (Dynamic debug: Add more flags) 12 13TST_TESTFUNC=ddebug_test 14TST_NEEDS_CMDS="awk /bin/echo" 15TST_NEEDS_TMPDIR=1 16TST_NEEDS_ROOT=1 17TST_SETUP=setup 18TST_CLEANUP=cleanup 19 20DEBUGFS_WAS_MOUNTED=0 21DEBUGFS_PATH="" 22DEBUGFS_CONTROL="" 23DYNDEBUG_STATEMENTS="./debug_statements" 24EMPTY_FLAG="=_" 25 26mount_debugfs() 27{ 28 if grep -q debugfs /proc/mounts ; then 29 DEBUGFS_WAS_MOUNTED=1 30 DEBUGFS_PATH=$(awk '/debugfs/{print $2}' /proc/mounts) 31 tst_res TINFO "debugfs already mounted at $DEBUGFS_PATH" 32 else 33 if ! grep -q debugfs /proc/filesystems ; then 34 tst_res TCONF "debugfs not supported" 35 fi 36 DEBUGFS_PATH="$PWD/tst_debug" 37 mkdir "$DEBUGFS_PATH" 38 if mount -t debugfs xxx "$DEBUGFS_PATH" ; then 39 tst_res TINFO "debugfs mounted at $DEBUGFS_PATH" 40 else 41 tst_res TFAIL "Unable to mount debugfs" 42 fi 43 fi 44} 45 46setup() 47{ 48 mount_debugfs 49 if [ ! -d "$DEBUGFS_PATH/dynamic_debug" ] ; then 50 tst_brk TBROK "Unable to find $DEBUGFS_PATH/dynamic_debug" 51 fi 52 DEBUGFS_CONTROL="$DEBUGFS_PATH/dynamic_debug/control" 53 if [ ! -e "$DEBUGFS_CONTROL" ] ; then 54 tst_brk TBROK "Unable to find $DEBUGFS_CONTROL" 55 fi 56 57 grep -v "^#" "$DEBUGFS_CONTROL" > "$DYNDEBUG_STATEMENTS" 58} 59 60do_flag() 61{ 62 local FLAG="$1" 63 local OPTION_TO_SET="$2" 64 local OPTION_VALUE="$3" 65 66 if ! echo "$OPTION_TO_SET $OPTION_VALUE $FLAG" > \ 67 "$DEBUGFS_CONTROL" ; then 68 tst_res TFAIL "Setting '$OPTION_TO_SET $OPTION_VALUE " \ 69 "$FLAG' failed with $?!" 70 fi 71} 72 73do_all_flags() 74{ 75 OPTION="$1" 76 ALL_INPUTS="$2" 77 78 for INPUT_LINE in $ALL_INPUTS; do 79 do_flag "+p" "$OPTION" "$INPUT_LINE" 80 do_flag "+flmt" "$OPTION" "$INPUT_LINE" 81 do_flag "-flmt" "$OPTION" "$INPUT_LINE" 82 do_flag "-p" "$OPTION" "$INPUT_LINE" 83 done 84 85 if awk -v emp="$EMPTY_FLAG" '$3 != emp' "$DEBUGFS_CONTROL" \ 86 | grep -v -q "^#" ; then 87 tst_res TFAIL "Failed to remove all set flags" 88 fi 89} 90 91ddebug_test() 92{ 93 dmesg > ./dmesg.old 94 95 DD_FUNCS=$(awk -F " |]" '{print $3}' "$DYNDEBUG_STATEMENTS" \ 96 | sort | uniq) 97 DD_FILES=$(awk -F " |:" '{print $1}' "$DYNDEBUG_STATEMENTS" \ 98 | sort | uniq) 99 DD_LINES=$(awk -F " |:" '{print $2}' "$DYNDEBUG_STATEMENTS" \ 100 | sort | uniq) 101 DD_MODULES=$(awk -F [][] '{print $2}' "$DYNDEBUG_STATEMENTS" \ 102 | sort | uniq) 103 104 do_all_flags "func" "$DD_FUNCS" 105 do_all_flags "file" "$DD_FILES" 106 do_all_flags "line" "$DD_LINES" 107 do_all_flags "module" "$DD_MODULES" 108 109 dmesg > ./dmesg.new 110 sed -i -e 1,`wc -l < ./dmesg.old`d ./dmesg.new 111 if grep -q -e "Kernel panic" -e "Oops" -e "general protection fault" \ 112 -e "general protection handler: wrong gs" -e "\(XEN\) Panic" \ 113 -e "fault" -e "warn" -e "\<BUG\>" ./dmesg.new ; then 114 tst_res TFAIL "Issues found in dmesg!" 115 else 116 tst_res TPASS "Dynamic debug OK" 117 fi 118} 119 120cleanup() 121{ 122 if [ -e "$DYNDEBUG_STATEMENTS" ]; then 123 FLAGS_SET=$(awk -v emp="$EMPTY_FLAG" '$3 != emp' $DYNDEBUG_STATEMENTS) 124 fi 125 if [ "$FLAGS_SET" ] ; then 126 /bin/echo "$FLAGS_SET" | while read -r FLAG_LINE ; do 127 /bin/echo -n "$FLAG_LINE" \ 128 | awk -v prf= -F " |:" \ 129 '{print "file "$1" line "$2" "prf $4}' \ 130 > "$DEBUGFS_CONTROL" 131 done 132 fi 133 if [ $DEBUGFS_WAS_MOUNTED -eq 0 -a -n "$DEBUGFS_PATH" ] ; then 134 tst_umount "$DEBUGFS_PATH" 135 fi 136} 137 138. tst_test.sh 139tst_run 140