From 174d238fc5088a30dbb35a6cf65c31a514ec1f10 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Sat, 31 Mar 2018 13:11:56 +0200
Subject: [PATCH] Add testings

---
 CMakeLists.txt               |  4 ++++
 src/spm_read_driver.c        |  1 +
 tests/CMakeLists.txt         |  8 ++++----
 tests/spm_convert_tests.c    |  7 ++++++-
 tests/spm_dof_expand_tests.c |  7 ++++++-
 tests/spm_dof_matvec_tests.c |  9 +++++++--
 tests/spm_dof_norm_tests.c   | 19 ++++++++++++-------
 tests/spm_matvec_tests.c     | 19 ++++++++++++-------
 tests/spm_norm_tests.c       | 19 ++++++++++++-------
 9 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 453ae75e..5cdca963 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -222,4 +222,8 @@ add_documented_files(
   src/spm_integers.c
   )
 
+## Executable and tests
+enable_testing()
+include(CTest)
+# Testing executables
 add_subdirectory(tests)
diff --git a/src/spm_read_driver.c b/src/spm_read_driver.c
index d07c461b..421128e3 100644
--- a/src/spm_read_driver.c
+++ b/src/spm_read_driver.c
@@ -167,6 +167,7 @@ spmReadDriver( spm_driver_t  driver,
 
         default:
             fprintf(stderr, "spmReadDriver: Driver not implemented\n");
+	    return SPM_ERR_UNKNOWN;
         }
     }
 
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index deed3b77..b1c55063 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -67,22 +67,22 @@ endforeach()
 # RSA
 if (PASTIX_WITH_FORTRAN)
   foreach(example ${SPM_TESTS} )
-    add_test(test_rsa_${example} ./${example} --rsa ${CMAKE_SOURCE_DIR}/test/matrix/small.rsa)
+    add_test(test_rsa_${example} ./${example} --rsa ${CMAKE_SOURCE_DIR}/tests/matrix/small.rsa)
   endforeach()
 endif()
 
 # Matrix Market
 foreach(example ${SPM_TESTS} ${SPM_DOF_TESTS} )
-  add_test(test_mm_${example} ./${example} --mm ${CMAKE_SOURCE_DIR}/test/matrix/young4c.mtx)
+  add_test(test_mm_${example} ./${example} --mm ${CMAKE_SOURCE_DIR}/tests/matrix/young4c.mtx)
 endforeach()
 
 # Harwell Boeing
 foreach(example ${SPM_TESTS} ${SPM_DOF_TESTS} )
-  add_test(test_hb_${example} ./${example} --hb ${CMAKE_SOURCE_DIR}/test/matrix/orsirr.rua)
+  add_test(test_hb_${example} ./${example} --hb ${CMAKE_SOURCE_DIR}/tests/matrix/orsirr.rua)
 endforeach()
 
 # Matrix Market - Hermitian
 foreach(example ${SPM_TESTS} ${SPM_DOF_TESTS} )
-  add_test(test_mm2_${example} ./${example} --mm ${CMAKE_SOURCE_DIR}/test/matrix/mhd1280b.mtx)
+  add_test(test_mm2_${example} ./${example} --mm ${CMAKE_SOURCE_DIR}/tests/matrix/mhd1280b.mtx)
 endforeach()
 
diff --git a/tests/spm_convert_tests.c b/tests/spm_convert_tests.c
index 914cad13..885d23d0 100644
--- a/tests/spm_convert_tests.c
+++ b/tests/spm_convert_tests.c
@@ -117,9 +117,14 @@ int main (int argc, char **argv)
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &spm, 0 );
+    rc = spmReadDriver( driver, filename, &spm, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     printf(" -- SPM Conversion Test --\n");
     spmConvert(SpmCSC, &spm);
 
diff --git a/tests/spm_dof_expand_tests.c b/tests/spm_dof_expand_tests.c
index c6d6161c..48302804 100644
--- a/tests/spm_dof_expand_tests.c
+++ b/tests/spm_dof_expand_tests.c
@@ -63,9 +63,14 @@ int main (int argc, char **argv)
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &original, 0 );
+    rc = spmReadDriver( driver, filename, &original, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     spmtype = original.mtxtype;
     printf(" -- SPM Dof Expand Test --\n");
 
diff --git a/tests/spm_dof_matvec_tests.c b/tests/spm_dof_matvec_tests.c
index 571e1e85..c73b8241 100644
--- a/tests/spm_dof_matvec_tests.c
+++ b/tests/spm_dof_matvec_tests.c
@@ -49,7 +49,7 @@ int main (int argc, char **argv)
     int spmtype, mtxtype, fmttype, baseval;
     int ret = SPM_SUCCESS;
     int err = 0;
-    int i, dofmax = 3;
+    int rc, i, dofmax = 3;
 
     /**
      * Get options from command line
@@ -57,9 +57,14 @@ int main (int argc, char **argv)
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &original, 0 );
+    rc = spmReadDriver( driver, filename, &original, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     if ( original.flttype == SpmPattern ) {
         spmGenFakeValues( &original );
     }
diff --git a/tests/spm_dof_norm_tests.c b/tests/spm_dof_norm_tests.c
index 43cc8720..cb6879fa 100644
--- a/tests/spm_dof_norm_tests.c
+++ b/tests/spm_dof_norm_tests.c
@@ -46,7 +46,7 @@ int main (int argc, char **argv)
     spm_driver_t driver;
     char *filename;
     int spmtype, mtxtype, fmttype, baseval;
-    int ret = SPM_SUCCESS;
+    int rc = SPM_SUCCESS;
     int err = 0;
     int i, dofmax = 4;
 
@@ -56,9 +56,14 @@ int main (int argc, char **argv)
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &original, 0 );
+    rc = spmReadDriver( driver, filename, &original, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     if ( original.flttype == SpmPattern ) {
         spmGenFakeValues( &original );
     }
@@ -99,22 +104,22 @@ int main (int argc, char **argv)
 
                     switch( spm->flttype ){
                     case SpmComplex64:
-                        ret = z_spm_norm_check( spm );
+                        rc = z_spm_norm_check( spm );
                         break;
 
                     case SpmComplex32:
-                        ret = c_spm_norm_check( spm );
+                        rc = c_spm_norm_check( spm );
                         break;
 
                     case SpmFloat:
-                        ret = s_spm_norm_check( spm );
+                        rc = s_spm_norm_check( spm );
                         break;
 
                     case SpmDouble:
                     default:
-                        ret = d_spm_norm_check( spm );
+                        rc = d_spm_norm_check( spm );
                     }
-                    PRINT_RES(ret);
+                    PRINT_RES(rc);
 
                     spmExit( spm );
                     free(spm);
diff --git a/tests/spm_matvec_tests.c b/tests/spm_matvec_tests.c
index 9a0eea6d..b608b09e 100644
--- a/tests/spm_matvec_tests.c
+++ b/tests/spm_matvec_tests.c
@@ -46,15 +46,20 @@ int main (int argc, char **argv)
     spm_driver_t driver;
     char *filename;
     int t,spmtype, mtxtype, baseval;
-    int ret = SPM_SUCCESS;
+    int rc = SPM_SUCCESS;
     int err = 0;
 
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &spm, 0 );
+    rc = spmReadDriver( driver, filename, &spm, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     if ( spm.flttype == SpmPattern ) {
         spmGenFakeValues( &spm );
     }
@@ -106,22 +111,22 @@ int main (int argc, char **argv)
 
                 switch( spm.flttype ){
                 case SpmComplex64:
-                    ret = z_spm_matvec_check( t, &spm );
+                    rc = z_spm_matvec_check( t, &spm );
                     break;
 
                 case SpmComplex32:
-                    ret = c_spm_matvec_check( t, &spm );
+                    rc = c_spm_matvec_check( t, &spm );
                 break;
 
                 case SpmFloat:
-                    ret = s_spm_matvec_check( t, &spm );
+                    rc = s_spm_matvec_check( t, &spm );
                     break;
 
                 case SpmDouble:
                 default:
-                    ret = d_spm_matvec_check( t, &spm );
+                    rc = d_spm_matvec_check( t, &spm );
                 }
-                PRINT_RES(ret);
+                PRINT_RES(rc);
             }
         }
     }
diff --git a/tests/spm_norm_tests.c b/tests/spm_norm_tests.c
index 2894e325..4b1d7bd1 100644
--- a/tests/spm_norm_tests.c
+++ b/tests/spm_norm_tests.c
@@ -46,7 +46,7 @@ int main (int argc, char **argv)
     spm_driver_t driver;
     char *filename;
     int spmtype, mtxtype, fmttype, baseval;
-    int ret = SPM_SUCCESS;
+    int rc = SPM_SUCCESS;
     int err = 0;
 
     /**
@@ -55,9 +55,14 @@ int main (int argc, char **argv)
     spmGetOptions( argc, argv,
 		   &driver, &filename );
 
-    spmReadDriver( driver, filename, &spm, 0 );
+    rc = spmReadDriver( driver, filename, &spm, 0 );
     free(filename);
 
+    if ( rc != SPM_SUCCESS ) {
+	fprintf(stderr, "ERROR: Could not read the file, stop the test !!!\n");
+	return EXIT_FAILURE;
+    }
+    
     if ( spm.flttype == SpmPattern ) {
         spmGenFakeValues( &spm );
     }
@@ -95,22 +100,22 @@ int main (int argc, char **argv)
 
                 switch( spm.flttype ){
                 case SpmComplex64:
-                    ret = z_spm_norm_check( &spm );
+                    rc = z_spm_norm_check( &spm );
                     break;
 
                 case SpmComplex32:
-                    ret = c_spm_norm_check( &spm );
+                    rc = c_spm_norm_check( &spm );
                     break;
 
                 case SpmFloat:
-                    ret = s_spm_norm_check( &spm );
+                    rc = s_spm_norm_check( &spm );
                     break;
 
                 case SpmDouble:
                 default:
-                    ret = d_spm_norm_check( &spm );
+                    rc = d_spm_norm_check( &spm );
                 }
-                PRINT_RES(ret);
+                PRINT_RES(rc);
             }
         }
     }
-- 
GitLab