1 1.12 charlott # $NetBSD: t_mixerctl.sh,v 1.12 2022/08/10 00:14:22 charlotte Exp $ 2 1.12 charlott # 3 1.12 charlott # Copyright (c) 2017 The NetBSD Foundation, Inc. 4 1.12 charlott # All rights reserved. 5 1.12 charlott # 6 1.12 charlott # This code is derived from software contributed to The NetBSD Foundation 7 1.12 charlott # by Charlotte Koch. 8 1.12 charlott # 9 1.12 charlott # Redistribution and use in source and binary forms, with or without 10 1.12 charlott # modification, are permitted provided that the following conditions 11 1.12 charlott # are met: 12 1.12 charlott # 1. Redistributions of source code must retain the above copyright 13 1.12 charlott # notice, this list of conditions and the following disclaimer. 14 1.12 charlott # 2. Redistributions in binary form must reproduce the above copyright 15 1.12 charlott # notice, this list of conditions and the following disclaimer in the 16 1.12 charlott # documentation and/or other materials provided with the distribution. 17 1.12 charlott # 18 1.12 charlott # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 1.12 charlott # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 1.12 charlott # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 1.12 charlott # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 1.12 charlott # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 1.12 charlott # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 1.12 charlott # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 1.12 charlott # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 1.12 charlott # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 1.12 charlott # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 1.12 charlott # POSSIBILITY OF SUCH DAMAGE. 29 1.12 charlott # 30 1.7 kre 31 1.7 kre audio_setup() { 32 1.7 kre # Open /dev/pad0 so we have a configured audio device. 33 1.7 kre # Do it in a way that guarantees the open happens before 34 1.7 kre # we proceed to the (</dev/mixer) below (do not expect 35 1.7 kre # cat to be running in time to open the device.) 36 1.7 kre 37 1.7 kre # Note: it is not important that the open of pad0 succeeds, 38 1.7 kre # if there is real audio hardware on the system, that can (will) 39 1.7 kre # be used instead, and having pad0 open is irrelevant. 40 1.7 kre # So, no errors reported if pad0 open fails. If there turns 41 1.7 kre # out to be no audio device of any kind, then the open of the 42 1.7 kre # mixer will fail, causing the test to be skipped. 43 1.7 kre 44 1.7 kre # Saving padpid and later killing it seems to be unnecessary, 45 1.7 kre # ATF appears to killpg() the process after the test finishes 46 1.7 kre # which is a good thing, otherwise a test that is skipped/fails 47 1.7 kre # would not kill the cat (doing it in a cleanup function is not 48 1.8 kre # convenient as it is a different execution environment, no shared 49 1.7 kre # variables, we would need to put $padpid in a file.) 50 1.7 kre 51 1.7 kre unset padpid 52 1.10 kre ( true </dev/pad0 ) >/dev/null 2>&1 && 53 1.9 kre { { cat >/dev/null & } < /dev/pad0 ; } 2>/dev/null && padpid=$! 54 1.7 kre 55 1.7 kre (</dev/mixer) >/dev/null 2>&1 || 56 1.7 kre atf_skip "no audio mixer available in kernel" 57 1.7 kre } 58 1.1 christos 59 1.1 christos atf_test_case noargs_usage 60 1.1 christos noargs_usage_head() { 61 1.1 christos atf_set "descr" "Ensure mixerctl(1) with no args prints a usage message" 62 1.1 christos } 63 1.1 christos noargs_usage_body() { 64 1.7 kre audio_setup 65 1.6 nat 66 1.11 kre atf_check -s exit:1 -o empty -e not-empty \ 67 1.1 christos mixerctl 68 1.6 nat 69 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || : 70 1.1 christos } 71 1.1 christos 72 1.1 christos atf_test_case showvalue 73 1.1 christos showvalue_head() { 74 1.1 christos atf_set "descr" "Ensure mixerctl(1) can print the value for all variables" 75 1.1 christos } 76 1.1 christos showvalue_body() { 77 1.7 kre audio_setup 78 1.4 kre 79 1.1 christos for var in $(mixerctl -a | awk -F= '{print $1}'); do 80 1.1 christos atf_check -s exit:0 -e ignore -o match:"^${var}=" \ 81 1.1 christos mixerctl ${var} 82 1.1 christos done 83 1.5 kre 84 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || : 85 1.1 christos } 86 1.1 christos 87 1.1 christos atf_test_case nflag 88 1.1 christos nflag_head() { 89 1.1 christos atf_set "descr" "Ensure 'mixerctl -n' actually suppresses some output" 90 1.1 christos } 91 1.1 christos nflag_body() { 92 1.7 kre audio_setup 93 1.4 kre 94 1.2 kre varname="$(mixerctl -a | sed -e 's/=.*//' -e q)" 95 1.1 christos 96 1.1 christos atf_check -s exit:0 -o match:"${varname}" -e ignore \ 97 1.1 christos mixerctl ${varname} 98 1.1 christos 99 1.1 christos atf_check -s exit:0 -o not-match:"${varname}" -e ignore \ 100 1.1 christos mixerctl -n ${varname} 101 1.5 kre 102 1.7 kre ${padpid+kill -HUP ${padpid}} 2>/dev/null || : 103 1.1 christos } 104 1.1 christos 105 1.1 christos atf_test_case nonexistant_device 106 1.1 christos nonexistant_device_head() { 107 1.1 christos atf_set "descr" "Ensure mixerctl(1) complains if provided a nonexistant mixer device" 108 1.1 christos } 109 1.1 christos nonexistant_device_body() { 110 1.1 christos atf_check -s not-exit:0 -o ignore -e match:"No such file" \ 111 1.4 kre mixerctl -a -d /a/b/c/d/e 112 1.1 christos } 113 1.1 christos 114 1.1 christos atf_init_test_cases() { 115 1.1 christos atf_add_test_case noargs_usage 116 1.1 christos atf_add_test_case showvalue 117 1.1 christos atf_add_test_case nflag 118 1.1 christos atf_add_test_case nonexistant_device 119 1.1 christos } 120