Skip to content

Commit

Permalink
Update to clealry show why the test passes or fails (trilinos#2247)
Browse files Browse the repository at this point in the history
Before, if any of the three criteria failed, it would jsut print "Test
failed".  But now it prints why it failed with details.

This test currently fails with Intel compilers (see trilinos#2247) but at least now it
shows you why (which was not clear at all before).

I also made usage of the default FancyOStream to avoid logic about what
process you are on for when you should be printing or not.  That is the best
way to handle parallel output and better test output control.

SQUASH AGAINST 'Update to clealry show why the test passes for fails (trilinos#2247)'
  • Loading branch information
bartlettroscoe committed Feb 28, 2018
1 parent 0862b7a commit c6206db
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions packages/nox/test/epetra/Thyra/Thyra_Heq.C
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
#include "Teuchos_CommandLineProcessor.hpp"
#include "Teuchos_FancyOStream.hpp"
#include "Teuchos_StandardCatchMacros.hpp"
#include "Teuchos_VerboseObject.hpp"
#include "Teuchos_TestingHelpers.hpp"

#include "Stratimikos_DefaultLinearSolverBuilder.hpp"
#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
Expand All @@ -84,6 +86,8 @@ using namespace std;
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
const Teuchos::RCP<Teuchos::FancyOStream> out =
Teuchos::VerboseObjectBase::getDefaultOStream();

// Create a communicator for Epetra objects
#ifdef HAVE_MPI
Expand Down Expand Up @@ -117,11 +121,9 @@ int main(int argc, char *argv[])
return parse_return;

if (verbose)
std::cout << "Verbosity Activated" << std::endl;
*out << "Verbosity Activated" << std::endl;
else
std::cout << "Verbosity Disabled" << std::endl;

int status = 0;
*out << "Verbosity Disabled" << std::endl;

const int num_elements = 400;

Expand Down Expand Up @@ -234,24 +236,30 @@ int main(int argc, char *argv[])
}
}

*out << "\nCheck for test pass/fail:\n";

bool loc_success = true;

// 1. Convergence
if (solvStatus != NOX::StatusTest::Converged)
status = 1;
TEUCHOS_TEST_EQUALITY_CONST(solvStatus, NOX::StatusTest::Converged, *out, loc_success);
// 2. Number of iterations
if (const_cast<Teuchos::ParameterList&>(solver->getList()).sublist("Output").get("Nonlinear Iterations", 0) != 18)
status = 2;
int numIterations = 0;
const int *numItersPtr = nullptr;
if (numItersPtr = Teuchos::getParameterPtr<int>(
solver->getList().sublist("Output"), "Nonlinear Iterations") )
{
numIterations = *numItersPtr;
}
TEUCHOS_TEST_EQUALITY_CONST(numIterations, 18, *out, loc_success);
// 3. Same reset solution
if (diff->norm() >= 1.0e-14)
status = 3;
TEUCHOS_TEST_COMPARE_CONST(diff->norm(), >=, 1.0e-14, *out, loc_success);

success = status==0;
success = loc_success;

if (Comm.MyPID() == 0) {
if (success)
std::cout << "Test passed!" << std::endl;
else
std::cout << "Test failed!" << std::endl;
}
if (success)
*out << "\nTest passed!" << std::endl;
else
*out << "\nTest failed!" << std::endl;
}
TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success);

Expand Down

0 comments on commit c6206db

Please sign in to comment.