Index: head/etc/mtree/BSD.tests.dist =================================================================== --- head/etc/mtree/BSD.tests.dist (revision 351480) +++ head/etc/mtree/BSD.tests.dist (revision 351481) @@ -1,1098 +1,1100 @@ # $FreeBSD$ # # Please see the file src/etc/mtree/README before making changes to this file. # /set type=dir uname=root gname=wheel mode=0755 . bin cat .. chflags .. chmod .. date .. dd .. echo .. expr .. ln .. ls .. mkdir .. mv .. pax .. pkill .. pwait .. rm .. rmdir .. sh builtins .. errors .. execution .. expansion .. invocation .. parameters .. parser .. set-e .. .. sleep .. test .. .. cddl lib .. sbin .. usr.bin ctfconvert .. ztest .. .. usr.sbin dtrace common aggs .. arithmetic .. arrays .. assocs .. begin .. bitfields .. buffering .. builtinvar .. cg .. clauses .. cpc .. decls .. drops .. dtraceUtil .. end .. env .. enum .. error .. exit .. fbtprovider .. funcs .. grammar .. include .. inline .. io .. ip .. java_api .. json .. lexer .. llquantize .. mdb .. mib .. misc .. multiaggs .. offsetof .. operators .. pid .. plockstat .. pointers .. pragma .. predicates .. preprocessor .. print .. printa .. printf .. privs .. probes .. proc .. profile-n .. providers .. raise .. rates .. safety .. scalars .. sched .. scripting .. sdt .. sizeof .. speculation .. stability .. stack .. stackdepth .. stop .. strlen .. strtoll .. struct .. sugar .. syscall .. sysevent .. tick-n .. trace .. tracemem .. translators .. typedef .. types .. uctf .. union .. usdt .. ustack .. vars .. version .. .. i386 arrays .. funcs .. pid .. ustack .. .. amd64 arrays .. .. .. zfsd .. .. .. etc rc.d .. .. games .. gnu lib .. usr.bin diff .. .. .. lib atf libatf-c detail .. .. libatf-c++ detail .. .. test-programs .. .. csu dynamic .. dynamiclib .. static .. .. googletest gmock .. gmock_main .. gtest .. gtest_main .. .. libarchive .. libbe .. libc c063 .. db .. gen execve .. posix_spawn .. .. hash data .. .. iconv .. inet .. locale .. net getaddrinfo data .. .. .. nss .. regex data .. .. resolv .. rpc .. ssp .. setjmp .. stdio .. stdlib .. string .. sys .. time .. tls dso .. .. termios .. ttyio .. .. libcam .. libcasper services cap_dns .. cap_grp .. cap_pwd .. cap_sysctl .. .. .. libcrypt .. libdevdctl .. libkvm .. libmp .. libnv .. libproc .. libregex data .. .. librt .. libsbuf .. libthr dlopen .. .. libutil .. libxo .. msun .. .. libexec atf atf-check .. atf-sh .. .. rtld-elf .. tftpd .. .. sbin bectl .. dhclient .. devd .. growfs .. ifconfig .. mdconfig .. pfctl files .. .. ping .. ping6 .. .. secure lib .. libexec .. usr.bin .. usr.sbin .. .. share examples tests atf .. googletest .. plain .. tap .. .. .. zoneinfo .. .. sys acl .. aio .. audit .. auditpipe .. capsicum .. cddl zfs bin .. include .. tests acl cifs .. nontrivial .. trivial .. .. atime .. bootfs .. cache .. cachefile .. clean_mirror .. cli_root zfs_upgrade .. zfs_promote .. zfs_clone .. zfs_property .. zfs_destroy .. zpool_create .. zpool_history .. zpool_expand .. zpool_remove .. zfs_mount .. zfs_unshare .. zdb .. zpool_online .. zpool_get .. zpool_export .. zfs_copies .. zfs_get .. zfs .. zpool_clear .. zpool_import blockfiles .. .. zpool .. zpool_offline .. zpool_replace .. zfs_rollback .. zpool_set .. zfs_send .. zfs_set .. zpool_detach .. zfs_diff .. zpool_scrub .. zfs_inherit .. zfs_snapshot .. zfs_share .. zpool_destroy .. zpool_status .. zfs_unmount .. zfs_receive .. zfs_create .. zpool_upgrade blockfiles .. .. zpool_add .. zfs_rename .. zpool_attach .. zfs_reservation .. .. cli_user misc .. zfs_list .. zpool_iostat .. zpool_list .. .. compression .. ctime .. delegate .. devices .. exec .. grow_pool .. grow_replicas .. history .. hotplug .. hotspare .. inheritance .. interop .. inuse .. iscsi .. large_files .. largest_pool .. link_count .. migration .. mmap .. mount .. mv_files .. nestedfs .. no_space .. online_offline .. pool_names .. poolversion .. quota .. redundancy .. refquota .. refreserv .. rename_dirs .. replacement .. reservation .. rootpool .. rsend .. scrub_mirror .. slog .. snapshot .. snapused .. sparse .. threadsappend .. truncate .. txg_integrity .. userquota .. utils_test .. write_dirs .. xattr .. zfsd .. zil .. zinject .. zones .. zvol zvol_ENOSPC .. zvol_cli .. zvol_misc .. zvol_swap .. .. zvol_thrash .. .. .. .. devrandom .. dtrace .. fifo .. file .. fs fusefs .. tmpfs .. .. geom class concat .. eli .. gate .. gpt .. mirror .. nop .. part .. raid3 .. shsec .. stripe .. uzip etalon .. .. .. .. kern acct .. execve .. pipe .. .. kqueue libkqueue .. .. mac bsdextended .. portacl .. .. mqueue .. net .. netinet .. netipsec tunnel .. .. netmap .. netpfil common .. pf ioctl .. .. .. opencrypto .. pjdfstest chflags .. chmod .. chown .. ftruncate .. granular .. link .. + mixer + .. mkdir .. mkfifo .. mknod .. open .. rename .. rmdir .. symlink .. truncate .. unlink .. utimensat .. .. posixshm .. sys .. vfs .. vm .. .. usr.bin apply .. awk .. basename .. bmake archives fmt_44bsd .. fmt_44bsd_mod .. fmt_oldbsd .. .. basic t0 .. t1 .. t2 .. t3 .. .. execution ellipsis .. empty .. joberr .. plus .. .. shell builtin .. meta .. path .. path_select .. replace .. select .. .. suffixes basic .. src_wild1 .. src_wild2 .. .. syntax directive-t0 .. enl .. funny-targets .. semi .. .. sysmk t0 2 1 .. .. mk .. .. t1 2 1 .. .. mk .. .. t2 2 1 .. .. mk .. .. .. variables modifier_M .. modifier_t .. opt_V .. t0 .. .. .. bsdcat .. calendar .. cmp .. compress .. cpio .. col .. comm .. csplit .. cut .. dc .. diff .. dirname .. du .. file2c .. find .. fold .. getconf .. grep .. gzip .. head .. hexdump .. ident .. indent .. join .. jot .. lastcomm .. limits .. m4 .. mkimg .. ncal .. opensm .. pr .. printf .. procstat .. rs .. sdiff .. sed regress.multitest.out .. .. seq .. soelim .. stat .. tail .. tar .. timeout .. tr .. truncate .. units .. uudecode .. uuencode .. uniq .. vmstat .. xargs .. xinstall .. xo .. yacc yacc .. .. .. usr.sbin chown .. etcupdate .. extattr .. fstyp .. makefs .. newsyslog .. nmtree .. praudit .. pw .. rpcbind .. sa .. .. .. # vim: set expandtab ts=4 sw=4: Index: head/usr.sbin/mixer/Makefile =================================================================== --- head/usr.sbin/mixer/Makefile (revision 351480) +++ head/usr.sbin/mixer/Makefile (revision 351481) @@ -1,6 +1,11 @@ # $FreeBSD$ +.include + PROG= mixer MAN= mixer.8 + +HAS_TESTS= +SUBDIR.${MK_TESTS}+= tests .include Index: head/usr.sbin/mixer/mixer.c =================================================================== --- head/usr.sbin/mixer/mixer.c (revision 351480) +++ head/usr.sbin/mixer/mixer.c (revision 351481) @@ -1,336 +1,341 @@ /* * This is an example of a mixer program for Linux * * updated 1/1/93 to add stereo, level query, broken * devmask kludge - cmetz@thor.tjhsst.edu * * (C) Craig Metz and Hannu Savolainen 1993. * * You may do anything you wish with this program. * * ditto for my modifications (John-Mark Gurney, 1997) */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include static const char *names[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; static void usage(int devmask, int recmask) __dead2; static int res_name(const char *name, int mask); static void print_recsrc(int recsrc, int recmask, int sflag); static void __dead2 usage(int devmask, int recmask) { int i, n; printf("usage: mixer [-f device] [-s | -S] [dev [+|-][voll[:[+|-]volr]] ...\n" " mixer [-f device] [-s | -S] recsrc ...\n" " mixer [-f device] [-s | -S] {^|+|-|=}rec rdev ...\n"); if (devmask != 0) { printf(" devices: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & devmask) { if (n) printf(", "); printf("%s", names[i]); n++; } } if (recmask != 0) { printf("\n rec devices: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & recmask) { if (n) printf(", "); printf("%s", names[i]); n++; } } printf("\n"); exit(1); } static int res_name(const char *name, int mask) { int foo; for (foo = 0; foo < SOUND_MIXER_NRDEVICES; foo++) if ((1 << foo) & mask && strcmp(names[foo], name) == 0) break; return (foo == SOUND_MIXER_NRDEVICES ? -1 : foo); } static void print_recsrc(int recsrc, int recmask, int sflag) { int i, n; if (recmask == 0) return; if (!sflag) printf("Recording source: "); for (i = 0, n = 0; i < SOUND_MIXER_NRDEVICES; i++) if ((1 << i) & recsrc) { if (sflag) printf("%srec ", n ? " +" : "="); else if (n) printf(", "); printf("%s", names[i]); n++; } if (!sflag) printf("\n"); } int main(int argc, char *argv[]) { char mixer[PATH_MAX] = "/dev/mixer"; char lstr[8], rstr[8]; char *name, *eptr; int devmask = 0, recmask = 0, recsrc = 0, orecsrc; int dusage = 0, drecsrc = 0, sflag = 0, Sflag = 0; int l, r, lrel, rrel; int ch, foo, bar, baz, dev, m, n, t; if ((name = strdup(basename(argv[0]))) == NULL) err(1, "strdup()"); if (strncmp(name, "mixer", 5) == 0 && name[5] != '\0') { n = strtol(name + 5, &eptr, 10) - 1; if (n > 0 && *eptr == '\0') snprintf(mixer, PATH_MAX - 1, "/dev/mixer%d", n); } free(name); name = mixer; n = 1; for (;;) { if (n >= argc || *argv[n] != '-') break; if (strlen(argv[n]) != 2) { if (strcmp(argv[n] + 1, "rec") != 0) dusage = 1; break; } ch = *(argv[n] + 1); if (ch == 'f' && n < argc - 1) { name = argv[n + 1]; n += 2; } else if (ch == 's') { sflag = 1; n++; } else if (ch == 'S') { Sflag = 1; n++; } else { dusage = 1; break; } } if (sflag && Sflag) dusage = 1; argc -= n - 1; argv += n - 1; if ((baz = open(name, O_RDWR)) < 0) err(1, "%s", name); if (ioctl(baz, SOUND_MIXER_READ_DEVMASK, &devmask) == -1) err(1, "SOUND_MIXER_READ_DEVMASK"); if (ioctl(baz, SOUND_MIXER_READ_RECMASK, &recmask) == -1) err(1, "SOUND_MIXER_READ_RECMASK"); if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) err(1, "SOUND_MIXER_READ_RECSRC"); orecsrc = recsrc; if (argc == 1 && dusage == 0) { for (foo = 0, n = 0; foo < SOUND_MIXER_NRDEVICES; foo++) { if (!((1 << foo) & devmask)) continue; if (ioctl(baz, MIXER_READ(foo),&bar) == -1) { warn("MIXER_READ"); continue; } if (Sflag || sflag) { printf("%s%s%c%d:%d", n ? " " : "", names[foo], Sflag ? ':' : ' ', bar & 0x7f, (bar >> 8) & 0x7f); n++; } else printf("Mixer %-8s is currently set to " "%3d:%d\n", names[foo], bar & 0x7f, (bar >> 8) & 0x7f); } if (n && recmask) printf(" "); print_recsrc(recsrc, recmask, Sflag || sflag); return (0); } argc--; argv++; n = 0; while (argc > 0 && dusage == 0) { if (strcmp("recsrc", *argv) == 0) { drecsrc = 1; argc--; argv++; continue; } else if (strcmp("rec", *argv + 1) == 0) { if (**argv != '+' && **argv != '-' && **argv != '=' && **argv != '^') { warnx("unknown modifier: %c", **argv); dusage = 1; break; } if (argc <= 1) { warnx("no recording device specified"); dusage = 1; break; } if ((dev = res_name(argv[1], recmask)) == -1) { warnx("unknown recording device: %s", argv[1]); dusage = 1; break; } switch (**argv) { case '+': recsrc |= (1 << dev); break; case '-': recsrc &= ~(1 << dev); break; case '=': recsrc = (1 << dev); break; case '^': recsrc ^= (1 << dev); break; } drecsrc = 1; argc -= 2; argv += 2; continue; } if ((t = sscanf(*argv, "%d:%d", &l, &r)) > 0) dev = 0; else if ((dev = res_name(*argv, devmask)) == -1) { warnx("unknown device: %s", *argv); dusage = 1; break; } lrel = rrel = 0; if (argc > 1) { m = sscanf(argv[1], "%7[^:]:%7s", lstr, rstr); + if (m == EOF) { + warnx("invalid value: %s", argv[1]); + dusage = 1; + break; + } if (m > 0) { if (*lstr == '+' || *lstr == '-') lrel = rrel = 1; l = strtol(lstr, NULL, 10); } if (m > 1) { if (*rstr == '+' || *rstr == '-') rrel = 1; r = strtol(rstr, NULL, 10); } } switch (argc > 1 ? m : t) { case 0: if (ioctl(baz, MIXER_READ(dev), &bar) == -1) { warn("MIXER_READ"); argc--; argv++; continue; } if (Sflag || sflag) { printf("%s%s%c%d:%d", n ? " " : "", names[dev], Sflag ? ':' : ' ', bar & 0x7f, (bar >> 8) & 0x7f); n++; } else printf("Mixer %-8s is currently set to " "%3d:%d\n", names[dev], bar & 0x7f, (bar >> 8) & 0x7f); argc--; argv++; break; case 1: r = l; /* FALLTHROUGH */ case 2: if (ioctl(baz, MIXER_READ(dev), &bar) == -1) { warn("MIXER_READ"); argc--; argv++; continue; } if (lrel) l = (bar & 0x7f) + l; if (rrel) r = ((bar >> 8) & 0x7f) + r; if (l < 0) l = 0; else if (l > 100) l = 100; if (r < 0) r = 0; else if (r > 100) r = 100; if (!Sflag) printf("Setting the mixer %s from %d:%d to " "%d:%d.\n", names[dev], bar & 0x7f, (bar >> 8) & 0x7f, l, r); l |= r << 8; if (ioctl(baz, MIXER_WRITE(dev), &l) == -1) warn("WRITE_MIXER"); argc -= 2; argv += 2; break; } } if (dusage) { close(baz); usage(devmask, recmask); /* NOTREACHED */ } if (orecsrc != recsrc) { if (ioctl(baz, SOUND_MIXER_WRITE_RECSRC, &recsrc) == -1) err(1, "SOUND_MIXER_WRITE_RECSRC"); if (ioctl(baz, SOUND_MIXER_READ_RECSRC, &recsrc) == -1) err(1, "SOUND_MIXER_READ_RECSRC"); } if (drecsrc) print_recsrc(recsrc, recmask, Sflag || sflag); close(baz); return (0); } Index: head/usr.sbin/mixer/tests/Makefile =================================================================== --- head/usr.sbin/mixer/tests/Makefile (nonexistent) +++ head/usr.sbin/mixer/tests/Makefile (revision 351481) @@ -0,0 +1,5 @@ +# $FreeBSD$ + +ATF_TESTS_SH+= mixer_test + +.include Property changes on: head/usr.sbin/mixer/tests/Makefile ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/usr.sbin/mixer/tests/mixer_test.sh =================================================================== --- head/usr.sbin/mixer/tests/mixer_test.sh (nonexistent) +++ head/usr.sbin/mixer/tests/mixer_test.sh (revision 351481) @@ -0,0 +1,123 @@ +# +# SPDX-License-Identifier: BSD-2-Clause-FreeBSD +# +# Copyright (c) 2019 Mateusz Piotrowski <0mp@FreeBSD.org> +# +# 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. + +# $FreeBSD$ + +mixer_unavailable() +{ + ! { mixer && mixer vol; } >/dev/null 2>&1 +} + +save_mixer_vol() +{ + atf_check -o match:'^[0-9]{1,3}:[0-9]{1,3}$' -o save:saved_vol \ + -x "mixer vol | awk '{print \$7}'" +} + +set_mixer_vol() +{ + atf_check \ + -o match:'^Setting the mixer vol from [0-9]{1,3}:[0-9]{1,3} to 0:0\.$' \ + mixer vol 0 +} + +restore_mixer_vol() +{ + if [ -r "saved_vol" ]; then + mixer vol "$(cat saved_vol)" + fi +} + +atf_test_case s_flag cleanup +s_flag_head() +{ + atf_set "descr" "Verify that the output of the -s flag could be " \ + "reused as command-line arguments to the mixer command" +} +s_flag_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + set_mixer_vol + atf_check -o inline:"vol 0:0" -o save:values mixer -s vol + atf_check -o inline:"Setting the mixer vol from 0:0 to 0:0.\n" \ + mixer $(cat values) +} +s_flag_cleanup() +{ + restore_mixer_vol +} + +atf_test_case S_flag cleanup +S_flag_head() +{ + atf_set "descr" "Verify that the output of the -S flag is " \ + "matching the documented behavior" +} +S_flag_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + set_mixer_vol + atf_check -o inline:"vol:0:0" mixer -S vol +} +S_flag_cleanup() +{ + restore_mixer_vol +} + +atf_test_case set_empty_value +set_empty_value_head() +{ + atf_set "descr" "Verify that mixer returns when the provided " \ + "value to set is an empty string instead of a number" + atf_set "timeout" "1" +} +set_empty_value_body() +{ + if mixer_unavailable; then + atf_skip "This test requires mixer support" + fi + save_mixer_vol + atf_check -s exit:1 -e inline:"mixer: invalid value: \n" \ + -o match:"^usage:" mixer vol "" +} +set_empty_value_cleanup() +{ + restore_mixer_vol +} + + +atf_init_test_cases() +{ + atf_add_test_case s_flag + atf_add_test_case S_flag + atf_add_test_case set_empty_value +} Property changes on: head/usr.sbin/mixer/tests/mixer_test.sh ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property