Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/dev/audio Sync with sys/dev/audio/audio.c rev1.62.



details:   https://anonhg.NetBSD.org/src/rev/2c87a22d11d8
branches:  trunk
changeset: 1007915:2c87a22d11d8
user:      isaki <isaki%NetBSD.org@localhost>
date:      Wed Mar 04 14:20:44 2020 +0000

description:
Sync with sys/dev/audio/audio.c rev1.62.
> Restore backward compatibility with netbsd-7 audio.

diffstat:

 tests/dev/audio/audiotest.c |  750 +++++++++++--------------------------------
 1 files changed, 192 insertions(+), 558 deletions(-)

diffs (truncated from 976 to 300 lines):

diff -r bbffafb86668 -r 2c87a22d11d8 tests/dev/audio/audiotest.c
--- a/tests/dev/audio/audiotest.c       Wed Mar 04 14:19:41 2020 +0000
+++ b/tests/dev/audio/audiotest.c       Wed Mar 04 14:20:44 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $      */
+/*     $NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $      */
 
 /*
  * Copyright (C) 2019 Tetsuya Isaki. All rights reserved.
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: audiotest.c,v 1.6 2020/02/22 05:53:19 isaki Exp $");
+__RCSID("$NetBSD: audiotest.c,v 1.7 2020/03/04 14:20:44 isaki Exp $");
 
 #include <errno.h>
 #include <fcntl.h>
@@ -106,7 +106,6 @@
 bool xp_sys_ok(int, int, const char *);
 bool xp_sys_ng(int, int, int, const char *);
 bool xp_sys_ptr(int, int, void *, const char *);
-bool xp_buffsize(int, bool, int, const char *);
 int debug_open(int, const char *, int);
 int debug_write(int, int, const void *, size_t);
 int debug_read(int, int, void *, size_t);
@@ -920,29 +919,6 @@
        return r;
 }
 
-/*
- * Check ai.*.buffer_size.
- * If exp == true, it expects that buffer_size is non-zero.
- * If exp == false, it expects that buffer_size is zero.
- */
-#define XP_BUFFSIZE(exp, act)  \
-       xp_buffsize(__LINE__, exp, act, #act)
-bool xp_buffsize(int line, bool exp, int act, const char *varname)
-{
-       bool r = true;
-
-       testcount++;
-       if (exp) {
-               if (act == 0)
-                       r = xp_fail(line, "%s expects non-zero but %d",
-                           varname, act);
-       } else {
-               if (act != 0)
-                       r = xp_fail(line, "%s expects zero but %d",
-                           varname, act);
-       }
-       return r;
-}
 
 /*
  * REQUIRED_* return immediately if condition does not meet.
@@ -1377,9 +1353,7 @@
  */
 
 void test_open_mode(int);
-void test_open_audio(int);
-void test_open_sound(int);
-void test_open_audioctl(int);
+void test_open(const char *, int);
 void test_open_simul(int, int);
 void try_open_multiuser(bool);
 void test_open_multiuser(bool);
@@ -1435,49 +1409,89 @@
 DEF(open_mode_WRONLY)  { test_open_mode(O_WRONLY); }
 DEF(open_mode_RDWR)    { test_open_mode(O_RDWR);   }
 
-
 /*
- * The initial parameters are always the same whenever you open /dev/audio.
+ * Check the initial parameters and stickiness.
+ * /dev/audio
+ *     The initial parameters are always the same whenever you open.
+ * /dev/sound and /dev/audioctl
+ *     The initial parameters are inherited from the last /dev/sound or
+ *     /dev/audio.
  */
 void
-test_open_audio(int mode)
+test_open(const char *devname, int mode)
 {
        struct audio_info ai;
        struct audio_info ai0;
+       char devfile[16];
        int fd;
        int r;
        int can_play;
        int can_rec;
-       bool pbuff;
-       bool rbuff;
-
-       TEST("open_audio_%s", openmode_str[mode] + 2);
-
+       int exp_mode;
+       int exp_encoding;
+       int exp_precision;
+       int exp_channels;
+       int exp_sample_rate;
+       int exp_pause;
+       int exp_popen;
+       int exp_ropen;
+
+       TEST("open_%s_%s", devname, openmode_str[mode] + 2);
+
+       snprintf(devfile, sizeof(devfile), "/dev/%s%d", devname, unit);
        can_play = mode2play(mode);
        can_rec  = mode2rec(mode);
-       if (can_play + can_rec == 0) {
-               /* Check whether it cannot be opened */
-               fd = OPEN(devaudio, mode);
-               XP_SYS_NG(ENXIO, fd);
-               return;
-       }
+       if (strcmp(devname, "audioctl") != 0) {
+               if (can_play + can_rec == 0) {
+                       /* Check whether it cannot be opened */
+                       fd = OPEN(devaudio, mode);
+                       XP_SYS_NG(ENXIO, fd);
+                       return;
+               }
+       }
+
+       /* /dev/audio is always initialized */
+       if (strcmp(devname, "audio") == 0) {
+               exp_encoding = AUDIO_ENCODING_ULAW;
+               exp_precision = 8;
+               exp_channels = 1;
+               exp_sample_rate = 8000;
+               exp_pause = 0;
+       } else {
+               exp_encoding = AUDIO_ENCODING_SLINEAR_LE;
+               exp_precision = 16;
+               exp_channels = 2;
+               exp_sample_rate = 11025;
+               exp_pause = 1;
+       }
+
+       /* /dev/audioctl is always "not opened" */
+       if (strcmp(devname, "audioctl") == 0) {
+               exp_mode = 0;
+               exp_popen = 0;
+               exp_ropen = 0;
+       } else {
+               exp_mode = mode2aumode(mode);
+               exp_popen = can_play;
+               exp_ropen = can_rec;
+       }
+
 
        /*
-        * NetBSD7,8 always has both buffers for playback and recording.
-        * NetBSD9 only has necessary buffers.
+        * At first, initialize the sticky parameters both of play and rec.
+        * This uses /dev/audio to verify /dev/audio.  It's not good way but
+        * I don't have better one...
         */
-       if (netbsd < 9) {
-               pbuff = true;
-               rbuff = true;
-       } else {
-               pbuff = can_play;
-               rbuff = can_rec;
-       }
+       fd = OPEN(devaudio, openable_mode());
+       REQUIRED_SYS_OK(fd);
+       r = CLOSE(fd);
+       REQUIRED_SYS_EQ(0, r);
 
        /*
-        * Open /dev/audio and check parameters
+        * Open target device and check the initial parameters
+        * At this moment, all devices are initialized by default.
         */
-       fd = OPEN(devaudio, mode);
+       fd = OPEN(devfile, mode);
        REQUIRED_SYS_OK(fd);
        memset(&ai, 0, sizeof(ai));
        r = IOCTL(fd, AUDIO_GETBUFINFO, &ai, "");
@@ -1485,23 +1499,24 @@
 
        XP_NE(0, ai.blocksize);
                /* hiwat/lowat */
-       XP_EQ(mode2aumode(mode), ai.mode);
+       XP_EQ(exp_mode, ai.mode);
        /* ai.play */
        XP_EQ(8000, ai.play.sample_rate);
        XP_EQ(1, ai.play.channels);
+       XP_EQ(8, ai.play.precision);
        XP_EQ(AUDIO_ENCODING_ULAW, ai.play.encoding);
                /* gain */
                /* port */
        XP_EQ(0, ai.play.seek);
                /* avail_ports */
-       XP_BUFFSIZE(pbuff, ai.play.buffer_size);
+       XP_NE(0, ai.play.buffer_size);
        XP_EQ(0, ai.play.samples);
        XP_EQ(0, ai.play.eof);
        XP_EQ(0, ai.play.pause);
        XP_EQ(0, ai.play.error);
        XP_EQ(0, ai.play.waiting);
                /* balance */
-       XP_EQ(can_play, ai.play.open);
+       XP_EQ(exp_popen, ai.play.open);
        XP_EQ(0, ai.play.active);
        /* ai.record */
        XP_EQ(8000, ai.record.sample_rate);
@@ -1512,14 +1527,14 @@
                /* port */
        XP_EQ(0, ai.record.seek);
                /* avail_ports */
-       XP_BUFFSIZE(rbuff, ai.record.buffer_size);
+       XP_NE(0, ai.record.buffer_size);
        XP_EQ(0, ai.record.samples);
        XP_EQ(0, ai.record.eof);
        XP_EQ(0, ai.record.pause);
        XP_EQ(0, ai.record.error);
        XP_EQ(0, ai.record.waiting);
                /* balance */
-       XP_EQ(can_rec, ai.record.open);
+       XP_EQ(exp_ropen, ai.record.open);
        /*
         * NetBSD7,8 (may?) be active when opened in recording mode but
         * recording has not started yet. (?)
@@ -1536,12 +1551,7 @@
         * Change much as possible
         */
        AUDIO_INITINFO(&ai);
-       ai.blocksize = ai0.blocksize * 2;
-       if (ai0.hiwat > 0)
-               ai.hiwat = ai0.hiwat - 1;
-       if (ai0.lowat < ai0.hiwat)
-               ai.lowat = ai0.lowat + 1;
-       ai.mode = ai.mode & ~AUMODE_PLAY_ALL;
+       ai.mode = ai0.mode ^ AUMODE_PLAY_ALL;
        ai.play.sample_rate = 11025;
        ai.play.channels = 2;
        ai.play.precision = 16;
@@ -1558,53 +1568,61 @@
        REQUIRED_SYS_EQ(0, r);
 
        /*
-        * Open /dev/audio again and check
+        * Open the same target device again and check
         */
-       fd = OPEN(devaudio, mode);
+       fd = OPEN(devfile, mode);
        REQUIRED_SYS_OK(fd);
        memset(&ai, 0, sizeof(ai));
        r = IOCTL(fd, AUDIO_GETBUFINFO, &ai, "");
        REQUIRED_SYS_EQ(0, r);
 
-       XP_EQ(ai0.blocksize, ai.blocksize);
-       XP_EQ(ai0.hiwat, ai.hiwat);
-       XP_EQ(ai0.lowat, ai.lowat);
-       XP_EQ(mode2aumode(mode), ai.mode);
+       XP_NE(0, ai.blocksize);
+               /* hiwat/lowat */
+       if (netbsd < 8) {
+               /*
+                * On NetBSD7, the behavior when changing ai.mode on
+                * /dev/audioctl can not be explained yet but I won't
+                * verify it more over.
+                */
+       } else {
+               /* On NetBSD9, changing mode never affects other fds */
+               XP_EQ(exp_mode, ai.mode);
+       }
        /* ai.play */
-       XP_EQ(8000, ai.play.sample_rate);
-       XP_EQ(1, ai.play.channels);
-       XP_EQ(8, ai.play.precision);
-       XP_EQ(AUDIO_ENCODING_ULAW, ai.play.encoding);
+       XP_EQ(exp_sample_rate, ai.play.sample_rate);
+       XP_EQ(exp_channels, ai.play.channels);
+       XP_EQ(exp_precision, ai.play.precision);
+       XP_EQ(exp_encoding, ai.play.encoding);
                /* gain */
                /* port */
        XP_EQ(0, ai.play.seek);
                /* avail_ports */
-       XP_EQ(ai0.play.buffer_size, ai.play.buffer_size);
+       XP_NE(0, ai.play.buffer_size);
        XP_EQ(0, ai.play.samples);
        XP_EQ(0, ai.play.eof);
-       XP_EQ(0, ai.play.pause);
+       XP_EQ(exp_pause, ai.play.pause);
        XP_EQ(0, ai.play.error);
        XP_EQ(0, ai.play.waiting);
                /* balance */
-       XP_EQ(can_play, ai.play.open);
+       XP_EQ(exp_popen, ai.play.open);
        XP_EQ(0, ai.play.active);
        /* ai.record */
-       XP_EQ(8000, ai.record.sample_rate);
-       XP_EQ(1, ai.record.channels);
-       XP_EQ(8, ai.record.precision);



Home | Main Index | Thread Index | Old Index