Home | History | Annotate | Line # | Download | only in mixerctl
t_mixerctl.sh revision 1.11
      1  1.11       kre # $NetBSD: t_mixerctl.sh,v 1.11 2021/12/18 10:50:48 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.8       kre 	# convenient as it is a different execution environment, no 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.10       kre 	( true </dev/pad0 ) >/dev/null 2>&1 &&
     25   1.9       kre 	    { { cat >/dev/null & } < /dev/pad0 ; } 2>/dev/null && padpid=$!
     26   1.7       kre 
     27   1.7       kre 	(</dev/mixer) >/dev/null 2>&1 ||
     28   1.7       kre 	    atf_skip "no audio mixer available in kernel"
     29   1.7       kre }
     30   1.1  christos 
     31   1.1  christos atf_test_case noargs_usage
     32   1.1  christos noargs_usage_head() {
     33   1.1  christos 	atf_set "descr" "Ensure mixerctl(1) with no args prints a usage message"
     34   1.1  christos }
     35   1.1  christos noargs_usage_body() {
     36   1.7       kre 	audio_setup
     37   1.6       nat 
     38  1.11       kre 	atf_check -s exit:1 -o empty -e not-empty \
     39   1.1  christos 		mixerctl
     40   1.6       nat 
     41   1.7       kre 	${padpid+kill -HUP ${padpid}} 2>/dev/null || :
     42   1.1  christos }
     43   1.1  christos 
     44   1.1  christos atf_test_case showvalue
     45   1.1  christos showvalue_head() {
     46   1.1  christos 	atf_set "descr" "Ensure mixerctl(1) can print the value for all variables"
     47   1.1  christos }
     48   1.1  christos showvalue_body() {
     49   1.7       kre 	audio_setup
     50   1.4       kre 
     51   1.1  christos 	for var in $(mixerctl -a | awk -F= '{print $1}'); do
     52   1.1  christos 		atf_check -s exit:0 -e ignore -o match:"^${var}=" \
     53   1.1  christos 			mixerctl ${var}
     54   1.1  christos 	done
     55   1.5       kre 
     56   1.7       kre 	${padpid+kill -HUP ${padpid}} 2>/dev/null || :
     57   1.1  christos }
     58   1.1  christos 
     59   1.1  christos atf_test_case nflag
     60   1.1  christos nflag_head() {
     61   1.1  christos 	atf_set "descr" "Ensure 'mixerctl -n' actually suppresses some output"
     62   1.1  christos }
     63   1.1  christos nflag_body() {
     64   1.7       kre 	audio_setup
     65   1.4       kre 
     66   1.2       kre 	varname="$(mixerctl -a | sed -e 's/=.*//' -e q)"
     67   1.1  christos 
     68   1.1  christos 	atf_check -s exit:0 -o match:"${varname}" -e ignore \
     69   1.1  christos 		mixerctl ${varname}
     70   1.1  christos 
     71   1.1  christos 	atf_check -s exit:0 -o not-match:"${varname}" -e ignore \
     72   1.1  christos 		mixerctl -n ${varname}
     73   1.5       kre 
     74   1.7       kre 	${padpid+kill -HUP ${padpid}} 2>/dev/null || :
     75   1.1  christos }
     76   1.1  christos 
     77   1.1  christos atf_test_case nonexistant_device
     78   1.1  christos nonexistant_device_head() {
     79   1.1  christos 	atf_set "descr" "Ensure mixerctl(1) complains if provided a nonexistant mixer device"
     80   1.1  christos }
     81   1.1  christos nonexistant_device_body() {
     82   1.1  christos 	atf_check -s not-exit:0  -o ignore -e match:"No such file" \
     83   1.4       kre 		mixerctl -a -d /a/b/c/d/e
     84   1.1  christos }
     85   1.1  christos 
     86   1.1  christos atf_init_test_cases() {
     87   1.1  christos 	atf_add_test_case noargs_usage
     88   1.1  christos 	atf_add_test_case showvalue
     89   1.1  christos 	atf_add_test_case nflag
     90   1.1  christos 	atf_add_test_case nonexistant_device
     91   1.1  christos }
     92