From nobody Sat Aug 24 12:09:12 2024 X-Original-To: dev-commits-src-main@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 4WrbMX2c6nz5T0kP; Sat, 24 Aug 2024 12:09:12 +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 4WrbMX2419z543k; Sat, 24 Aug 2024 12:09:12 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724501352; 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=odysnduDq2Zk6hoSuOa/J47c0sTdmNLeQwwZrgKCJck=; b=yN2aXTvd3rEc7zxb6fCVRhxHKFMZfgHQUN03U9CaleUcUkVVMvgJJd727M72DWaBS2IqcX qr8D2qLnC25qWQT+j9+3ws1m//aQEJhZcNWxUpJblBkBzLUkBUgo8WhW0w0iJVxuJRgiwC NyAn+aeM2sEMTXpSSJomBDXk/TBbgGmyCuuzxAmztLfxkO7XGf7OAqVUqCamH8QBFr0RJC fdpaitez0TZGTmMrEdwyB4ATUaUPpXvp323c9X5wdRrzuiVdajZbuVxu2DN8w99W/OKqHs 8guG5kzLKT7k/UH7s17xZhcX7XjL9aQ23CNjfL5r5UQ12bqKyL2/ki9UFW8PEA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724501352; a=rsa-sha256; cv=none; b=JYB1WFliLCNumg2djpBT5N/a3A652Xitxwn1vFmx5Gj1JAu3OvSIai4MJMqIbwnOZ4pb19 ZWCg7gTcH5aIfd81mL1cq/9JiRdl6t3KVUP3AWbU1mouBGtsxpuj0+gQ9+KGgkihK8QlYn CU5B4OxvECzVADl5wzxkALcGjQDWCZ8rKIgAmwJAhI0CYSYPV+chIC6Lq55SRJq3AxZ+WA rcz9344OFIT9XrAR8QmlXDsoeZLWx83VT/8SVf1AqAVujYJ5bkQ9FUqNCjAbipYCz06S12 c4YyaUe8GnWQqUelitl10vZm4JMGtFzpAbcipHme+Y5iwkKNX61bxkoMDcs6eQ== 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=1724501352; 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=odysnduDq2Zk6hoSuOa/J47c0sTdmNLeQwwZrgKCJck=; b=u244J+PKwob7ywlmxR2fl47XR9NsHsWRe8THzb/fDQ52hYrjlDMrL4rV59uST954sZlFhL hEUEbcNvo96hUjMNcM/E0fxxw44piE7b5W9HS8GziOyOwG7Bv8qVq1ELGHqpra0kBAyWnS beigj0hS94lg9EgrNinVpJ1UQ2Uwi3gIkFoEvs4lISFkCUxuN+iYTGhJwt781obtT3Lve6 ynMqUM2q24IYE4MfI2y1ddnDjNv4lpMsM43muPQbZRICdj/Bk8UztYTuHqyZjg1VCys56P GGrRcLHwhND1e2aNiVTy8Y7puipk5DyJJDSXEXjYPMUPjbP77YQsFDEjvFvQzw== 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 4WrbMX1g6Zzv0V; Sat, 24 Aug 2024 12:09:12 +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 47OC9CRs048007; Sat, 24 Aug 2024 12:09:12 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47OC9Cku048004; Sat, 24 Aug 2024 12:09:12 GMT (envelope-from git) Date: Sat, 24 Aug 2024 12:09:12 GMT Message-Id: <202408241209.47OC9Cku048004@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: 2668e76d6e76 - main - sound tests: Add SNDSTIOC_ADD_USER_DEVS test List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 2668e76d6e764c5c361156ffa3d39eb02ce8e5d9 Auto-Submitted: auto-generated The branch main has been updated by christos: URL: https://cgit.FreeBSD.org/src/commit/?id=2668e76d6e764c5c361156ffa3d39eb02ce8e5d9 commit 2668e76d6e764c5c361156ffa3d39eb02ce8e5d9 Author: Christos Margiolis AuthorDate: 2024-08-24 12:07:29 +0000 Commit: Christos Margiolis CommitDate: 2024-08-24 12:07:29 +0000 sound tests: Add SNDSTIOC_ADD_USER_DEVS test Test whether the SNDSTIOC_ADD_USER_DEVS IOCTL (registers a userland device to /dev/sndstat) works properly. Sponsored by: The FreeBSD Foundation MFC after: 2 days Reviewed by: dev_submerge.ch Differential Revision: https://reviews.freebsd.org/D46228 --- tests/sys/sound/sndstat.c | 187 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 183 insertions(+), 4 deletions(-) diff --git a/tests/sys/sound/sndstat.c b/tests/sys/sound/sndstat.c index 7c030dfa8b58..553c745ec950 100644 --- a/tests/sys/sound/sndstat.c +++ b/tests/sys/sound/sndstat.c @@ -30,8 +30,9 @@ #include #include -#include #include +#include +#include #include #include @@ -59,8 +60,7 @@ ATF_TC_BODY(sndstat_nv, tc) const nvlist_t * const *cdi; struct sndstioc_nv_arg arg; size_t nitems, nchans, i, j; - int fd, rc; - int pchan, rchan; + int fd, rc, pchan, rchan; load_dummy(); @@ -135,7 +135,6 @@ ATF_TC_BODY(sndstat_nv, tc) } #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; @@ -206,9 +205,189 @@ ATF_TC_BODY(sndstat_nv, tc) close(fd); } +#define UDEV_PROVIDER "sndstat_udev" +#define UDEV_NAMEUNIT "sndstat_udev" +#define UDEV_DEVNODE "sndstat_udev" +#define UDEV_DESC "Test Device" +#define UDEV_PCHAN 1 +#define UDEV_RCHAN 1 +#define UDEV_MIN_RATE 8000 +#define UDEV_MAX_RATE 96000 +#define UDEV_FORMATS (AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE) +#define UDEV_MIN_CHN 1 +#define UDEV_MAX_CHN 2 + +ATF_TC(sndstat_udev); +ATF_TC_HEAD(sndstat_udev, tc) +{ + atf_tc_set_md_var(tc, "descr", "/dev/sndstat userdev interface test"); +} + +ATF_TC_BODY(sndstat_udev, tc) +{ + nvlist_t *nvl, *di, *dichild; + const nvlist_t * const *rdi; + struct sndstioc_nv_arg arg; + const char *str; + size_t nitems, i; + int fd, rc, pchan, rchan, n; + + load_dummy(); + + if ((fd = open("/dev/sndstat", O_RDWR)) < 0) + atf_tc_skip("/dev/sndstat not found, load sound(4)"); + + nvl = nvlist_create(0); + ATF_REQUIRE(nvl != NULL); + + di = nvlist_create(0); + ATF_REQUIRE(di != NULL); + + dichild = nvlist_create(0); + ATF_REQUIRE(dichild != NULL); + + nvlist_add_string(di, SNDST_DSPS_PROVIDER, UDEV_PROVIDER); + nvlist_add_string(di, SNDST_DSPS_NAMEUNIT, UDEV_NAMEUNIT); + nvlist_add_string(di, SNDST_DSPS_DESC, UDEV_DESC); + nvlist_add_string(di, SNDST_DSPS_DEVNODE, UDEV_DEVNODE); + nvlist_add_number(di, SNDST_DSPS_PCHAN, UDEV_PCHAN); + nvlist_add_number(di, SNDST_DSPS_RCHAN, UDEV_RCHAN); + + nvlist_add_number(dichild, SNDST_DSPS_INFO_MIN_RATE, UDEV_MIN_RATE); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MAX_RATE, UDEV_MAX_RATE); + nvlist_add_number(dichild, SNDST_DSPS_INFO_FORMATS, UDEV_FORMATS); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MIN_CHN, UDEV_MIN_CHN); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MAX_CHN, UDEV_MAX_CHN); + + nvlist_add_nvlist(di, SNDST_DSPS_INFO_PLAY, dichild); + nvlist_add_nvlist(di, SNDST_DSPS_INFO_REC, dichild); + + nvlist_append_nvlist_array(nvl, SNDST_DSPS, di); + ATF_REQUIRE_EQ(nvlist_error(nvl), 0); + + arg.buf = nvlist_pack(nvl, &arg.nbytes); + ATF_REQUIRE_MSG(arg.buf != NULL, "failed to pack nvlist"); + + rc = ioctl(fd, SNDSTIOC_ADD_USER_DEVS, &arg); + free(arg.buf); + ATF_REQUIRE_EQ_MSG(rc, 0, "ioctl(SNDSTIOC_ADD_USER_DEVS) failed"); + + nvlist_destroy(di); + nvlist_destroy(dichild); + nvlist_destroy(nvl); + + /* Read back registered values. */ + 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"); + + rdi = nvlist_get_nvlist_array(nvl, SNDST_DSPS, &nitems); + for (i = 0; i < nitems; i++) { +#define NV(type, item, var) do { \ + ATF_REQUIRE_MSG(nvlist_exists(rdi[i], SNDST_DSPS_ ## item), \ + "SNDST_DSPS_" #item " does not exist"); \ + var = nvlist_get_ ## type (rdi[i], SNDST_DSPS_ ## item); \ +} while (0) + /* Search for our device. */ + NV(string, NAMEUNIT, str); + if (strcmp(str, UDEV_NAMEUNIT) == 0) + break; + } + if (i == nitems) + atf_tc_fail("userland device %s not found", UDEV_NAMEUNIT); + + NV(string, NAMEUNIT, str); + ATF_CHECK(strcmp(str, UDEV_NAMEUNIT) == 0); + + NV(bool, FROM_USER, n); + ATF_CHECK(n); + + NV(string, DEVNODE, str); + ATF_CHECK(strcmp(str, UDEV_DEVNODE) == 0); + + NV(string, DESC, str); + ATF_CHECK(strcmp(str, UDEV_DESC) == 0); + + NV(string, PROVIDER, str); + ATF_CHECK(strcmp(str, UDEV_PROVIDER) == 0); + + NV(number, PCHAN, pchan); + ATF_CHECK(pchan == UDEV_PCHAN); + if (pchan && !nvlist_exists(rdi[i], SNDST_DSPS_INFO_PLAY)) + atf_tc_fail("playback channel list empty"); + + NV(number, RCHAN, rchan); + ATF_CHECK(rchan == UDEV_RCHAN); + if (rchan && !nvlist_exists(rdi[i], SNDST_DSPS_INFO_REC)) + atf_tc_fail("recording channel list empty"); +#undef NV + +#define NV(type, mode, item, var) do { \ + ATF_REQUIRE_MSG(nvlist_exists(nvlist_get_nvlist(rdi[i], \ + SNDST_DSPS_INFO_ ## mode), SNDST_DSPS_INFO_ ## item), \ + "SNDST_DSPS_INFO_" #item " does not exist"); \ + var = nvlist_get_ ## type (nvlist_get_nvlist(rdi[i], \ + SNDST_DSPS_INFO_ ## mode), SNDST_DSPS_INFO_ ## item); \ +} while (0) + if (pchan) { + NV(number, PLAY, MIN_RATE, n); + ATF_CHECK(n == UDEV_MIN_RATE); + + NV(number, PLAY, MAX_RATE, n); + ATF_CHECK(n == UDEV_MAX_RATE); + + NV(number, PLAY, FORMATS, n); + ATF_CHECK(n == UDEV_FORMATS); + + NV(number, PLAY, MIN_CHN, n); + ATF_CHECK(n == UDEV_MIN_CHN); + + NV(number, PLAY, MAX_CHN, n); + ATF_CHECK(n == UDEV_MAX_CHN); + } + if (rchan) { + NV(number, REC, MIN_RATE, n); + ATF_CHECK(n == UDEV_MIN_RATE); + + NV(number, REC, MAX_RATE, n); + ATF_CHECK(n == UDEV_MAX_RATE); + + NV(number, REC, FORMATS, n); + ATF_CHECK(n == UDEV_FORMATS); + + NV(number, REC, MIN_CHN, n); + ATF_CHECK(n == UDEV_MIN_CHN); + + NV(number, REC, MAX_CHN, n); + ATF_CHECK(n == UDEV_MAX_CHN); + } +#undef NV + + free(arg.buf); + nvlist_destroy(nvl); + close(fd); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, sndstat_nv); + ATF_TP_ADD_TC(tp, sndstat_udev); return (atf_no_error()); }