diff --git a/src/KOKKOS/pair_snap_kokkos.h b/src/KOKKOS/pair_snap_kokkos.h index 9acf3011ce..b7208a577c 100644 --- a/src/KOKKOS/pair_snap_kokkos.h +++ b/src/KOKKOS/pair_snap_kokkos.h @@ -50,6 +50,7 @@ struct TagPairSNAPBeta{}; struct TagPairSNAPComputeBi{}; struct TagPairSNAPTransformBi{}; // re-order blist from AoSoA to AoS struct TagPairSNAPComputeYi{}; +struct TagPairSNAPComputeYiWithZlist{}; template struct TagPairSNAPComputeFusedDeidrj{}; @@ -121,11 +122,11 @@ public: template KOKKOS_INLINE_FUNCTION - void operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team) const; + void operator() (TagPairSNAPComputeForce,const int& ii) const; template KOKKOS_INLINE_FUNCTION - void operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team, EV_FLOAT&) const; + void operator() (TagPairSNAPComputeForce,const int& ii, EV_FLOAT&) const; KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPBetaCPU,const int& ii) const; @@ -161,6 +162,9 @@ public: KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPComputeYi,const int iatom_mod, const int idxz, const int iatom_div) const; + KOKKOS_INLINE_FUNCTION + void operator() (TagPairSNAPComputeYiWithZlist,const int iatom_mod, const int idxz, const int iatom_div) const; + template KOKKOS_INLINE_FUNCTION void operator() (TagPairSNAPComputeFusedDeidrj,const typename Kokkos::TeamPolicy >::member_type& team) const; diff --git a/src/KOKKOS/pair_snap_kokkos_impl.h b/src/KOKKOS/pair_snap_kokkos_impl.h index 2578f3d47c..f624131377 100644 --- a/src/KOKKOS/pair_snap_kokkos_impl.h +++ b/src/KOKKOS/pair_snap_kokkos_impl.h @@ -373,14 +373,16 @@ void PairSNAPKokkos::compute(int eflag_in, //Compute beta = dE_i/dB_i for all i in list typename Kokkos::RangePolicy policy_beta(0,chunk_size); Kokkos::parallel_for("ComputeBeta",policy_beta,*this); - - //ComputeYi - // team_size_compute_yi is defined in `pair_snap_kokkos.h` const int idxz_max = snaKK.idxz_max; - Snap3DRangePolicy - policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); - Kokkos::parallel_for("ComputeYi",policy_compute_yi,*this); - + if (quadraticflag || eflag) { + Snap3DRangePolicy + policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); + Kokkos::parallel_for("ComputeYiWithZlist",policy_compute_yi,*this); + } else { + Snap3DRangePolicy + policy_compute_yi({0,0,0},{vector_length,idxz_max,chunk_size_div},{vector_length,tile_size_compute_yi,1}); + Kokkos::parallel_for("ComputeYi",policy_compute_yi,*this); + } } // Fused ComputeDuidrj, ComputeDeidrj @@ -418,30 +420,21 @@ void PairSNAPKokkos::compute(int eflag_in, //ComputeForce { - int team_size = team_size_default; if (evflag) { if (neighflag == HALF) { - check_team_size_reduce >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_reduce(policy_force - ,*this,ev_tmp); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_reduce(policy_force, *this, ev_tmp); } else if (neighflag == HALFTHREAD) { - check_team_size_reduce >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_reduce(policy_force - ,*this,ev_tmp); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_reduce(policy_force, *this, ev_tmp); } } else { if (neighflag == HALF) { - check_team_size_for >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_for(policy_force - ,*this); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_for(policy_force, *this); } else if (neighflag == HALFTHREAD) { - check_team_size_for >(chunk_size,team_size); - typename Kokkos::TeamPolicy > policy_force(chunk_size,team_size,vector_length); - Kokkos::parallel_for(policy_force - ,*this); + typename Kokkos::RangePolicy > policy_force(0,chunk_size); + Kokkos::parallel_for(policy_force, *this); } } } @@ -796,6 +789,19 @@ void PairSNAPKokkos::operator() (TagPairSN my_sna.compute_yi(iatom_mod,jjz,iatom_div,d_beta_pack); } +template +KOKKOS_INLINE_FUNCTION +void PairSNAPKokkos::operator() (TagPairSNAPComputeYiWithZlist,const int iatom_mod, const int jjz, const int iatom_div) const { + SNAKokkos my_sna = snaKK; + + const int iatom = iatom_mod + iatom_div * vector_length; + if (iatom >= chunk_size) return; + + if (jjz >= my_sna.idxz_max) return; + + my_sna.compute_yi_with_zlist(iatom_mod,jjz,iatom_div,d_beta_pack); +} + template KOKKOS_INLINE_FUNCTION void PairSNAPKokkos::operator() (TagPairSNAPComputeZi,const int iatom_mod, const int jjz, const int iatom_div) const { @@ -1137,20 +1143,19 @@ void PairSNAPKokkos::operator() (TagPairSN template template KOKKOS_INLINE_FUNCTION -void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team, EV_FLOAT& ev) const { +void PairSNAPKokkos::operator() (TagPairSNAPComputeForce, const int& ii, EV_FLOAT& ev) const { // The f array is duplicated for OpenMP, atomic for CUDA, and neither for Serial - auto v_f = ScatterViewHelper::value,decltype(dup_f),decltype(ndup_f)>::get(dup_f,ndup_f); auto a_f = v_f.template access::value>(); - int ii = team.league_rank(); const int i = d_ilist[ii + chunk_offset]; + SNAKokkos my_sna = snaKK; + const int ninside = d_ninside(ii); - Kokkos::parallel_for (Kokkos::TeamThreadRange(team,ninside), - [&] (const int jj) { + for (int jj = 0; jj < ninside; jj++) { int j = my_sna.inside(ii,jj); F_FLOAT fij[3]; @@ -1158,28 +1163,23 @@ void PairSNAPKokkos::operator() (TagPairSN fij[1] = my_sna.dedr(ii,jj,1); fij[2] = my_sna.dedr(ii,jj,2); - Kokkos::single(Kokkos::PerThread(team), [&] () { - a_f(i,0) += fij[0]; - a_f(i,1) += fij[1]; - a_f(i,2) += fij[2]; - a_f(j,0) -= fij[0]; - a_f(j,1) -= fij[1]; - a_f(j,2) -= fij[2]; - - // tally global and per-atom virial contribution - - if (EVFLAG) { - if (vflag_either) { - v_tally_xyz(ev,i,j, - fij[0],fij[1],fij[2], - -my_sna.rij(ii,jj,0),-my_sna.rij(ii,jj,1), - -my_sna.rij(ii,jj,2)); - } + a_f(i,0) += fij[0]; + a_f(i,1) += fij[1]; + a_f(i,2) += fij[2]; + a_f(j,0) -= fij[0]; + a_f(j,1) -= fij[1]; + a_f(j,2) -= fij[2]; + // tally global and per-atom virial contribution + if (EVFLAG) { + if (vflag_either) { + v_tally_xyz(ev,i,j, + fij[0],fij[1],fij[2], + -my_sna.rij(ii,jj,0),-my_sna.rij(ii,jj,1), + -my_sna.rij(ii,jj,2)); } + } - }); - }); - + } // tally energy contribution if (EVFLAG) { @@ -1189,48 +1189,41 @@ void PairSNAPKokkos::operator() (TagPairSN const int ielem = d_map[itype]; auto d_coeffi = Kokkos::subview(d_coeffelem, ielem, Kokkos::ALL); - Kokkos::single(Kokkos::PerTeam(team), [&] () { + // evdwl = energy of atom I, sum over coeffs_k * Bi_k - // evdwl = energy of atom I, sum over coeffs_k * Bi_k + auto evdwl = d_coeffi[0]; - auto evdwl = d_coeffi[0]; + // E = beta.B + 0.5*B^t.alpha.B - // E = beta.B + 0.5*B^t.alpha.B + const auto idxb_max = snaKK.idxb_max; - const auto idxb_max = snaKK.idxb_max; + // linear contributions - // linear contributions + for (int icoeff = 0; icoeff < ncoeff; icoeff++) { + const auto idxb = icoeff % idxb_max; + const auto idx_chem = icoeff / idxb_max; + evdwl += d_coeffi[icoeff+1]*my_sna.blist(idxb,idx_chem,ii); + } + // quadratic contributions + if (quadraticflag) { + int k = ncoeff+1; for (int icoeff = 0; icoeff < ncoeff; icoeff++) { const auto idxb = icoeff % idxb_max; const auto idx_chem = icoeff / idxb_max; - evdwl += d_coeffi[icoeff+1]*my_sna.blist(idxb,idx_chem,ii); - } - - // quadratic contributions - - if (quadraticflag) { - int k = ncoeff+1; - for (int icoeff = 0; icoeff < ncoeff; icoeff++) { - const auto idxb = icoeff % idxb_max; - const auto idx_chem = icoeff / idxb_max; - auto bveci = my_sna.blist(idxb,idx_chem,ii); - - evdwl += 0.5*d_coeffi[k++]*bveci*bveci; - for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) { - auto jdxb = jcoeff % idxb_max; - auto jdx_chem = jcoeff / idxb_max; - auto bvecj = my_sna.blist(jdxb,jdx_chem,ii); - - evdwl += d_coeffi[k++]*bveci*bvecj; - } + auto bveci = my_sna.blist(idxb,idx_chem,ii); + evdwl += 0.5*d_coeffi[k++]*bveci*bveci; + for (int jcoeff = icoeff+1; jcoeff < ncoeff; jcoeff++) { + auto jdxb = jcoeff % idxb_max; + auto jdx_chem = jcoeff / idxb_max; + auto bvecj = my_sna.blist(jdxb,jdx_chem,ii); + evdwl += d_coeffi[k++]*bveci*bvecj; } } - - //ev_tally_full(i,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); - if (eflag_global) ev.evdwl += evdwl; - if (eflag_atom) d_eatom[i] += evdwl; - }); + } + //ev_tally_full(i,2.0*evdwl,0.0,0.0,0.0,0.0,0.0); + if (eflag_global) ev.evdwl += evdwl; + if (eflag_atom) d_eatom[i] += evdwl; } } } @@ -1238,9 +1231,9 @@ void PairSNAPKokkos::operator() (TagPairSN template template KOKKOS_INLINE_FUNCTION -void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const typename Kokkos::TeamPolicy >::member_type& team) const { +void PairSNAPKokkos::operator() (TagPairSNAPComputeForce,const int& ii) const { EV_FLOAT ev; - this->template operator()(TagPairSNAPComputeForce(), team, ev); + this->template operator()(TagPairSNAPComputeForce(), ii, ev); } /* ---------------------------------------------------------------------- */ diff --git a/src/KOKKOS/sna_kokkos.h b/src/KOKKOS/sna_kokkos.h index 55983f2a90..33ef37ca98 100644 --- a/src/KOKKOS/sna_kokkos.h +++ b/src/KOKKOS/sna_kokkos.h @@ -125,6 +125,9 @@ inline void compute_yi(int,int,int, const Kokkos::View &beta_pack); // ForceSNAP KOKKOS_INLINE_FUNCTION + void compute_yi_with_zlist(int,int,int, + const Kokkos::View &beta_pack); // ForceSNAP + KOKKOS_INLINE_FUNCTION void compute_bi(const int&, const int&, const int&); // ForceSNAP // functions for bispectrum coefficients, CPU only diff --git a/src/KOKKOS/sna_kokkos_impl.h b/src/KOKKOS/sna_kokkos_impl.h index 2a44f943d3..2b55f97c30 100644 --- a/src/KOKKOS/sna_kokkos_impl.h +++ b/src/KOKKOS/sna_kokkos_impl.h @@ -880,6 +880,59 @@ void SNAKokkos::compute_yi(int iatom_mod, } // end loop over elem1 } +/* ---------------------------------------------------------------------- + compute Yi from Ui without storing Zi, looping over zlist indices. + AoSoA data layout to take advantage of coalescing, avoiding warp + divergence. GPU version. +------------------------------------------------------------------------- */ + +template +KOKKOS_INLINE_FUNCTION +void SNAKokkos::compute_yi_with_zlist(int iatom_mod, int jjz, int iatom_div, + const Kokkos::View &beta_pack) +{ + real_type betaj; + const int j1 = idxz(jjz, 0); + const int j2 = idxz(jjz, 1); + const int j = idxz(jjz, 2); + const int jju_half = idxz(jjz, 9); + int idouble = 0; + for (int elem1 = 0; elem1 < nelements; elem1++) { + for (int elem2 = 0; elem2 < nelements; elem2++) { + auto ztmp = zlist_pack(iatom_mod,jjz,idouble,iatom_div); + // apply to z(j1,j2,j,ma,mb) to unique element of y(j) + // find right y_list[jju] and beta(iatom,jjb) entries + // multiply and divide by j+1 factors + // account for multiplicity of 1, 2, or 3 + // pick out right beta value + for (int elem3 = 0; elem3 < nelements; elem3++) { + if (j >= j1) { + const int jjb = idxb_block(j1, j2, j); + const auto itriple = ((elem1 * nelements + elem2) * nelements + elem3) * idxb_max + jjb; + if (j1 == j) { + if (j2 == j) betaj = 3 * beta_pack(iatom_mod, itriple, iatom_div); + else betaj = 2 * beta_pack(iatom_mod, itriple, iatom_div); + } else betaj = beta_pack(iatom_mod, itriple, iatom_div); + } else if (j >= j2) { + const int jjb = idxb_block(j, j2, j1); + const auto itriple = ((elem3 * nelements + elem2) * nelements + elem1) * idxb_max + jjb; + if (j2 == j) betaj = 2 * beta_pack(iatom_mod, itriple, iatom_div); + else betaj = beta_pack(iatom_mod, itriple, iatom_div); + } else { + const int jjb = idxb_block(j2, j, j1); + const auto itriple = ((elem2 * nelements + elem3) * nelements + elem1) * idxb_max + jjb; + betaj = beta_pack(iatom_mod, itriple, iatom_div); + } + if (!bnorm_flag && j1 > j) + betaj *= (j1 + 1) / (j + 1.0); + Kokkos::atomic_add(&(ylist_pack_re(iatom_mod, jju_half, elem3, iatom_div)), betaj*ztmp.re); + Kokkos::atomic_add(&(ylist_pack_im(iatom_mod, jju_half, elem3, iatom_div)), betaj*ztmp.im); + } // end loop over elem3 + idouble++; + } // end loop over elem2 + } // end loop over elem1 +} + /* ---------------------------------------------------------------------- Fused calculation of the derivative of Ui w.r.t. atom j and accumulation into dEidRj. GPU only. diff --git a/src/USER-REACTION/fix_bond_react.cpp b/src/USER-REACTION/fix_bond_react.cpp index 91354506d1..94d1a596f8 100644 --- a/src/USER-REACTION/fix_bond_react.cpp +++ b/src/USER-REACTION/fix_bond_react.cpp @@ -965,7 +965,7 @@ void FixBondReact::post_integrate() // forward comm of partner, so ghosts have it commflag = 2; - comm->forward_comm_fix(this,2); + comm->forward_comm_fix(this,1); // consider for reaction: // only if both atoms list each other as winning bond partner @@ -2566,6 +2566,7 @@ void FixBondReact::unlimit_bond() } // really should only communicate this per-atom property, not entire reneighboring + MPI_Allreduce(MPI_IN_PLACE,&unlimitflag,1,MPI_INT,MPI_MAX,world); if (unlimitflag) next_reneighbor = update->ntimestep; } diff --git a/unittest/formats/CMakeLists.txt b/unittest/formats/CMakeLists.txt index 7b96cf2d32..be0d14c47d 100644 --- a/unittest/formats/CMakeLists.txt +++ b/unittest/formats/CMakeLists.txt @@ -40,70 +40,55 @@ set_tests_properties(DumpAtom PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS if(PKG_COMPRESS) find_program(GZIP_BINARY NAMES gzip REQUIRED) - add_executable(test_dump_atom_gz test_dump_atom_gz.cpp) - target_link_libraries(test_dump_atom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomGZ COMMAND test_dump_atom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_atom_compressed test_dump_atom_compressed.cpp compressed_dump_test_main.cpp) + target_link_libraries(test_dump_atom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_custom_gz test_dump_custom_gz.cpp) - target_link_libraries(test_dump_custom_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomGZ COMMAND test_dump_custom_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_custom_compressed test_dump_custom_compressed.cpp compressed_dump_test_main.cpp) + target_link_libraries(test_dump_custom_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_cfg_gz test_dump_cfg_gz.cpp) - target_link_libraries(test_dump_cfg_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_cfg_compressed test_dump_cfg_compressed.cpp compressed_dump_test_main.cpp) + target_link_libraries(test_dump_cfg_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_xyz_gz test_dump_xyz_gz.cpp) - target_link_libraries(test_dump_xyz_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_local_compressed test_dump_local_compressed.cpp compressed_dump_test_main.cpp) + target_link_libraries(test_dump_local_compressed PRIVATE lammps GTest::GMock GTest::GTest) - add_executable(test_dump_local_gz test_dump_local_gz.cpp) - target_link_libraries(test_dump_local_gz PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalGZ COMMAND test_dump_local_gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "GZIP_BINARY=${GZIP_BINARY}") + add_executable(test_dump_xyz_compressed test_dump_xyz_compressed.cpp compressed_dump_test_main.cpp) + target_link_libraries(test_dump_xyz_compressed PRIVATE lammps GTest::GMock GTest::GTest) + + add_test(NAME DumpAtomGZ COMMAND test_dump_atom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpCustomGZ COMMAND test_dump_custom_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpCfgGZ COMMAND test_dump_cfg_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpLocalGZ COMMAND test_dump_local_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") + + add_test(NAME DumpXYZGZ COMMAND test_dump_xyz_compressed gz WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZGZ PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${GZIP_BINARY}") find_package(PkgConfig REQUIRED) pkg_check_modules(Zstd IMPORTED_TARGET libzstd>=1.4) find_program(ZSTD_BINARY NAMES zstd) if(Zstd_FOUND AND ZSTD_BINARY) - add_executable(test_dump_atom_zstd test_dump_atom_zstd.cpp) - target_link_libraries(test_dump_atom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpAtomZstd COMMAND test_dump_atom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpAtomZstd COMMAND test_dump_atom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpAtomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_custom_zstd test_dump_custom_zstd.cpp) - target_link_libraries(test_dump_custom_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCustomZstd COMMAND test_dump_custom_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCustomZstd COMMAND test_dump_custom_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCustomZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_cfg_zstd test_dump_cfg_zstd.cpp) - target_link_libraries(test_dump_cfg_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpCfgZstd COMMAND test_dump_cfg_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpCfgZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_xyz_zstd test_dump_xyz_zstd.cpp) - target_link_libraries(test_dump_xyz_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpLocalZstd COMMAND test_dump_local_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") - add_executable(test_dump_local_zstd test_dump_local_zstd.cpp) - target_link_libraries(test_dump_local_zstd PRIVATE lammps GTest::GMock GTest::GTest) - add_test(NAME DumpLocalZstd COMMAND test_dump_local_zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR}") - set_tests_properties(DumpLocalZstd PROPERTIES ENVIRONMENT "ZSTD_BINARY=${ZSTD_BINARY}") + add_test(NAME DumpXYZZstd COMMAND test_dump_xyz_compressed zstd WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + set_tests_properties(DumpXYZZstd PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};COMPRESS_BINARY=${ZSTD_BINARY}") endif() endif() diff --git a/unittest/formats/compressed_dump_test.h b/unittest/formats/compressed_dump_test.h new file mode 100644 index 0000000000..c8afb2aac3 --- /dev/null +++ b/unittest/formats/compressed_dump_test.h @@ -0,0 +1,107 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ +#ifndef TESTCASE_COMPRESSED_DUMP__H +#define TESTCASE_COMPRESSED_DUMP__H + +#include "../testing/core.h" +#include "../testing/systems/melt.h" +#include + +extern const char * COMPRESS_SUFFIX; +extern const char * COMPRESS_EXTENSION; +extern char * COMPRESS_BINARY; + +class CompressedDumpTest : public MeltTest { +protected: + std::string dump_style; + std::string compression_style; + +public: + CompressedDumpTest(const std::string & dump_style) : MeltTest(), dump_style(dump_style) { + compression_style = fmt::format("{}/{}", dump_style, COMPRESS_SUFFIX); + } + + std::string text_dump_filename(std::string ident) { + return fmt::format("dump_{}_text_{}", COMPRESS_SUFFIX, ident); + } + + std::string compressed_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}.{}", COMPRESS_SUFFIX, ident, COMPRESS_EXTENSION); + } + + std::string converted_dump_filename(std::string ident) { + return fmt::format("dump_{}_compressed_{}", COMPRESS_SUFFIX, ident); + } + + void enable_triclinic() + { + if (!verbose) ::testing::internal::CaptureStdout(); + command("change_box all triclinic"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); + + if (!dump_modify_options.empty()) { + command(fmt::format("dump_modify id {}", dump_modify_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string dump_options, std::string dump_modify_options, int ntimesteps) + { + generate_text_and_compressed_dump(text_file, compressed_file, + dump_options, dump_options, + dump_modify_options, dump_modify_options, ntimesteps); + } + + void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, + std::string text_options, std::string compressed_options, + std::string text_modify_options, std::string compressed_modify_options, + int ntimesteps) + { + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, text_options)); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, compressed_options)); + + if (!text_modify_options.empty()) { + command(fmt::format("dump_modify id0 {}", text_modify_options)); + } + + if (!compressed_modify_options.empty()) { + command(fmt::format("dump_modify id1 {}", compressed_modify_options)); + } + + command(fmt::format("run {}", ntimesteps)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } + + std::string convert_compressed_to_text(std::string compressed_file) + { + if (!verbose) ::testing::internal::CaptureStdout(); + std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); + std::string cmdline = + fmt::format("{} -d -c {} > {}", COMPRESS_BINARY, compressed_file, converted_file); + system(cmdline.c_str()); + if (!verbose) ::testing::internal::GetCapturedStdout(); + return converted_file; + } +}; + +#endif diff --git a/unittest/formats/compressed_dump_test_main.cpp b/unittest/formats/compressed_dump_test_main.cpp new file mode 100644 index 0000000000..e1334f1b9b --- /dev/null +++ b/unittest/formats/compressed_dump_test_main.cpp @@ -0,0 +1,66 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + http://lammps.sandia.gov, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "compressed_dump_test.h" +#include "../testing/utils.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + +const char * COMPRESS_SUFFIX = nullptr; +const char * COMPRESS_EXTENSION = nullptr; +char * COMPRESS_BINARY = nullptr; +bool verbose = false; + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + ::testing::InitGoogleMock(&argc, argv); + + if (argc < 2) { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + if(strcmp(argv[1], "gz") == 0) { + COMPRESS_SUFFIX = "gz"; + COMPRESS_EXTENSION = "gz"; + } else if(strcmp(argv[1], "zstd") == 0) { + COMPRESS_SUFFIX = "zstd"; + COMPRESS_EXTENSION = "zst"; + } else { + std::cerr << "usage: " << argv[0] << " (gz|zstd)\n\n" << std::endl; + return 1; + } + + COMPRESS_BINARY = getenv("COMPRESS_BINARY"); + + // handle arguments passed via environment variable + if (const char *var = getenv("TEST_ARGS")) { + std::vector env = utils::split_words(var); + for (auto arg : env) { + if (arg == "-v") { + verbose = true; + } + } + } + + if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; + + int rv = RUN_ALL_TESTS(); + MPI_Finalize(); + return rv; +} diff --git a/unittest/formats/test_dump_atom.cpp b/unittest/formats/test_dump_atom.cpp index 2472aabf2d..39cefdccea 100644 --- a/unittest/formats/test_dump_atom.cpp +++ b/unittest/formats/test_dump_atom.cpp @@ -24,6 +24,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpAtomTest : public MeltTest { std::string dump_style = "atom"; diff --git a/unittest/formats/test_dump_atom_compressed.cpp b/unittest/formats/test_dump_atom_compressed.cpp new file mode 100644 index 0000000000..ed591184c3 --- /dev/null +++ b/unittest/formats/test_dump_atom_compressed.cpp @@ -0,0 +1,388 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpAtomCompressTest : public CompressedDumpTest { +public: + DumpAtomCompressTest() : CompressedDumpTest("atom") { + } +}; + +//------------------------------------------------------------------------------------------------- +// compressed files +//------------------------------------------------------------------------------------------------- + +TEST_F(DumpAtomCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto text_file = text_dump_filename("run0.melt"); + auto compressed_file = compressed_dump_filename("run0.melt"); + + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + } + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename("run0.melt"))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt"; + auto base_name_0 = "multi_file_run1_0.melt"; + auto base_name_1 = "multi_file_run1_1.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + if(compression_style == "atom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt"; + auto base_name_0 = "multi_file_pad_run1_000.melt"; + auto base_name_1 = "multi_file_pad_run1_001.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpAtomCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpAtomCompressTest, compressed_with_units_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_with_time_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_triclinic_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "tri_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + enable_triclinic(); + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_units_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "tri_with_units_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + enable_triclinic(); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no units yes", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_time_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "tri_with_time_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + enable_triclinic(); + generate_text_and_compressed_dump(text_file, compressed_file, "", "scale no time yes", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_triclinic_with_image_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "tri_with_image_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + enable_triclinic(); + generate_text_and_compressed_dump(text_file, compressed_file, "", "image yes", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpAtomCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "atom/gz") GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpAtomCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "atom/gz") GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpAtomCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} diff --git a/unittest/formats/test_dump_atom_gz.cpp b/unittest/formats/test_dump_atom_gz.cpp deleted file mode 100644 index c8f2eb500c..0000000000 --- a/unittest/formats/test_dump_atom_gz.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpAtomGZTest : public MeltTest { - std::string dump_style = "atom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -//------------------------------------------------------------------------------------------------- -// GZ compressed files -//------------------------------------------------------------------------------------------------- - -TEST_F(DumpAtomGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_run0.melt"; - auto compressed_file = "dump_gz_compressed_run0.melt.gz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_THAT(converted_file, Eq("dump_gz_compressed_run0.melt")); - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_with_units_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_units_run0.melt.gz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", - 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_with_time_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_with_time_run0.melt.gz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_triclinic_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_tri_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_run0.melt.gz"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_triclinic_with_units_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_units_run0.melt.gz"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no units yes", - 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_triclinic_with_time_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_time_run0.melt.gz"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "scale no time yes", - 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomGZTest, compressed_triclinic_with_image_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_gz_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_gz_compressed_tri_with_image_run0.melt.gz"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/gz", "image yes", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_atom_zstd.cpp b/unittest/formats/test_dump_atom_zstd.cpp deleted file mode 100644 index 41c2fd3c79..0000000000 --- a/unittest/formats/test_dump_atom_zstd.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -#include - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpAtomZSTDTest : public MeltTest { - std::string dump_style = "atom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {}", dump_style, dump_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -//------------------------------------------------------------------------------------------------- -// ZSTD compressed files -//------------------------------------------------------------------------------------------------- - -TEST_F(DumpAtomZSTDTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_run0.melt"; - auto compressed_file = "dump_zstd_compressed_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_THAT(converted_file, Eq("dump_zstd_compressed_run0.melt")); - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_units_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_with_time_run0.melt.zst"; - - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_units_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_units_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_units_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no units yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_time_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_time_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_time_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "scale no time yes", - 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpAtomZSTDTest, compressed_triclinic_with_image_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_zstd_text_tri_with_image_run0.melt"; - auto compressed_file = "dump_zstd_compressed_tri_with_image_run0.melt.zst"; - - enable_triclinic(); - generate_text_and_compressed_dump(text_file, compressed_file, "atom/zstd", "image yes", 0); - - // make sure file is closed - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_cfg.cpp b/unittest/formats/test_dump_cfg.cpp index a7f331a0d0..327a9caca7 100644 --- a/unittest/formats/test_dump_cfg.cpp +++ b/unittest/formats/test_dump_cfg.cpp @@ -21,6 +21,8 @@ using ::testing::Eq; +bool verbose = false; + class DumpCfgTest : public MeltTest { std::string dump_style = "cfg"; diff --git a/unittest/formats/test_dump_cfg_compressed.cpp b/unittest/formats/test_dump_cfg_compressed.cpp new file mode 100644 index 0000000000..834a71db70 --- /dev/null +++ b/unittest/formats/test_dump_cfg_compressed.cpp @@ -0,0 +1,283 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCfgCompressTest : public CompressedDumpTest { +public: + DumpCfgCompressTest() : CompressedDumpTest("cfg") { + } +}; + +//------------------------------------------------------------------------------------------------- +// compressed files +//------------------------------------------------------------------------------------------------- + +TEST_F(DumpCfgCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpCfgCompressTest, compressed_unwrap_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "unwrap_run*.melt.cfg"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + + auto base_name_0 = "unwrap_run0.melt.cfg"; + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_run1_1.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + if(compression_style == "cfg/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_pad_run1_000.melt.cfg"; + auto base_name_1 = "multi_file_pad_run1_001.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCfgCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.cfg"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.cfg"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.cfg"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "cfg/gz") GTEST_SKIP(); + + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.cfg"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCfgCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run*.melt.cfg"; + auto base_name_0 = "modify_clevel_run0.melt.cfg"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} diff --git a/unittest/formats/test_dump_cfg_gz.cpp b/unittest/formats/test_dump_cfg_gz.cpp deleted file mode 100644 index ced307dc0a..0000000000 --- a/unittest/formats/test_dump_cfg_gz.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgGZTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_gz_compressed_run0.melt.cfg.gz"; - auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgGZTest, compressed_unwrap_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_gz_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_gz_compressed_run*.melt.cfg.gz"; - auto text_file = "dump_cfg_unwrap_gz_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_gz_compressed_run0.melt.cfg.gz"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_cfg_zstd.cpp b/unittest/formats/test_dump_cfg_zstd.cpp deleted file mode 100644 index c13a3d5eaf..0000000000 --- a/unittest/formats/test_dump_cfg_zstd.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpCfgZstdTest : public MeltTest { - std::string dump_style = "cfg"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCfgZstdTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_zstd_compressed_run0.melt.cfg.zst"; - auto fields = "mass type xs ys zs id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCfgZstdTest, compressed_unwrap_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_cfg_unwrap_zstd_text_run*.melt.cfg"; - auto compressed_files = "dump_cfg_unwrap_zstd_compressed_run*.melt.cfg.zst"; - auto text_file = "dump_cfg_unwrap_zstd_text_run0.melt.cfg"; - auto compressed_file = "dump_cfg_unwrap_zstd_compressed_run0.melt.cfg.zst"; - auto fields = "mass type xsu ysu zsu id proc procp1 x y z ix iy iz vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "cfg/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_custom.cpp b/unittest/formats/test_dump_custom.cpp index dee27d9f0d..f2d7935426 100644 --- a/unittest/formats/test_dump_custom.cpp +++ b/unittest/formats/test_dump_custom.cpp @@ -22,6 +22,7 @@ using ::testing::Eq; char *BINARY2TXT_BINARY = nullptr; +bool verbose = false; class DumpCustomTest : public MeltTest { std::string dump_style = "custom"; diff --git a/unittest/formats/test_dump_custom_compressed.cpp b/unittest/formats/test_dump_custom_compressed.cpp new file mode 100644 index 0000000000..fb70206590 --- /dev/null +++ b/unittest/formats/test_dump_custom_compressed.cpp @@ -0,0 +1,266 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpCustomCompressTest : public CompressedDumpTest { +public: + DumpCustomCompressTest() : CompressedDumpTest("custom") { + } +}; + +TEST_F(DumpCustomCompressTest, compressed_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_run1.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "units yes", "units yes checksum yes", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + } + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpCustomCompressTest, compressed_triclinic_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "custom_tri_run1.melt"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; + + enable_triclinic(); + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "units yes", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.custom"; + auto base_name_0 = "multi_file_run1_0.melt.custom"; + auto base_name_1 = "multi_file_run1_1.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + if(compression_style == "custom/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.custom"; + auto base_name_0 = "multi_file_pad_run1_000.melt.custom"; + auto base_name_1 = "multi_file_pad_run1_001.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpCustomCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.custom"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.custom"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.custom"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "custom/gz") GTEST_SKIP(); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.custom"), fields)); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpCustomCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.custom"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} diff --git a/unittest/formats/test_dump_custom_gz.cpp b/unittest/formats/test_dump_custom_gz.cpp deleted file mode 100644 index 67c9b535aa..0000000000 --- a/unittest/formats/test_dump_custom_gz.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *GZIP_BINARY = nullptr; - -class DumpCustomGZTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomGZTest, compressed_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_text_run1.melt"; - auto compressed_file = "dump_custom_gz_compressed_run1.melt.gz"; - auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomGZTest, compressed_triclinic_run1) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_gz_tri_text_run1.melt"; - auto compressed_file = "dump_custom_gz_tri_compressed_run1.melt.gz"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/gz", fields, "units yes", - 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_custom_zstd.cpp b/unittest/formats/test_dump_custom_zstd.cpp deleted file mode 100644 index 40328d5592..0000000000 --- a/unittest/formats/test_dump_custom_zstd.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -using ::testing::Eq; - -char *ZSTD_BINARY = nullptr; - -class DumpCustomZstdTest : public MeltTest { - std::string dump_style = "custom"; - -public: - void enable_triclinic() - { - if (!verbose) ::testing::internal::CaptureStdout(); - command("change_box all triclinic"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_dump(std::string dump_file, std::string fields, std::string dump_modify_options, - int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id all {} 1 {} {}", dump_style, dump_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpCustomZstdTest, compressed_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_compressed_run1.melt.zst"; - auto fields = "id type proc x y z ix iy iz xs ys zs xu yu zu xsu ysu zsu vx vy vz fx fy fz"; - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -TEST_F(DumpCustomZstdTest, compressed_triclinic_run1) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_file = "dump_custom_zstd_tri_text_run1.melt"; - auto compressed_file = "dump_custom_zstd_tri_compressed_run1.melt.zst"; - auto fields = "id type proc x y z xs ys zs xsu ysu zsu vx vy vz fx fy fz"; - - enable_triclinic(); - - generate_text_and_compressed_dump(text_file, compressed_file, "custom/zstd", fields, - "units yes", 1); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_local_compressed.cpp b/unittest/formats/test_dump_local_compressed.cpp new file mode 100644 index 0000000000..20f90984a1 --- /dev/null +++ b/unittest/formats/test_dump_local_compressed.cpp @@ -0,0 +1,256 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpLocalCompressTest : public CompressedDumpTest { +public: + DumpLocalCompressTest() : CompressedDumpTest("local") { + } + + void SetUp() override { + CompressedDumpTest::SetUp(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command("compute comp all pair/local dist eng"); + if (!verbose) ::testing::internal::GetCapturedStdout(); + } +}; + +TEST_F(DumpLocalCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.local"; + auto base_name_0 = "run0.melt.local"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto fields = "index c_comp[1]"; + + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, fields, fields, "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, fields, "", 0); + } + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.local"; + auto base_name_0 = "multi_file_run1_0.melt.local"; + auto base_name_1 = "multi_file_run1_1.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "index c_comp[1]"; + + if(compression_style == "local/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, fields, "", 1); + } + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.local"; + auto base_name_0 = "multi_file_pad_run1_000.melt.local"; + auto base_name_1 = "multi_file_pad_run1_001.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpLocalCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.local"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.local"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.local"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.local"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "local/gz") GTEST_SKIP(); + + auto fields = "index c_comp[1]"; + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.local"), fields)); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpLocalCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.local"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + auto fields = "index c_comp[1]"; + + generate_text_and_compressed_dump(text_file, compressed_file, fields, fields, "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} diff --git a/unittest/formats/test_dump_local_gz.cpp b/unittest/formats/test_dump_local_gz.cpp deleted file mode 100644 index 6ae25ae33d..0000000000 --- a/unittest/formats/test_dump_local_gz.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_gz_text_run*.melt.local"; - auto compressed_files = "dump_local_gz_compressed_run*.melt.local.gz"; - auto text_file = "dump_local_gz_text_run0.melt.local"; - auto compressed_file = "dump_local_gz_compressed_run0.melt.local.gz"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/gz", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_local_zstd.cpp b/unittest/formats/test_dump_local_zstd.cpp deleted file mode 100644 index 4a15baf4ca..0000000000 --- a/unittest/formats/test_dump_local_zstd.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpLocalGZTest : public MeltTest { - std::string dump_style = "local"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, std::string fields, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {} {}", dump_style, text_file, fields)); - command(fmt::format("dump id1 all {} 1 {} {}", compression_style, compressed_file, fields)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpLocalGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - if (!verbose) ::testing::internal::CaptureStdout(); - command("compute comp all pair/local dist eng"); - if (!verbose) ::testing::internal::GetCapturedStdout(); - - auto text_files = "dump_local_zstd_text_run*.melt.local"; - auto compressed_files = "dump_local_zstd_compressed_run*.melt.local.zst"; - auto text_file = "dump_local_zstd_text_run0.melt.local"; - auto compressed_file = "dump_local_zstd_compressed_run0.melt.local.zst"; - auto fields = "index c_comp[1]"; - - generate_text_and_compressed_dump(text_files, compressed_files, "local/zstd", fields, "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_xyz_compressed.cpp b/unittest/formats/test_dump_xyz_compressed.cpp new file mode 100644 index 0000000000..f80201872c --- /dev/null +++ b/unittest/formats/test_dump_xyz_compressed.cpp @@ -0,0 +1,239 @@ +/* ---------------------------------------------------------------------- + LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator + https://lammps.sandia.gov/, Sandia National Laboratories + Steve Plimpton, sjplimp@sandia.gov + + Copyright (2003) Sandia Corporation. Under the terms of Contract + DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains + certain rights in this software. This software is distributed under + the GNU General Public License. + + See the README file in the top-level LAMMPS directory. +------------------------------------------------------------------------- */ + +#include "../testing/utils.h" +#include "compressed_dump_test.h" +#include "fmt/format.h" +#include "utils.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include + + +using ::testing::Eq; + +class DumpXYZCompressTest : public CompressedDumpTest { +public: + DumpXYZCompressTest() : CompressedDumpTest("xyz") { + } +}; + +TEST_F(DumpXYZCompressTest, compressed_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "run*.melt.xyz"; + auto base_name_0 = "run0.melt.xyz"; + auto text_files = text_dump_filename(base_name); + auto compressed_files = compressed_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", "", "checksum yes", 0); + } else { + generate_text_and_compressed_dump(text_files, compressed_files, "", "", 0); + } + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(compressed_file_0); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + delete_file(text_file_0); + delete_file(compressed_file_0); + delete_file(converted_file_0); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_run1_1.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + if(compression_style == "xyz/zstd") { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "checksum no", 1); + } else { + generate_text_and_compressed_dump(text_file, compressed_file, "", "", 1); + } + + TearDown(); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_pad_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_pad_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_pad_run1_000.melt.xyz"; + auto base_name_1 = "multi_file_pad_run1_001.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "pad 3", 1); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + + auto converted_file_0 = convert_compressed_to_text(compressed_file_0); + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + + ASSERT_THAT(converted_file_0, Eq(converted_dump_filename(base_name_0))); + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_FILE_EXISTS(converted_file_0); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EQUAL(text_file_0, converted_file_0); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + + delete_file(text_file_0); + delete_file(text_file_1); + delete_file(compressed_file_0); + delete_file(compressed_file_1); + delete_file(converted_file_0); + delete_file(converted_file_1); +} + +TEST_F(DumpXYZCompressTest, compressed_multi_file_with_maxfiles_run1) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "multi_file_maxfiles_run1_*.melt.xyz"; + auto base_name_0 = "multi_file_maxfiles_run1_0.melt.xyz"; + auto base_name_1 = "multi_file_maxfiles_run1_1.melt.xyz"; + auto base_name_2 = "multi_file_maxfiles_run1_2.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto text_file_0 = text_dump_filename(base_name_0); + auto text_file_1 = text_dump_filename(base_name_1); + auto text_file_2 = text_dump_filename(base_name_2); + auto compressed_file = compressed_dump_filename(base_name); + auto compressed_file_0 = compressed_dump_filename(base_name_0); + auto compressed_file_1 = compressed_dump_filename(base_name_1); + auto compressed_file_2 = compressed_dump_filename(base_name_2); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "maxfiles 2", 2); + + TearDown(); + + ASSERT_FILE_NOT_EXISTS(text_file_0); + ASSERT_FILE_EXISTS(text_file_1); + ASSERT_FILE_EXISTS(text_file_2); + ASSERT_FILE_NOT_EXISTS(compressed_file_0); + ASSERT_FILE_EXISTS(compressed_file_1); + ASSERT_FILE_EXISTS(compressed_file_2); + + auto converted_file_1 = convert_compressed_to_text(compressed_file_1); + auto converted_file_2 = convert_compressed_to_text(compressed_file_2); + + ASSERT_THAT(converted_file_1, Eq(converted_dump_filename(base_name_1))); + ASSERT_THAT(converted_file_2, Eq(converted_dump_filename(base_name_2))); + ASSERT_FILE_EXISTS(converted_file_1); + ASSERT_FILE_EXISTS(converted_file_2); + ASSERT_FILE_EQUAL(text_file_1, converted_file_1); + ASSERT_FILE_EQUAL(text_file_2, converted_file_2); + + delete_file(text_file_1); + delete_file(text_file_2); + delete_file(compressed_file_1); + delete_file(compressed_file_2); + delete_file(converted_file_1); + delete_file(converted_file_2); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_multi_bad_param) +{ + if (compression_style != "xyz/gz") GTEST_SKIP(); + + if (!verbose) ::testing::internal::CaptureStdout(); + command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_dump_filename("modify_multi_bad_param_run0_*.melt.xyz"))); + if (!verbose) ::testing::internal::GetCapturedStdout(); + + TEST_FAILURE(".*ERROR: Illegal dump_modify command: compression level must in the range of.*", + command("dump_modify id1 pad 3 compression_level 12"); + ); +} + +TEST_F(DumpXYZCompressTest, compressed_modify_clevel_run0) +{ + if (!COMPRESS_BINARY) GTEST_SKIP(); + + auto base_name = "modify_clevel_run0.melt.xyz"; + auto text_file = text_dump_filename(base_name); + auto compressed_file = compressed_dump_filename(base_name); + + generate_text_and_compressed_dump(text_file, compressed_file, "", "", "", "compression_level 3", 0); + + TearDown(); + + ASSERT_FILE_EXISTS(text_file); + ASSERT_FILE_EXISTS(compressed_file); + + auto converted_file = convert_compressed_to_text(compressed_file); + + ASSERT_THAT(converted_file, Eq(converted_dump_filename(base_name))); + ASSERT_FILE_EXISTS(converted_file); + ASSERT_FILE_EQUAL(text_file, converted_file); + delete_file(text_file); + delete_file(compressed_file); + delete_file(converted_file); +} diff --git a/unittest/formats/test_dump_xyz_gz.cpp b/unittest/formats/test_dump_xyz_gz.cpp deleted file mode 100644 index aef54b4820..0000000000 --- a/unittest/formats/test_dump_xyz_gz.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *GZIP_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", GZIP_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!GZIP_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_gz_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_gz_compressed_run*.melt.xyz.gz"; - auto text_file = "dump_xyz_gz_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_gz_compressed_run0.melt.xyz.gz"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/gz", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - GZIP_BINARY = getenv("GZIP_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/formats/test_dump_xyz_zstd.cpp b/unittest/formats/test_dump_xyz_zstd.cpp deleted file mode 100644 index ce0b4ed143..0000000000 --- a/unittest/formats/test_dump_xyz_zstd.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* ---------------------------------------------------------------------- - LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator - https://lammps.sandia.gov/, Sandia National Laboratories - Steve Plimpton, sjplimp@sandia.gov - - Copyright (2003) Sandia Corporation. Under the terms of Contract - DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains - certain rights in this software. This software is distributed under - the GNU General Public License. - - See the README file in the top-level LAMMPS directory. -------------------------------------------------------------------------- */ - -#include "../testing/core.h" -#include "../testing/systems/melt.h" -#include "../testing/utils.h" -#include "fmt/format.h" -#include "utils.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" - -char *ZSTD_BINARY = nullptr; - -using ::testing::Eq; - -class DumpXYZGZTest : public MeltTest { - std::string dump_style = "xyz"; - -public: - void generate_text_and_compressed_dump(std::string text_file, std::string compressed_file, - std::string compression_style, - std::string dump_modify_options, int ntimesteps) - { - if (!verbose) ::testing::internal::CaptureStdout(); - command(fmt::format("dump id0 all {} 1 {}", dump_style, text_file)); - command(fmt::format("dump id1 all {} 1 {}", compression_style, compressed_file)); - - if (!dump_modify_options.empty()) { - command(fmt::format("dump_modify id0 {}", dump_modify_options)); - command(fmt::format("dump_modify id1 {}", dump_modify_options)); - } - - command(fmt::format("run {}", ntimesteps)); - if (!verbose) ::testing::internal::GetCapturedStdout(); - } - - std::string convert_compressed_to_text(std::string compressed_file) - { - if (!verbose) ::testing::internal::CaptureStdout(); - std::string converted_file = compressed_file.substr(0, compressed_file.find_last_of('.')); - std::string cmdline = - fmt::format("{} -d -c {} > {}", ZSTD_BINARY, compressed_file, converted_file); - system(cmdline.c_str()); - if (!verbose) ::testing::internal::GetCapturedStdout(); - return converted_file; - } -}; - -TEST_F(DumpXYZGZTest, compressed_run0) -{ - if (!ZSTD_BINARY) GTEST_SKIP(); - - auto text_files = "dump_xyz_zstd_text_run*.melt.xyz"; - auto compressed_files = "dump_xyz_zstd_compressed_run*.melt.xyz.zst"; - auto text_file = "dump_xyz_zstd_text_run0.melt.xyz"; - auto compressed_file = "dump_xyz_zstd_compressed_run0.melt.xyz.zst"; - - generate_text_and_compressed_dump(text_files, compressed_files, "xyz/zstd", "", 0); - - TearDown(); - - ASSERT_FILE_EXISTS(text_file); - ASSERT_FILE_EXISTS(compressed_file); - - auto converted_file = convert_compressed_to_text(compressed_file); - - ASSERT_FILE_EXISTS(converted_file); - ASSERT_FILE_EQUAL(text_file, converted_file); - delete_file(text_file); - delete_file(compressed_file); - delete_file(converted_file); -} - -int main(int argc, char **argv) -{ - MPI_Init(&argc, &argv); - ::testing::InitGoogleMock(&argc, argv); - - // handle arguments passed via environment variable - if (const char *var = getenv("TEST_ARGS")) { - std::vector env = utils::split_words(var); - for (auto arg : env) { - if (arg == "-v") { - verbose = true; - } - } - } - - ZSTD_BINARY = getenv("ZSTD_BINARY"); - - if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true; - - int rv = RUN_ALL_TESTS(); - MPI_Finalize(); - return rv; -} diff --git a/unittest/testing/core.h b/unittest/testing/core.h index 5852f7fd06..6243eb219e 100644 --- a/unittest/testing/core.h +++ b/unittest/testing/core.h @@ -39,7 +39,7 @@ using ::testing::MatchesRegex; } // whether to print verbose output (i.e. not capturing LAMMPS screen output). -bool verbose = false; +extern bool verbose; class LAMMPSTest : public ::testing::Test { public: diff --git a/unittest/testing/utils.h b/unittest/testing/utils.h index 39a11a3e12..c76b37872a 100644 --- a/unittest/testing/utils.h +++ b/unittest/testing/utils.h @@ -70,6 +70,9 @@ static bool file_exists(const std::string &filename) } #define ASSERT_FILE_EXISTS(NAME) ASSERT_TRUE(file_exists(NAME)) +#define ASSERT_FILE_NOT_EXISTS(NAME) ASSERT_FALSE(file_exists(NAME)) #define ASSERT_FILE_EQUAL(FILE_A, FILE_B) ASSERT_TRUE(equal_lines(FILE_A, FILE_B)) + + #endif