#!/usr/bin/perl -w
use strict;
use strict 'refs';
# ************************************************************************
# 
#                 Anasazi:  Block Eigensolver Package
#                 Copyright (2004) Sandia Corporation
# 
# Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
# license for use of this work by or on behalf of the U.S. Government.
# 
# This library is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#  
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#  
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
# USA
# Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
# 
# ************************************************************************
#
printf
  "\n*****************************************************".
  "\n*** Running Anasazi tests (no news is good news) ****".
  "\n*****************************************************\n";

my $success = 1;  # Boolean (false=0,true=nonzero)
my $mpirun;       # stratus="prun -n", any other platform="mpirun -np"
my $result;       # success=0, failure=nonzero
#
# Check for the mpirun command on this platform, which will
# be set by the test harness.  If it isn't specified, use 'mpirun'.
#
$result = $ENV{"TRILINOS_TEST_HARNESS_MPIGO_COMMAND"};
if (!$result) {
  $result = "mpirun -np";
}
$mpirun = $result . " 3 ";

#************************************
# Modal solver utils test
#************************************

$result = system ($mpirun . "./ModalSolverUtils/ModalSolverUtils_test.exe");
if ($result != 0) {
  # If we failed run it again in verbose mode.
  $success = 0;
  printf
    "\n\n*****************************************".
    "\n*** Running ModalSolverUtils test ****".
    "\n*****************************************\n\n";
  system ($mpirun . "./ModalSolverUtils/ModalSolverUtils_test.exe -v");
} else {
  printf 
    "\n ****** ModalSolverUtils MPI test PASSED ****** \n";
}

#************************************
# MVOPTester utils test
#************************************

$result = system ($mpirun . "./MVOPTester/MVOPTester_test.exe");
if ($result != 0) {
  # If we failed run it again in verbose mode.
  $success = 0;
  printf
    "\n\n*****************************************".
    "\n*** Running MVOPTester test ****".
    "\n*****************************************\n\n";
  system ($mpirun . "./MVOPTester/MVOPTester_test.exe -v");
} else {
  printf 
    "\n ****** MVOPTester MPI test PASSED ****** \n";
}

#************************************
# Block Krylov-Schur test
#************************************

$result = system ($mpirun . "./BlockKrylovSchur/BlockKrylovSchur_test.exe");
if ($result != 0) {
  # If we failed run it again in verbose mode.
  $success = 0;
  printf
    "\n\n*****************************************".
    "\n*** Running BlockKrylovSchur test ****".
    "\n*****************************************\n\n";
  system ($mpirun . "./BlockKrylovSchur/BlockKrylovSchur_test.exe -v");
} else {
  printf 
    "\n ****** BlockKrylovSchur MPI test PASSED ****** \n";
}

#************************************
# Block Davidson test
#************************************

$result = system ($mpirun . "./BlockDavidson/BlockDavidson_test.exe");
if ($result != 0) {
  # If we failed run it again in verbose mode.
  $success = 0;
  printf
    "\n\n*****************************************".
    "\n*** Running BlockDavidson test ****".
    "\n*****************************************\n\n";
  system ($mpirun . "./BlockDavidson/BlockDavidson_test.exe -v");
} else {
  printf 
    "\n ****** BlockDavidson MPI test PASSED ****** \n";
}

#************************************
# LOBPCG test
#************************************

$result = system ($mpirun . "./LOBPCG/LOBPCG_test.exe");
if ($result != 0) {
  # If we failed run it again in verbose mode.
  $success = 0;
  printf
    "\n\n*****************************************".
    "\n*** Running LOBPCG test ****".
    "\n*****************************************\n\n";
  system ($mpirun . "./LOBPCG/LOBPCG_test.exe -v");
} else {
  printf 
    "\n ****** LOBPCG MPI test PASSED ****** \n";
}


# Return 0 if all the tests were successful, else return -1.
exit ($success ? 0 : -1 );
