openmpi-nightly-coverity: use far simpler version of safe_system()
The previous safe_system() is quite thorough, but much more than we really need in this script. Use a far simpler version that is significantly easier to maintain. Also log some of the critical steps that a human can examine the output upon a failure (e.g., when the failure happens when launched via cron). Finally, set the version number to not include "openmpi-", because Coverity has a limited-width display of the version number.
Этот коммит содержится в:
родитель
b27ba475ef
Коммит
b207736170
@ -52,148 +52,29 @@ sub verbose {
|
|||||||
|
|
||||||
# run a command and save the stdout / stderr
|
# run a command and save the stdout / stderr
|
||||||
sub safe_system {
|
sub safe_system {
|
||||||
my ($cmd) = shift;
|
my $allowed_to_fail = shift;
|
||||||
my ($logfilename) = shift;
|
my $cmd = shift;
|
||||||
|
my $stdout_file = shift;
|
||||||
|
|
||||||
print "*** Running command: $cmd\n" if ($debug_arg);
|
# Redirect stdout if requested or not verbose
|
||||||
pipe OUTread, OUTwrite;
|
if (defined($stdout_file)) {
|
||||||
|
$stdout_file = "$logfile_dir_arg/$stdout_file";
|
||||||
# Child
|
unlink($stdout_file);
|
||||||
|
$cmd .= " >$stdout_file";
|
||||||
my $pid;
|
} elsif (!$debug_arg) {
|
||||||
if (($pid = fork()) == 0) {
|
$cmd .= " >/dev/null";
|
||||||
close OUTread;
|
|
||||||
|
|
||||||
close(STDERR);
|
|
||||||
open STDERR, ">&OUTwrite"
|
|
||||||
|| die "Can't redirect stderr\n";
|
|
||||||
select STDERR;
|
|
||||||
$| = 1;
|
|
||||||
|
|
||||||
close(STDOUT);
|
|
||||||
open STDOUT, ">&OUTwrite"
|
|
||||||
|| die "Can't redirect stdout\n";
|
|
||||||
select STDOUT;
|
|
||||||
$| = 1;
|
|
||||||
|
|
||||||
# Turn shell-quoted words ("foo bar baz") into individual tokens
|
|
||||||
|
|
||||||
my @tokens;
|
|
||||||
while ($cmd =~ /\".*\"/) {
|
|
||||||
my $prefix;
|
|
||||||
my $middle;
|
|
||||||
my $suffix;
|
|
||||||
|
|
||||||
$cmd =~ /(.*?)\"(.*?)\"(.*)/;
|
|
||||||
$prefix = $1;
|
|
||||||
$middle = $2;
|
|
||||||
$suffix = $3;
|
|
||||||
|
|
||||||
if ($prefix) {
|
|
||||||
foreach my $token (split(' ', $prefix)) {
|
|
||||||
push(@tokens, $token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($middle) {
|
|
||||||
push(@tokens, $middle);
|
|
||||||
} else {
|
|
||||||
push(@tokens, "");
|
|
||||||
}
|
|
||||||
$cmd = $suffix;
|
|
||||||
}
|
|
||||||
if ($cmd) {
|
|
||||||
push(@tokens, split(' ', $cmd));
|
|
||||||
}
|
|
||||||
|
|
||||||
# Run it!
|
|
||||||
|
|
||||||
exec(@tokens) ||
|
|
||||||
die "Can't execute command: $cmd\n";
|
|
||||||
}
|
}
|
||||||
close OUTwrite;
|
$cmd .= " 2>&1";
|
||||||
|
|
||||||
# Parent
|
my $rc = system($cmd);
|
||||||
|
if (0 != $rc && !$allowed_to_fail) {
|
||||||
my (@out);
|
# If we die/fail, ensure to change out of the temp tree so
|
||||||
my ($rin, $rout);
|
# that it can be removed upon exit.
|
||||||
my $done = 1;
|
|
||||||
|
|
||||||
# Keep watching over the pipe(s)
|
|
||||||
|
|
||||||
$rin = '';
|
|
||||||
vec($rin, fileno(OUTread), 1) = 1;
|
|
||||||
|
|
||||||
while ($done > 0) {
|
|
||||||
my $nfound = select($rout = $rin, undef, undef, undef);
|
|
||||||
|
|
||||||
if (vec($rout, fileno(OUTread), 1) == 1) {
|
|
||||||
my $data = <OUTread>;
|
|
||||||
if (!defined($data)) {
|
|
||||||
vec($rin, fileno(OUTread), 1) = 0;
|
|
||||||
--$done;
|
|
||||||
} else {
|
|
||||||
push(@out, $data);
|
|
||||||
print "OUT:$data" if ($debug_arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# The pipes are closed, so the process should be dead. Reap it.
|
|
||||||
|
|
||||||
waitpid($pid, 0);
|
|
||||||
my $status = $?;
|
|
||||||
print "*** Command complete, exit status: $status\n" if ($debug_arg);
|
|
||||||
|
|
||||||
# Return an anonymous hash containing the relevant data
|
|
||||||
|
|
||||||
my $ret = {
|
|
||||||
stdout_and_stderr => \@out,
|
|
||||||
status => $status
|
|
||||||
};
|
|
||||||
|
|
||||||
# If the command failed, just quit
|
|
||||||
if ($status != 0) {
|
|
||||||
print "*** Command \"$cmd\" exited with non-zero status ($status); exiting\n";
|
|
||||||
chdir("/");
|
chdir("/");
|
||||||
exit($status);
|
die "Command $cmd failed: exit status $rc";
|
||||||
}
|
}
|
||||||
|
system("cat $stdout_file")
|
||||||
# If a log filename was given, and we have a logfile dir, then
|
if ($debug_arg && -f $stdout_file);
|
||||||
# write logfiles for stdout/stderr.
|
|
||||||
if (defined($logfilename) && defined($logfile_dir_arg)) {
|
|
||||||
my $filename = "$logfile_dir_arg/$logfilename";
|
|
||||||
|
|
||||||
# Exit status
|
|
||||||
open(OUT, ">$filename-status.out") ||
|
|
||||||
die "Can't write to $filename-status.out";
|
|
||||||
print OUT "Exit status: $status\n";
|
|
||||||
close(OUT);
|
|
||||||
|
|
||||||
# Stdout+stderr
|
|
||||||
if ($#out >= 0) {
|
|
||||||
open(OUT, ">$filename-stdout-stderr.out") ||
|
|
||||||
die "Can't write to $filename-stdout-stderr.out";
|
|
||||||
print OUT @out;
|
|
||||||
close(OUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# If we failed, just die
|
|
||||||
if ($ret->{status} != 0) {
|
|
||||||
print "=== Failed to $cmd\n";
|
|
||||||
print "=== Last few lines of stdout/stderr:\n";
|
|
||||||
my $i = $#{$ret->{stdout}} - 500;
|
|
||||||
$i = 0
|
|
||||||
if ($i < 0);
|
|
||||||
while ($i <= $#{$ret->{stdout}}) {
|
|
||||||
print $ret->{stdout}[$i];
|
|
||||||
++$i;
|
|
||||||
}
|
|
||||||
chdir("/");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
@ -209,8 +90,8 @@ verbose "*** Working in $dir\n";
|
|||||||
# Get the coverity tool, put it in our path
|
# Get the coverity tool, put it in our path
|
||||||
|
|
||||||
verbose "*** Downloading coverity tool\n";
|
verbose "*** Downloading coverity tool\n";
|
||||||
safe_system("wget https://scan.coverity.com/download/linux-64 --post-data \"token=$coverity_token_arg\&project=OpenMPI\" -O coverity_tool.tgz");
|
safe_system(0, "wget https://scan.coverity.com/download/linux-64 --post-data \"token=$coverity_token_arg\&project=OpenMPI\" -O coverity_tool.tgz");
|
||||||
safe_system("tar xf coverity_tool.tgz");
|
safe_system(0, "tar xf coverity_tool.tgz");
|
||||||
opendir(my $dh, ".") ||
|
opendir(my $dh, ".") ||
|
||||||
die "Can't opendir .";
|
die "Can't opendir .";
|
||||||
my @files = grep { /^cov/ && -d "./$_" } readdir($dh);
|
my @files = grep { /^cov/ && -d "./$_" } readdir($dh);
|
||||||
@ -224,34 +105,34 @@ $ENV{PATH} = "$cov_dir:$ENV{PATH}";
|
|||||||
# Expand the OMPI tarball, build it
|
# Expand the OMPI tarball, build it
|
||||||
|
|
||||||
verbose "*** Extracting OMPI tarball\n";
|
verbose "*** Extracting OMPI tarball\n";
|
||||||
safe_system("tar xf $filename_arg");
|
safe_system(0, "tar xf $filename_arg");
|
||||||
my $tarball_filename = basename($filename_arg);
|
my $tarball_filename = basename($filename_arg);
|
||||||
$tarball_filename =~ m/^(.+)\.tar.+$/;
|
$tarball_filename =~ m/^openmpi-(.+)\.tar.+$/;
|
||||||
my $ompi_ver = $1;
|
my $ompi_ver = $1;
|
||||||
chdir($ompi_ver);
|
chdir("openmpi-$ompi_ver");
|
||||||
|
|
||||||
verbose "*** Configuring OMPI tarball\n";
|
verbose "*** Configuring OMPI tarball\n";
|
||||||
safe_system("./configure $configure_args");
|
safe_system(0, "./configure $configure_args", "configure");
|
||||||
|
|
||||||
verbose "*** Building OMPI tarball\n";
|
verbose "*** Building OMPI tarball\n";
|
||||||
safe_system("cov-build --dir cov-int make $make_args");
|
safe_system(0, "cov-build --dir cov-int make $make_args", "cov-build");
|
||||||
|
|
||||||
# Tar up the Coverity results
|
# Tar up the Coverity results
|
||||||
verbose "*** Tarring up results\n";
|
verbose "*** Tarring up results\n";
|
||||||
safe_system("tar jcf $ompi_ver-analyzed.tar.bz2 cov-int");
|
safe_system(0, "tar jcf $ompi_ver-analyzed.tar.bz2 cov-int");
|
||||||
|
|
||||||
# If not dry-run, submit to Coverity
|
# If not dry-run, submit to Coverity
|
||||||
if ($dry_run_arg) {
|
if ($dry_run_arg) {
|
||||||
verbose "*** Would have submitted, but this is a dry run\n";
|
verbose "*** Would have submitted, but this is a dry run\n";
|
||||||
} else {
|
} else {
|
||||||
verbose "*** Submitting results\n";
|
verbose "*** Submitting results\n";
|
||||||
safe_system("curl --form token=$coverity_token_arg " .
|
safe_system(0, "curl --form token=$coverity_token_arg " .
|
||||||
"--form email=jsquyres\@cisco.com " .
|
"--form email=jsquyres\@cisco.com " .
|
||||||
"--form file=\@$ompi_ver-analyzed.tar.bz2 " .
|
"--form file=\@$ompi_ver-analyzed.tar.bz2 " .
|
||||||
"--form version=$ompi_ver " .
|
"--form version=$ompi_ver " .
|
||||||
"--form description=nightly-master " .
|
"--form description=nightly-master " .
|
||||||
"https://scan.coverity.com/builds?project=OpenMPI",
|
"https://scan.coverity.com/builds?project=OpenMPI",
|
||||||
"coverity");
|
"coverity-submit");
|
||||||
}
|
}
|
||||||
|
|
||||||
verbose("*** All done\n");
|
verbose("*** All done\n");
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user