#!/usr/bin/perl -w
use strict;
use strict 'refs';

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 );
