t_mixerctl.sh revision 1.7 1 1.7 kre # $NetBSD: t_mixerctl.sh,v 1.7 2017/07/18 12:40:57 kre Exp $
2 1.7 kre
3 1.7 kre audio_setup() {
4 1.7 kre # Open /dev/pad0 so we have a configured audio device.
5 1.7 kre # Do it in a way that guarantees the open happens before
6 1.7 kre # we proceed to the (</dev/mixer) below (do not expect
7 1.7 kre # cat to be running in time to open the device.)
8 1.7 kre
9 1.7 kre # Note: it is not important that the open of pad0 succeeds,
10 1.7 kre # if there is real audio hardware on the system, that can (will)
11 1.7 kre # be used instead, and having pad0 open is irrelevant.
12 1.7 kre # So, no errors reported if pad0 open fails. If there turns
13 1.7 kre # out to be no audio device of any kind, then the open of the
14 1.7 kre # mixer will fail, causing the test to be skipped.
15 1.7 kre
16 1.7 kre # Saving padpid and later killing it seems to be unnecessary,
17 1.7 kre # ATF appears to killpg() the process after the test finishes
18 1.7 kre # which is a good thing, otherwise a test that is skipped/fails
19 1.7 kre # would not kill the cat (doing it in a cleanup function is not
20 1.7 kre # convenient as it is a different execution environment, so shared
21 1.7 kre # variables, we would need to put $padpid in a file.)
22 1.7 kre
23 1.7 kre unset padpid
24 1.7 kre { { cat >/dev/null & } < /dev/pad0 ; } 2>/dev/null && padpid=$!
25 1.7 kre
26 1.7 kre (</dev/mixer) >/dev/null 2>&1 ||
27 1.7 kre atf_skip "no audio mixer available in kernel"
28 1.7 kre }
29 1.1 christos
30 1.1 christos atf_test_case noargs_usage
31 1.1 christos noargs_usage_head() {
32 1.1 christos atf_set "descr" "Ensure mixerctl(1) with no args prints a usage message"
33 1.1 christos }
34 1.1 christos noargs_usage_body() {
35 1.7 kre audio_setup
36 1.6 nat
37 1.1 christos atf_check -s exit:0 -o not-empty -e ignore \
38 1.1 christos mixerctl
39 1.6 nat
40 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || :
41 1.1 christos }
42 1.1 christos
43 1.1 christos atf_test_case showvalue
44 1.1 christos showvalue_head() {
45 1.1 christos atf_set "descr" "Ensure mixerctl(1) can print the value for all variables"
46 1.1 christos }
47 1.1 christos showvalue_body() {
48 1.7 kre audio_setup
49 1.4 kre
50 1.1 christos for var in $(mixerctl -a | awk -F= '{print $1}'); do
51 1.1 christos atf_check -s exit:0 -e ignore -o match:"^${var}=" \
52 1.1 christos mixerctl ${var}
53 1.1 christos done
54 1.5 kre
55 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || :
56 1.1 christos }
57 1.1 christos
58 1.1 christos atf_test_case nflag
59 1.1 christos nflag_head() {
60 1.1 christos atf_set "descr" "Ensure 'mixerctl -n' actually suppresses some output"
61 1.1 christos }
62 1.1 christos nflag_body() {
63 1.7 kre audio_setup
64 1.4 kre
65 1.2 kre varname="$(mixerctl -a | sed -e 's/=.*//' -e q)"
66 1.1 christos
67 1.1 christos atf_check -s exit:0 -o match:"${varname}" -e ignore \
68 1.1 christos mixerctl ${varname}
69 1.1 christos
70 1.1 christos atf_check -s exit:0 -o not-match:"${varname}" -e ignore \
71 1.1 christos mixerctl -n ${varname}
72 1.5 kre
73 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || :
74 1.1 christos }
75 1.1 christos
76 1.1 christos atf_test_case nonexistant_device
77 1.1 christos nonexistant_device_head() {
78 1.1 christos atf_set "descr" "Ensure mixerctl(1) complains if provided a nonexistant mixer device"
79 1.1 christos }
80 1.1 christos nonexistant_device_body() {
81 1.1 christos atf_check -s not-exit:0 -o ignore -e match:"No such file" \
82 1.4 kre mixerctl -a -d /a/b/c/d/e
83 1.1 christos }
84 1.1 christos
85 1.1 christos atf_init_test_cases() {
86 1.1 christos atf_add_test_case noargs_usage
87 1.1 christos atf_add_test_case showvalue
88 1.1 christos atf_add_test_case nflag
89 1.1 christos atf_add_test_case nonexistant_device
90 1.1 christos }
91