9512fe850e98fdd448c638ca63fdd92a8a510255ahl# CDDL HEADER START
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# The contents of this file are subject to the terms of the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# Common Development and Distribution License (the "License").
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# You may not use this file except in compliance with the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# See the License for the specific language governing permissions
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# and limitations under the License.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# When distributing Covered Code, include this CDDL HEADER in each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# If applicable, add the following below this CDDL HEADER, with the
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# fields enclosed by brackets "[]" replaced with your own identifying
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# information: Portions Copyright [yyyy] [name of copyright owner]
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# CDDL HEADER END
e77b06d21580f630e0a7c437495ab283d3672828tomee# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# Use is subject to license terms.
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill# Copyright (c) 2011, Joyent, Inc. All rights reserved.
e5803b76927480e8f9b67b22201c484ccf4c2bcfAdam H. Leventhal# Copyright (c) 2012 by Delphix. All rights reserved.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl$PNAME =~ s:.*/::;
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill$USAGE = "Usage: $PNAME [-abfFghjlnqs] [-d dir] [-i isa] "
9512fe850e98fdd448c638ca63fdd92a8a510255ahl . "[-x opt[=arg]] [file | dir ...]\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# If no test files are specified on the command-line, execute a find on "."
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# and append any tst.*.d, tst.*.ksh, err.*.d or drp.*.d files found within
9512fe850e98fdd448c638ca63fdd92a8a510255ahl# the directory tree.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl my($s) = @_;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl $s = substr($s, 0, $i) if (($i = rindex($s, '/')) != -1);
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill my ($exec) = (@_);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -a execute test suite using anonymous enablings\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -b execute bad ioctl test program\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -d specify directory for test results files and cores\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -g enable libumem debugging when running tests\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee print "\t -f force bypassed tests to run\n";
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill print "\t -F force tests to be run, even if missing dependencies\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -h display verbose usage message\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -i specify ISA to test instead of isaexec(3C) default\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee print "\t -j execute test suite using jdtrace (Java API) only\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -l save log file of results and PIDs used by tests\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee print "\t -n execute test suite using dtrace(1m) only\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -q set quiet mode (only report errors and summary)\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -s save results files even for tests that pass\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl print "\t -x pass corresponding -x argument to dtrace(1M)\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl my($msg) = @_;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl my(@parms) = @_;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl my($n) = 0;
9512fe850e98fdd448c638ca63fdd92a8a510255ahl while (-d "$opt_d/failure.$n") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl unless (mkdir "$opt_d/failure.$n") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl warn "ERROR: failed to make directory $opt_d/failure.$n: $!\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(125);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (-f "$opt_d/$pid.core") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (-f "$opt_d/$pid.out") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rename("$opt_d/$pid.out", "$opt_d/failure.$n/$pid.out");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (-f "$opt_d/$pid.err") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rename("$opt_d/$pid.err", "$opt_d/failure.$n/$pid.err");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (-f "$opt_d/$pid.core") {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl rename("$opt_d/$pid.core", "$opt_d/failure.$n/$pid.core");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl my($msg) = @_;
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee# Trim leading and trailing whitespace
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee my($s) = @_;
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee $s =~ s/^\s*//;
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee $s =~ s/\s*$//;
e77b06d21580f630e0a7c437495ab283d3672828tomee# Load exception set of skipped tests from the file at the given
e77b06d21580f630e0a7c437495ab283d3672828tomee# pathname. The test names are assumed to be paths relative to $dt_tst,
e77b06d21580f630e0a7c437495ab283d3672828tomee# for example: common/aggs/tst.neglquant.d, and specify tests to be
e77b06d21580f630e0a7c437495ab283d3672828tomee while (<STDIN>) {
e77b06d21580f630e0a7c437495ab283d3672828tomee # line is non-empty and not a comment
e77b06d21580f630e0a7c437495ab283d3672828tomee if ((length($line) > 0) && ($line =~ /^\s*[^\s#]/ )) {
e77b06d21580f630e0a7c437495ab283d3672828tomee# Return 1 if the test is found in the exception set, 0 otherwise.
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee my($i) = -1;
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee # hash absolute pathname after $dt_tst/
23b5c241225a8ade2b6b9f06ebb891ee459e3b02tomee if ($i == 0) {
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# Iterate over the set of test files specified on the command-line or by a find
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# on "$defdir/common", "$defdir/$MACH" and "$defdir/$PLATFORM" and execute each
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# one. If the test file is executable, we fork and exec it. If the test is a
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# .ksh file, we run it with $ksh_path. Otherwise we run dtrace -s on it. If
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# the file is named tst.* we assume it should return exit status 0. If the
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# file is named err.* we assume it should return exit status 1. If the file is
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# named err.D_[A-Z0-9]+[.*].d we use dtrace -xerrtags and examine stderr to
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# ensure that a matching error tag was produced. If the file is named
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# drp.[A-Z0-9]+[.*].d we use dtrace -xdroptags and examine stderr to ensure
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# that a matching drop tag was produced. If any *.out or *.err files are found
c7158ae983f5a04c4a998f468ecefba6d23ba721tariq# we perform output comparisons.
e77b06d21580f630e0a7c437495ab283d3672828tomee# run_tests takes two arguments: The first is the pathname of the dtrace
e77b06d21580f630e0a7c437495ab283d3672828tomee# command to invoke when running the tests. The second is the pathname
e77b06d21580f630e0a7c437495ab283d3672828tomee# of a file (may be the empty string) listing tests that ought to be
e77b06d21580f630e0a7c437495ab283d3672828tomee# skipped (skipped tests are listed as paths relative to $dt_tst, for
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill die "$PNAME: $dtrace not found; aborting\n" unless (-x "$dtrace");
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill logmsg("executing tests using $dtrace ...\n");
e77b06d21580f630e0a7c437495ab283d3672828tomee $file =~ m:.*/((.*)\.(\w+)):;
e77b06d21580f630e0a7c437495ab283d3672828tomee } elsif ($name =~ /^err\./) {
e77b06d21580f630e0a7c437495ab283d3672828tomee errmsg("ERROR: $file is not a valid test file name\n");
e77b06d21580f630e0a7c437495ab283d3672828tomee if ($opt_a && ($status != 0 || $tag != 0 || $droptag != 0 ||
e77b06d21580f630e0a7c437495ab283d3672828tomee "ERROR: failed to fork to run $exe: $!\n");
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: failed to exec $exe: $!\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee errmsg("ERROR: failed to fork to run test $file: $!\n");
e77b06d21580f630e0a7c437495ab283d3672828tomee unless (chdir($dir)) {
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: failed to chdir for $file: $!\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee exec("$ksh_path /dev/stdin $dtrace");
e77b06d21580f630e0a7c437495ab283d3672828tomee } elsif (-x $name) {
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: $name is executable\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: failed to exec for $file: $!\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee # We can chuck the earler output.
e77b06d21580f630e0a7c437495ab283d3672828tomee # This is an anonymous enabling. We need to get
e77b06d21580f630e0a7c437495ab283d3672828tomee # the module unloaded.
e77b06d21580f630e0a7c437495ab283d3672828tomee system("svcadm disable -s " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "svc:/network/nfs/mapid:default");
e77b06d21580f630e0a7c437495ab283d3672828tomee system("modunload -i 0 ; modunload -i 0 ; " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "modunload -i 0");
e77b06d21580f630e0a7c437495ab283d3672828tomee if (!system("modinfo | grep dtrace")) {
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: couldn't unload dtrace\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee system("svcadm enable " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "-s svc:/network/nfs/mapid:default");
e77b06d21580f630e0a7c437495ab283d3672828tomee # DTrace is gone. Now update_drv(1M), and rip
e77b06d21580f630e0a7c437495ab283d3672828tomee # everything out again.
e77b06d21580f630e0a7c437495ab283d3672828tomee system("update_drv dtrace");
e77b06d21580f630e0a7c437495ab283d3672828tomee system("modunload -i 0 ; modunload -i 0 ; " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "modunload -i 0");
e77b06d21580f630e0a7c437495ab283d3672828tomee if (!system("modinfo | grep dtrace")) {
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: couldn't unload dtrace\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee system("svcadm enable " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "-s svc:/network/nfs/mapid:default");
e77b06d21580f630e0a7c437495ab283d3672828tomee # Now bring DTrace back in.
e77b06d21580f630e0a7c437495ab283d3672828tomee system("sync ; sync");
e77b06d21580f630e0a7c437495ab283d3672828tomee system("dtrace -l -n bogusprobe 1> /dev/null " .
e77b06d21580f630e0a7c437495ab283d3672828tomee system("svcadm enable -s " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "svc:/network/nfs/mapid:default");
e77b06d21580f630e0a7c437495ab283d3672828tomee # That should have caused DTrace to reload with
e77b06d21580f630e0a7c437495ab283d3672828tomee # the new configuration file. Now we can try to
e77b06d21580f630e0a7c437495ab283d3672828tomee # snag our anonymous state.
e77b06d21580f630e0a7c437495ab283d3672828tomee "test $file: $!\n");
e77b06d21580f630e0a7c437495ab283d3672828tomee unless (chdir($dir)) {
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: failed to chdir " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "for $file: $!\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee warn "ERROR: failed to exec for $file: $!\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee die "$PNAME: failed to create output file in $opt_d " .
e77b06d21580f630e0a7c437495ab283d3672828tomee "(cd elsewhere or use -d)\n";
e77b06d21580f630e0a7c437495ab283d3672828tomee if (-f "$file.out" &&
e77b06d21580f630e0a7c437495ab283d3672828tomee if (-f "$file.err" &&
e77b06d21580f630e0a7c437495ab283d3672828tomee while (<TSTERR>) {
e77b06d21580f630e0a7c437495ab283d3672828tomee if (/\[$droptag\] /) {
e77b06d21580f630e0a7c437495ab283d3672828tomee unless ($found) {
e77b06d21580f630e0a7c437495ab283d3672828tomee unless ($opt_s) {
e77b06d21580f630e0a7c437495ab283d3672828tomee # If we're running with anonymous enablings, we need to
e77b06d21580f630e0a7c437495ab283d3672828tomee # restore the .conf file.
e77b06d21580f630e0a7c437495ab283d3672828tomee system("modunload -i 0 ; modunload -i 0 ; modunload -i 0");
e77b06d21580f630e0a7c437495ab283d3672828tomee system("update_drv dtrace");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl if (-f $arg) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl } elsif (-d $arg) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl die "$PNAME: $arg is not a valid file or directory\n";
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill my @dependencies = ("gcc", "make", "java", "perl");
c090e5dfb10cc96e71e6b0f55bf98c18027b002cBryan Cantrill die "$PNAME: '$dep' not found (use -F to force run)\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahlfind(\&wanted, "$defdir/common") if (scalar(@ARGV) == 0);
c7158ae983f5a04c4a998f468ecefba6d23ba721tariqfind(\&wanted, "$defdir/$PLATFORM") if (scalar(@ARGV) == 0);
e77b06d21580f630e0a7c437495ab283d3672828tomee%exception_lists = ("$jdtrace_path" => "$bindir/exception.lst");
e77b06d21580f630e0a7c437495ab283d3672828tomee push(@dtrace_cmds, "/usr/sbin/$opt_i/dtrace") if ($opt_i);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl die "$PNAME: -d arg must be absolute path\n" unless ($opt_d =~ /^\//);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl die "$PNAME: -d arg $opt_d is not a directory\n" unless (-d "$opt_d");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl system("coreadm -p $opt_d/%p.core");
9512fe850e98fdd448c638ca63fdd92a8a510255ahl system("coreadm -p $dir/%p.core");
9512fe850e98fdd448c638ca63fdd92a8a510255ahldie "$PNAME: failed to open $PNAME.$$.log: $!\n"
9512fe850e98fdd448c638ca63fdd92a8a510255ahl warn "ERROR: failed to exec badioctl: $!\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(127);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl # If we're going to be bad, we're just going to iterate over each
9512fe850e98fdd448c638ca63fdd92a8a510255ahl # test file.
9512fe850e98fdd448c638ca63fdd92a8a510255ahl unless (chdir($dir)) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl warn "ERROR: failed to chdir for $file: $!\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(126);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl warn "ERROR: failed to exec for $file: $!\n";
9512fe850e98fdd448c638ca63fdd92a8a510255ahl exit(127);
9512fe850e98fdd448c638ca63fdd92a8a510255ahl unless ($opt_s) {
9512fe850e98fdd448c638ca63fdd92a8a510255ahl unless ($opt_s) {
e77b06d21580f630e0a7c437495ab283d3672828tomee# Run all the tests specified on the command-line (the entire test suite
e77b06d21580f630e0a7c437495ab283d3672828tomee# by default) once for each dtrace command tested, skipping any tests
e77b06d21580f630e0a7c437495ab283d3672828tomee# not valid for that command.
e77b06d21580f630e0a7c437495ab283d3672828tomee run_tests($dtrace_cmd, $exception_lists{$dtrace_cmd});
9512fe850e98fdd448c638ca63fdd92a8a510255ahl$opt_q = 0; # force final summary to appear regardless of -q option