head	1.4;
access;
symbols
	RELENG_8_4:1.4.0.2
	RELENG_9_1_0_RELEASE:1.3.16.1.4.2
	RELENG_9_1:1.3.16.1.0.4
	RELENG_9_1_BP:1.3.16.1
	RELENG_8_3_0_RELEASE:1.3.10.1.8.1
	RELENG_8_3:1.3.10.1.0.8
	RELENG_8_3_BP:1.3.10.1
	RELENG_9_0_0_RELEASE:1.3.16.1.2.1
	RELENG_9_0:1.3.16.1.0.2
	RELENG_9_0_BP:1.3.16.1
	RELENG_9:1.3.0.16
	RELENG_9_BP:1.3
	RELENG_7_4_0_RELEASE:1.3.14.1
	RELENG_8_2_0_RELEASE:1.3.10.1.6.1
	RELENG_7_4:1.3.0.14
	RELENG_7_4_BP:1.3
	RELENG_8_2:1.3.10.1.0.6
	RELENG_8_2_BP:1.3.10.1
	RELENG_8_1_0_RELEASE:1.3.10.1.4.1
	RELENG_8_1:1.3.10.1.0.4
	RELENG_8_1_BP:1.3.10.1
	RELENG_7_3_0_RELEASE:1.3.12.1
	RELENG_7_3:1.3.0.12
	RELENG_7_3_BP:1.3
	RELENG_8_0_0_RELEASE:1.3.10.1.2.1
	RELENG_8_0:1.3.10.1.0.2
	RELENG_8_0_BP:1.3.10.1
	RELENG_8:1.3.0.10
	RELENG_8_BP:1.3
	RELENG_7_2_0_RELEASE:1.3.8.1
	RELENG_7_2:1.3.0.8
	RELENG_7_2_BP:1.3
	RELENG_7_1_0_RELEASE:1.3.6.1
	RELENG_7_1:1.3.0.6
	RELENG_7_1_BP:1.3
	RELENG_7_0_0_RELEASE:1.3
	RELENG_7_0:1.3.0.4
	RELENG_7_0_BP:1.3
	RELENG_7:1.3.0.2
	RELENG_7_BP:1.3
	old_RELENG_6_2_0_RELEASE:1.2
	old_RELENG_6_2:1.2.0.22
	old_RELENG_6_2_BP:1.2
	old_RELENG_5_5_0_RELEASE:1.2
	old_RELENG_5_5:1.2.0.20
	old_RELENG_5_5_BP:1.2
	old_RELENG_6_1_0_RELEASE:1.2
	old_RELENG_6_1:1.2.0.18
	old_RELENG_6_1_BP:1.2
	old_RELENG_6_0_0_RELEASE:1.2
	old_RELENG_6_0:1.2.0.16
	old_RELENG_6_0_BP:1.2
	old_RELENG_6:1.2.0.14
	old_RELENG_6_BP:1.2
	old_RELENG_5_4_0_RELEASE:1.2
	old_RELENG_5_4:1.2.0.12
	old_RELENG_5_4_BP:1.2
	old_RELENG_5_3_0_RELEASE:1.2
	old_RELENG_5_3:1.2.0.10
	old_RELENG_5_3_BP:1.2
	old_RELENG_5:1.2.0.8
	old_RELENG_5_BP:1.2
	old_RELENG_5_2_1_RELEASE:1.2
	old_RELENG_5_2_0_RELEASE:1.2
	old_RELENG_5_2:1.2.0.6
	old_RELENG_5_2_BP:1.2
	old_RELENG_5_1_0_RELEASE:1.2
	old_RELENG_5_1:1.2.0.4
	old_RELENG_5_1_BP:1.2
	old_RELENG_5_0_0_RELEASE:1.2
	old_RELENG_5_0:1.2.0.2
	old_RELENG_5_0_BP:1.2
	old_old_RELENG_4_6_2_RELEASE:1.1.2.2
	old_old_RELENG_4_6_1_RELEASE:1.1.2.2
	old_old_RELENG_4_6_0_RELEASE:1.1.2.2
	old_old_RELENG_4_6:1.1.2.2.0.6
	old_old_RELENG_4_6_BP:1.1.2.2
	old_old_RELENG_4_5_0_RELEASE:1.1.2.2
	old_old_RELENG_4_5:1.1.2.2.0.4
	old_old_RELENG_4_5_BP:1.1.2.2
	old_old_RELENG_4_4_0_RELEASE:1.1.2.2
	old_old_RELENG_4_4:1.1.2.2.0.2
	old_old_RELENG_4_4_BP:1.1.2.2
	old_old_RELENG_4_3_0_RELEASE:1.1.2.1
	old_old_RELENG_4_3:1.1.2.1.0.2
	old_old_RELENG_4_3_BP:1.1.2.1
	old_old_RELENG_4_2_0_RELEASE:1.1.2.1
	old_old_RELENG_4_1_1_RELEASE:1.1.2.1
	old_old_PRE_SMPNG:1.1
	old_old_RELENG_4_1_0_RELEASE:1.1.2.1
	old_old_RELENG_4:1.1.0.2;
locks; strict;
comment	@# @;


1.4
date	2012.11.17.01.49.54;	author svnexp;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2007.10.09.13.42.26;	author obrien;	state Exp;
branches
	1.3.2.1
	1.3.6.1
	1.3.8.1
	1.3.10.1
	1.3.12.1
	1.3.14.1
	1.3.16.1;
next	1.2;

1.2
date	2001.05.20.23.11.54;	author jasone;	state Exp;
branches;
next	1.1;

1.1
date	2000.04.24.21.07.40;	author jasone;	state Exp;
branches
	1.1.2.1;
next	;

1.4.2.1
date	2012.11.17.01.49.54;	author svnexp;	state dead;
branches;
next	1.4.2.2;

1.4.2.2
date	2013.03.28.13.03.17;	author svnexp;	state Exp;
branches;
next	;

1.3.2.1
date	2012.11.17.08.02.50;	author svnexp;	state Exp;
branches;
next	;

1.3.6.1
date	2008.11.25.02.59.29;	author kensmith;	state Exp;
branches;
next	;

1.3.8.1
date	2009.04.15.03.14.26;	author kensmith;	state Exp;
branches;
next	;

1.3.10.1
date	2009.08.03.08.13.06;	author kensmith;	state Exp;
branches
	1.3.10.1.2.1
	1.3.10.1.4.1
	1.3.10.1.6.1
	1.3.10.1.8.1;
next	1.3.10.2;

1.3.10.2
date	2012.11.17.10.36.08;	author svnexp;	state Exp;
branches;
next	;

1.3.10.1.2.1
date	2009.10.25.01.10.29;	author kensmith;	state Exp;
branches;
next	;

1.3.10.1.4.1
date	2010.06.14.02.09.06;	author kensmith;	state Exp;
branches;
next	;

1.3.10.1.6.1
date	2010.12.21.17.09.25;	author kensmith;	state Exp;
branches;
next	;

1.3.10.1.8.1
date	2012.03.03.06.15.13;	author kensmith;	state Exp;
branches;
next	1.3.10.1.8.2;

1.3.10.1.8.2
date	2012.11.17.08.24.49;	author svnexp;	state Exp;
branches;
next	;

1.3.12.1
date	2010.02.10.00.26.20;	author kensmith;	state Exp;
branches;
next	;

1.3.14.1
date	2010.12.21.17.10.29;	author kensmith;	state Exp;
branches;
next	1.3.14.2;

1.3.14.2
date	2012.11.17.08.16.48;	author svnexp;	state Exp;
branches;
next	;

1.3.16.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches
	1.3.16.1.2.1
	1.3.16.1.4.1;
next	1.3.16.2;

1.3.16.2
date	2012.11.17.11.36.24;	author svnexp;	state Exp;
branches;
next	;

1.3.16.1.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.3.16.1.2.2;

1.3.16.1.2.2
date	2012.11.17.08.36.24;	author svnexp;	state Exp;
branches;
next	;

1.3.16.1.4.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.3.16.1.4.2;

1.3.16.1.4.2
date	2012.11.17.08.47.14;	author svnexp;	state Exp;
branches;
next	;

1.1.2.1
date	2000.07.17.22.18.33;	author jasone;	state Exp;
branches;
next	1.1.2.2;

1.1.2.2
date	2001.06.22.21.44.27;	author jasone;	state Exp;
branches;
next	;


desc
@@


1.4
log
@Switching exporter and resync
@
text
@#!/usr/bin/perl -w
#-*-mode:perl-*-
#############################################################################
#
# Copyright (C) 1999-2001 Jason Evans <jasone@@freebsd.org>.
# 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(s), this list of conditions and the following disclaimer as
#    the first lines of this file unmodified other than the possible
#    addition of one or more copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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.
#
#############################################################################
#
# Test harness.
#
# $FreeBSD: head/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
#
#############################################################################

# Shut off buffering.
select(STDOUT);
$| = 1;

#
# Parse command-line arguments.
#
use Getopt::Long;
Getopt::Long::config("bundling"); # Allow -hv rather than forcing -h -v.

# Set option defaults for optional arguments.
$opt_help = 0;
$opt_verbose = 0;
$opt_quiet = 0;
$opt_srcdir = ".";
$opt_objdir = ".";
$opt_ustats = 0;
$opt_zero = 0;

$opt_retval =
&GetOptions("h|help" => \$opt_help,
	    "v|verbose" => \$opt_verbose,
	    "q|quiet" => \$opt_quiet,
	    "s|srcdir=s" => \$opt_srcdir,
            "o|objdir=s" => \$opt_objdir,
	    "u|ustats" => \$opt_ustats,
	    "z|zero" => \$opt_zero
	    );

if ($opt_help)
{
    &usage();
    exit(0);
}

if ($opt_retval == 0)
{
    &usage();
    exit 1;
}

if ($opt_verbose && $opt_quiet)
{
    print STDERR "-v and -q are incompatible\n";
    &usage();
    exit 1;
}

if ($#ARGV + 1 == 0)
{
    print STDERR "No tests specified\n";
    &usage();
    exit 1;
}

if ($opt_verbose)
{
    print STDERR "Option values: h:$opt_help, v:$opt_verbose, "
	. "s:\"$opt_srcdir\", o:\"$opt_objdir\" "
	. "q:$opt_quiet, u:$opt_ustats, z:$opt_zero\n";
    printf STDERR "Tests (%d total): @@ARGV\n", $#ARGV + 1;
}

#
# Create and print header.
#
@@TSTATS =
(
 "--------------------------------------------------------------------------\n",
 "Test                                      c_user c_system c_total     chng\n",
 " passed/FAILED                            h_user h_system h_total   %% chng\n"
 );

if (!$opt_quiet)
{
    foreach $line (@@TSTATS)
    {
	printf STDOUT "$line";
    }
}

#
# Run sequence test(s).
#
$total_utime = 0.0; # Total user time.
$total_stime = 0.0; # Total system time.
$total_hutime = 0.0; # Total historical user time.
$total_hstime = 0.0; # Total historical system time.
$total_ntime = 0.0; # Total time for tests that have historical data.

foreach $test (@@ARGV)
{
    # Strip out any whitespace in $test.
    $test =~ s/^\s*(.*)\s*$/$1/;

    $okay = 1;

    if (-e "$opt_srcdir/$test.exp")
    {
	# Diff mode.

	($okay, $utime, $stime) = &run_test($test);

	if (-e "$opt_objdir/$test.out")
	{
	    `diff $opt_srcdir/$test.exp $opt_objdir/$test.out > $opt_objdir/$test.diff 2>&1`;
	    if ($?)
	    {
		# diff returns non-zero if there is a difference.
		$okay = 0;
	    }
	}
	else
	{
	    $okay = 0;
	    if ($opt_verbose)
	    {
		print STDERR
		    "Nonexistent output file \"$opt_objdir/$test.out\"\n";
	    }
	}

	($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
    }
    else
    {
	# Sequence mode.

	($okay, $utime, $stime) = &run_test($test);

	if (open (STEST_OUT, "<$opt_objdir/$test.out"))
	{
	    $num_subtests = 0;
	    $num_failed_subtests = 0;

	    while (defined($line = <STEST_OUT>))
	    {
		if ($line =~ /1\.\.(\d+)/)
		{
		    $num_subtests = $1;
		    last;
		}
	    }
	    if ($num_subtests == 0)
	    {
		$okay = 0;
		if ($opt_verbose)
		{
		    print STDERR "Malformed or missing 1..n line\n";
		}
	    }
	    else
	    {
		for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
		{
		    while (defined($line = <STEST_OUT>))
		    {
			if ($line =~ /^not\s+ok\s+(\d+)?/)
			{
			    $not = 1;
			    $test_num = $1;
			    last;
			}
			elsif ($line =~ /^ok\s+(\d+)?/)
			{
			    $not = 0;
			    $test_num = $1;
			    last;
			}
		    }
		    if (defined($line))
		    {
			if (defined($test_num) && ($test_num != $subtest))
			{
			    # There was no output printed for one or more tests.
			    for (; $subtest < $test_num; $subtest++)
			    {
				$num_failed_subtests++;
			    }
			}
			if ($not)
			{
			    $num_failed_subtests++;
			}
		    }
		    else
		    {
			for (; $subtest <= $num_subtests; $subtest++)
			{
			    $num_failed_subtests++;
			}
		    }
		}

		if (0 < $num_failed_subtests)
		{
		    $okay = 0;
		}
	    }
	}
	else
	{
	    if (!$opt_quiet)
	    {
		print STDERR "Cannot open output file \"$opt_objdir/$test.out\"\n";
	    }
	    exit 1;
	}

	($hutime, $hstime) = &print_stats($test, $okay,
					  $num_failed_subtests, $num_subtests,
					  $utime, $stime);
    }

    $total_hutime += $hutime;
    $total_hstime += $hstime;

    if ($okay)
    {
	$total_utime += $utime;
	$total_stime += $stime;
    }
    else
    {
	@@FAILED_TESTS = (@@FAILED_TESTS, $test);
    }

    # If there were historical data, add the run time to the total time to 
    # compare against the historical run time.
    if (0 < ($hutime + $hstime))
    {
	$total_ntime += $utime + $stime;
    }
}

# Print summary stats.
$tt_str = sprintf ("%d / %d passed (%5.2f%%%%)",
		   ($#ARGV + 1) - ($#FAILED_TESTS + 1),
		   $#ARGV + 1,
		   (($#ARGV + 1) - ($#FAILED_TESTS + 1))
		   / ($#ARGV + 1) * 100);

$t_str = sprintf ("Totals                                   %7.2f  %7.2f %7.2f"
                  . "  %7.2f\n"
		  . " %s %7.2f  %7.2f %7.2f %7.2f%%%%\n",
		  $total_utime, $total_stime, $total_utime + $total_stime,
		  ($total_ntime - ($total_hutime + $total_hstime)),
		  $tt_str . ' ' x (40 - length($tt_str)),
		  $total_hutime, $total_hstime, $total_hutime + $total_hstime,
		  ($total_hutime + $total_hstime == 0.0) ? 0.0 :
		  (($total_ntime
		    - ($total_hutime + $total_hstime))
		   / ($total_hutime + $total_hstime) * 100));

@@TSTATS = ("--------------------------------------------------------------------------\n",
	   $t_str,
	   "--------------------------------------------------------------------------\n"
	   );
if (!$opt_quiet)
{
    foreach $line (@@TSTATS)
    {
	printf STDOUT "$line";
    }
}

if ($#FAILED_TESTS >= 0)
{
    # One or more tests failed, so return an error.
    exit 1;
}
# End of main execution.

sub run_test
{
    my ($test) = @@_;
    my ($okay) = 1;
    my ($tutime, $tstime);
    my ($utime, $stime, $cutime, $cstime);
    my (@@TSTATS, @@TPATH);
    my ($t_str);
    my ($srcdir, $objdir);

    # Get the path component of $test, if any.
    @@TPATH = split(/\//, $test);
    pop(@@TPATH);
    $srcdir = join('/', ($opt_srcdir, @@TPATH));
    $objdir = join('/', ($opt_objdir, @@TPATH));

    @@TSTATS = ("--------------------------------------------------------------------------\n");

    $t_str = sprintf ("%s%s", $test, ' ' x (40 - length($test)));
    @@TSTATS = (@@TSTATS, $t_str);
    @@STATS = (@@STATS, @@TSTATS);
    if (!$opt_quiet)
    {
	foreach $line (@@TSTATS)
	{
	    printf STDOUT "$line";
	}
    }

    ($utime, $stime, $cutime, $cstime) = times;
    `$opt_objdir/$test $srcdir $objdir > $opt_objdir/$test.out 2>&1`;
    ($utime, $stime, $tutime, $tstime) = times;

    # Subtract the before time from the after time.
    $tutime -= $cutime;
    $tstime -= $cstime;

    if ($opt_zero)
    {
	if ($?)
	{
	    $okay = 0;
	    if ($opt_verbose)
	    {
		print STDERR
		    "\"$opt_objdir/$test > $opt_objdir/$test.out 2>&1\" returned $?\n";
	    }
	}
    }

    return ($okay, $tutime, $tstime);
}

sub print_stats
{
    my ($test, $okay, $failed_subtests, $subtests, $utime, $stime) = @@_;
    my ($hutime, $hstime);
#    my (TEST_PERF);
    my (@@TSTATS);
    my ($t_str, $pass_str);

    $pass_str = $okay ? "passed" : "*** FAILED ***";
    if ((0 != $subtests) && (!$okay))
    {
	$pass_str = $pass_str . " ($failed_subtests/$subtests failed)";
    }
    $pass_str = $pass_str . ' ' x (39 - length($pass_str));
    
    if (-r "$test.perf")
    {
	if (!open (TEST_PERF, "<$opt_objdir/$test.perf"))
	{
	    print STDERR "Unable to open \"$opt_objdir/$test.perf\"\n";
	    exit 1;
	}
	$_ = <TEST_PERF>;

	($hutime, $hstime) = split;
	close TEST_PERF;

	$t_str = sprintf (" %7.2f  %7.2f %7.2f  %7.2f\n"
			  . " %s %7.2f  %7.2f %7.2f %7.2f%%%%\n",
			  $utime, $stime, $utime + $stime,
			  ($utime + $stime) - ($hutime + $hstime),
			  $pass_str,
			  $hutime, $hstime, $hutime + $hstime,
			  (($hutime + $hstime) == 0.0) ? 0.0 :
			  ((($utime + $stime) - ($hutime + $hstime))
			   / ($hutime + $hstime) * 100));
    }
    else
    {
	$hutime = 0.0;
	$hstime = 0.0;

	$t_str = sprintf (" %7.2f  %7.2f %7.2f        \n"
			  . " %s\n",
			  $utime, $stime, $utime + $stime,
			  $pass_str);
    }
    @@TSTATS = ($t_str);
    if (!$opt_quiet)
    {
	foreach $line (@@TSTATS)
	{
	    printf STDOUT "$line";
	}
    }

    if ($okay && $opt_ustats)
    {
	if (!open (TEST_PERF, ">$opt_objdir/$test.perf"))
	{
	    if (!$opt_quiet)
	    {
		print STDERR "Unable to update \"$opt_objdir/$test.perf\"\n";
	    }
	}
	else
	{
	    print TEST_PERF "$utime $stime\n";
	    close TEST_PERF;
	}
    }

    return ($hutime, $hstime);
}

sub usage
{
    print <<EOF;
$0 usage:
    $0 [<options>] <test>+

    Option        | Description
    --------------+-------------------------------------------------------------
    -h --help     | Print usage and exit.
    -v --verbose  | Verbose (incompatible with quiet).
    -q --quiet    | Quiet (incompatible with verbose).
    -s --srcdir   | Path to source tree (default is ".").
    -o --objdir   | Path to object tree (default is ".").
    -u --ustats   | Update historical statistics (stored in "<test>.perf".
    -z --zero     | Consider non-zero exit code to be an error.
    --------------+-------------------------------------------------------------

    If <test>.exp exists, <test>'s output is diff'ed with <test>.exp.  Any
    difference is considered failure.

    If <test>.exp does not exist, output to stdout of the following form is
    expected:

        1..<n>
        {not }ok[ 1]
        {not }ok[ 2]
        ...
        {not }ok[ n]

    1 <= <n> < 2^31

    Lines which do not match the patterns shown above are ignored.
EOF
}
@


1.4.2.1
log
@file verify was added on branch RELENG_8_4 on 2013-03-28 13:03:17 +0000
@
text
@d1 474
@


1.4.2.2
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/248810
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@a0 474
#!/usr/bin/perl -w
#-*-mode:perl-*-
#############################################################################
#
# Copyright (C) 1999-2001 Jason Evans <jasone@@freebsd.org>.
# 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(s), this list of conditions and the following disclaimer as
#    the first lines of this file unmodified other than the possible
#    addition of one or more copyright notices.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice(s), 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 COPYRIGHT HOLDER(S) ``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 COPYRIGHT HOLDER(S) 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.
#
#############################################################################
#
# Test harness.
#
# $FreeBSD: releng/8.4/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
#
#############################################################################

# Shut off buffering.
select(STDOUT);
$| = 1;

#
# Parse command-line arguments.
#
use Getopt::Long;
Getopt::Long::config("bundling"); # Allow -hv rather than forcing -h -v.

# Set option defaults for optional arguments.
$opt_help = 0;
$opt_verbose = 0;
$opt_quiet = 0;
$opt_srcdir = ".";
$opt_objdir = ".";
$opt_ustats = 0;
$opt_zero = 0;

$opt_retval =
&GetOptions("h|help" => \$opt_help,
	    "v|verbose" => \$opt_verbose,
	    "q|quiet" => \$opt_quiet,
	    "s|srcdir=s" => \$opt_srcdir,
            "o|objdir=s" => \$opt_objdir,
	    "u|ustats" => \$opt_ustats,
	    "z|zero" => \$opt_zero
	    );

if ($opt_help)
{
    &usage();
    exit(0);
}

if ($opt_retval == 0)
{
    &usage();
    exit 1;
}

if ($opt_verbose && $opt_quiet)
{
    print STDERR "-v and -q are incompatible\n";
    &usage();
    exit 1;
}

if ($#ARGV + 1 == 0)
{
    print STDERR "No tests specified\n";
    &usage();
    exit 1;
}

if ($opt_verbose)
{
    print STDERR "Option values: h:$opt_help, v:$opt_verbose, "
	. "s:\"$opt_srcdir\", o:\"$opt_objdir\" "
	. "q:$opt_quiet, u:$opt_ustats, z:$opt_zero\n";
    printf STDERR "Tests (%d total): @@ARGV\n", $#ARGV + 1;
}

#
# Create and print header.
#
@@TSTATS =
(
 "--------------------------------------------------------------------------\n",
 "Test                                      c_user c_system c_total     chng\n",
 " passed/FAILED                            h_user h_system h_total   %% chng\n"
 );

if (!$opt_quiet)
{
    foreach $line (@@TSTATS)
    {
	printf STDOUT "$line";
    }
}

#
# Run sequence test(s).
#
$total_utime = 0.0; # Total user time.
$total_stime = 0.0; # Total system time.
$total_hutime = 0.0; # Total historical user time.
$total_hstime = 0.0; # Total historical system time.
$total_ntime = 0.0; # Total time for tests that have historical data.

foreach $test (@@ARGV)
{
    # Strip out any whitespace in $test.
    $test =~ s/^\s*(.*)\s*$/$1/;

    $okay = 1;

    if (-e "$opt_srcdir/$test.exp")
    {
	# Diff mode.

	($okay, $utime, $stime) = &run_test($test);

	if (-e "$opt_objdir/$test.out")
	{
	    `diff $opt_srcdir/$test.exp $opt_objdir/$test.out > $opt_objdir/$test.diff 2>&1`;
	    if ($?)
	    {
		# diff returns non-zero if there is a difference.
		$okay = 0;
	    }
	}
	else
	{
	    $okay = 0;
	    if ($opt_verbose)
	    {
		print STDERR
		    "Nonexistent output file \"$opt_objdir/$test.out\"\n";
	    }
	}

	($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
    }
    else
    {
	# Sequence mode.

	($okay, $utime, $stime) = &run_test($test);

	if (open (STEST_OUT, "<$opt_objdir/$test.out"))
	{
	    $num_subtests = 0;
	    $num_failed_subtests = 0;

	    while (defined($line = <STEST_OUT>))
	    {
		if ($line =~ /1\.\.(\d+)/)
		{
		    $num_subtests = $1;
		    last;
		}
	    }
	    if ($num_subtests == 0)
	    {
		$okay = 0;
		if ($opt_verbose)
		{
		    print STDERR "Malformed or missing 1..n line\n";
		}
	    }
	    else
	    {
		for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
		{
		    while (defined($line = <STEST_OUT>))
		    {
			if ($line =~ /^not\s+ok\s+(\d+)?/)
			{
			    $not = 1;
			    $test_num = $1;
			    last;
			}
			elsif ($line =~ /^ok\s+(\d+)?/)
			{
			    $not = 0;
			    $test_num = $1;
			    last;
			}
		    }
		    if (defined($line))
		    {
			if (defined($test_num) && ($test_num != $subtest))
			{
			    # There was no output printed for one or more tests.
			    for (; $subtest < $test_num; $subtest++)
			    {
				$num_failed_subtests++;
			    }
			}
			if ($not)
			{
			    $num_failed_subtests++;
			}
		    }
		    else
		    {
			for (; $subtest <= $num_subtests; $subtest++)
			{
			    $num_failed_subtests++;
			}
		    }
		}

		if (0 < $num_failed_subtests)
		{
		    $okay = 0;
		}
	    }
	}
	else
	{
	    if (!$opt_quiet)
	    {
		print STDERR "Cannot open output file \"$opt_objdir/$test.out\"\n";
	    }
	    exit 1;
	}

	($hutime, $hstime) = &print_stats($test, $okay,
					  $num_failed_subtests, $num_subtests,
					  $utime, $stime);
    }

    $total_hutime += $hutime;
    $total_hstime += $hstime;

    if ($okay)
    {
	$total_utime += $utime;
	$total_stime += $stime;
    }
    else
    {
	@@FAILED_TESTS = (@@FAILED_TESTS, $test);
    }

    # If there were historical data, add the run time to the total time to 
    # compare against the historical run time.
    if (0 < ($hutime + $hstime))
    {
	$total_ntime += $utime + $stime;
    }
}

# Print summary stats.
$tt_str = sprintf ("%d / %d passed (%5.2f%%%%)",
		   ($#ARGV + 1) - ($#FAILED_TESTS + 1),
		   $#ARGV + 1,
		   (($#ARGV + 1) - ($#FAILED_TESTS + 1))
		   / ($#ARGV + 1) * 100);

$t_str = sprintf ("Totals                                   %7.2f  %7.2f %7.2f"
                  . "  %7.2f\n"
		  . " %s %7.2f  %7.2f %7.2f %7.2f%%%%\n",
		  $total_utime, $total_stime, $total_utime + $total_stime,
		  ($total_ntime - ($total_hutime + $total_hstime)),
		  $tt_str . ' ' x (40 - length($tt_str)),
		  $total_hutime, $total_hstime, $total_hutime + $total_hstime,
		  ($total_hutime + $total_hstime == 0.0) ? 0.0 :
		  (($total_ntime
		    - ($total_hutime + $total_hstime))
		   / ($total_hutime + $total_hstime) * 100));

@@TSTATS = ("--------------------------------------------------------------------------\n",
	   $t_str,
	   "--------------------------------------------------------------------------\n"
	   );
if (!$opt_quiet)
{
    foreach $line (@@TSTATS)
    {
	printf STDOUT "$line";
    }
}

if ($#FAILED_TESTS >= 0)
{
    # One or more tests failed, so return an error.
    exit 1;
}
# End of main execution.

sub run_test
{
    my ($test) = @@_;
    my ($okay) = 1;
    my ($tutime, $tstime);
    my ($utime, $stime, $cutime, $cstime);
    my (@@TSTATS, @@TPATH);
    my ($t_str);
    my ($srcdir, $objdir);

    # Get the path component of $test, if any.
    @@TPATH = split(/\//, $test);
    pop(@@TPATH);
    $srcdir = join('/', ($opt_srcdir, @@TPATH));
    $objdir = join('/', ($opt_objdir, @@TPATH));

    @@TSTATS = ("--------------------------------------------------------------------------\n");

    $t_str = sprintf ("%s%s", $test, ' ' x (40 - length($test)));
    @@TSTATS = (@@TSTATS, $t_str);
    @@STATS = (@@STATS, @@TSTATS);
    if (!$opt_quiet)
    {
	foreach $line (@@TSTATS)
	{
	    printf STDOUT "$line";
	}
    }

    ($utime, $stime, $cutime, $cstime) = times;
    `$opt_objdir/$test $srcdir $objdir > $opt_objdir/$test.out 2>&1`;
    ($utime, $stime, $tutime, $tstime) = times;

    # Subtract the before time from the after time.
    $tutime -= $cutime;
    $tstime -= $cstime;

    if ($opt_zero)
    {
	if ($?)
	{
	    $okay = 0;
	    if ($opt_verbose)
	    {
		print STDERR
		    "\"$opt_objdir/$test > $opt_objdir/$test.out 2>&1\" returned $?\n";
	    }
	}
    }

    return ($okay, $tutime, $tstime);
}

sub print_stats
{
    my ($test, $okay, $failed_subtests, $subtests, $utime, $stime) = @@_;
    my ($hutime, $hstime);
#    my (TEST_PERF);
    my (@@TSTATS);
    my ($t_str, $pass_str);

    $pass_str = $okay ? "passed" : "*** FAILED ***";
    if ((0 != $subtests) && (!$okay))
    {
	$pass_str = $pass_str . " ($failed_subtests/$subtests failed)";
    }
    $pass_str = $pass_str . ' ' x (39 - length($pass_str));
    
    if (-r "$test.perf")
    {
	if (!open (TEST_PERF, "<$opt_objdir/$test.perf"))
	{
	    print STDERR "Unable to open \"$opt_objdir/$test.perf\"\n";
	    exit 1;
	}
	$_ = <TEST_PERF>;

	($hutime, $hstime) = split;
	close TEST_PERF;

	$t_str = sprintf (" %7.2f  %7.2f %7.2f  %7.2f\n"
			  . " %s %7.2f  %7.2f %7.2f %7.2f%%%%\n",
			  $utime, $stime, $utime + $stime,
			  ($utime + $stime) - ($hutime + $hstime),
			  $pass_str,
			  $hutime, $hstime, $hutime + $hstime,
			  (($hutime + $hstime) == 0.0) ? 0.0 :
			  ((($utime + $stime) - ($hutime + $hstime))
			   / ($hutime + $hstime) * 100));
    }
    else
    {
	$hutime = 0.0;
	$hstime = 0.0;

	$t_str = sprintf (" %7.2f  %7.2f %7.2f        \n"
			  . " %s\n",
			  $utime, $stime, $utime + $stime,
			  $pass_str);
    }
    @@TSTATS = ($t_str);
    if (!$opt_quiet)
    {
	foreach $line (@@TSTATS)
	{
	    printf STDOUT "$line";
	}
    }

    if ($okay && $opt_ustats)
    {
	if (!open (TEST_PERF, ">$opt_objdir/$test.perf"))
	{
	    if (!$opt_quiet)
	    {
		print STDERR "Unable to update \"$opt_objdir/$test.perf\"\n";
	    }
	}
	else
	{
	    print TEST_PERF "$utime $stime\n";
	    close TEST_PERF;
	}
    }

    return ($hutime, $hstime);
}

sub usage
{
    print <<EOF;
$0 usage:
    $0 [<options>] <test>+

    Option        | Description
    --------------+-------------------------------------------------------------
    -h --help     | Print usage and exit.
    -v --verbose  | Verbose (incompatible with quiet).
    -q --quiet    | Quiet (incompatible with verbose).
    -s --srcdir   | Path to source tree (default is ".").
    -o --objdir   | Path to object tree (default is ".").
    -u --ustats   | Update historical statistics (stored in "<test>.perf".
    -z --zero     | Consider non-zero exit code to be an error.
    --------------+-------------------------------------------------------------

    If <test>.exp exists, <test>'s output is diff'ed with <test>.exp.  Any
    difference is considered failure.

    If <test>.exp does not exist, output to stdout of the following form is
    expected:

        1..<n>
        {not }ok[ 1]
        {not }ok[ 2]
        ...
        {not }ok[ n]

    1 <= <n> < 2^31

    Lines which do not match the patterns shown above are ignored.
EOF
}
@


1.3
log
@Repo copy libpthreads to libkse.
This introduces the WITHOUT_LIBKSE nob,
and changes WITHOUT_LIBPTHREADS to mean with neither threading libs.
Approved by:	re(kensmith)
@
text
@d36 1
a36 1
# $FreeBSD$
@


1.3.2.1
log
@Switch importer
@
text
@d36 1
a36 1
# $FreeBSD: stable/7/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.16.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.3.16.2
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d36 1
a36 1
# $FreeBSD: stable/9/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.16.1.4.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.3.16.1.4.2
log
@Switch importer
@
text
@d36 1
a36 1
# $FreeBSD: releng/9.1/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.16.1.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.3.16.1.2.2
log
@Switch importer
@
text
@d36 1
a36 1
# $FreeBSD: releng/9.0/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.14.1
log
@SVN rev 216618 on 2010-12-21 17:10:29Z by kensmith

Copy stable/7 to releng/7.4 in preparation for FreeBSD-7.4 release.

Approved by:	re (implicit)
@
text
@@


1.3.14.2
log
@Switch importer
@
text
@d36 1
a36 1
# $FreeBSD: releng/7.4/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.12.1
log
@SVN rev 203736 on 2010-02-10 00:26:20Z by kensmith

Copy stable/7 to releng/7.3 as part of the 7.3-RELEASE process.

Approved by:	re (implicit)
@
text
@@


1.3.10.1
log
@SVN rev 196045 on 2009-08-03 08:13:06Z by kensmith

Copy head to stable/8 as part of 8.0 Release cycle.

Approved by:	re (Implicit)
@
text
@@


1.3.10.2
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242909
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242909 | dim | 2012-11-12 07:47:19 +0000 (Mon, 12 Nov 2012) | 20 lines
## SVN ##
## SVN ## MFC r242625:
## SVN ##
## SVN ## Remove duplicate const specifiers in many drivers (I hope I got all of
## SVN ## them, please let me know if not).  Most of these are of the form:
## SVN ##
## SVN ## static const struct bzzt_type {
## SVN ##       [...list of members...]
## SVN ## } const bzzt_devs[] = {
## SVN ##       [...list of initializers...]
## SVN ## };
## SVN ##
## SVN ## The second const is unnecessary, as arrays cannot be modified anyway,
## SVN ## and if the elements are const, the whole thing is const automatically
## SVN ## (e.g. it is placed in .rodata).
## SVN ##
## SVN ## I have verified this does not change the binary output of a full kernel
## SVN ## build (except for build timestamps embedded in the object files).
## SVN ##
## SVN ## Reviewed by:	yongari, marius
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d36 1
a36 1
# $FreeBSD: stable/8/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.10.1.8.1
log
@SVN rev 232438 on 2012-03-03 06:15:13Z by kensmith

Copy stable/8 to releng/8.3 as part of 8.3-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.3.10.1.8.2
log
@Switch importer
@
text
@d36 1
a36 1
# $FreeBSD: releng/8.3/lib/libkse/test/verify 172491 2007-10-09 13:42:34Z obrien $
@


1.3.10.1.6.1
log
@SVN rev 216617 on 2010-12-21 17:09:25Z by kensmith

Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.

Approved by:	re (implicit)
@
text
@@


1.3.10.1.4.1
log
@SVN rev 209145 on 2010-06-14 02:09:06Z by kensmith

Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.

Approved by:	re (implicit)
@
text
@@


1.3.10.1.2.1
log
@SVN rev 198460 on 2009-10-25 01:10:29Z by kensmith

Copy stable/8 to releng/8.0 as part of 8.0-RELEASE release procedure.

Approved by:	re (implicit)
@
text
@@


1.3.8.1
log
@SVN rev 191087 on 2009-04-15 03:14:26Z by kensmith

Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.

Approved by:	re (implicit)
@
text
@@


1.3.6.1
log
@SVN rev 185281 on 2008-11-25 02:59:29Z by kensmith

Create releng/7.1 in preparation for moving into RC phase of 7.1 release
cycle.

Approved by:	re (implicit)
@
text
@@


1.2
log
@Update the verify script.
@
text
@d36 1
a36 1
# $FreeBSD: src/lib/libc_r/test/verify,v 1.1 2000/04/24 21:07:40 jasone Exp $
@


1.1
log
@Automated regression test harness for libc_r.  Existing tests are integrated,
a new test for POSIX semaphores was added, and examples of harness usage are
included.
@
text
@d5 1
a5 1
# Copyright (C) 1999-2000 Jason Evans <jasone@@freebsd.org>.
d36 1
a36 1
# $FreeBSD$
d55 1
d63 2
a64 1
            "s|srcdir=s" => \$opt_srcdir,
a68 31
$mode = "d";
for ($i = 0; $i <= $#ARGV; $i++)
{
    if (($ARGV[$i] eq "-s") || ($ARGV[$i] eq "--sequence"))
    {
	$mode = "s";
    }
    elsif (($ARGV[$i] eq "-d") || ($ARGV[$i] eq "--diff"))
    {
	$mode = "d";
    }
    elsif (-x $ARGV[$i])
    {
	if ($mode eq "s")
	{
	    @@STESTS = (@@STESTS, $ARGV[$i]);
	}
	else
	{
	    @@DTESTS = (@@DTESTS, $ARGV[$i]);
	}
    }
    else
    {
	if (!$opt_quiet)
	{
	    print STDERR "Cannot run \"$ARGV[$i]\"\n";
	}
    }
}

d88 1
a88 1
if ($#STESTS + $#DTESTS + 2 == 0)
d97 4
a100 4
    print STDERR "Option values: h:$opt_help, v:$opt_verbose, q:$opt_quiet, "
	. "u:$opt_ustats\n";
    printf STDERR "Sequence tests (%d total): @@STESTS\n", $#STESTS + 1;
    printf STDERR "Diff tests (%d total): @@DTESTS\n", $#DTESTS + 1;
d130 1
a130 1
foreach $test (@@STESTS)
d132 3
a134 1
    # sequence mode.
d137 1
a137 3
    ($okay, $utime, $stime) = &run_test($test);

    if (open (STEST_OUT, "<./$test.out"))
d139 1
a139 1
	$num_failed_subtests = 0;
d141 1
a141 1
	$_ = <STEST_OUT>;
d143 1
a143 1
	if ($_ =~ /1\.\.(\d+)/)
d145 6
a150 1
	    $num_subtests = $1;
a153 1
	    $num_subtests = 0;
d157 2
a158 1
		print STDERR "Malformed 1..n line: \"$_\"\n";
d161 10
a170 1
	for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
d172 3
d177 1
a177 1
		if ($line =~ /^not\s+ok\s+(\d+)?/)
d179 1
a179 2
		    $not = 1;
		    $test_num = $1;
d182 5
a186 1
		elsif ($line =~ /^ok\s+(\d+)?/)
d188 1
a188 3
		    $not = 0;
		    $test_num = $1;
		    last;
d191 1
a191 1
	    if (defined($line))
d193 1
a193 1
		if (defined($test_num) && ($test_num != $subtest))
d195 31
a225 2
		    # There was no output printed for one or more tests.
		    for (; $subtest < $test_num; $subtest++)
d227 4
a230 1
			$num_failed_subtests++;
d233 2
a234 1
		if ($not)
d236 1
a236 1
		    $num_failed_subtests++;
d239 4
a242 1
	    else
d244 1
a244 4
		for (; $subtest <= $num_subtests; $subtest++)
		{
		    $num_failed_subtests++;
		}
d246 1
d249 3
a251 62
	if (0 < $num_failed_subtests)
	{
	    $okay = 0;
	}
    }
    else
    {
	if (!$opt_quiet)
	{
	    print STDERR "Cannot open output file \"$test.out\"\n";
	}
	exit 1;
    }

    ($hutime, $hstime) = &print_stats($test, $okay, 
				      $num_failed_subtests, $num_subtests,
				      $utime, $stime);
    $total_hutime += $hutime;
    $total_hstime += $hstime;

    if ($okay)
    {
	$total_utime += $utime;
	$total_stime += $stime;
    }
    else
    {
	@@FAILED_TESTS = (@@FAILED_TESTS, $test);
    }

    # If there were historical data, add the run time to the total time to 
    # compare against the historical run time.
    if (0 < ($hutime + $hstime))
    {
	$total_ntime += $utime + $stime;
    }
}
foreach $test (@@DTESTS)
{
    # Diff mode.
    $okay = 1;

    ($okay, $utime, $stime) = &run_test($test);

    if (-e "./$test.out" && -e "$opt_srcdir/$test.exp")
    {
	`diff ./$test.out $opt_srcdir/$test.exp > ./$test.diff 2>&1`;
	if ($?)
	{
	    # diff returns non-zero if there is a difference.
	    $okay = 0;
	}
    }
    else
    {
	$okay = 0;
	if ($opt_verbose)
	{
	    print STDERR
		"Nonexistent expected output file \"$opt_srcdir/$test.exp\"\n";
            print STDERR "\$opt_srcdir is \"$opt_srcdir\"\n";
	}
a253 1
    ($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
d277 4
a280 4
		   ($#STESTS + $#DTESTS + 2) - ($#FAILED_TESTS + 1),
		   $#STESTS + $#DTESTS + 2,
		   (($#STESTS + $#DTESTS + 2) - ($#FAILED_TESTS + 1))
		   / ($#STESTS + $#DTESTS + 2) * 100);
d306 5
d319 1
a319 1
    my (@@TSTATS);
d321 7
d343 1
a343 1
    `./$test $opt_srcdir > ./$test.out 2>&1`;
d357 2
a358 1
		print STDERR "\"./$test > ./$test.out 2>&1\" returned $?\n";
d383 1
a383 1
	if (!open (TEST_PERF, "<./$test.perf"))
d385 1
a385 1
	    print STDERR "Unable to open \"./$test.perf\"\n";
d424 1
a424 1
	if (!open (TEST_PERF, ">./$test.perf"))
d428 1
a428 1
		print STDERR "Unable to update \"$test.perf\"\n";
d445 1
a445 1
    $0 [<options>] -- {[-s | -d | --sequence | --diff] <test>+}+
d453 1
d458 15
a472 23
    Flag          | Description
    --------------+-------------------------------------------------------------
    -s --sequence | Sequence mode (default).
                  | Output to stdout of the following form is expected:
                  | 
                  | -----------------
                  | 1..<n>
                  | {not} ok [1]
                  | {not} ok [2]
                  | ...
                  | {not} ok [n]
                  | -----------------
                  | 
                  | 1 <= <n> < 2^31
                  | 
                  | Lines which do not match the patterns shown above are
                  | ignored, except that the 1..<n> construct must be the first
                  | line of output seen.
                  | 
    -d --diff     | Diff mode (incompatible with sequence mode).
                  | If <test>.exp exists, diff it with the output from <test> to
                  | determine success or failure.
    --------------+-------------------------------------------------------------
@


1.1.2.1
log
@MFC: Add a test framework, convert existing tests to work with the
framework, and add a test for semaphores.
@
text
@@


1.1.2.2
log
@MFC: Update libc_r test suite.
@
text
@d5 1
a5 1
# Copyright (C) 1999-2001 Jason Evans <jasone@@freebsd.org>.
d36 1
a36 1
# $FreeBSD: src/lib/libc_r/test/verify,v 1.1.2.1 2000/07/17 22:18:33 jasone Exp $
a54 1
$opt_objdir = ".";
d62 1
a62 2
	    "s|srcdir=s" => \$opt_srcdir,
            "o|objdir=s" => \$opt_objdir,
d67 31
d117 1
a117 1
if ($#ARGV + 1 == 0)
d126 4
a129 4
    print STDERR "Option values: h:$opt_help, v:$opt_verbose, "
	. "s:\"$opt_srcdir\", o:\"$opt_objdir\" "
	. "q:$opt_quiet, u:$opt_ustats, z:$opt_zero\n";
    printf STDERR "Tests (%d total): @@ARGV\n", $#ARGV + 1;
d159 1
a159 1
foreach $test (@@ARGV)
d161 2
a162 2
    # Strip out any whitespace in $test.
    $test =~ s/^\s*(.*)\s*$/$1/;
d164 1
a164 1
    $okay = 1;
d166 1
a166 1
    if (-e "$opt_srcdir/$test.exp")
d168 1
a168 1
	# Diff mode.
d170 1
a170 1
	($okay, $utime, $stime) = &run_test($test);
d172 1
a172 1
	if (-e "$opt_objdir/$test.out")
d174 1
a174 6
	    `diff $opt_srcdir/$test.exp $opt_objdir/$test.out > $opt_objdir/$test.diff 2>&1`;
	    if ($?)
	    {
		# diff returns non-zero if there is a difference.
		$okay = 0;
	    }
d178 1
d182 1
a182 2
		print STDERR
		    "Nonexistent output file \"$opt_objdir/$test.out\"\n";
d185 1
a185 10

	($hutime, $hstime) = &print_stats($test, $okay, 0, 0, $utime, $stime);
    }
    else
    {
	# Sequence mode.

	($okay, $utime, $stime) = &run_test($test);

	if (open (STEST_OUT, "<$opt_objdir/$test.out"))
a186 3
	    $num_subtests = 0;
	    $num_failed_subtests = 0;

d189 1
a189 1
		if ($line =~ /1\.\.(\d+)/)
d191 2
a192 1
		    $num_subtests = $1;
d195 1
a195 5
	    }
	    if ($num_subtests == 0)
	    {
		$okay = 0;
		if ($opt_verbose)
d197 3
a199 1
		    print STDERR "Malformed or missing 1..n line\n";
d202 1
a202 1
	    else
d204 1
a204 1
		for ($subtest = 1; $subtest <= $num_subtests; $subtest++)
d206 2
a207 1
		    while (defined($line = <STEST_OUT>))
d209 1
a209 34
			if ($line =~ /^not\s+ok\s+(\d+)?/)
			{
			    $not = 1;
			    $test_num = $1;
			    last;
			}
			elsif ($line =~ /^ok\s+(\d+)?/)
			{
			    $not = 0;
			    $test_num = $1;
			    last;
			}
		    }
		    if (defined($line))
		    {
			if (defined($test_num) && ($test_num != $subtest))
			{
			    # There was no output printed for one or more tests.
			    for (; $subtest < $test_num; $subtest++)
			    {
				$num_failed_subtests++;
			    }
			}
			if ($not)
			{
			    $num_failed_subtests++;
			}
		    }
		    else
		    {
			for (; $subtest <= $num_subtests; $subtest++)
			{
			    $num_failed_subtests++;
			}
d212 8
a219 2

		if (0 < $num_failed_subtests)
d221 1
a221 1
		    $okay = 0;
d225 9
a233 1
	else
d235 1
a235 5
	    if (!$opt_quiet)
	    {
		print STDERR "Cannot open output file \"$opt_objdir/$test.out\"\n";
	    }
	    exit 1;
d237 30
d268 20
a287 3
	($hutime, $hstime) = &print_stats($test, $okay,
					  $num_failed_subtests, $num_subtests,
					  $utime, $stime);
d290 1
d314 4
a317 4
		   ($#ARGV + 1) - ($#FAILED_TESTS + 1),
		   $#ARGV + 1,
		   (($#ARGV + 1) - ($#FAILED_TESTS + 1))
		   / ($#ARGV + 1) * 100);
a342 5
if ($#FAILED_TESTS >= 0)
{
    # One or more tests failed, so return an error.
    exit 1;
}
d351 1
a351 1
    my (@@TSTATS, @@TPATH);
a352 7
    my ($srcdir, $objdir);

    # Get the path component of $test, if any.
    @@TPATH = split(/\//, $test);
    pop(@@TPATH);
    $srcdir = join('/', ($opt_srcdir, @@TPATH));
    $objdir = join('/', ($opt_objdir, @@TPATH));
d368 1
a368 1
    `$opt_objdir/$test $srcdir $objdir > $opt_objdir/$test.out 2>&1`;
d382 1
a382 2
		print STDERR
		    "\"$opt_objdir/$test > $opt_objdir/$test.out 2>&1\" returned $?\n";
d407 1
a407 1
	if (!open (TEST_PERF, "<$opt_objdir/$test.perf"))
d409 1
a409 1
	    print STDERR "Unable to open \"$opt_objdir/$test.perf\"\n";
d448 1
a448 1
	if (!open (TEST_PERF, ">$opt_objdir/$test.perf"))
d452 1
a452 1
		print STDERR "Unable to update \"$opt_objdir/$test.perf\"\n";
d469 1
a469 1
    $0 [<options>] <test>+
a476 1
    -o --objdir   | Path to object tree (default is ".").
d481 23
a503 15
    If <test>.exp exists, <test>'s output is diff'ed with <test>.exp.  Any
    difference is considered failure.

    If <test>.exp does not exist, output to stdout of the following form is
    expected:

        1..<n>
        {not }ok[ 1]
        {not }ok[ 2]
        ...
        {not }ok[ n]

    1 <= <n> < 2^31

    Lines which do not match the patterns shown above are ignored.
@


