diff --git a/example/ALL_Staggered.cpp b/example/ALL_Staggered.cpp index 328fb23916382ef59c26b2ea43bb56c2514289bc..5f6e5d64248b9e321b50e51feb28b70478e77198 100644 --- a/example/ALL_Staggered.cpp +++ b/example/ALL_Staggered.cpp @@ -228,6 +228,7 @@ int main(int argc, char** argv) jall->printVTKoutlines(CurrentStep); } catch (ALL::FilesystemErrorException &e) { std::cout << e.what() << std::endl; + std::exit(2); // Maybe also treat this error in some way, e.g. whether the simulation // should abort if no output could be written or not. } diff --git a/example/ALL_Staggered_f.F90 b/example/ALL_Staggered_f.F90 index 88a9576085a3f40cc2c9767d26f43baff1405056..e2a1894e41ac9ba48d1eefc13d3218dd7ace707f 100644 --- a/example/ALL_Staggered_f.F90 +++ b/example/ALL_Staggered_f.F90 @@ -139,7 +139,7 @@ contains integer :: my_rank, maximum_rank integer :: i,j type(ALL_t) :: jall -#ifdef ALL_VTK_OUTPUT +#ifdef ALL_VTK_OUTPUT_EXAMPLE character (len=ALL_ERROR_LENGTH) :: error_msg #endif @@ -209,7 +209,7 @@ contains write(stdout,'(a,i0,"/",i0)') "Starting step: ", current_step, number_of_steps flush(stdout) endif -#ifdef ALL_VTK_OUTPUT +#ifdef ALL_VTK_OUTPUT_EXAMPLE call ALL_reset_error() call jall%print_vtk_outlines(current_step) if(ALL_error() /= 0) then @@ -217,6 +217,8 @@ contains write(stdout, '(a)') error_msg ! Maybe also abort if the output is necesssary or handle this ! some other way. + call MPI_Abort(MPI_COMM_WORLD, 2, error) + stop endif #endif call jall%balance() @@ -227,7 +229,7 @@ contains call MPI_Barrier(MPI_COMM_WORLD, error) enddo -#ifdef ALL_VTK_OUTPUT +#ifdef ALL_VTK_OUTPUT_EXAMPLE call ALL_reset_error() call jall%print_vtk_outlines(current_step) if(ALL_error() /= 0) then @@ -235,6 +237,8 @@ contains write(stdout, '(a)') error_msg ! Maybe also abort if the output is necesssary or handle this ! some other way. + call MPI_Abort(MPI_COMM_WORLD, 2, error) + stop endif #endif diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 12a1e44073d88cb5b633439ef4c25425cce1c384..029269dab8cd1e9dbf16cd0074965e73a6b1db07 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -44,6 +44,7 @@ install(TARGETS read_binary_output add_executable(ALL_Staggered ALL_Staggered.cpp) if(CM_ALL_VTK_OUTPUT) + target_compile_definitions(ALL_Staggered PRIVATE ALL_VTK_OUTPUT_EXAMPLE) target_include_directories(ALL_Staggered PUBLIC ${VTK_INCLUDE_DIRS}) target_link_libraries(ALL_Staggered PUBLIC ${VTK_LIBRARY_DIRS}) endif(CM_ALL_VTK_OUTPUT) @@ -111,6 +112,7 @@ if(CM_ALL_FORTRAN) add_executable(ALL_Staggered_f ALL_Staggered_f.F90) if(CM_ALL_VTK_OUTPUT) + target_compile_definitions(ALL_Staggered_f PRIVATE ALL_VTK_OUTPUT_EXAMPLE) target_include_directories(ALL_Staggered_f PUBLIC ${VTK_INCLUDE_DIRS}) target_link_libraries(ALL_Staggered_f PUBLIC ${VTK_LIBRARY_DIRS}) endif(CM_ALL_VTK_OUTPUT) diff --git a/include/ALL.hpp b/include/ALL.hpp index 2308e0a689838e7220b9090d5955e5cec15fcdeb..f0c685ecc23c53da38e19791f3df8bd30bb07d67 100644 --- a/include/ALL.hpp +++ b/include/ALL.hpp @@ -822,10 +822,20 @@ private: errno = 0; mode_t mode = S_IRWXU | S_IRWXG; // rwx for user and group if(mkdir(filename, mode)) { - if(errno == EEXIST) return; + if(errno != EEXIST) { + throw FilesystemErrorException( + __FILE__, __func__, __LINE__, + "Could not create output directory."); + } + } + // check permission in case directory already existed, but had wrong + // permissions + struct stat attr; + stat(filename, &attr); + if( (attr.st_mode & S_IRWXU) != S_IRWXU) { throw FilesystemErrorException( __FILE__, __func__, __LINE__, - "Could not create output directory."); + "Possibly already existing directory does not have correct permissions (rwx) for user"); } } diff --git a/src/ALL_fortran.cpp b/src/ALL_fortran.cpp index 36f46c31d0e622db2dbfd88fba1883cf7879e3bc..004cda9edfd2efb234118882c33e4cb864059b75 100644 --- a/src/ALL_fortran.cpp +++ b/src/ALL_fortran.cpp @@ -302,6 +302,10 @@ void all_errdesc_c(char *description, size_t len) { } else { strncpy(description, "No error", len); } + // Use space padding instead of zero padding + // WARNING: The result is no longer a zero terminated string! + size_t msg_len = strlen(description); + memset(description+msg_len, ' ', len-msg_len); } }//extern "C" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 67946b019d1dafb26ccf88b105a758147865a308..68f5bca9eaa4941f610bccd21c4cc487e2d6c239 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,4 +2,7 @@ add_subdirectory(unit) if(CM_ALL_TESTS_INTEGRATION) add_subdirectory(feature) endif() +if(CM_ALL_FORTRAN) + add_subdirectory(fortran_error) +endif() # vim: sw=4 ts=4 et diff --git a/tests/fortran_error/CMakeLists.txt b/tests/fortran_error/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e25c3e8b3b3076801cbc76f4e99cd620b378d19 --- /dev/null +++ b/tests/fortran_error/CMakeLists.txt @@ -0,0 +1,31 @@ +# The VTK error test case, where the output directory is not accessible. +include(FindUnixCommands) +set(OUT_DIR vtk_outline) +add_test( + NAME fortran_error_vtk_setup + COMMAND ${BASH} -c "mkdir -p ${OUT_DIR} && chmod -x ${OUT_DIR}; exit $?" + ) +set_tests_properties(fortran_error_vtk_setup PROPERTIES + LABELS "ALL;fortran_error" + FIXTURES_SETUP fortran_error_filesystem + ) +add_test( + NAME fortran_error_vtk_cleanup + COMMAND ${BASH} -c "chmod +x ${OUT_DIR} && rm -rf ${OUT_DIR}" + ) +set_tests_properties(fortran_error_vtk_cleanup PROPERTIES + LABELS "ALL;fortran_error" + FIXTURES_CLEANUP fortran_error_filesystem + ) +add_test( + NAME fortran_error_vtk + COMMAND ${BASH} -c "mpirun -n 1 $<TARGET_FILE:ALL_Staggered_f>; exit $?" + ) +set_tests_properties(fortran_error_vtk PROPERTIES + LABELS "ALL;fortran_error" + FIXTURES_REQUIRED fortran_error_filesystem + WILL_FAIL TRUE + ) + + +# vim: et sw=4 ts=4