From nobody Sat Jul 27 11:56: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 4WWNPd1SKvz5S6n5; Sat, 27 Jul 2024 11:56: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 4WWNPd0BkLz42lK; Sat, 27 Jul 2024 11:56:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1722081381; 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=qXudAkY+CjgpN15gfNXuFd4mCffoD7zOqKqto8EV5q8=; b=w0sGEGV/fA1wtMB+sEVYn2qg7disZPA2Hwibxp7iaW12uycEpe4dEnsw6uW+VuZG1CjU6G CpVvMODATYY6k1faS22DRYBNP8E++yanKOvTKcOgAQA1O3sugiDA5SjVbtgpDAsXtjh8gt DKLWhkpCsUHb/AoMsZny+r1TdaWnsdJupHJ3C7clpFUjSVlThcP74d3Zfb4OwshNTL5xii NL/wZiGZuFdwIbYNlWcj3CaQs2951lVdrp1nERg9dPs36rIdD0GSFVyeh/AUiwXCBtvJc8 G73ZD/3O4HXfXSN7xehZ9AhjsseZyhixOaBbqRwCUICq+TADa6mO669cPWipIw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1722081381; a=rsa-sha256; cv=none; b=inHvTi5che4RLhK9DEXgdkYYXiOw3aFOQI2a6HHPixHO1N9MzjsF0L4Lr4JyW90umtMXd1 IZYVrkrQrsbzcKa4QsYjF1cY3/dduKVCntfHU71UHutrcYdt4M/hOjkz4dz2H7ejveTvPT rnMwfkHWFRM/VAMk+OxVJtC7EhCsEEBm3YUYrCP8CaRi4JyMw2fKwwJ8NwcyBqrFrtV2ts f3zym9iQCsUe+aQ3sUa+eTIhWHTO0jJeKSfw5kx8P0f4HuF3UJPv8su/O3uY65G6RXeAzD 6rLcPZLJCjQ3O8K7UV2A4xR2CWt6ArmtJbD6Ec9b3WStSPc/+a30s3OvdCS7iQ== 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=1722081381; 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=qXudAkY+CjgpN15gfNXuFd4mCffoD7zOqKqto8EV5q8=; b=AT91wedNt5LmSJvD2WWGjd53GpiKcbXBfFQr3CNQ8Me4EnZA8EBbbtACnSyrIKPGfv2IBJ B3ErZbk3M7GQjxEXE774NjmF9Qtz4geNnq04BlEkvGXO29wSaofuyLz7gNYiBBxOlhyhLk neSg0GJL8sdp5rxVB50eQndTGJjfMFov4V1qmvaWZhX0TOPdwJz4aEqN+ErmD0V5F1BuML sRZ58/VBBD31rrkoZ2ceKEzaszbdDG8Yh2AHTviGJtxSRDvdfpB/Paz/cjbok4vfMkoneJ ZC2R0cF04B4g6phx7brseBvQgybQvJNHlaj8CrfNuI+oN4fZ2oW3ihYjRkNqHw== 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 4WWNPc6x5gz15yM; Sat, 27 Jul 2024 11:56: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 46RBuKPY039749; Sat, 27 Jul 2024 11:56:20 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 46RBuKsh039746; Sat, 27 Jul 2024 11:56:20 GMT (envelope-from git) Date: Sat, 27 Jul 2024 11:56:20 GMT Message-Id: <202407271156.46RBuKsh039746@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: 95eb4b873b6a - main - sound tests: Add sndstat nvlist ATF test 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: 95eb4b873b6a8b527c5bd78d7191975dfca38998 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=95eb4b873b6a8b527c5bd78d7191975dfca38998 commit 95eb4b873b6a8b527c5bd78d7191975dfca38998 Author: Christos Margiolis AuthorDate: 2024-07-27 11:55:03 +0000 Commit: Christos Margiolis CommitDate: 2024-07-27 11:55:03 +0000 sound tests: Add sndstat nvlist ATF test Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch, markj Differential Revision: https://reviews.freebsd.org/D45901 --- tests/sys/Makefile | 1 + tests/sys/sound/Makefile | 9 ++ tests/sys/sound/sndstat.c | 214 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) diff --git a/tests/sys/Makefile b/tests/sys/Makefile index 7167f77ff471..e64268e5a397 100644 --- a/tests/sys/Makefile +++ b/tests/sys/Makefile @@ -30,6 +30,7 @@ TESTS_SUBDIRS+= netpfil TESTS_SUBDIRS+= opencrypto TESTS_SUBDIRS+= posixshm TESTS_SUBDIRS+= ses +TESTS_SUBDIRS+= sound TESTS_SUBDIRS+= sys TESTS_SUBDIRS+= vfs TESTS_SUBDIRS+= vm diff --git a/tests/sys/sound/Makefile b/tests/sys/sound/Makefile new file mode 100644 index 000000000000..fb731fb8ab61 --- /dev/null +++ b/tests/sys/sound/Makefile @@ -0,0 +1,9 @@ +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/sys/sound + +ATF_TESTS_C+= sndstat + +LDFLAGS+= -lnv + +.include diff --git a/tests/sys/sound/sndstat.c b/tests/sys/sound/sndstat.c new file mode 100644 index 000000000000..7c030dfa8b58 --- /dev/null +++ b/tests/sys/sound/sndstat.c @@ -0,0 +1,214 @@ +/*- + * 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. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static void +load_dummy(void) +{ + if (kldload("snd_dummy.ko") < 0 && errno != EEXIST) + atf_tc_skip("snd_dummy.ko not found"); +} + +ATF_TC(sndstat_nv); +ATF_TC_HEAD(sndstat_nv, tc) +{ + atf_tc_set_md_var(tc, "descr", "/dev/sndstat nvlist test"); +} + +ATF_TC_BODY(sndstat_nv, tc) +{ + nvlist_t *nvl; + const nvlist_t * const *di; + const nvlist_t * const *cdi; + struct sndstioc_nv_arg arg; + size_t nitems, nchans, i, j; + int fd, rc; + int pchan, rchan; + + load_dummy(); + + if ((fd = open("/dev/sndstat", O_RDONLY)) < 0) + atf_tc_skip("/dev/sndstat not found, load sound(4)"); + + rc = ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL); + ATF_REQUIRE_EQ(rc, 0); + + arg.nbytes = 0; + arg.buf = NULL; + rc = ioctl(fd, SNDSTIOC_GET_DEVS, &arg); + ATF_REQUIRE_EQ_MSG(rc, 0, "ioctl(SNDSTIOC_GET_DEVS#1) failed"); + + arg.buf = malloc(arg.nbytes); + ATF_REQUIRE(arg.buf != NULL); + + rc = ioctl(fd, SNDSTIOC_GET_DEVS, &arg); + ATF_REQUIRE_EQ_MSG(rc, 0, "ioctl(SNDSTIOC_GET_DEVS#2) failed"); + + nvl = nvlist_unpack(arg.buf, arg.nbytes, 0); + ATF_REQUIRE(nvl != NULL); + + if (nvlist_empty(nvl) || !nvlist_exists(nvl, SNDST_DSPS)) + atf_tc_skip("no soundcards attached"); + + di = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems); + for (i = 0; i < nitems; i++) { +#define NV(type, item) do { \ + ATF_REQUIRE_MSG(nvlist_exists(di[i], SNDST_DSPS_ ## item), \ + "SNDST_DSPS_" #item " does not exist"); \ + nvlist_get_ ## type (di[i], SNDST_DSPS_ ## item); \ +} while (0) + NV(string, NAMEUNIT); + NV(bool, FROM_USER); + NV(string, DEVNODE); + NV(string, DESC); + NV(string, PROVIDER); + NV(number, PCHAN); + NV(number, RCHAN); +#undef NV + + /* Cannot asign using the macro. */ + pchan = nvlist_get_number(di[i], SNDST_DSPS_PCHAN); + rchan = nvlist_get_number(di[i], SNDST_DSPS_RCHAN); + + if (pchan && !nvlist_exists(di[i], SNDST_DSPS_INFO_PLAY)) + atf_tc_fail("playback channel list empty"); + if (rchan && !nvlist_exists(di[i], SNDST_DSPS_INFO_REC)) + atf_tc_fail("recording channel list empty"); + +#define NV(type, mode, item) do { \ + ATF_REQUIRE_MSG(nvlist_exists(nvlist_get_nvlist(di[i], \ + SNDST_DSPS_INFO_ ## mode), SNDST_DSPS_INFO_ ## item), \ + "SNDST_DSPS_INFO_" #item " does not exist"); \ + nvlist_get_ ## type (nvlist_get_nvlist(di[i], \ + SNDST_DSPS_INFO_ ## mode), SNDST_DSPS_INFO_ ## item); \ +} while (0) + if (pchan) { + NV(number, PLAY, MIN_RATE); + NV(number, PLAY, MAX_RATE); + NV(number, PLAY, FORMATS); + NV(number, PLAY, MIN_CHN); + NV(number, PLAY, MAX_CHN); + } + if (rchan) { + NV(number, REC, MIN_RATE); + NV(number, REC, MAX_RATE); + NV(number, REC, FORMATS); + NV(number, REC, MIN_CHN); + NV(number, REC, MAX_CHN); + } +#undef NV + + /* XXX Do we need to skip the TC? userdevs won't have this list */ + if (!nvlist_exists(di[i], SNDST_DSPS_PROVIDER_INFO)) + continue; + +#define NV(type, item) do { \ + ATF_REQUIRE_MSG(nvlist_exists(nvlist_get_nvlist(di[i], \ + SNDST_DSPS_PROVIDER_INFO), SNDST_DSPS_SOUND4_ ## item), \ + "SNDST_DSPS_SOUND4_" #item " does not exist"); \ + nvlist_get_ ## type (nvlist_get_nvlist(di[i], \ + SNDST_DSPS_PROVIDER_INFO), SNDST_DSPS_SOUND4_ ## item); \ +} while (0) + NV(number, UNIT); + NV(string, STATUS); + NV(bool, BITPERFECT); + NV(number, PVCHAN); + NV(number, PVCHANRATE); + NV(number, PVCHANFORMAT); + NV(number, RVCHAN); + NV(number, PVCHANRATE); + NV(number, PVCHANFORMAT); +#undef NV + + if (!nvlist_exists(nvlist_get_nvlist(di[i], + SNDST_DSPS_PROVIDER_INFO), SNDST_DSPS_SOUND4_CHAN_INFO)) + atf_tc_fail("channel info list empty"); + + cdi = nvlist_get_nvlist_array( + nvlist_get_nvlist(di[i], SNDST_DSPS_PROVIDER_INFO), + SNDST_DSPS_SOUND4_CHAN_INFO, &nchans); + for (j = 0; j < nchans; j++) { +#define NV(type, item) do { \ + ATF_REQUIRE_MSG(nvlist_exists(cdi[j], SNDST_DSPS_SOUND4_CHAN_ ## item), \ + "SNDST_DSPS_SOUND4_CHAN_" #item " does not exist"); \ + nvlist_get_ ## type (cdi[j], SNDST_DSPS_SOUND4_CHAN_ ## item); \ +} while (0) + NV(string, NAME); + NV(string, PARENTCHAN); + NV(number, UNIT); + NV(number, CAPS); + NV(number, LATENCY); + NV(number, RATE); + NV(number, FORMAT); + NV(number, PID); + NV(string, COMM); + NV(number, INTR); + NV(number, XRUNS); + NV(number, FEEDCNT); + NV(number, LEFTVOL); + NV(number, RIGHTVOL); + NV(number, HWBUF_FORMAT); + NV(number, HWBUF_SIZE); + NV(number, HWBUF_BLKSZ); + NV(number, HWBUF_BLKCNT); + NV(number, HWBUF_FREE); + NV(number, HWBUF_READY); + NV(number, SWBUF_FORMAT); + NV(number, SWBUF_SIZE); + NV(number, SWBUF_BLKSZ); + NV(number, SWBUF_BLKCNT); + NV(number, SWBUF_FREE); + NV(number, SWBUF_READY); + NV(string, FEEDERCHAIN); +#undef NV + } + } + + free(arg.buf); + nvlist_destroy(nvl); + close(fd); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, sndstat_nv); + + return (atf_no_error()); +}