diff --git a/tests/sys/sound/sndstat.c b/tests/sys/sound/sndstat.c --- a/tests/sys/sound/sndstat.c +++ b/tests/sys/sound/sndstat.c @@ -30,8 +30,9 @@ #include #include -#include #include +#include +#include #include #include @@ -46,26 +47,15 @@ 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) +static void +read_all(int fd) { 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)"); + int rc, pchan, rchan; rc = ioctl(fd, SNDSTIOC_REFRESH_DEVS, NULL); ATF_REQUIRE_EQ(rc, 0); @@ -135,7 +125,6 @@ } #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; @@ -203,12 +192,92 @@ free(arg.buf); nvlist_destroy(nvl); +} + +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) +{ + int fd; + + load_dummy(); + + if ((fd = open("/dev/sndstat", O_RDONLY)) < 0) + atf_tc_skip("/dev/sndstat not found, load sound(4)"); + read_all(fd); + close(fd); +} + +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; + struct sndstioc_nv_arg arg; + int fd, rc; + + 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, "sndstat_udev"); + nvlist_add_string(di, SNDST_DSPS_NAMEUNIT, "sndstat_udev"); + nvlist_add_string(di, SNDST_DSPS_DESC, "Test Device"); + nvlist_add_string(di, SNDST_DSPS_DEVNODE, "sndstat_udev"); + nvlist_add_number(di, SNDST_DSPS_PCHAN, 1); + nvlist_add_number(di, SNDST_DSPS_RCHAN, 2); + + nvlist_add_number(dichild, SNDST_DSPS_INFO_MIN_RATE, 8000); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MAX_RATE, 96000); + nvlist_add_number(dichild, SNDST_DSPS_INFO_FORMATS, + AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MIN_CHN, 1); + nvlist_add_number(dichild, SNDST_DSPS_INFO_MAX_CHN, 2); + + 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. */ + read_all(fd); 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()); }