[MOAB-dev] commit/MOAB: danwu: Updated TestErrorHandling and TestErrorHandlingPar examples.

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Feb 27 20:09:28 CST 2014


1 new commit in MOAB:

https://bitbucket.org/fathomteam/moab/commits/77a62b343cd3/
Changeset:   77a62b343cd3
Branch:      error_handling_enhancement
User:        danwu
Date:        2014-02-28 03:08:53
Summary:     Updated TestErrorHandling and TestErrorHandlingPar examples.

Affected #:  2 files

diff --git a/examples/TestErrorHandling.cpp b/examples/TestErrorHandling.cpp
index 3e16667..f160ab8 100644
--- a/examples/TestErrorHandling.cpp
+++ b/examples/TestErrorHandling.cpp
@@ -1,8 +1,7 @@
 /** @example TestErrorHandling.cpp \n
- * Description: Demonstrates enhanced error handling of MOAB. \n
- * This example tests MOAB's trace back error handler. \n
+ * Description: This example tests MOAB's trace back error handler. \n
  *
- * To run: ./TestErrorHandling \n
+ * <b>To run</b>: ./TestErrorHandling <test_case_num> \n
  */
 
 #include "moab/Core.hpp"
@@ -15,130 +14,9 @@
 using namespace moab;
 using namespace std;
 
-// Functions that create and handle contrived errors
-// Call hierarchy: A calls B, and B calls C
-#ifdef USE_ERROR_INFO_CLASS
-ErrorInfo FunctionC(int n)
-{
-  if (1 == n) {
-    // No error occurs
-    return ERROR_INFO_SUCCESS;
-  }
-  else if (2 == n) {
-    // Simulate MB_FILE_WRITE_ERROR
-    SET_ERR(MB_FILE_WRITE_ERROR, "FunctionC() created a contrived error MB_FILE_WRITE_ERROR");
-  }
-  else if (3 == n) {
-    // Simulate MB_NOT_IMPLEMENTED
-    ErrorInfo err_info(MB_NOT_IMPLEMENTED);
-    err_info << "n = " << n << ", FunctionC() created a contrived error MB_NOT_IMPLEMENTED (this message is built with C++ streaming)";
-    SET_ERR1(err_info);
-  }
-
-  return ERROR_INFO_SUCCESS;
-}
-
-ErrorInfo FunctionB(int n)
-{
-  ErrorInfo err_info = FunctionC(n);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-ErrorInfo FunctionA(int n)
-{
-  ErrorInfo err_info = FunctionB(n);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-#else
-ErrorCode FunctionC(int n)
-{
-  if (1 == n) {
-    // No error occurs
-    return MB_SUCCESS;
-  }
-  else if (2 == n) {
-    // Simulate MB_FILE_WRITE_ERROR
-    SET_ERR(MB_FILE_WRITE_ERROR, "FunctionC() created a contrived error MB_FILE_WRITE_ERROR");
-  }
-  else if (3 == n) {
-    // Simulate MB_NOT_IMPLEMENTED
-    SET_ERR_STR(MB_NOT_IMPLEMENTED, "n = " << n << ", FunctionC() created a contrived error MB_NOT_IMPLEMENTED (this message is built with C++ streaming)");
-  }
-
-  return MB_SUCCESS;
-}
-
-ErrorCode FunctionB(int n)
-{
-  ErrorCode err_code = FunctionC(n);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-
-ErrorCode FunctionA(int n)
-{
-  ErrorCode err_code = FunctionB(n);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-#endif
-
-#ifdef USE_ERROR_INFO_CLASS
-// In this test case, no error occurs in the call hierarchy
-ErrorInfo TestErrorHandling_1()
-{
-  ErrorInfo err_info = FunctionA(1);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-// In this test case, a contrived error MB_FILE_WRITE_ERROR is returned by FunctionC
-ErrorInfo TestErrorHandling_2()
-{
-  ErrorInfo err_info = FunctionA(2);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-// In this test case, a contrived error MB_NOT_IMPLEMENTED is returned by FunctionC
-// The error message is built with C++ streaming
-ErrorInfo TestErrorHandling_3()
-{
-  ErrorInfo err_info = FunctionA(3);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-#else
-// In this test case, no error occurs in the call hierarchy
+// In this test case, an error MB_FILE_DOES_NOT_EXIST is returned by MOAB
 ErrorCode TestErrorHandling_1()
 {
-  ErrorCode err_code = FunctionA(1);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-
-// In this test case, a contrived error MB_FILE_WRITE_ERROR is returned by FunctionC
-ErrorCode TestErrorHandling_2()
-{
-  ErrorCode err_code = FunctionA(2);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-
-// In this test case, a contrived error MB_NOT_IMPLEMENTED is returned by FunctionC
-// The error message is built with C++ streaming
-ErrorCode TestErrorHandling_3()
-{
-  ErrorCode err_code = FunctionA(3);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-
-// In this test case, a real error MB_FILE_DOES_NOT_EXIST is returned by MOAB
-ErrorCode TestErrorHandling_4()
-{
   Core moab;
   Interface& mb = moab;
 
@@ -148,8 +26,8 @@ ErrorCode TestErrorHandling_4()
   return MB_SUCCESS;
 }
 
-// In this test case, a real error MB_INDEX_OUT_OF_RANGE is returned by MOAB
-ErrorCode TestErrorHandling_5()
+// In this test case, an error MB_INDEX_OUT_OF_RANGE is returned by MOAB
+ErrorCode TestErrorHandling_2()
 {
   Core moab;
   Interface& mb = moab;
@@ -160,8 +38,8 @@ ErrorCode TestErrorHandling_5()
   return MB_SUCCESS;
 }
 
-// In this test case, a real error MB_NOT_IMPLEMENTED is returned by MOAB
-ErrorCode TestErrorHandling_6()
+// In this test case, an error MB_NOT_IMPLEMENTED is returned by MOAB
+ErrorCode TestErrorHandling_3()
 {
   Core moab;
   Interface& mb = moab;
@@ -172,42 +50,33 @@ ErrorCode TestErrorHandling_6()
 
   return MB_SUCCESS;
 }
-#endif
 
 int main(int argc, char** argv)
 {
+  // The required arg is a test case number (1, 2 or 3)
+  if (argc < 2) {
+    cout << "Usage: " << argv[0] << " <test_case_num>" << endl;
+    return 0;
+  }
+
 #ifdef USE_MPI
   MPI_Init(&argc, &argv);
 #endif
 
   MBErrorHandler_Init();
 
-  cout << "--------------------Running test case 1 start--------------------" << endl;
-  TestErrorHandling_1();
-  cout << "--------------------Running test case 1 end----------------------\n" << endl;
-
-  cout << "--------------------Running test case 2 start--------------------" << endl;
-  TestErrorHandling_2();
-  cout << "--------------------Running test case 2 end----------------------\n" << endl;
-
-  cout << "--------------------Running test case 3 start--------------------" << endl;
-  TestErrorHandling_3();
-  cout << "--------------------Running test case 3 end----------------------\n" << endl;
-
-#ifdef USE_ERROR_INFO_CLASS
-#else
-  cout << "--------------------Running test case 4 start--------------------" << endl;
-  TestErrorHandling_4();
-  cout << "--------------------Running test case 4 end----------------------\n" << endl;
-
-  cout << "--------------------Running test case 5 start--------------------" << endl;
-  TestErrorHandling_5();
-  cout << "--------------------Running test case 5 end----------------------\n" << endl;
+  ErrorCode rval = MB_SUCCESS;
 
-  cout << "--------------------Running test case 6 start--------------------" << endl;
-  TestErrorHandling_6();
-  cout << "--------------------Running test case 6 end----------------------\n" << endl;
-#endif
+  int test_case_num = atoi(argv[1]);
+  if (1 == test_case_num) {
+    rval = TestErrorHandling_1();CHK_ERR(rval);
+  }
+  else if (2 == test_case_num) {
+    rval = TestErrorHandling_2();CHK_ERR(rval);
+  }
+  else if (3 == test_case_num) {
+    rval = TestErrorHandling_3();CHK_ERR(rval);
+  }
 
   MBErrorHandler_Finalize();
 

diff --git a/examples/TestErrorHandlingPar.cpp b/examples/TestErrorHandlingPar.cpp
index eed938c..0e3a6c2 100644
--- a/examples/TestErrorHandlingPar.cpp
+++ b/examples/TestErrorHandlingPar.cpp
@@ -1,160 +1,103 @@
-/** @example TestErrorHandlingPar.cpp
- * Description: Demonstrates enhanced error handling of parallel MOAB.\n
- * This example tests MOAB's trace back error handler in parallel.\n
+/** @example TestErrorHandlingPar.cpp \n
+ * Description: This example tests MOAB's trace back error handler in parallel.\n
  *
- * <b>To run</b>: mpiexec -np <n> ./TestErrorHandlingPar \n
+ * <b>To run</b>: mpiexec -np <n> ./TestErrorHandlingPar <test_case_num> \n
  */
 
 #include "moab/Core.hpp"
-
 #ifdef USE_MPI
 #include "moab_mpi.h"
 #endif
 
-using namespace moab;
-
-// Functions that create and handle a contrived error
-// Call hierarchy: A calls B, and B calls C
-#ifdef USE_ERROR_INFO_CLASS
-ErrorInfo FunctionC(int rank)
-{
-  // Simulate MB_FILE_WRITE_ERROR
-  ErrorInfo err_info(MB_FILE_WRITE_ERROR);
-  err_info << "FunctionC() created a contrived error MB_FILE_WRITE_ERROR in processor " << rank;
-  SET_ERR1(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-ErrorInfo FunctionB(int rank)
-{
-  ErrorInfo err_info = FunctionC(rank);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-ErrorInfo FunctionA(int rank)
-{
-  ErrorInfo err_info = FunctionB(rank);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-
-// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC in each processor
-ErrorInfo TestErrorHandlingPar(int rank)
-{
-  ErrorInfo err_info = FunctionA(rank);CHK_ERR(err_info);
-
-  return ERROR_INFO_SUCCESS;
-}
-#else
-ErrorCode FunctionC(int rank)
-{
-  // Simulate MB_FILE_WRITE_ERROR
-  SET_ERR_STR(MB_FILE_WRITE_ERROR, "FunctionC() created a contrived error MB_FILE_WRITE_ERROR in processor " << rank);
-
-  return MB_SUCCESS;
-}
-
-ErrorCode FunctionB(int rank)
-{
-  ErrorCode err_code = FunctionC(rank);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-
-ErrorCode FunctionA(int rank)
-{
-  ErrorCode err_code = FunctionB(rank);CHK_ERR(err_code);
-
-  return MB_SUCCESS;
-}
-#endif
-
-#ifdef USE_ERROR_INFO_CLASS
-// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC in each processor
-ErrorInfo TestErrorHandlingPar_1()
-{
-  int rank = 0;
-#ifdef USE_MPI
-  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
-#endif
+#include <iostream>
 
-  ErrorInfo err_info = FunctionA(rank);CHK_ERR(err_info);
+using namespace moab;
+using namespace std;
 
-  return ERROR_INFO_SUCCESS;
-}
-#else
-// In this test case, MB_FILE_WRITE_ERROR is returned by FunctionC in each processor
+// In this test case, an error MB_FILE_DOES_NOT_EXIST is returned by MOAB
+// Note, as a global fatal error, it is only printed by processor 0
 ErrorCode TestErrorHandlingPar_1()
 {
-  int rank = 0;
+  Core moab;
+  Interface& mb = moab;
+
+  std::string opts = ";;";
 #ifdef USE_MPI
-  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
+  // Use parallel options
+  opts += "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
 #endif
 
-  ErrorCode err_code = FunctionA(rank);CHK_ERR(err_code);
+  // Load a file that does not exist
+  ErrorCode rval = mb.load_file("no_such_file.nc", NULL, opts.c_str());CHK_ERR(rval);
 
   return MB_SUCCESS;
 }
 
-// In this test case, a real error MB_FILE_DOES_NOT_EXIST is returned by MOAB
+// In this test case, an error MB_INDEX_OUT_OF_RANGE is returned by MOAB
 ErrorCode TestErrorHandlingPar_2()
 {
   Core moab;
   Interface& mb = moab;
 
-  std::string opts;
+  std::string opts = ";;";
 #ifdef USE_MPI
   // Use parallel options
-  opts = std::string(";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL");
-#else
-  opts = std::string(";;");
+  opts += "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
 #endif
 
-  // Load a file that does not exist
-  ErrorCode rval = mb.load_file("no_such_file.nc", NULL, opts.c_str());CHK_ERR(rval);
+  // Load a file that is not recognized by MOAB
+  ErrorCode rval = mb.load_file("TestErrorHandlingPar.cpp", NULL, opts.c_str());CHK_ERR(rval);
 
   return MB_SUCCESS;
 }
 
-// In this test case, a real error MB_INDEX_OUT_OF_RANGE is returned by MOAB
+// In this test case, an error MB_NOT_IMPLEMENTED is returned by MOAB
+// Note, as a global fatal error, it is only printed by processor 0
 ErrorCode TestErrorHandlingPar_3()
 {
   Core moab;
   Interface& mb = moab;
 
-  std::string opts;
+  std::string opts = ";;";
 #ifdef USE_MPI
   // Use parallel options
-  opts = std::string(";;PARALLEL=READ_PART;PARTITION_METHOD=TRIVIAL");
-#else
-  opts = std::string(";;");
+  opts += "PARALLEL=READ_PART;PARTITION_METHOD=SQIJ";
 #endif
 
-  // Load a file that is not recognized by MOAB
-  ErrorCode rval = mb.load_file("TestErrorHandlingPar.cpp", NULL, opts.c_str());CHK_ERR(rval);
+  // Load a CAM-FV file and read a variable on edges (not supported yet)
+  string test_file = string(MESH_DIR) + string("/io/fv26x46x72.t.3.nc");
+  opts += ";VARIABLE=US";
+  ErrorCode rval = mb.load_file(test_file.c_str(), NULL, opts.c_str());CHK_ERR(rval);
 
   return MB_SUCCESS;
 }
-#endif
 
 int main(int argc, char** argv)
 {
+  // The required arg is a test case number (1, 2 or 3)
+  if (argc < 2) {
+    cout << "Usage: " << argv[0] << " <test_case_num>" << endl;
+    return 0;
+  }
+
 #ifdef USE_MPI
   MPI_Init(&argc, &argv);
 #endif
 
   MBErrorHandler_Init();
 
-  TestErrorHandlingPar_1();
-
-#ifdef USE_ERROR_INFO_CLASS
-#else
-  TestErrorHandlingPar_2();
-
-  TestErrorHandlingPar_3();
-#endif
+  ErrorCode rval = MB_SUCCESS;
+
+  int test_case_num = atoi(argv[1]);
+  if (1 == test_case_num) {
+    rval = TestErrorHandlingPar_1();CHK_ERR(rval);
+  }
+  else if (2 == test_case_num) {
+    rval = TestErrorHandlingPar_2();CHK_ERR(rval);
+  }
+  else if (3 == test_case_num) {
+    rval = TestErrorHandlingPar_3();CHK_ERR(rval);
+  }
 
   MBErrorHandler_Finalize();

Repository URL: https://bitbucket.org/fathomteam/moab/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the moab-dev mailing list