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