[Zrouter-src-freebsd] ZRouter.org: push to FreeBSD HEAD tree

zrouter-src-freebsd at zrouter.org zrouter-src-freebsd at zrouter.org
Wed Feb 1 10:56:04 UTC 2012


details:   http://zrouter.org/hg/FreeBSD/head//rev/7c1ab5fac5ed
changeset: 296:7c1ab5fac5ed
user:      ray at terran.dlink.ua
date:      Wed Feb 01 11:25:49 2012 +0200
description:
Update regression tests

diffstat:

 head/tools/regression/bin/sh/builtins/for2.0      |    9 +
 head/tools/regression/bin/sh/builtins/for3.0      |    8 +
 head/tools/regression/sbin/mdconfig/00.t          |   47 +++
 head/tools/regression/sbin/mdconfig/mdconfig.test |  231 +++++++++++++++
 head/tools/regression/sbin/mdconfig/run           |  329 ++++++++++++++++++++++
 head/tools/regression/usr.bin/cc/Makefile         |   12 +
 head/tools/regression/usr.bin/cc/float.c          |  271 ++++++++++++++++++
 head/tools/regression/usr.bin/cc/float.t          |   10 +
 8 files changed, 917 insertions(+), 0 deletions(-)

diffs (949 lines):

diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/bin/sh/builtins/for2.0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/bin/sh/builtins/for2.0	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,9 @@
+# $FreeBSD: head/tools/regression/bin/sh/builtins/for2.0 230463 2012-01-22 14:00:33Z jilles $
+
+r=x
+f() { return 42; }
+f
+for i in x; do
+	r=$?
+done
+[ "$r" = 42 ]
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/bin/sh/builtins/for3.0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/bin/sh/builtins/for3.0	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,8 @@
+# $FreeBSD: head/tools/regression/bin/sh/builtins/for3.0 230463 2012-01-22 14:00:33Z jilles $
+
+r=x
+f() { return 42; }
+for i in x`f`; do
+	r=$?
+done
+[ "$r" = 42 ]
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/sbin/mdconfig/00.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/sbin/mdconfig/00.t	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,47 @@
+#!/bin/sh
+#
+# Copyright (c) 2012 Edward Tomasz Napierała <trasz at 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, 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: head/tools/regression/sbin/mdconfig/00.t 230505 2012-01-24 13:23:52Z trasz $
+#
+
+# This is a wrapper script to run mdconfig.test.
+
+echo "1..1"
+
+if [ `whoami` != "root" ]; then
+	echo "not ok 1 - you need to be root to run this test."
+	exit 1
+fi
+
+TESTDIR=$(dirname $(realpath $0))
+
+perl $TESTDIR/run $TESTDIR/mdconfig.test > /dev/null
+
+if [ $? -eq 0 ]; then
+	echo "ok 1"
+else
+	echo "not ok 1"
+fi
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/sbin/mdconfig/mdconfig.test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/sbin/mdconfig/mdconfig.test	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,231 @@
+# Copyright (c) 2012 Edward Tomasz Napierała <trasz at 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, 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: head/tools/regression/sbin/mdconfig/mdconfig.test 230591 2012-01-26 18:16:16Z trasz $
+#
+
+# This is a test for mdconfig(8) functionality.  Run it as root:
+#
+# /usr/src/tools/regression/mdconfig/run /usr/src/tools/regression/mdconfig/mdconfig.test
+#
+# WARNING: Creates files in unsafe way.
+
+$ whoami
+> root
+$ umask 022
+$ truncate -s 1gb xxx
+
+$ mdconfig -l
+
+$ mdconfig -af xxx
+> md0
+
+# This awk thing is to strip the file path.
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Check different valid syntax variations: implicit -a.
+
+$ mdconfig xxx
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Explicit -t vnode.
+
+$ mdconfig -a -t vnode -f xxx
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Size for vnodes - smaller than the actual file.
+
+$ mdconfig -a -t vnode -f xxx -s 128m
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 128M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         134217728       # mediasize in bytes (128M)
+>         262144          # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Size for vnodes - larger than the actual file.
+
+$ mdconfig -a -t vnode -f xxx -s 128g
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 128G
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         137438953472    # mediasize in bytes (128G)
+>         268435456       # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Sector size for vnodes.
+
+$ mdconfig -a -t vnode -f xxx -S 2048
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 vnode 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         2048            # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         524288          # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Malloc type.
+
+$ mdconfig -a -t malloc -s 1g
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 malloc 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Swap type.
+
+$ mdconfig -a -t swap -s 1g
+> md0
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 swap 1024M
+
+$ diskinfo -v /dev/md0 | expand
+> /dev/md0
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 0
+
+# Attaching with a specific unit number.
+
+$ mdconfig -as 1g -u 42
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md42 swap 1024M
+
+$ diskinfo -v /dev/md42 | expand
+> /dev/md42
+>         512             # sectorsize
+>         1073741824      # mediasize in bytes (1.0G)
+>         2097152         # mediasize in sectors
+>         0               # stripesize
+>         0               # stripeoffset
+>
+
+$ mdconfig -du 42
+
+# Querying.
+
+$ mdconfig -as 1g
+> md0
+$ mdconfig -as 2g -u 42
+
+$ mdconfig -lv | awk '{ print $1, $2, $3 }'
+> md0 swap 1024M
+> md42 swap 2048M
+
+$ mdconfig -lvu 0 | awk '{ print $1, $2, $3 }'
+> md0 swap 1024M
+
+$ mdconfig -lvu 42 | awk '{ print $1, $2, $3 }'
+> md42 swap 2048M
+
+$ mdconfig -lvu 24 | awk '{ print $1, $2, $3 }'
+
+$ mdconfig -du 42
+$ mdconfig -du 0
+
+$ rm xxx
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/sbin/mdconfig/run
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/sbin/mdconfig/run	Wed Feb 01 11:25:49 2012 +0200
@@ -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: head/tools/regression/sbin/mdconfig/run 230505 2012-01-24 13:23:52Z trasz $
+#
+
+#
+# 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 /(?<!\\)\s+/, $line ];
+      $prog_line = $lineno;
+      $in = [];
+      $out = [];
+    }
+  } else {
+    process_test($prog, $prog_line, $in, $out);
+    last;
+  }
+}
+
+my $status = sprintf("%d commands (%d passed, %d failed)",
+	$tests, $tests-$failed, $failed);
+if (isatty(fileno(STDOUT))) {
+	if ($failed) {
+		$status = "\033[31m\033[1m" . $status . "\033[m";
+	} else {
+		$status = "\033[32m" . $status . "\033[m";
+	}
+}
+print $status, "\n";
+exit $failed ? 1 : 0;
+
+
+sub process_test($$$$) {
+  my ($prog, $prog_line, $in, $out) = @_;
+
+  return unless @$prog;
+
+       my $p = [ @$prog ];
+       print "[$prog_line] \$ ", join(' ',
+             map { s/\s/\\$&/g; $_ } @$p), " -- ";
+       my $result = exec_test($prog, $in);
+       my @good = ();
+       my $nmax = (@$out > @$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 (<IN>) {
+      #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;
+  }
+}
+
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/usr.bin/cc/Makefile
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/usr.bin/cc/Makefile	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,12 @@
+# $FreeBSD: head/tools/regression/usr.bin/cc/Makefile 230368 2012-01-20 06:57:21Z das $
+
+TESTS=	float
+CFLAGS+=-lm
+
+.PHONY: tests
+tests: ${TESTS}
+	for p in ${TESTS}; do ${.OBJDIR}/$$p; done
+
+.PHONY: clean
+clean:
+	-rm -f ${TESTS}
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/usr.bin/cc/float.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/usr.bin/cc/float.c	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,271 @@
+/*-
+ * Copyright (c) 2012 David Schultz <das at 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, 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.
+ */
+
+/*
+ * Test that floating-point arithmetic works as specified by the C standard.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: head/tools/regression/usr.bin/cc/float.c 230368 2012-01-20 06:57:21Z das $");
+
+#include <fenv.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+
+#ifdef  __i386__
+#include <ieeefp.h>
+#endif
+
+#define	ALL_STD_EXCEPT	(FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
+			 FE_OVERFLOW | FE_UNDERFLOW)
+
+#define	TWICE(x)		((x) + (x))
+#define	test(desc, pass)	test1((desc), (pass), 0)
+#define	skiptest(desc, pass)	test1((desc), (pass), 1)
+
+#pragma STDC FENV_ACCESS ON
+
+static const float one_f = 1.0 + FLT_EPSILON / 2;
+static const double one_d = 1.0 + DBL_EPSILON / 2;
+static const long double one_ld = 1.0L + LDBL_EPSILON / 2;
+
+static int testnum, failures;
+
+static void
+test1(const char *testdesc, int pass, int skip)
+{
+
+	testnum++;
+	printf("%sok %d - %s%s\n", pass || skip ? "" : "not ", testnum, 
+	    skip ? "(SKIPPED) " : "", testdesc);
+	if (!pass && !skip)
+		failures++;
+}
+
+/*
+ * Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
+ */
+static int
+fpequal(long double d1, long double d2)
+{
+
+	if (d1 != d2)
+		return (isnan(d1) && isnan(d2));
+	return (copysignl(1.0, d1) == copysignl(1.0, d2));
+}
+
+void
+run_zero_opt_test(double d1, double d2)
+{
+
+	test("optimizations don't break the sign of 0",
+	     fpequal(d1 - d2, 0.0)
+	     && fpequal(-d1 + 0.0, 0.0)
+	     && fpequal(-d1 - d2, -0.0)
+	     && fpequal(-(d1 - d2), -0.0)
+	     && fpequal(-d1 - (-d2), 0.0));
+}
+
+void
+run_inf_opt_test(double d)
+{
+
+	test("optimizations don't break infinities",
+	     fpequal(d / d, NAN) && fpequal(0.0 * d, NAN));
+}
+
+static inline double
+todouble(long double ld)
+{
+
+	return (ld);
+}
+
+static inline float
+tofloat(double d)
+{
+
+	return (d);
+}
+
+void
+run_tests(void)
+{
+	volatile long double vld;
+	long double ld;
+	volatile double vd;
+	double d;
+	volatile float vf;
+	float f;
+	int x;
+
+	test("sign bits", fpequal(-0.0, -0.0) && !fpequal(0.0, -0.0));
+
+	vd = NAN;
+	test("NaN equality", fpequal(NAN, NAN) && NAN != NAN && vd != vd);
+
+	feclearexcept(ALL_STD_EXCEPT);
+	test("NaN comparison returns false", !(vd <= vd));
+	/*
+	 * XXX disabled; gcc/amd64 botches this IEEE 754 requirement by
+	 * emitting ucomisd instead of comisd.
+	 */
+	skiptest("FENV_ACCESS: NaN comparison raises invalid exception",
+	    fetestexcept(ALL_STD_EXCEPT) == FE_INVALID);
+
+	vd = 0.0;
+	run_zero_opt_test(vd, vd);
+
+	vd = INFINITY;
+	run_inf_opt_test(vd);
+
+	feclearexcept(ALL_STD_EXCEPT);
+	vd = INFINITY;
+	x = (int)vd;
+	/* XXX disabled (works with -O0); gcc doesn't support FENV_ACCESS */
+	skiptest("FENV_ACCESS: Inf->int conversion raises invalid exception",
+	    fetestexcept(ALL_STD_EXCEPT) == FE_INVALID);
+
+	/* Raising an inexact exception here is an IEEE-854 requirement. */
+	feclearexcept(ALL_STD_EXCEPT);
+	vd = 0.75;
+	x = (int)vd;
+	test("0.75->int conversion rounds toward 0, raises inexact exception",
+	     x == 0 && fetestexcept(ALL_STD_EXCEPT) == FE_INEXACT);
+
+	feclearexcept(ALL_STD_EXCEPT);
+	vd = -42.0;
+	x = (int)vd;
+	test("-42.0->int conversion is exact, raises no exception",
+	     x == -42 && fetestexcept(ALL_STD_EXCEPT) == 0);
+
+	feclearexcept(ALL_STD_EXCEPT);
+	x = (int)INFINITY;
+	/* XXX disabled; gcc doesn't support FENV_ACCESS */
+	skiptest("FENV_ACCESS: const Inf->int conversion raises invalid",
+	    fetestexcept(ALL_STD_EXCEPT) == FE_INVALID);
+
+	feclearexcept(ALL_STD_EXCEPT);
+	x = (int)0.5;
+	/* XXX disabled; gcc doesn't support FENV_ACCESS */
+	skiptest("FENV_ACCESS: const double->int conversion raises inexact",
+	     x == 0 && fetestexcept(ALL_STD_EXCEPT) == FE_INEXACT);
+
+	test("compile-time constants don't have too much precision",
+	     one_f == 1.0L && one_d == 1.0L && one_ld == 1.0L);
+
+	test("const minimum rounding precision",
+	     1.0F + FLT_EPSILON != 1.0F &&
+	     1.0 + DBL_EPSILON != 1.0 &&
+	     1.0L + LDBL_EPSILON != 1.0L);
+
+	/* It isn't the compiler's fault if this fails on FreeBSD/i386. */
+	vf = FLT_EPSILON;
+	vd = DBL_EPSILON;
+	vld = LDBL_EPSILON;
+	test("runtime minimum rounding precision",
+	     1.0F + vf != 1.0F && 1.0 + vd != 1.0 && 1.0L + vld != 1.0L);
+
+	test("explicit float to float conversion discards extra precision",
+	     (float)(1.0F + FLT_EPSILON * 0.5F) == 1.0F &&
+	     (float)(1.0F + vf * 0.5F) == 1.0F);
+	test("explicit double to float conversion discards extra precision",
+	     (float)(1.0 + FLT_EPSILON * 0.5) == 1.0F &&
+	     (float)(1.0 + vf * 0.5) == 1.0F);
+	test("explicit ldouble to float conversion discards extra precision",
+	     (float)(1.0L + FLT_EPSILON * 0.5L) == 1.0F &&
+	     (float)(1.0L + vf * 0.5L) == 1.0F);
+
+	test("explicit double to double conversion discards extra precision",
+	     (double)(1.0 + DBL_EPSILON * 0.5) == 1.0 &&
+	     (double)(1.0 + vd * 0.5) == 1.0);
+	test("explicit ldouble to double conversion discards extra precision",
+	     (double)(1.0L + DBL_EPSILON * 0.5L) == 1.0 &&
+	     (double)(1.0L + vd * 0.5L) == 1.0);
+
+	/*
+	 * FLT_EVAL_METHOD > 1 implies that float expressions are always
+	 * evaluated in double precision or higher, but some compilers get
+	 * this wrong when registers spill to memory.  The following expression
+	 * forces a spill when there are at most 8 FP registers.
+	 */
+	test("implicit promption to double or higher precision is consistent",
+#if FLT_EVAL_METHOD == 1 || FLT_EVAL_METHOD == 2 || defined(__i386__)
+	       TWICE(TWICE(TWICE(TWICE(TWICE(
+	           TWICE(TWICE(TWICE(TWICE(1.0F + vf * 0.5F)))))))))
+	     == (1.0 + FLT_EPSILON * 0.5) * 512.0
+#else
+	     1
+#endif
+	    );
+
+	f = 1.0 + FLT_EPSILON * 0.5;
+	d = 1.0L + DBL_EPSILON * 0.5L;
+	test("const assignment discards extra precision", f == 1.0F && d == 1.0);
+
+	f = 1.0 + vf * 0.5;
+	d = 1.0L + vd * 0.5L;
+	test("variable assignment discards explicit extra precision",
+	     f == 1.0F && d == 1.0);
+	f = 1.0F + vf * 0.5F;
+	d = 1.0 + vd * 0.5;
+	test("variable assignment discards implicit extra precision",
+	     f == 1.0F && d == 1.0);
+
+	test("return discards extra precision",
+	     tofloat(1.0 + vf * 0.5) == 1.0F &&
+	     todouble(1.0L + vd * 0.5L) == 1.0);
+
+	fesetround(FE_UPWARD);
+	/* XXX disabled (works with -frounding-math) */
+	skiptest("FENV_ACCESS: constant arithmetic respects rounding mode",
+	    1.0F + FLT_MIN == 1.0F + FLT_EPSILON &&
+	    1.0 + DBL_MIN == 1.0 + DBL_EPSILON &&
+	    1.0L + LDBL_MIN == 1.0L + LDBL_EPSILON);
+	fesetround(FE_TONEAREST);
+
+	ld = vld * 0.5;
+	test("associativity is respected",
+	     1.0L + ld + (LDBL_EPSILON * 0.5) == 1.0L &&
+	     1.0L + (LDBL_EPSILON * 0.5) + ld == 1.0L &&
+	     ld + 1.0 + (LDBL_EPSILON * 0.5) == 1.0L &&
+	     ld + (LDBL_EPSILON * 0.5) + 1.0 == 1.0L + LDBL_EPSILON);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+	printf("1..26\n");
+
+#ifdef  __i386__
+	fpsetprec(FP_PE);
+#endif
+	run_tests();
+
+	return (failures);
+}
diff -r 223015cf1402 -r 7c1ab5fac5ed head/tools/regression/usr.bin/cc/float.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/head/tools/regression/usr.bin/cc/float.t	Wed Feb 01 11:25:49 2012 +0200
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD: head/tools/regression/usr.bin/cc/float.t 230368 2012-01-20 06:57:21Z das $
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable


More information about the Zrouter-src-freebsd mailing list