summaryrefslogtreecommitdiff
path: root/tests/drv_module_reload_basic
blob: 98f36940b3be33c97e70a1842c15ced82470c016 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
#
# Testcase: Reload the drm module
#
# ... we've broken this way too often :(
#

SOURCE_DIR="$( dirname "${BASH_SOURCE[0]}" )"
. $SOURCE_DIR/drm_lib.sh

# no other drm service should be running, so we can just unbind

# return 0 if module by name $1 is loaded according to lsmod
function mod_loaded()
{
	lsmod | grep -w "^$1" &> /dev/null
}

function reload() {
	local snd_hda_intel_unloaded

	echo Reloading i915.ko with $*

	# we must kick away fbcon (but only fbcon)
	for vtcon in /sys/class/vtconsole/vtcon*/ ; do
		if grep "frame buffer device" $vtcon/name > /dev/null ; then
			echo unbinding $vtcon: `cat $vtcon/name`
			echo 0 > $vtcon/bind
		fi
	done

	# The sound driver uses our power well
	pkill alsactl
	snd_hda_intel_unloaded=0
	if mod_loaded snd_hda_intel; then
		# unbind sound cards
		for card in $(find /sys/bus/pci/drivers/snd_hda_intel -name "0000:*" -printf "%f\n"); do
			echo $card > /sys/bus/pci/drivers/snd_hda_intel/unbind
		done

		if rmmod snd_hda_intel; then
			snd_hda_intel_unloaded=1
		else
			lsmod >&2
			lsof /dev/snd/* >&2
		fi
	fi

	# gen5 only
	if mod_loaded intel_ips; then
		rmmod intel_ips
	fi

	if ! rmmod i915; then
		lsmod >&2
		return $IGT_EXIT_SKIP
	fi
	#ignore errors in intel-gtt, often built-in
	rmmod intel-gtt &> /dev/null
	# drm may be used by other devices (nouveau, radeon, udl, etc)
	rmmod drm_kms_helper &> /dev/null
	rmmod drm &> /dev/null

	if mod_loaded i915; then
		echo WARNING: i915.ko still loaded!
		return $IGT_EXIT_FAILURE
	else
		echo module successfully unloaded
	fi

	modprobe i915 $*

	if [ -f /sys/class/vtconsole/vtcon1/bind ]; then
		echo 1 > /sys/class/vtconsole/vtcon1/bind
	fi

	modprobe -q snd_hda_intel || return $snd_hda_intel_unloaded
}

function finish_load() {
	# does the device exist?
	if $SOURCE_DIR/gem_alive > /dev/null ; then
		echo "module successfully loaded again"
	else
		echo "failed to reload module successfully"
		return $IGT_EXIT_FAILURE
	fi

	# then try to run something
	if ! $SOURCE_DIR/gem_exec_store > /dev/null ; then
		echo "failed to execute a simple batch after reload"
		return $IGT_EXIT_FAILURE
	fi

	return $IGT_EXIT_SUCCESS
}

hda_dynamic_debug_enable

reload || exit $?
finish_load || exit $?

# Repeat the module reload trying to to generate faults
for i in $(seq 1 4); do
	reload inject_load_failure=$i
done

reload || exit $?
finish_load

exit $?