about summary refs log tree commit diff
path: root/debian/tests/killswitches-no-urfkill
blob: 4736ffba0c079db11d812aeae52fdf2842e272a8 (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
#!/bin/sh

if dpkg --print-architecture | grep s390; then
    echo "Skipping rfkill tests on s390 (LP: #1855009)"
    exit 77
fi

if dpkg --print-architecture | grep i386; then
    echo "Skipping rfkill tests on i386 (LP: #1855183)"
    exit 77
fi

set -e

make -f debian/tests/Makefile fake-rfkill
# poor man's dependency resolver
DEPS=$(modinfo debian/tests/fake-rfkill.ko | sed -n '/depends:/ {s/^.*://; s/[[:space:]]*$//; p}')
[ -z "$DEPS" ] || modprobe "$DEPS"
insmod debian/tests/fake-rfkill.ko

fake_id=$(rfkill list | grep fake | awk -F: '{ print $1; }')

service NetworkManager start
sleep 30

# test blocking the device
rfkill block $fake_id
if ! rfkill list $fake_id | grep 'Soft' | awk '{ print $3; }' | grep -qc yes; then
	echo "ERROR: could not block fake device"
	rmmod fake-rfkill || true
	exit 1
fi

# The systemd-rfkill service starts up whenever rfkill changes state, so on a
# 1-cpu system that might delay the event change from reaching nm before the
# check below, causing this test to fail.  The settle added here delays the
# nmcli check until after the rfkill uevent has definitely been processed.
udevadm settle

if ! LC_MESSAGES=C nmcli radio wifi | grep -qc disabled; then
	echo "ERROR: NM could not track device state."
	rmmod fake-rfkill || true
	exit 1
fi

# test unblocking the device
rfkill unblock $fake_id
if ! rfkill list $fake_id | grep 'Soft' | awk '{ print $3; }' | grep -qc no; then
	echo "ERROR: could not unblock fake device"
	rmmod fake-rfkill || true
	exit 1
fi

# same reason as above, however since systemd-rfkill stays running for 30 secs or so
# it's unlikely that it would start up again here, but it's still safer to call settle
udevadm settle

if ! LC_MESSAGES=C nmcli radio wifi | grep -qc enabled; then
	echo "ERROR: NM could not track device state to enabled."
	rmmod fake-rfkill || true
	exit 1
fi

rmmod fake-rfkill
make -f debian/tests/Makefile clean-rfkill

echo OK