summaryrefslogtreecommitdiff
path: root/regress/sys
diff options
context:
space:
mode:
authorJacob Meuser <jakemsr@cvs.openbsd.org>2007-07-06 00:42:13 +0000
committerJacob Meuser <jakemsr@cvs.openbsd.org>2007-07-06 00:42:13 +0000
commitd5aca3c4fbca59367ae7e4186ab0ecd9a4fcd046 (patch)
tree2e3d9ea465503ff298fcde8c957220918054284c /regress/sys
parent104848780a926a6e597e8a9dd90e81ea4d6752fc (diff)
regression test for AUDIO_GETINFO/AUDIO_SETINFO ioctls
Diffstat (limited to 'regress/sys')
-rw-r--r--regress/sys/dev/audio_info/Makefile11
-rw-r--r--regress/sys/dev/audio_info/audiotest_gsinfo.1121
-rw-r--r--regress/sys/dev/audio_info/audiotest_gsinfo.c212
3 files changed, 344 insertions, 0 deletions
diff --git a/regress/sys/dev/audio_info/Makefile b/regress/sys/dev/audio_info/Makefile
new file mode 100644
index 00000000000..ae5fab7ffb1
--- /dev/null
+++ b/regress/sys/dev/audio_info/Makefile
@@ -0,0 +1,11 @@
+# $OpenBSD: Makefile,v 1.1.1.1 2007/07/06 00:42:12 jakemsr Exp $
+
+PROG= audiotest_gsinfo
+CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes
+MAN1= audiotest_gsinfo.1
+
+.ifndef DO_AUTEST
+REGRESS_SKIP=
+.endif
+
+.include <bsd.regress.mk>
diff --git a/regress/sys/dev/audio_info/audiotest_gsinfo.1 b/regress/sys/dev/audio_info/audiotest_gsinfo.1
new file mode 100644
index 00000000000..1c0dc86e937
--- /dev/null
+++ b/regress/sys/dev/audio_info/audiotest_gsinfo.1
@@ -0,0 +1,121 @@
+.\"
+.\" Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.\" $Id: audiotest_gsinfo.1,v 1.1 2007/07/06 00:42:12 jakemsr Exp $
+.\"
+.Dd $Mdocdate: July 5 2007
+.Dt AUDIOTEST_GSINFO 1
+.Os
+.Sh NAME
+.Nm audiotest_gsinfo
+.Nd test
+.Ar AUDIO_GETINFO
+and
+.Ar AUDIO_SETINFO
+.Sh SYNOPSIS
+.Nm audiotest_gsinfo
+.Bk -words
+.Op Fl f Ar device
+.Ek
+.Sh DESCRIPTION
+The
+.Nm
+command performs an
+.Ar AUDIO_GETINFO
+.Xr ioctl 2
+to get the current
+.Xr audio 4
+settings, then uses these settings in an
+.Ar AUDIO_SETINFO
+.Xr ioctl 2 .
+The options are as follows:
+.Bl -tag -width "-f device"
+.It Fl f Ar device
+.Xr audio 4
+device to use.
+Defaults to
+.Dq /dev/audio .
+.El
+.Pp
+.Nm
+first checks that an
+.Dv AUDIO_GETINFO
+ioctl will succeed.
+If it is not successful, it will exit with status 1.
+.Pp
+If it is successful,
+.Nm
+will perform an
+.Dv AUDIO_SETINFO
+ioctl, using the values in its
+.Vt audio_info_t
+argument that were received in the previous
+.Dv AUDIO_GETINFO
+ioctl.
+If the
+.Dv AUDIO_SETINFO
+ioctl is successful,
+.Nm
+will exit with status 0.
+.Pp
+If the
+.Dv AUDIO_SETINFO
+ioctl is not successful,
+.Nm
+will perform an
+.Dv AUDIO_SETINFO
+ioctl using the default
+.Vt audio_info_t
+values as given by
+.Dv AUDIO_INITINFO .
+If this
+.Dv AUDIO_SETINFO
+is not successful,
+.Nm
+will exit with status 1.
+.Pp
+Otherwise,
+.Nm
+will run a series of
+.Dv AUDIO_SETINFO
+ioctls where a single field in the
+.Vt audio_info_t
+structure is set to values from the
+.Dv AUDIO_GETINFO
+ioctl, the other values being default.
+As this series of ioctls is performed,
+.Nm
+will print the
+.Vt audio_info_t
+field that is using values from the
+.Dv AUDIO_GETINFO
+ioctl, as well as the value it is using.
+If the ioctl fails,
+.Nm
+will print
+.Dq <- ERROR
+immediately following the value.
+After all fields of the
+.Vt audio_info_t
+structure have been used,
+.Nm
+will exit with status 1.
+.Sh SEE ALSO
+.Xr audio 4 ,
+.Xr ioctl 2
+.Sh AUTHORS
+.Nm
+and this manual page were written by
+.An Jacob Meuser Aq jakemsr@sdf.lonestar.org .
diff --git a/regress/sys/dev/audio_info/audiotest_gsinfo.c b/regress/sys/dev/audio_info/audiotest_gsinfo.c
new file mode 100644
index 00000000000..19642041c60
--- /dev/null
+++ b/regress/sys/dev/audio_info/audiotest_gsinfo.c
@@ -0,0 +1,212 @@
+/*
+ * Copyright (c) 2007 Jacob Meuser <jakemsr@sdf.lonestar.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <sys/audioio.h>
+#include <err.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+extern char *optarg;
+extern int optind;
+
+int audio_info_set(int);
+int test_pr_members(int, int);
+int test_main_members(int);
+void audio_set_init(void);
+void audio_set_test(int);
+
+audio_info_t audio_if_init;
+audio_info_t audio_if_get;
+audio_info_t audio_if_set;
+
+
+
+int
+audio_info_set(int audio_fd)
+{
+ return ioctl(audio_fd, AUDIO_SETINFO, &audio_if_set);
+}
+
+
+void
+audio_set_init(void)
+{
+ AUDIO_INITINFO(&audio_if_init);
+ audio_if_set = audio_if_init;
+}
+
+
+void
+audio_set_test(int audio_fd)
+{
+ if (audio_info_set(audio_fd) < 0)
+ printf(" <- ERROR\n");
+ else
+ printf("\n");
+}
+
+
+int
+test_pr_members(int audio_fd, int mode)
+{
+struct audio_prinfo *s, *g;
+
+ if (mode) {
+ g = &audio_if_get.play;
+ s = &audio_if_set.play;
+ } else {
+ g = &audio_if_get.record;
+ s = &audio_if_set.record;
+ }
+
+ printf("%s.sample_rate = %u", (mode ? "play" : "record"), g->sample_rate);
+ audio_set_init();
+ s->sample_rate = g->sample_rate;
+ audio_set_test(audio_fd);
+
+ printf("%s.encoding = %u", (mode ? "play" : "record"), g->encoding);
+ audio_set_init();
+ s->encoding = g->encoding;
+ audio_set_test(audio_fd);
+
+ printf("%s.precision = %u", (mode ? "play" : "record"), g->precision);
+ audio_set_init();
+ s->precision = g->precision;
+ audio_set_test(audio_fd);
+
+ printf("%s.channels = %u", (mode ? "play" : "record"), g->channels);
+ audio_set_init();
+ s->channels = g->channels;
+ audio_set_test(audio_fd);
+
+ printf("%s.port = %u", (mode ? "play" : "record"), g->port);
+ audio_set_init();
+ s->port = g->port;
+ audio_set_test(audio_fd);
+
+ printf("%s.gain = %u", (mode ? "play" : "record"), g->gain);
+ audio_set_init();
+ s->gain = g->gain;
+ audio_set_test(audio_fd);
+
+ printf("%s.balance = %u", (mode ? "play" : "record"), g->balance);
+ audio_set_init();
+ s->balance = g->balance;
+ audio_set_test(audio_fd);
+
+ printf("%s.pause = %u", (mode ? "play" : "record"), g->pause);
+ audio_set_init();
+ s->pause = g->pause;
+ audio_set_test(audio_fd);
+
+ return 0;
+}
+
+int
+test_main_members(int audio_fd)
+{
+ printf("mode = %d", audio_if_get.mode);
+ audio_set_init();
+ audio_if_set.mode = audio_if_get.mode;
+ audio_set_test(audio_fd);
+
+ printf("monitor_gain = %d", audio_if_get.monitor_gain);
+ audio_set_init();
+ audio_if_set.monitor_gain = audio_if_get.monitor_gain;
+ audio_set_test(audio_fd);
+
+ printf("blocksize = %d", audio_if_get.blocksize);
+ audio_set_init();
+ audio_if_set.blocksize = audio_if_get.blocksize;
+ audio_set_test(audio_fd);
+
+ printf("hiwat = %d", audio_if_get.hiwat);
+ audio_set_init();
+ audio_if_set.hiwat = audio_if_get.hiwat;
+ audio_set_test(audio_fd);
+
+ printf("lowat = %d", audio_if_get.lowat);
+ audio_set_init();
+ audio_if_set.lowat = audio_if_get.lowat;
+ audio_set_test(audio_fd);
+
+ return 0;
+}
+
+int
+main(int argc, char *argv[])
+{
+char *audio_device;
+int audio_fd;
+int ch;
+int exval;
+
+ audio_device = "/dev/audio";
+
+ while ((ch = getopt(argc, argv, "f:")) != -1) {
+ switch (ch) {
+ case 'f':
+ audio_device = optarg;
+ break;
+ default:
+ break;
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ audio_fd = -1;
+ if ((audio_fd = open(audio_device, O_WRONLY)) < 0)
+ err(1, "could not open %s", audio_device);
+
+ AUDIO_INITINFO(&audio_if_init);
+ AUDIO_INITINFO(&audio_if_get);
+ AUDIO_INITINFO(&audio_if_set);
+
+ audio_if_set = audio_if_init;
+
+ if (audio_info_set(audio_fd) < 0)
+ err(1, "results will be invalid");
+
+ if (ioctl(audio_fd, AUDIO_GETINFO, &audio_if_get) < 0)
+ err(1, "AUDIO_GETINFO audio_if_get");
+
+ exval = 1;
+
+ audio_if_set = audio_if_get;
+ if (audio_info_set(audio_fd) < 0)
+ warn("AUDIO_SETINFO audio_if_get");
+ else {
+ exval = 0;
+ goto done;
+ }
+
+ test_pr_members(audio_fd, 1); /* play */
+ test_pr_members(audio_fd, 0); /* record */
+ test_main_members(audio_fd);
+
+done:
+
+ if (audio_fd != -1)
+ close(audio_fd);
+
+ exit(exval);
+}