194a86f3fSChristos Margiolis# 294a86f3fSChristos Margiolis# SPDX-License-Identifier: BSD-2-Clause 394a86f3fSChristos Margiolis# 494a86f3fSChristos Margiolis# Copyright (c) 2024 The FreeBSD Foundation 594a86f3fSChristos Margiolis# 694a86f3fSChristos Margiolis# This software was developed by Christos Margiolis <christos@FreeBSD.org> 794a86f3fSChristos Margiolis# under sponsorship from the FreeBSD Foundation. 894a86f3fSChristos Margiolis# 994a86f3fSChristos Margiolis# Redistribution and use in source and binary forms, with or without 1094a86f3fSChristos Margiolis# modification, are permitted provided that the following conditions 1194a86f3fSChristos Margiolis# are met: 1294a86f3fSChristos Margiolis# 1. Redistributions of source code must retain the above copyright 1394a86f3fSChristos Margiolis# notice, this list of conditions and the following disclaimer. 1494a86f3fSChristos Margiolis# 2. Redistributions in binary form must reproduce the above copyright 1594a86f3fSChristos Margiolis# notice, this list of conditions and the following disclaimer in the 1694a86f3fSChristos Margiolis# documentation and/or other materials provided with the distribution. 1794a86f3fSChristos Margiolis# 1894a86f3fSChristos Margiolis# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1994a86f3fSChristos Margiolis# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2094a86f3fSChristos Margiolis# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2194a86f3fSChristos Margiolis# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2294a86f3fSChristos Margiolis# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2394a86f3fSChristos Margiolis# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2494a86f3fSChristos Margiolis# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2594a86f3fSChristos Margiolis# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2694a86f3fSChristos Margiolis# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2794a86f3fSChristos Margiolis# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2894a86f3fSChristos Margiolis# SUCH DAMAGE. 2994a86f3fSChristos Margiolis 3094a86f3fSChristos Margiolismixer_exists() 3194a86f3fSChristos Margiolis{ 3294a86f3fSChristos Margiolis if ! mixer >/dev/null 2>&1; then 3394a86f3fSChristos Margiolis atf_skip "no mixer available" 3494a86f3fSChristos Margiolis fi 3594a86f3fSChristos Margiolis} 3694a86f3fSChristos Margiolis 3794a86f3fSChristos Margiolissave_conf() 3894a86f3fSChristos Margiolis{ 3994a86f3fSChristos Margiolis atf_check -o save:test_mixer_conf mixer -o 4094a86f3fSChristos Margiolis} 4194a86f3fSChristos Margiolis 4294a86f3fSChristos Margiolisrestore_conf() 4394a86f3fSChristos Margiolis{ 4494a86f3fSChristos Margiolis mixer_exists 4594a86f3fSChristos Margiolis test -r "test_mixer_conf" && mixer $(cat test_mixer_conf) 4694a86f3fSChristos Margiolis} 4794a86f3fSChristos Margiolis 4894a86f3fSChristos Margiolisload_dummy() 4994a86f3fSChristos Margiolis{ 5094a86f3fSChristos Margiolis if ! kldload -n snd_dummy; then 5194a86f3fSChristos Margiolis atf_skip "cannot load snd_dummy.ko" 5294a86f3fSChristos Margiolis fi 5394a86f3fSChristos Margiolis} 5494a86f3fSChristos Margiolis 5594a86f3fSChristos Margiolisset_default() 5694a86f3fSChristos Margiolis{ 5794a86f3fSChristos Margiolis deflt_unit="$(mixer | grep ^pcm | cut -f1 -d:)" 5894a86f3fSChristos Margiolis dummy_unit="$(mixer -a | grep "Dummy Audio Device" | cut -f1 -d:)" 5994a86f3fSChristos Margiolis 6094a86f3fSChristos Margiolis atf_check -o save:test_mixer_deflt_unit echo ${deflt_unit} 6194a86f3fSChristos Margiolis atf_check -o save:test_mixer_dummy_unit echo ${dummy_unit} 6294a86f3fSChristos Margiolis 6394a86f3fSChristos Margiolis # Set the dummy as the default 6494a86f3fSChristos Margiolis mixer -d ${dummy_unit} 6594a86f3fSChristos Margiolis} 6694a86f3fSChristos Margiolis 6794a86f3fSChristos Margiolisrestore_default() 6894a86f3fSChristos Margiolis{ 69*080c8512SOlivier Cochard-Labbé test -r "test_mixer_deflt_unit" && 70*080c8512SOlivier Cochard-Labbé mixer -d $(cat test_mixer_deflt_unit) || true 7194a86f3fSChristos Margiolis} 7294a86f3fSChristos Margiolis 7394a86f3fSChristos Margiolisatf_test_case o_flag cleanup 7494a86f3fSChristos Margioliso_flag_head() 7594a86f3fSChristos Margiolis{ 7694a86f3fSChristos Margiolis atf_set "descr" "Verify that the output of the -o flag can be used " \ 7794a86f3fSChristos Margiolis "as valid input" 7894a86f3fSChristos Margiolis} 7994a86f3fSChristos Margioliso_flag_body() 8094a86f3fSChristos Margiolis{ 8194a86f3fSChristos Margiolis load_dummy 8294a86f3fSChristos Margiolis mixer_exists 8394a86f3fSChristos Margiolis set_default 8494a86f3fSChristos Margiolis 8594a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer $(mixer -o) 8694a86f3fSChristos Margiolis} 8794a86f3fSChristos Margioliso_flag_cleanup() 8894a86f3fSChristos Margiolis{ 8994a86f3fSChristos Margiolis restore_default 9094a86f3fSChristos Margiolis} 9194a86f3fSChristos Margiolis 9294a86f3fSChristos Margiolisatf_test_case d_flag cleanup 9394a86f3fSChristos Margiolisd_flag_head() 9494a86f3fSChristos Margiolis{ 9594a86f3fSChristos Margiolis atf_set "descr" "Test default unit setting" 9694a86f3fSChristos Margiolis} 9794a86f3fSChristos Margiolisd_flag_body() 9894a86f3fSChristos Margiolis{ 9994a86f3fSChristos Margiolis load_dummy 10094a86f3fSChristos Margiolis mixer_exists 10194a86f3fSChristos Margiolis set_default 10294a86f3fSChristos Margiolis 10394a86f3fSChristos Margiolis dev="${dummy_unit}" 10494a86f3fSChristos Margiolis unit=$(echo ${dev} | sed 's/pcm//') 10594a86f3fSChristos Margiolis 10694a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer -d ${dev} 10794a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer -d ${unit} 10894a86f3fSChristos Margiolis} 10994a86f3fSChristos Margiolisd_flag_cleanup() 11094a86f3fSChristos Margiolis{ 11194a86f3fSChristos Margiolis restore_default 11294a86f3fSChristos Margiolis} 11394a86f3fSChristos Margiolis 11494a86f3fSChristos Margiolisatf_test_case volume cleanup 11594a86f3fSChristos Margiolisvolume_head() 11694a86f3fSChristos Margiolis{ 11794a86f3fSChristos Margiolis atf_set "descr" "Test volume setting" 11894a86f3fSChristos Margiolis} 11994a86f3fSChristos Margiolisvolume_body() 12094a86f3fSChristos Margiolis{ 12194a86f3fSChristos Margiolis load_dummy 12294a86f3fSChristos Margiolis mixer_exists 12394a86f3fSChristos Margiolis set_default 12494a86f3fSChristos Margiolis save_conf 12594a86f3fSChristos Margiolis 12694a86f3fSChristos Margiolis # Test lower bound 12794a86f3fSChristos Margiolis mixer vol.volume=0 12894a86f3fSChristos Margiolis atf_check -o match:"0.00:0.00" mixer vol.volume 12994a86f3fSChristos Margiolis 13094a86f3fSChristos Margiolis mixer vol.volume=-2 13194a86f3fSChristos Margiolis atf_check -o match:"0.00:0.00" mixer vol.volume 13294a86f3fSChristos Margiolis 13394a86f3fSChristos Margiolis mixer vol.volume=-1:-2 13494a86f3fSChristos Margiolis atf_check -o match:"0.00:0.00" mixer vol.volume 13594a86f3fSChristos Margiolis 13694a86f3fSChristos Margiolis mixer vol.volume=-110% 13794a86f3fSChristos Margiolis atf_check -o match:"0.00:0.00" mixer vol.volume 13894a86f3fSChristos Margiolis 13994a86f3fSChristos Margiolis # Test higher bound 14094a86f3fSChristos Margiolis mixer vol.volume=1 14194a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 14294a86f3fSChristos Margiolis 14394a86f3fSChristos Margiolis mixer vol.volume=+1.01 14494a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 14594a86f3fSChristos Margiolis 14694a86f3fSChristos Margiolis mixer vol.volume=2 14794a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 14894a86f3fSChristos Margiolis 14994a86f3fSChristos Margiolis mixer vol.volume=+1:+1 15094a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 15194a86f3fSChristos Margiolis 15294a86f3fSChristos Margiolis mixer vol.volume=2:2 15394a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 15494a86f3fSChristos Margiolis 15594a86f3fSChristos Margiolis mixer vol.volume=100% 15694a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 15794a86f3fSChristos Margiolis 15894a86f3fSChristos Margiolis mixer vol.volume=110% 15994a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 16094a86f3fSChristos Margiolis 16194a86f3fSChristos Margiolis mixer vol.volume=+110% 16294a86f3fSChristos Margiolis atf_check -o match:"1.00:1.00" mixer vol.volume 16394a86f3fSChristos Margiolis 16494a86f3fSChristos Margiolis # Test percentages 16594a86f3fSChristos Margiolis mixer vol.volume=1 16694a86f3fSChristos Margiolis 16794a86f3fSChristos Margiolis mixer vol.volume=-10% 16894a86f3fSChristos Margiolis atf_check -o match:"0.90:0.90" mixer vol.volume 16994a86f3fSChristos Margiolis 17094a86f3fSChristos Margiolis mixer vol.volume=+5% 17194a86f3fSChristos Margiolis atf_check -o match:"0.95:0.95" mixer vol.volume 17294a86f3fSChristos Margiolis 17394a86f3fSChristos Margiolis mixer vol.volume=80% 17494a86f3fSChristos Margiolis atf_check -o match:"0.80:0.80" mixer vol.volume 17594a86f3fSChristos Margiolis 17694a86f3fSChristos Margiolis # Test left:right assignment 17794a86f3fSChristos Margiolis mixer vol.volume=0.80:0.70 17894a86f3fSChristos Margiolis atf_check -o match:"0.80:0.70" mixer vol.volume 17994a86f3fSChristos Margiolis 18094a86f3fSChristos Margiolis mixer vol.volume=+5%:+10% 18194a86f3fSChristos Margiolis atf_check -o match:"0.85:0.80" mixer vol.volume 18294a86f3fSChristos Margiolis 18394a86f3fSChristos Margiolis mixer vol.volume=-5%:-10% 18494a86f3fSChristos Margiolis atf_check -o match:"0.80:0.70" mixer vol.volume 18594a86f3fSChristos Margiolis 18694a86f3fSChristos Margiolis mixer vol.volume=+10%:-15% 18794a86f3fSChristos Margiolis atf_check -o match:"0.90:0.55" mixer vol.volume 18894a86f3fSChristos Margiolis 18994a86f3fSChristos Margiolis # Test wrong values 19094a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer vol.volume=foobar 19194a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer vol.volume=2oo:b4r 19294a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer vol.volume=+f0o:1 19394a86f3fSChristos Margiolis} 19494a86f3fSChristos Margiolisvolume_cleanup() 19594a86f3fSChristos Margiolis{ 19694a86f3fSChristos Margiolis restore_conf 19794a86f3fSChristos Margiolis restore_default 19894a86f3fSChristos Margiolis} 19994a86f3fSChristos Margiolis 20094a86f3fSChristos Margiolisatf_test_case mute cleanup 20194a86f3fSChristos Margiolismute_head() 20294a86f3fSChristos Margiolis{ 20394a86f3fSChristos Margiolis atf_set "descr" "Test muting" 20494a86f3fSChristos Margiolis} 20594a86f3fSChristos Margiolismute_body() 20694a86f3fSChristos Margiolis{ 20794a86f3fSChristos Margiolis load_dummy 20894a86f3fSChristos Margiolis mixer_exists 20994a86f3fSChristos Margiolis set_default 21094a86f3fSChristos Margiolis save_conf 21194a86f3fSChristos Margiolis 21294a86f3fSChristos Margiolis # Check that the mute control exists 21394a86f3fSChristos Margiolis atf_check -o not-empty mixer vol.mute 21494a86f3fSChristos Margiolis 21594a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=off 21694a86f3fSChristos Margiolis atf_check -o match:"=off" mixer vol.mute 21794a86f3fSChristos Margiolis 21894a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=on 21994a86f3fSChristos Margiolis atf_check -o match:"=on" mixer vol.mute 22094a86f3fSChristos Margiolis 22194a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=toggle 22294a86f3fSChristos Margiolis atf_check -o match:"=off" mixer vol.mute 22394a86f3fSChristos Margiolis 22494a86f3fSChristos Margiolis # Test deprecated interface 22594a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=0 22694a86f3fSChristos Margiolis atf_check -o match:"=off" mixer vol.mute 22794a86f3fSChristos Margiolis 22894a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=1 22994a86f3fSChristos Margiolis atf_check -o match:"=on" mixer vol.mute 23094a86f3fSChristos Margiolis 23194a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer vol.mute=^ 23294a86f3fSChristos Margiolis atf_check -o match:"=off" mixer vol.mute 23394a86f3fSChristos Margiolis 23494a86f3fSChristos Margiolis # Test wrong values 23594a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer vol.mute=foobar 23694a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer vol.mute=10 23794a86f3fSChristos Margiolis} 23894a86f3fSChristos Margiolismute_cleanup() 23994a86f3fSChristos Margiolis{ 24094a86f3fSChristos Margiolis restore_conf 24194a86f3fSChristos Margiolis restore_default 24294a86f3fSChristos Margiolis} 24394a86f3fSChristos Margiolis 24494a86f3fSChristos Margiolisatf_test_case recsrc cleanup 24594a86f3fSChristos Margiolisrecsrc_head() 24694a86f3fSChristos Margiolis{ 24794a86f3fSChristos Margiolis atf_set "descr" "Test recording source handling" 24894a86f3fSChristos Margiolis} 24994a86f3fSChristos Margiolisrecsrc_body() 25094a86f3fSChristos Margiolis{ 25194a86f3fSChristos Margiolis load_dummy 25294a86f3fSChristos Margiolis mixer_exists 25394a86f3fSChristos Margiolis set_default 25494a86f3fSChristos Margiolis save_conf 25594a86f3fSChristos Margiolis test -n "$(mixer -s)" || atf_skip "no recording source found" 25694a86f3fSChristos Margiolis 25794a86f3fSChristos Margiolis recsrc=$(mixer -s | awk '{print $2}') 25894a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=add 25994a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=remove 26094a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=set 26194a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=toggle 26294a86f3fSChristos Margiolis 26394a86f3fSChristos Margiolis # Test deprecated interface 26494a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=+ 26594a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=- 26694a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc== 26794a86f3fSChristos Margiolis atf_check -o ignore -e empty mixer ${recsrc}.recsrc=^ 26894a86f3fSChristos Margiolis 26994a86f3fSChristos Margiolis # Test wrong values 27094a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer ${recsrc}.recsrc=foobar 27194a86f3fSChristos Margiolis atf_check -o ignore -e not-empty mixer ${recsrc}.recsrc=10 27294a86f3fSChristos Margiolis} 27394a86f3fSChristos Margiolisrecsrc_cleanup() 27494a86f3fSChristos Margiolis{ 27594a86f3fSChristos Margiolis restore_conf 27694a86f3fSChristos Margiolis restore_default 27794a86f3fSChristos Margiolis} 27894a86f3fSChristos Margiolis 27994a86f3fSChristos Margiolisatf_init_test_cases() 28094a86f3fSChristos Margiolis{ 28194a86f3fSChristos Margiolis atf_add_test_case o_flag 28294a86f3fSChristos Margiolis atf_add_test_case d_flag 28394a86f3fSChristos Margiolis atf_add_test_case volume 28494a86f3fSChristos Margiolis atf_add_test_case mute 28594a86f3fSChristos Margiolis atf_add_test_case recsrc 28694a86f3fSChristos Margiolis} 287