diff --git a/sPuReMD/Makefile.am b/sPuReMD/Makefile.am index 2531185b87dbb0b8cd6b4ba80864e75265be43fd..92d61d1fd85e7a54ec316aa0b90e4731c93a720b 100644 --- a/sPuReMD/Makefile.am +++ b/sPuReMD/Makefile.am @@ -20,9 +20,23 @@ check_PROGRAMS = TESTS = if BUILD_TEST +check_PROGRAMS += tests/test_spuremd +check_PROGRAMS += tests/test_lin_alg check_PROGRAMS += tests/test_vector TESTS += $(check_PROGRAMS) +tests_test_spuremd_SOURCES = tests/test_spuremd.cpp +tests_test_spuremd_CPPFLAGS = -Isrc $(GTEST_CPPFLAGS) +tests_test_spuremd_CXXFLAGS = $(GTEST_CXXFLAGS) +tests_test_spuremd_LDFLAGS = $(GTEST_LDFLAGS) $(GTEST_LIBS) +tests_test_spuremd_LDADD = lib/libspuremd.la -lgtest + +tests_test_lin_alg_SOURCES = tests/test_lin_alg.cpp +tests_test_lin_alg_CPPFLAGS = -Isrc $(GTEST_CPPFLAGS) +tests_test_lin_alg_CXXFLAGS = $(GTEST_CXXFLAGS) +tests_test_lin_alg_LDFLAGS = $(GTEST_LDFLAGS) $(GTEST_LIBS) +tests_test_lin_alg_LDADD = -lgtest + tests_test_vector_SOURCES = tests/test_vector.cpp tests_test_vector_CPPFLAGS = -Isrc $(GTEST_CPPFLAGS) tests_test_vector_CXXFLAGS = $(GTEST_CXXFLAGS) diff --git a/sPuReMD/src/spuremd.h b/sPuReMD/src/spuremd.h index ed2b98d3cc21ab0a68d5195d4e33ffe422685dfd..3a78242bd768e2674c727ac882f74b69b2a5e336 100644 --- a/sPuReMD/src/spuremd.h +++ b/sPuReMD/src/spuremd.h @@ -29,6 +29,10 @@ #include "mytypes.h" +#ifdef __cplusplus +extern "C" { +#endif + void* setup( const char * const, const char * const, const char * const ); @@ -40,5 +44,9 @@ int cleanup( const void * const ); reax_atom* get_atoms( const void * const ); +#ifdef __cplusplus +} +#endif + #endif diff --git a/sPuReMD/tests/test_lin_alg.cpp b/sPuReMD/tests/test_lin_alg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a475f8c3dacb419d63b95983e3078b3eb89022e7 --- /dev/null +++ b/sPuReMD/tests/test_lin_alg.cpp @@ -0,0 +1,92 @@ +#include <gtest/gtest.h> + +#include "mytypes.h" +#include "allocate.c" +#include "lin_alg.c" +#include "list.c" +#include "tool_box.c" +#include "vector.c" + +#define VEC_SIZE (100) + + +namespace +{ + class LinAlgTest : public ::testing::Test + { + protected: + real *a, *res; + sparse_matrix *sm; + + LinAlgTest( ) + { + if ( !Allocate_Matrix( &sm, VEC_SIZE, VEC_SIZE ) || + (a = (real *) malloc( VEC_SIZE * sizeof(real))) == NULL || + (res = (real *) malloc( VEC_SIZE * sizeof(real))) == NULL ) + { + throw new std::bad_alloc( ); + } + } + + virtual ~LinAlgTest( ) + { + if ( a != NULL ) + { + free( a ); + } + if ( res != NULL ) + { + free( res ); + } + if ( sm != NULL ) + { + Deallocate_Matrix( sm ); + } + + } + + virtual void SetUp( ) + { + for ( int i = 0; i < VEC_SIZE; ++i ) + { + a[i] = 1.0; + } + + // set up sparse matrix which is an identity matrix in our case + for ( int i = 0; i < sm->n + 1; i++ ) + { + sm->start[i] = i; + } + + for ( int i = 0; i < sm->start[sm->n]; i++ ) + { + sm->j[i] = i; + sm->val[i] = 1.0; + } + } + + + virtual void TearDown( ) + { + + } + }; + + + TEST_F(LinAlgTest, Sparse_MatVec) + { + Sparse_MatVec( sm, a, res ); + + for ( int i = 0; i < VEC_SIZE; ++i ) + { + ASSERT_EQ( res[i], a[i] ); + } + } +} + + +int main( int argc, char **argv ) +{ + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS( ); +} diff --git a/sPuReMD/tests/test_spuremd.cpp b/sPuReMD/tests/test_spuremd.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ac83d54eec527454cafc3c529e4fc79afc299f3 --- /dev/null +++ b/sPuReMD/tests/test_spuremd.cpp @@ -0,0 +1,64 @@ +#include <gtest/gtest.h> + +#include "spuremd.h" + + +namespace +{ + class SPuReMDTest : public ::testing::Test + { + protected: + void *handle; + + SPuReMDTest ( ) + { + } + + virtual ~SPuReMDTest ( ) + { + } + + virtual void SetUp( ) + { + } + + virtual void TearDown( ) + { + if ( handle != NULL ) + { + cleanup( handle ); + } + } + }; + + + TEST_F(SPuReMDTest, water_6540) + { + handle = setup( "../data/benchmarks/water/water_6540.pdb", + "../data/benchmarks/water/ffield.water", + "../environ/param.gpu.water" ); + + ASSERT_EQ( simulate( handle ), SPUREMD_SUCCESS ); + + //TODO: check energy after evolving system, e.g., 100 steps + } + + + TEST_F(SPuReMDTest, silica_6000) + { + handle = setup( "../data/benchmarks/silica/silica_6000.pdb", + "../data/benchmarks/silica/ffield-bio", + "../environ/param.gpu.water" ); + + ASSERT_EQ( simulate( handle ), SPUREMD_SUCCESS ); + + //TODO: check energy after evolving system, e.g., 100 steps + } +} + + +int main( int argc, char **argv ) +{ + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS( ); +}