Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F142764801
D53188.id164687.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D53188.id164687.diff
View Options
diff --git a/tests/sys/sound/Makefile b/tests/sys/sound/Makefile
--- a/tests/sys/sound/Makefile
+++ b/tests/sys/sound/Makefile
@@ -3,6 +3,7 @@
TESTSDIR= ${TESTSBASE}/sys/sound
ATF_TESTS_C+= pcm_read_write
+ATF_TESTS_C+= polling
ATF_TESTS_C+= sndstat
CFLAGS+= -I${SRCTOP}/sys
diff --git a/tests/sys/sound/polling.c b/tests/sys/sound/polling.c
new file mode 100644
--- /dev/null
+++ b/tests/sys/sound/polling.c
@@ -0,0 +1,190 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2025 The FreeBSD Foundation
+ *
+ * This software was developed by Christos Margiolis <christos@FreeBSD.org>
+ * 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 <sys/event.h>
+#include <sys/soundcard.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#define FMT_ERR(s) s ": %s", strerror(errno)
+#define REPEAT 16
+
+static int
+oss_init(void)
+{
+ int fd, tmp, rc;
+
+ fd = open("/dev/dsp.dummy", O_RDWR);
+ ATF_REQUIRE_MSG(fd >= 0, FMT_ERR("open"));
+
+ tmp = 2;
+ rc = ioctl(fd, SNDCTL_DSP_CHANNELS, &tmp);
+ ATF_REQUIRE_EQ_MSG(rc, 0, FMT_ERR("ioctl"));
+
+ tmp = AFMT_S16_LE;
+ rc = ioctl(fd, SNDCTL_DSP_SETFMT, &tmp);
+ ATF_REQUIRE_EQ_MSG(rc, 0, FMT_ERR("ioctl"));
+
+ tmp = 48000;
+ rc = ioctl(fd, SNDCTL_DSP_SPEED, &tmp);
+ ATF_REQUIRE_EQ_MSG(rc, 0, FMT_ERR("ioctl"));
+
+ return (fd);
+}
+
+ATF_TC(poll_kqueue);
+ATF_TC_HEAD(poll_kqueue, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "kqueue(2) test");
+ atf_tc_set_md_var(tc, "require.kmods", "snd_dummy");
+}
+
+ATF_TC_BODY(poll_kqueue, tc)
+{
+ struct kevent ev;
+ int16_t buf[32];
+ int fd, kq, i;
+
+ fd = oss_init();
+
+ kq = kqueue();
+ ATF_REQUIRE_MSG(kq >= 0, FMT_ERR("kqueue"));
+ EV_SET(&ev, fd, EVFILT_READ, EV_ADD | EV_CLEAR, 0, 0, 0);
+ ATF_REQUIRE_MSG(kevent(kq, &ev, 1, NULL, 0, NULL) == 0,
+ FMT_ERR("kevent"));
+ for (i = 0; i < REPEAT; i++) {
+ ATF_REQUIRE_MSG(kevent(kq, NULL, 0, &ev, 1, NULL) == 1,
+ FMT_ERR("kevent"));
+ ATF_REQUIRE_MSG((ev.flags & EV_ERROR) == 0, "EV_ERROR is set");
+ ATF_REQUIRE_MSG(ev.data != 0, "data is %ld", ev.data);
+ ATF_REQUIRE_MSG(read(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("read"));
+ }
+ EV_SET(&ev, fd, EVFILT_READ, EV_DELETE, 0, 0, 0);
+
+ kq = kqueue();
+ ATF_REQUIRE_MSG(kq >= 0, FMT_ERR("kqueue"));
+ EV_SET(&ev, fd, EVFILT_WRITE, EV_ADD | EV_CLEAR, 0, 0, 0);
+ ATF_REQUIRE_MSG(kevent(kq, &ev, 1, NULL, 0, NULL) == 0,
+ FMT_ERR("kevent"));
+ for (i = 0; i < REPEAT; i++) {
+ ATF_REQUIRE_MSG(kevent(kq, NULL, 0, &ev, 1, NULL) == 1,
+ FMT_ERR("kevent"));
+ ATF_REQUIRE_MSG((ev.flags & EV_ERROR) == 0, "EV_ERROR is set");
+ ATF_REQUIRE_MSG(ev.data != 0, "data is %ld", ev.data);
+ ATF_REQUIRE_MSG(write(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("write"));
+ }
+ EV_SET(&ev, fd, EVFILT_WRITE, EV_DELETE, 0, 0, 0);
+
+ close(kq);
+ close(fd);
+}
+
+ATF_TC(poll_poll);
+ATF_TC_HEAD(poll_poll, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "poll(2) test");
+ atf_tc_set_md_var(tc, "require.kmods", "snd_dummy");
+}
+
+ATF_TC_BODY(poll_poll, tc)
+{
+ struct pollfd pfd[2];
+ int16_t buf[32];
+ int fd, i;
+
+ fd = oss_init();
+
+ for (i = 0; i < REPEAT; i++) {
+ pfd[0].fd = fd;
+ pfd[0].events = POLLIN;
+ pfd[1].fd = fd;
+ pfd[1].events = POLLOUT;
+ ATF_REQUIRE_MSG(poll(pfd, sizeof(pfd) / sizeof(struct pollfd),
+ -1) > 0, FMT_ERR("poll"));
+
+ if (pfd[0].revents) {
+ ATF_REQUIRE_MSG(read(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("read"));
+ }
+ if (pfd[1].revents) {
+ ATF_REQUIRE_MSG(write(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("write"));
+ }
+ }
+ close(fd);
+}
+
+ATF_TC(poll_select);
+ATF_TC_HEAD(poll_select, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "select(2) test");
+ atf_tc_set_md_var(tc, "require.kmods", "snd_dummy");
+}
+
+ATF_TC_BODY(poll_select, tc)
+{
+ fd_set fds[2];
+ int16_t buf[32];
+ int fd, i;
+
+ fd = oss_init();
+
+ for (i = 0; i < REPEAT; ++i) {
+ FD_ZERO(fds);
+ FD_SET(fd, fds);
+ ATF_REQUIRE_MSG(select(fd + 1, &fds[0], &fds[1], NULL, NULL) > 0,
+ FMT_ERR("select"));
+ if (FD_ISSET(fd, &fds[0])) {
+ ATF_REQUIRE_MSG(read(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("read"));
+ }
+ if (FD_ISSET(fd, &fds[1])) {
+ ATF_REQUIRE_MSG(write(fd, buf, sizeof(buf)) >= 0,
+ FMT_ERR("write"));
+ }
+ }
+ close(fd);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, poll_kqueue);
+ ATF_TP_ADD_TC(tp, poll_poll);
+ ATF_TP_ADD_TC(tp, poll_select);
+
+ return (atf_no_error());
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jan 24, 8:09 AM (20 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27895154
Default Alt Text
D53188.id164687.diff (5 KB)
Attached To
Mode
D53188: sound tests: Test polling
Attached
Detach File
Event Timeline
Log In to Comment