From owner-svn-src-all@FreeBSD.ORG Sun Mar 16 02:07:10 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id BE5CBB43; Sun, 16 Mar 2014 02:07:10 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id A8BA7F08; Sun, 16 Mar 2014 02:07:10 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2G27ANk002273; Sun, 16 Mar 2014 02:07:10 GMT (envelope-from jmmv@svn.freebsd.org) Received: (from jmmv@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2G278F7002261; Sun, 16 Mar 2014 02:07:08 GMT (envelope-from jmmv@svn.freebsd.org) Message-Id: <201403160207.s2G278F7002261@svn.freebsd.org> From: Julio Merino Date: Sun, 16 Mar 2014 02:07:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r263220 - in head: etc/mtree sbin sbin/dhclient sbin/dhclient/tests sbin/growfs sbin/growfs/tests sbin/mdconfig sbin/mdconfig/tests sbin/tests tools/regression/sbin X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Mar 2014 02:07:10 -0000 Author: jmmv Date: Sun Mar 16 02:07:08 2014 New Revision: 263220 URL: http://svnweb.freebsd.org/changeset/base/263220 Log: Migrate tools/regression/sbin/ to the new tests layout. Pretty much all that this change does is shuffles the code around and hooks it into the regular build. The code of the old tests has not changed. Added: head/sbin/dhclient/tests/ - copied from r263215, head/tools/regression/sbin/dhclient/ head/sbin/growfs/tests/ - copied from r263215, head/tools/regression/sbin/growfs/ head/sbin/growfs/tests/legacy_test.pl - copied, changed from r263215, head/tools/regression/sbin/growfs/regress.t head/sbin/mdconfig/tests/ - copied from r263215, head/tools/regression/sbin/mdconfig/ head/sbin/mdconfig/tests/legacy_test.sh - copied, changed from r263215, head/tools/regression/sbin/mdconfig/00.t - copied unchanged from r263215, head/tools/regression/sbin/mdconfig/run head/sbin/tests/ head/sbin/tests/Makefile (contents, props changed) Directory Properties: head/sbin/mdconfig/tests/run.pl (props changed) Deleted: head/sbin/growfs/tests/regress.t head/sbin/mdconfig/tests/00.t head/sbin/mdconfig/tests/run head/tools/regression/sbin/ Modified: head/etc/mtree/BSD.tests.dist head/sbin/Makefile head/sbin/dhclient/Makefile head/sbin/dhclient/tests/Makefile head/sbin/growfs/Makefile head/sbin/growfs/tests/Makefile head/sbin/mdconfig/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Sun Mar 16 01:55:30 2014 (r263219) +++ head/etc/mtree/BSD.tests.dist Sun Mar 16 02:07:08 2014 (r263220) @@ -68,6 +68,14 @@ .. .. .. + sbin + dhclient + .. + growfs + .. + mdconfig + .. + .. share examples tests Modified: head/sbin/Makefile ============================================================================== --- head/sbin/Makefile Sun Mar 16 01:55:30 2014 (r263219) +++ head/sbin/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -118,6 +118,10 @@ SUBDIR+= quotacheck SUBDIR+= routed .endif +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include SUBDIR:= ${SUBDIR:O} Modified: head/sbin/dhclient/Makefile ============================================================================== --- head/sbin/dhclient/Makefile Sun Mar 16 01:55:30 2014 (r263219) +++ head/sbin/dhclient/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -31,6 +31,8 @@ # OF THE POSSIBILITY OF SUCH DAMAGE. # +.include + SRCS= dhclient.c clparse.c alloc.c dispatch.c hash.c bpf.c options.c \ tree.c conflex.c errwarn.c inet.c packet.c convert.c tables.c \ parse.c privsep.c @@ -44,4 +46,8 @@ LDADD= -lutil WARNS?= 2 +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include Modified: head/sbin/dhclient/tests/Makefile ============================================================================== --- head/tools/regression/sbin/dhclient/Makefile Sun Mar 16 00:57:26 2014 (r263215) +++ head/sbin/dhclient/tests/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -1,17 +1,15 @@ # $FreeBSD$ -.PATH: ${.CURDIR}/../../../../sbin/dhclient +TESTSDIR= ${TESTSBASE}/sbin/dhclient -SRCS= alloc.c convert.c hash.c options.c tables.c \ - fake.c \ - option-domain-search.c +.PATH: ${.CURDIR}/.. -CFLAGS+= -I${.CURDIR}/../../../../sbin/dhclient -LDADD= -lutil +PLAIN_TESTS_C= option-domain-search_test +SRCS.option-domain-search_test= alloc.c convert.c hash.c options.c \ + tables.c fake.c option-domain-search.c +CFLAGS.option-domain-search_test+= -I${.CURDIR}/.. +LDADD.option-domain-search_test= -lutil -PROG= option-domain-search - -NO_MAN= WARNS?= 2 -.include +.include Modified: head/sbin/growfs/Makefile ============================================================================== --- head/sbin/growfs/Makefile Sun Mar 16 01:55:30 2014 (r263219) +++ head/sbin/growfs/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -6,6 +6,8 @@ #GFSDBG= +.include + .PATH: ${.CURDIR}/../mount PROG= growfs @@ -20,4 +22,8 @@ SRCS+= debug.c DPADD= ${LIBUTIL} LDADD= -lutil +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include Modified: head/sbin/growfs/tests/Makefile ============================================================================== --- head/tools/regression/sbin/growfs/Makefile Sun Mar 16 00:57:26 2014 (r263215) +++ head/sbin/growfs/tests/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -1,6 +1,7 @@ # $FreeBSD$ -all test: - prove -vmw regress.t +TESTSDIR= ${TESTSBASE}/sbin/growfs -clean: +TAP_TESTS_PERL= legacy_test + +.include Copied and modified: head/sbin/growfs/tests/legacy_test.pl (from r263215, head/tools/regression/sbin/growfs/regress.t) ============================================================================== --- head/tools/regression/sbin/growfs/regress.t Sun Mar 16 00:57:26 2014 (r263215, copy source) +++ head/sbin/growfs/tests/legacy_test.pl Sun Mar 16 02:07:08 2014 (r263220) @@ -1,5 +1,3 @@ -#! /usr/bin/perl -# # $FreeBSD$ use strict; Modified: head/sbin/mdconfig/Makefile ============================================================================== --- head/sbin/mdconfig/Makefile Sun Mar 16 01:55:30 2014 (r263219) +++ head/sbin/mdconfig/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -1,9 +1,15 @@ # $FreeBSD$ +.include + PROG= mdconfig MAN= mdconfig.8 DPADD= ${LIBUTIL} ${LIBGEOM} ${LIBBSDXML} ${LIBSBUF} LDADD= -lutil -lgeom -lbsdxml -lsbuf +.if ${MK_TESTS} != "no" +SUBDIR+= tests +.endif + .include Copied and modified: head/sbin/mdconfig/tests/legacy_test.sh (from r263215, head/tools/regression/sbin/mdconfig/00.t) ============================================================================== --- head/tools/regression/sbin/mdconfig/00.t Sun Mar 16 00:57:26 2014 (r263215, copy source) +++ head/sbin/mdconfig/tests/legacy_test.sh Sun Mar 16 02:07:08 2014 (r263220) @@ -38,7 +38,7 @@ fi TESTDIR=$(dirname $(realpath $0)) -perl $TESTDIR/run $TESTDIR/mdconfig.test > /dev/null +__PERL__ -w -U $TESTDIR/run $TESTDIR/mdconfig.test > /dev/null if [ $? -eq 0 ]; then echo "ok 1" Copied: head/sbin/mdconfig/tests/run.pl (from r263215, head/tools/regression/sbin/mdconfig/run) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sbin/mdconfig/tests/run.pl Sun Mar 16 02:07:08 2014 (r263220, copy of r263215, head/tools/regression/sbin/mdconfig/run) @@ -0,0 +1,329 @@ +#!/usr/bin/perl -w -U + +# Copyright (c) 2007, 2008 Andreas Gruenbacher. +# All rights reserved. +# +# 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, +# without modification, immediately at the beginning of the file. +# 2. The name of the author may not be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# Alternatively, this software may be distributed under the terms of the +# GNU Public License ("GPL"). +# +# 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$ +# + +# +# Possible improvements: +# +# - distinguish stdout and stderr output +# - add environment variable like assignments +# - run up to a specific line +# - resume at a specific line +# + +use strict; +use FileHandle; +use Getopt::Std; +use POSIX qw(isatty setuid getcwd); +use vars qw($opt_l $opt_v); + +no warnings qw(taint); + +$opt_l = ~0; # a really huge number +getopts('l:v'); + +my ($OK, $FAILED) = ("ok", "failed"); +if (isatty(fileno(STDOUT))) { + $OK = "\033[32m" . $OK . "\033[m"; + $FAILED = "\033[31m\033[1m" . $FAILED . "\033[m"; +} + +sub exec_test($$); +sub process_test($$$$); + +my ($prog, $in, $out) = ([], [], []); +my $prog_line = 0; +my ($tests, $failed) = (0,0); +my $lineno; +my $width = ($ENV{COLUMNS} || 80) >> 1; + +for (;;) { + my $line = <>; $lineno++; + if (defined $line) { + # Substitute %VAR and %{VAR} with environment variables. + $line =~ s[%(\w+)][$ENV{$1}]eg; + $line =~ s[%{(\w+)}][$ENV{$1}]eg; + } + if (defined $line) { + if ($line =~ s/^\s*< ?//) { + push @$in, $line; + } elsif ($line =~ s/^\s*> ?//) { + push @$out, $line; + } else { + process_test($prog, $prog_line, $in, $out); + last if $prog_line >= $opt_l; + + $prog = []; + $prog_line = 0; + } + if ($line =~ s/^\s*\$ ?//) { + $prog = [ map { s/\\(.)/$1/g; $_ } split /(? @$result) ? @$out : @$result; + for (my $n=0; $n < $nmax; $n++) { + my $use_re; + if (defined $out->[$n] && $out->[$n] =~ /^~ /) { + $use_re = 1; + $out->[$n] =~ s/^~ //g; + } + + if (!defined($out->[$n]) || !defined($result->[$n]) || + (!$use_re && $result->[$n] ne $out->[$n]) || + ( $use_re && $result->[$n] !~ /^$out->[$n]/)) { + push @good, ($use_re ? '!~' : '!='); + } + else { + push @good, ($use_re ? '=~' : '=='); + } + } + my $good = !(grep /!/, @good); + $tests++; + $failed++ unless $good; + print $good ? $OK : $FAILED, "\n"; + if (!$good || $opt_v) { + for (my $n=0; $n < $nmax; $n++) { + my $l = defined($out->[$n]) ? $out->[$n] : "~"; + chomp $l; + my $r = defined($result->[$n]) ? $result->[$n] : "~"; + chomp $r; + print sprintf("%-" . ($width-3) . "s %s %s\n", + $r, $good[$n], $l); + } + } +} + + +sub su($) { + my ($user) = @_; + + $user ||= "root"; + + my ($login, $pass, $uid, $gid) = getpwnam($user) + or return [ "su: user $user does not exist\n" ]; + my @groups = (); + my $fh = new FileHandle("/etc/group") + or return [ "opening /etc/group: $!\n" ]; + while (<$fh>) { + chomp; + my ($group, $passwd, $gid, $users) = split /:/; + foreach my $u (split /,/, $users) { + push @groups, $gid + if ($user eq $u); + } + } + $fh->close; + + my $groups = join(" ", ($gid, $gid, @groups)); + #print STDERR "[[$groups]]\n"; + $! = 0; # reset errno + $> = 0; + $( = $gid; + $) = $groups; + if ($!) { + return [ "su: $!\n" ]; + } + if ($uid != 0) { + $> = $uid; + #$< = $uid; + if ($!) { + return [ "su: $prog->[1]: $!\n" ]; + } + } + #print STDERR "[($>,$<)($(,$))]"; + return []; +} + + +sub sg($) { + my ($group) = @_; + + my $gid = getgrnam($group) + or return [ "sg: group $group does not exist\n" ]; + my %groups = map { $_ eq $gid ? () : ($_ => 1) } (split /\s/, $)); + + #print STDERR "<<", join("/", keys %groups), ">>\n"; + my $groups = join(" ", ($gid, $gid, keys %groups)); + #print STDERR "[[$groups]]\n"; + $! = 0; # reset errno + if ($> != 0) { + my $uid = $>; + $> = 0; + $( = $gid; + $) = $groups; + $> = $uid; + } else { + $( = $gid; + $) = $groups; + } + if ($!) { + return [ "sg: $!\n" ]; + } + print STDERR "[($>,$<)($(,$))]"; + return []; +} + + +sub exec_test($$) { + my ($prog, $in) = @_; + local (*IN, *IN_DUP, *IN2, *OUT_DUP, *OUT, *OUT2); + my $needs_shell = (join('', @$prog) =~ /[][|<>"'`\$\*\?]/); + + if ($prog->[0] eq "umask") { + umask oct $prog->[1]; + return []; + } elsif ($prog->[0] eq "cd") { + if (!chdir $prog->[1]) { + return [ "chdir: $prog->[1]: $!\n" ]; + } + $ENV{PWD} = getcwd; + return []; + } elsif ($prog->[0] eq "su") { + return su($prog->[1]); + } elsif ($prog->[0] eq "sg") { + return sg($prog->[1]); + } elsif ($prog->[0] eq "export") { + my ($name, $value) = split /=/, $prog->[1]; + # FIXME: need to evaluate $value, so that things like this will work: + # export dir=$PWD/dir + $ENV{$name} = $value; + return []; + } elsif ($prog->[0] eq "unset") { + delete $ENV{$prog->[1]}; + return []; + } + + pipe *IN2, *OUT + or die "Can't create pipe for reading: $!"; + open *IN_DUP, "<&STDIN" + or *IN_DUP = undef; + open *STDIN, "<&IN2" + or die "Can't duplicate pipe for reading: $!"; + close *IN2; + + open *OUT_DUP, ">&STDOUT" + or die "Can't duplicate STDOUT: $!"; + pipe *IN, *OUT2 + or die "Can't create pipe for writing: $!"; + open *STDOUT, ">&OUT2" + or die "Can't duplicate pipe for writing: $!"; + close *OUT2; + + *STDOUT->autoflush(); + *OUT->autoflush(); + + $SIG{CHLD} = 'IGNORE'; + + if (fork()) { + # Server + if (*IN_DUP) { + open *STDIN, "<&IN_DUP" + or die "Can't duplicate STDIN: $!"; + close *IN_DUP + or die "Can't close STDIN duplicate: $!"; + } + open *STDOUT, ">&OUT_DUP" + or die "Can't duplicate STDOUT: $!"; + close *OUT_DUP + or die "Can't close STDOUT duplicate: $!"; + + foreach my $line (@$in) { + #print "> $line"; + print OUT $line; + } + close *OUT + or die "Can't close pipe for writing: $!"; + + my $result = []; + while () { + #print "< $_"; + if ($needs_shell) { + s#^/bin/sh: line \d+: ##; + } + push @$result, $_; + } + return $result; + } else { + # Client + $< = $>; + close IN + or die "Can't close read end for input pipe: $!"; + close OUT + or die "Can't close write end for output pipe: $!"; + close OUT_DUP + or die "Can't close STDOUT duplicate: $!"; + local *ERR_DUP; + open ERR_DUP, ">&STDERR" + or die "Can't duplicate STDERR: $!"; + open STDERR, ">&STDOUT" + or die "Can't join STDOUT and STDERR: $!"; + + if ($needs_shell) { + exec ('/bin/sh', '-c', join(" ", @$prog)); + } else { + exec @$prog; + } + print STDERR $prog->[0], ": $!\n"; + exit; + } +} + Added: head/sbin/tests/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sbin/tests/Makefile Sun Mar 16 02:07:08 2014 (r263220) @@ -0,0 +1,10 @@ +# $FreeBSD$ + +.include + +TESTSDIR= ${TESTSBASE}/sbin + +.PATH: ${.CURDIR:H:H}/tests +KYUAFILE= yes + +.include