diff --git a/source/module_io/test/read_exit_file_test.cpp b/source/module_io/test/read_exit_file_test.cpp index 4532495ea1..aa889571a8 100644 --- a/source/module_io/test/read_exit_file_test.cpp +++ b/source/module_io/test/read_exit_file_test.cpp @@ -30,54 +30,76 @@ TEST_F(ReadStopFileTest, read_exit_file) // case 1: no such file int stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 0); + MPI_Barrier(MPI_COMM_WORLD); // case 2: no keywords in the file - std::ofstream ofs(filename.c_str(), std::ios::out); - ofs << "no keywords\n\ntest" << std::endl; - ofs.close(); + std::ofstream ofs; + if (GlobalV::MY_RANK == 0) + { + ofs.open(filename.c_str(), std::ios::out); + ofs << "no keywords\n\ntest" << std::endl; + ofs.close(); + } + MPI_Barrier(MPI_COMM_WORLD); stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 0); MPI_Barrier(MPI_COMM_WORLD); - std::remove(filename.c_str()); // case 3: stop_ion = false stop_elec = false - ofs.open(filename.c_str(), std::ios::out); - ofs << "stop_ion false\nstop_elec 0" << std::endl; - ofs.close(); + if (GlobalV::MY_RANK == 0) + { + std::remove(filename.c_str()); + ofs.open(filename.c_str(), std::ios::out); + ofs << "stop_ion false\nstop_elec 0" << std::endl; + ofs.close(); + } + MPI_Barrier(MPI_COMM_WORLD); stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 0); MPI_Barrier(MPI_COMM_WORLD); - std::remove(filename.c_str()); // case 4: stop_ion = true stop_elec = false - ofs.open(filename.c_str(), std::ios::out); - ofs << "stop_ion true\nstop_elec f" << std::endl; - ofs.close(); + if (GlobalV::MY_RANK == 0) + { + std::remove(filename.c_str()); + ofs.open(filename.c_str(), std::ios::out); + ofs << "stop_ion true\nstop_elec f" << std::endl; + ofs.close(); + } + MPI_Barrier(MPI_COMM_WORLD); stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 1); MPI_Barrier(MPI_COMM_WORLD); - std::remove(filename.c_str()); // case 5: stop_ion = false stop_elec = true - ofs.open(filename.c_str(), std::ios::out); - ofs << "stop_ion F\nstop_elec 1" << std::endl; - ofs.close(); + if (GlobalV::MY_RANK == 0) + { + std::remove(filename.c_str()); + ofs.open(filename.c_str(), std::ios::out); + ofs << "stop_ion F\nstop_elec 1" << std::endl; + ofs.close(); + } + MPI_Barrier(MPI_COMM_WORLD); stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 2); MPI_Barrier(MPI_COMM_WORLD); - std::remove(filename.c_str()); // case 6: stop_ion = true stop_elec = true - ofs.open(filename.c_str(), std::ios::out); - ofs << "stop_ion T\nstop_elec t" << std::endl; - ofs.close(); + if (GlobalV::MY_RANK == 0) + { + std::remove(filename.c_str()); + ofs.open(filename.c_str(), std::ios::out); + ofs << "stop_ion T\nstop_elec t" << std::endl; + ofs.close(); + } + MPI_Barrier(MPI_COMM_WORLD); stop = ModuleIO::read_exit_file(GlobalV::MY_RANK, filename, ofs_running); EXPECT_EQ(stop, 2); MPI_Barrier(MPI_COMM_WORLD); - std::remove(filename.c_str()); ofs_running.close(); std::remove(output.c_str()); + std::remove(filename.c_str()); } int main(int argc, char** argv)