From nobody Mon Jul 29 15:35:20 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 4WXj9P2gxGz5RSQH; Mon, 29 Jul 2024 15:35:21 +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 4WXj9P03dBz42R0; Mon, 29 Jul 2024 15:35:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722267321; 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=R5XW2Q72Ikmuov4B82jKyIycD/bXeCTLS6mwVNfCXss=; b=FKo6TcF1hAgUy9ze56/kEe3jet1iI2EAZx3b5+/P+1oZ7awiieRYtQ8aM6/UC9wHzKYjW/ iZn3TK1kzCFvznMXNQqYr+SovbmdjmrjXYbCP12pT/UgXn0qYi6huYXAEFUf9bEkmt1eCk bLh+q/OOi2/1QDpiv62cUcIr+hzRHwGgeWcyXlvZFfD8ozjGvzzUpbqNyX9HfreNbzuwrO +VhuVqYuy9QpJP+1w+IDyNNsaBfmW2bPxnwom5L9hSDuuIi1JgyQIP/r+ASKoYeazr+Sf6 2H1SpphdjDSjAj5BERiPm6kD6qcsaaN5YmvPgfPwssRGTRNDbvV69iiBJ0P9aA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722267321; a=rsa-sha256; cv=none; b=jSJd5OUoeWMo+KzD5mBsCLtKQnA3kV6PZ0VJM1NpZ6IA/0PeHaIU3RtkTFzRn9H5owSmZb RinJmYjz0pfDroEsZgnHqNAEs1CU813LEfJCgRyLF/UVNHRuqrg1ngwn2C6iPX5IgIX7Jl 6sOoz0KgMRpXL+5IRxR8JC3BpqiO8mlbkxojTnxFW7UO7SB9fmte+EzWzOz8R0BvUI3988 ro+3b+RP1Tvm+aOANgUcJcMTuuYNymGkEta3OjdW24VWXozOhr+I1uSFFQDuUh25RdcOGA dk7my/8nj/0P/LZM7Dte8J80XkBdcs+Wz6kHo7D7AjIzruoJObCi43vsRhbG/g== 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=1722267321; 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=R5XW2Q72Ikmuov4B82jKyIycD/bXeCTLS6mwVNfCXss=; b=kk7BmSORm6oQu1rH3qlWpRRE0UsIb7AHmH8hNnUONntTDDaGWUQUE6r0vnnJXylE3s89FM UbOCxMvV/mkL65r/j9IliN3jT/QJMzLUQTZHAlpQTbFHKPVrXsW+gyT1y3XG9yKPi3Eest VuMwplNQNvbPEBskFG89hqC1uOYUaz42BX+U+PWIpzCMZ6gsNTQDjiMUtJ+nZxVfA8hoj3 ZavFV7dBVumFa8EPbeYUG1sksKM23OwWMbPxK87fWZM3ey1jUAfIVke7T126iHRP6KEsK4 koJyWsHgw3mcx8+PdrPAk5eizzfoiQ5xlljsoiiWleupCy/DTSmg0FAlRzHftQ== 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 4WXj9N6mKSzgDH; Mon, 29 Jul 2024 15:35:20 +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 46TFZKWV002449; Mon, 29 Jul 2024 15:35:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46TFZKrB002445; Mon, 29 Jul 2024 15:35:20 GMT (envelope-from git) Date: Mon, 29 Jul 2024 15:35:20 GMT Message-Id: <202407291535.46TFZKrB002445@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Christos Margiolis Subject: git: f55b8bba6092 - stable/14 - 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/stable/14 X-Git-Reftype: branch X-Git-Commit: f55b8bba60922af0381894fdfc801bb0b04dc5c4 Auto-Submitted: auto-generated The branch stable/14 has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=f55b8bba60922af0381894fdfc801bb0b04dc5c4 commit f55b8bba60922af0381894fdfc801bb0b04dc5c4 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:14 +0000 Commit: Christos Margiolis CommitDate: 2024-07-29 15:34:54 +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 (cherry picked from commit 94a86f3f69205a6de3c07ae60daf4f5f920e9b82) --- 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 0dab386e0873..213166e952dc 100644 --- a/usr.sbin/mixer/Makefile +++ b/usr.sbin/mixer/Makefile @@ -6,4 +6,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 +}