From nobody Sat Jul 27 11:56:23 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WWNPg3Zjlz5S6Kt; Sat, 27 Jul 2024 11:56:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4WWNPg2Fy1z431k; Sat, 27 Jul 2024 11:56:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722081383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WNMT+tiaemUF772ggnb3rAITGn88gYSuH4H4IjoIiLs=; b=O+ruTL1/ISV87CSr7ZKDS9mMlwcmpd2e5basqLgq9odKTDEGTfgzn2gK8Yi5FcgsWQ0cHE QUFk9isqNq7vyJPSScqr1ORyuXFzHwdPLRi2oU36GpZPY9XLsmrGIJKGV1os6W09qTYm6A 3JUPMsFb/LzGFGVSG+gycDC5vz2d/On2bi2uE6tzlyDJzfKyJWAJGLAqRs49PXRfWsaQU6 X0yjrNHucdlLmujBZ0dGquWcI+g2zeuPUYXjhfdDDWFaxzH8+7i1irP+UTStKD+Lvl9hpg cf0pMgeFpTVBJK/a3BIeUT9ybAE1NP24qTAQP+jTgRC3W/LuGllX3cyVaAFvrA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722081383; a=rsa-sha256; cv=none; b=FXMa2PXvfYHabW5Rq6DeJ/xl1wxnR4iRUcFgfoMNU3cyGwFwk29xicdK8KCxs9TQuADP2i 6dNZl6QfrL9dwylZsXsbatR9q+THUh5SH9bdf8Px5RF5Xo/LTx9LdUDtzbJ66T6jxhJIDp xxvYXc7zQLFf07IsqiG4eetKXSIbdhKOWS4QtqOBVLg6QWWwvMJqloWcyYhajwuIfpY5e2 dEAIifZ0U8Fpk2cWoMmtvZkiJFMkwrPsWg7btQizvm+LGSKe0r6T9DSGZ6jvFnbxF7J5It xqqqAQrZy1Y24cdcl9ZRaRoid1P0zGx31fRRzAUeTDti6VMcnlghyQLA6Hcgqg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722081383; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WNMT+tiaemUF772ggnb3rAITGn88gYSuH4H4IjoIiLs=; b=Xy+cogdAsFu/x8DthI7wa0goOOEG0wkzk2nNzBHa/HDmbWrISuj2CO3qlsJdD+R0Y1stcc 6CG1PZ3jZP7xKcGvZ/EbJ5MdTk2TT8c77TeKjjKkSJddGW/RxaMaE3bmVInK+nX4vn2UlI vwnvOwv961eLQjuNqjribqAPvBDj/sp6SDcR4hInqSAjt5cv4Djb2Ruz62klTgmHiybTKi IZ7dXuUyOV5HN/nAQeByRj3c2RoZH3/q5xK/f8CWk/+c3BNcxm6b9h1c66w6j8wmUUEmTM pWh5eKrUi7IpigcjsQ8OGtBK82za9984aXptYzUfo8Desrj10f4CBWxfrv9q0w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4WWNPg1qfFz15Zk; Sat, 27 Jul 2024 11:56:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 46RBuNfH039842; Sat, 27 Jul 2024 11:56:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46RBuNvd039839; Sat, 27 Jul 2024 11:56:23 GMT (envelope-from git) Date: Sat, 27 Jul 2024 11:56:23 GMT Message-Id: <202407271156.46RBuNvd039839@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Christos Margiolis Subject: git: 94a86f3f6920 - main - mixer(8): Add tests List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: christos X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 94a86f3f69205a6de3c07ae60daf4f5f920e9b82 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=94a86f3f69205a6de3c07ae60daf4f5f920e9b82 commit 94a86f3f69205a6de3c07ae60daf4f5f920e9b82 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:14 +0000 Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:14 +0000 mixer(8): Add tests Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D45974 --- usr.sbin/mixer/Makefile | 3 + usr.sbin/mixer/tests/Makefile | 3 + usr.sbin/mixer/tests/mixer_test.sh | 285 +++++++++++++++++++++++++++++++++++++ 3 files changed, 291 insertions(+) diff --git a/usr.sbin/mixer/Makefile b/usr.sbin/mixer/Makefile index 7789a28e99ad..9e96c2f2d2e8 100644 --- a/usr.sbin/mixer/Makefile +++ b/usr.sbin/mixer/Makefile @@ -5,4 +5,7 @@ SRCS= ${PROG}.c MAN= ${PROG}.8 LDFLAGS+= -lmixer +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests + .include diff --git a/usr.sbin/mixer/tests/Makefile b/usr.sbin/mixer/tests/Makefile new file mode 100644 index 000000000000..9a5bb3a183ab --- /dev/null +++ b/usr.sbin/mixer/tests/Makefile @@ -0,0 +1,3 @@ +ATF_TESTS_SH+= mixer_test + +.include diff --git a/usr.sbin/mixer/tests/mixer_test.sh b/usr.sbin/mixer/tests/mixer_test.sh new file mode 100755 index 000000000000..e1321ad9ee13 --- /dev/null +++ b/usr.sbin/mixer/tests/mixer_test.sh @@ -0,0 +1,285 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 The FreeBSD Foundation +# +# This software was developed by Christos Margiolis +# under sponsorship from the FreeBSD Foundation. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +mixer_exists() +{ + if ! mixer >/dev/null 2>&1; then + atf_skip "no mixer available" + fi +} + +save_conf() +{ + atf_check -o save:test_mixer_conf mixer -o +} + +restore_conf() +{ + mixer_exists + test -r "test_mixer_conf" && mixer $(cat test_mixer_conf) +} + +load_dummy() +{ + if ! kldload -n snd_dummy; then + atf_skip "cannot load snd_dummy.ko" + fi +} + +set_default() +{ + deflt_unit="$(mixer | grep ^pcm | cut -f1 -d:)" + dummy_unit="$(mixer -a | grep "Dummy Audio Device" | cut -f1 -d:)" + + atf_check -o save:test_mixer_deflt_unit echo ${deflt_unit} + atf_check -o save:test_mixer_dummy_unit echo ${dummy_unit} + + # Set the dummy as the default + mixer -d ${dummy_unit} +} + +restore_default() +{ + test -r "test_mixer_deflt_unit" && mixer -d $(cat test_mixer_deflt_unit) +} + +atf_test_case o_flag cleanup +o_flag_head() +{ + atf_set "descr" "Verify that the output of the -o flag can be used " \ + "as valid input" +} +o_flag_body() +{ + load_dummy + mixer_exists + set_default + + atf_check -o ignore -e empty mixer $(mixer -o) +} +o_flag_cleanup() +{ + restore_default +} + +atf_test_case d_flag cleanup +d_flag_head() +{ + atf_set "descr" "Test default unit setting" +} +d_flag_body() +{ + load_dummy + mixer_exists + set_default + + dev="${dummy_unit}" + unit=$(echo ${dev} | sed 's/pcm//') + + atf_check -o ignore -e empty mixer -d ${dev} + atf_check -o ignore -e empty mixer -d ${unit} +} +d_flag_cleanup() +{ + restore_default +} + +atf_test_case volume cleanup +volume_head() +{ + atf_set "descr" "Test volume setting" +} +volume_body() +{ + load_dummy + mixer_exists + set_default + save_conf + + # Test lower bound + mixer vol.volume=0 + atf_check -o match:"0.00:0.00" mixer vol.volume + + mixer vol.volume=-2 + atf_check -o match:"0.00:0.00" mixer vol.volume + + mixer vol.volume=-1:-2 + atf_check -o match:"0.00:0.00" mixer vol.volume + + mixer vol.volume=-110% + atf_check -o match:"0.00:0.00" mixer vol.volume + + # Test higher bound + mixer vol.volume=1 + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=+1.01 + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=2 + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=+1:+1 + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=2:2 + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=100% + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=110% + atf_check -o match:"1.00:1.00" mixer vol.volume + + mixer vol.volume=+110% + atf_check -o match:"1.00:1.00" mixer vol.volume + + # Test percentages + mixer vol.volume=1 + + mixer vol.volume=-10% + atf_check -o match:"0.90:0.90" mixer vol.volume + + mixer vol.volume=+5% + atf_check -o match:"0.95:0.95" mixer vol.volume + + mixer vol.volume=80% + atf_check -o match:"0.80:0.80" mixer vol.volume + + # Test left:right assignment + mixer vol.volume=0.80:0.70 + atf_check -o match:"0.80:0.70" mixer vol.volume + + mixer vol.volume=+5%:+10% + atf_check -o match:"0.85:0.80" mixer vol.volume + + mixer vol.volume=-5%:-10% + atf_check -o match:"0.80:0.70" mixer vol.volume + + mixer vol.volume=+10%:-15% + atf_check -o match:"0.90:0.55" mixer vol.volume + + # Test wrong values + atf_check -o ignore -e not-empty mixer vol.volume=foobar + atf_check -o ignore -e not-empty mixer vol.volume=2oo:b4r + atf_check -o ignore -e not-empty mixer vol.volume=+f0o:1 +} +volume_cleanup() +{ + restore_conf + restore_default +} + +atf_test_case mute cleanup +mute_head() +{ + atf_set "descr" "Test muting" +} +mute_body() +{ + load_dummy + mixer_exists + set_default + save_conf + + # Check that the mute control exists + atf_check -o not-empty mixer vol.mute + + atf_check -o ignore -e empty mixer vol.mute=off + atf_check -o match:"=off" mixer vol.mute + + atf_check -o ignore -e empty mixer vol.mute=on + atf_check -o match:"=on" mixer vol.mute + + atf_check -o ignore -e empty mixer vol.mute=toggle + atf_check -o match:"=off" mixer vol.mute + + # Test deprecated interface + atf_check -o ignore -e empty mixer vol.mute=0 + atf_check -o match:"=off" mixer vol.mute + + atf_check -o ignore -e empty mixer vol.mute=1 + atf_check -o match:"=on" mixer vol.mute + + atf_check -o ignore -e empty mixer vol.mute=^ + atf_check -o match:"=off" mixer vol.mute + + # Test wrong values + atf_check -o ignore -e not-empty mixer vol.mute=foobar + atf_check -o ignore -e not-empty mixer vol.mute=10 +} +mute_cleanup() +{ + restore_conf + restore_default +} + +atf_test_case recsrc cleanup +recsrc_head() +{ + atf_set "descr" "Test recording source handling" +} +recsrc_body() +{ + load_dummy + mixer_exists + set_default + save_conf + test -n "$(mixer -s)" || atf_skip "no recording source found" + + recsrc=$(mixer -s | awk '{print $2}') + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=add + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=remove + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=set + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=toggle + + # Test deprecated interface + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=+ + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=- + atf_check -o ignore -e empty mixer ${recsrc}.recsrc== + atf_check -o ignore -e empty mixer ${recsrc}.recsrc=^ + + # Test wrong values + atf_check -o ignore -e not-empty mixer ${recsrc}.recsrc=foobar + atf_check -o ignore -e not-empty mixer ${recsrc}.recsrc=10 +} +recsrc_cleanup() +{ + restore_conf + restore_default +} + +atf_init_test_cases() +{ + atf_add_test_case o_flag + atf_add_test_case d_flag + atf_add_test_case volume + atf_add_test_case mute + atf_add_test_case recsrc +}