Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc: Hoist helper code out of eeh-basic

Hoist some of the useful test environment checking and prep code into
eeh-functions.sh so they can be reused in other tests.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20201103044503.917128-1-oohall@gmail.com

authored by

Oliver O'Halloran and committed by
Michael Ellerman
db82f709 718aae91

+51 -36
+3 -36
tools/testing/selftests/powerpc/eeh/eeh-basic.sh
··· 1 1 #!/bin/sh 2 2 # SPDX-License-Identifier: GPL-2.0-only 3 3 4 - KSELFTESTS_SKIP=4 5 - 6 4 . ./eeh-functions.sh 7 5 8 - if ! eeh_supported ; then 9 - echo "EEH not supported on this system, skipping" 10 - exit $KSELFTESTS_SKIP; 11 - fi 12 - 13 - if [ ! -e "/sys/kernel/debug/powerpc/eeh_dev_check" ] && \ 14 - [ ! -e "/sys/kernel/debug/powerpc/eeh_dev_break" ] ; then 15 - echo "debugfs EEH testing files are missing. Is debugfs mounted?" 16 - exit $KSELFTESTS_SKIP; 17 - fi 6 + eeh_test_prep # NB: may exit 18 7 19 8 pre_lspci=`mktemp` 20 9 lspci > $pre_lspci 21 - 22 - # Bump the max freeze count to something absurd so we don't 23 - # trip over it while breaking things. 24 - echo 5000 > /sys/kernel/debug/powerpc/eeh_max_freezes 25 10 26 11 # record the devices that we break in here. Assuming everything 27 12 # goes to plan we should get them back once the recover process ··· 15 30 16 31 # Build up a list of candidate devices. 17 32 for dev in `ls -1 /sys/bus/pci/devices/ | grep '\.0$'` ; do 18 - # skip bridges since we can't recover them (yet...) 19 - if [ -e "/sys/bus/pci/devices/$dev/pci_bus" ] ; then 20 - echo "$dev, Skipped: bridge" 33 + if ! eeh_can_break $dev ; then 21 34 continue; 22 35 fi 23 36 24 - # Skip VFs for now since we don't have a reliable way 25 - # to break them. 37 + # Skip VFs for now since we don't have a reliable way to break them. 26 38 if [ -e "/sys/bus/pci/devices/$dev/physfn" ] ; then 27 39 echo "$dev, Skipped: virtfn" 28 - continue; 29 - fi 30 - 31 - if [ "ahci" = "$(basename $(realpath /sys/bus/pci/devices/$dev/driver))" ] ; then 32 - echo "$dev, Skipped: ahci doesn't support recovery" 33 - continue 34 - fi 35 - 36 - # Don't inject errosr into an already-frozen PE. This happens with 37 - # PEs that contain multiple PCI devices (e.g. multi-function cards) 38 - # and injecting new errors during the recovery process will probably 39 - # result in the recovery failing and the device being marked as 40 - # failed. 41 - if ! pe_ok $dev ; then 42 - echo "$dev, Skipped: Bad initial PE state" 43 40 continue; 44 41 fi 45 42
+48
tools/testing/selftests/powerpc/eeh/eeh-functions.sh
··· 1 1 #!/bin/sh 2 2 # SPDX-License-Identifier: GPL-2.0-only 3 3 4 + export KSELFTESTS_SKIP=4 5 + 4 6 pe_ok() { 5 7 local dev="$1" 6 8 local path="/sys/bus/pci/devices/$dev/eeh_pe_state" ··· 39 37 eeh_supported() { 40 38 test -e /proc/powerpc/eeh && \ 41 39 grep -q 'EEH Subsystem is enabled' /proc/powerpc/eeh 40 + } 41 + 42 + eeh_test_prep() { 43 + if ! eeh_supported ; then 44 + echo "EEH not supported on this system, skipping" 45 + exit $KSELFTESTS_SKIP; 46 + fi 47 + 48 + if [ ! -e "/sys/kernel/debug/powerpc/eeh_dev_check" ] && \ 49 + [ ! -e "/sys/kernel/debug/powerpc/eeh_dev_break" ] ; then 50 + echo "debugfs EEH testing files are missing. Is debugfs mounted?" 51 + exit $KSELFTESTS_SKIP; 52 + fi 53 + 54 + # Bump the max freeze count to something absurd so we don't 55 + # trip over it while breaking things. 56 + echo 5000 > /sys/kernel/debug/powerpc/eeh_max_freezes 57 + } 58 + 59 + eeh_can_break() { 60 + # skip bridges since we can't recover them (yet...) 61 + if [ -e "/sys/bus/pci/devices/$dev/pci_bus" ] ; then 62 + echo "$dev, Skipped: bridge" 63 + return 1; 64 + fi 65 + 66 + # The ahci driver doesn't support error recovery. If the ahci device 67 + # happens to be hosting the root filesystem, and then we go and break 68 + # it the system will generally go down. We should probably fix that 69 + # at some point 70 + if [ "ahci" = "$(basename $(realpath /sys/bus/pci/devices/$dev/driver))" ] ; then 71 + echo "$dev, Skipped: ahci doesn't support recovery" 72 + return 1; 73 + fi 74 + 75 + # Don't inject errosr into an already-frozen PE. This happens with 76 + # PEs that contain multiple PCI devices (e.g. multi-function cards) 77 + # and injecting new errors during the recovery process will probably 78 + # result in the recovery failing and the device being marked as 79 + # failed. 80 + if ! pe_ok $dev ; then 81 + echo "$dev, Skipped: Bad initial PE state" 82 + return 1; 83 + fi 84 + 85 + return 0 42 86 } 43 87 44 88 eeh_one_dev() {