Skip to content

Commit

Permalink
Merge 363ec19 into e19b886
Browse files Browse the repository at this point in the history
  • Loading branch information
benegee committed Aug 24, 2023
2 parents e19b886 + 363ec19 commit f6f6143
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 8 deletions.
41 changes: 40 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ jobs:
- name: Install HDF5
run: |
sudo apt-get install -y libhdf5-openmpi-dev
- name: Install gtest
run: |
sudo apt-get install -y libgtest-dev
- name: Install t8code
run: |
T8CODE_RELEASE=1.4.1
Expand All @@ -110,10 +113,12 @@ jobs:
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-cpp --coverage -O0" \
-DCMAKE_Fortran_FLAGS="-cpp --coverage -O0" \
-DCMAKE_EXE_LINKER_FLAGS="--coverage" \
-DCMAKE_SHARED_LINKER_FLAGS="--coverage"
-DCMAKE_SHARED_LINKER_FLAGS="--coverage" \
-DTESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia
- name: Build
run: |
cd build
Expand All @@ -131,9 +136,12 @@ jobs:
# Note that we set the Julia depot to `~/.julia` *ONLY* to make use of the
# julia-actions/cache above (which unfortunately hardcoded the `~/.julia`
# directory). For this reason, we also need to use `--force`
# Still create subfolder `julia-depot`, which reflects the typical default
# and is tested below
run: |
mkdir libtrixi-julia
cd libtrixi-julia
mkdir julia-depot
../install/bin/libtrixi-init-julia .. \
--hdf5-library /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so \
--t8code-library ../t8code-local/prefix/lib/libt8.so \
Expand Down Expand Up @@ -165,6 +173,37 @@ jobs:
../build/examples/trixi_controller_data_f . libelixir_p4est2d_dgsem_euler_sedov.jl
env:
LIBTRIXI_DEBUG: all
- name: Check error handling of examples
if: ${{ matrix.test_type == 'coverage' }}
run: |
cd libtrixi-julia
set +e # disable early exit on non-zero exit code
for command in "../build/examples/simple_trixi_controller_c" \
"../build/examples/simple_trixi_controller_c ." \
"../build/examples/simple_trixi_controller_f" \
"../build/examples/simple_trixi_controller_f ." \
"../build/examples/trixi_controller_data_c" \
"../build/examples/trixi_controller_data_c ." \
"../build/examples/trixi_controller_data_f" \
"../build/examples/trixi_controller_data_f ."
do
$command
if [ $? -ne 2 ]; then
echo "Wrong exit code for $command! Expected 2, got $?"
exit 1
fi
done
env:
LIBTRIXI_DEBUG: all
JULIA_DEPOT_PATH: ~/.julia
- name: Run CTest/gtest tests
if: ${{ matrix.test_type == 'coverage' }}
run: |
cd build/test
ctest -V
env:
LIBTRIXI_DEBUG: all
JULIA_DEPOT_PATH: ~/.julia
- name: Run memory checks with Valgrind
if: ${{ matrix.test_type == 'valgrind' }}
run: |
Expand Down
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,20 @@ list ( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" )
# Find Julia
find_package( Julia REQUIRED )



# Find MPI
find_package( MPI REQUIRED )

# Find google test on demand
option( TESTING "Build tests using google test" )
if( TESTING )
find_package( GTest REQUIRED )
if ( NOT DEFINED JULIA_PROJECT_PATH )
message( WARNING "JULIA_PROJECT_PATH not set, tests will not work.")
else()
set( JULIA_PROJECT_PATH ${JULIA_PROJECT_PATH} CACHE PATH "Path to julia project.")
endif()
endif()



# Library target
Expand Down Expand Up @@ -88,6 +97,10 @@ target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} )
# Add examples
add_subdirectory( examples )

# Add test on demand
if( TESTING )
add_subdirectory( test )
endif()


# Install configuration
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_trixi_controller.f90
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ program simple_trixi_controller_f
write(error_unit, '(a)') "ERROR: missing arguments: PROJECT_DIR LIBELIXIR_PATH"
write(error_unit, '(a)') ""
write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH"
stop 1
call exit(2)
else if (command_argument_count() < 2) then
call get_command_argument(0, argument)
write(error_unit, '(a)') "ERROR: missing argument: LIBELIXIR_PATH"
write(error_unit, '(a)') ""
write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH"
stop 1
call exit(2)
end if

! Initialize Trixi
Expand Down
4 changes: 2 additions & 2 deletions examples/trixi_controller_data.f90
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ program simple_trixi_controller_f
write(error_unit, '(a)') "ERROR: missing arguments: PROJECT_DIR LIBELIXIR_PATH"
write(error_unit, '(a)') ""
write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH"
stop 1
call exit(2)
else if (command_argument_count() < 2) then
call get_command_argument(0, argument)
write(error_unit, '(a)') "ERROR: missing argument: LIBELIXIR_PATH"
write(error_unit, '(a)') ""
write(error_unit, '(3a)') "usage: ", trim(argument), " PROJECT_DIR LIBELIXIR_PATH"
stop 1
call exit(2)
end if


Expand Down
5 changes: 4 additions & 1 deletion src/auxiliary.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ void update_depot_path(const char * project_directory, const char * depot_path)

// Construct absolute path
char absolute_path[PATH_MAX];
realpath(path, absolute_path);
char * ret = realpath(path, absolute_path);
if (ret == NULL) {
print_and_die("could not resolve depot path", LOC);
}

// Set environment variable
setenv("JULIA_DEPOT_PATH", absolute_path, 1);
Expand Down
46 changes: 46 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
enable_testing()

include( GoogleTest )

set ( TESTS
auxiliary.cpp
interface_c.cpp )


foreach ( TEST ${TESTS} )

get_filename_component ( TEST_BASE ${TEST} NAME_WE )

# define target
set ( TARGET_NAME ${TEST_BASE} )
add_executable ( ${TARGET_NAME} ${TEST})

# set libraries to link
target_link_libraries(
${TARGET_NAME}
PRIVATE MPI::MPI_C ${PROJECT_NAME} ${PROJECT_NAME}_tls GTest::gtest_main
)

# set include directories
target_include_directories(
${TARGET_NAME}
PRIVATE ${CMAKE_SOURCE_DIR}/src
)

# set runtime path for installed binaries
set_target_properties(
${TARGET_NAME}
PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib"
)

# enable warnings
target_compile_options( ${TARGET_NAME} PRIVATE -Wall -Wextra -Werror )

# pass julia project path
target_compile_definitions( ${TARGET_NAME} PRIVATE
JULIA_PROJECT_PATH=\"${JULIA_PROJECT_PATH}\" )

# discover tests
gtest_discover_tests( ${TARGET_NAME} )

endforeach()
93 changes: 93 additions & 0 deletions test/auxiliary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <gtest/gtest.h>


extern "C" {
int show_debug_output();
void update_depot_path(const char * project_directory, const char * depot_path);
}

// Julia project path defined via cmake
const char * julia_project_path = JULIA_PROJECT_PATH;

const char* default_depot_path = "julia-depot";


TEST(AuxiliaryTest, DebugOutput) {

const char * envvar = "LIBTRIXI_DEBUG";

// environment variable not set -> no debug output
unsetenv(envvar);
EXPECT_EQ( show_debug_output(), 0 );

// environment variable set to "all" -> debug output
setenv(envvar, "all", /*overwrite*/ 1 );
EXPECT_EQ( show_debug_output(), 1 );

// environment variable set to "c" -> debug output
setenv(envvar, "c", /*overwrite*/ 1 );
EXPECT_EQ( show_debug_output(), 1 );

// environment variable set to "julia" -> no debug output
setenv(envvar, "julia", /*overwrite*/ 1 );
EXPECT_EQ( show_debug_output(), 0 );
}


TEST(AuxiliaryTest, DepotPath) {

const char * depot_envvar = "JULIA_DEPOT_PATH";

// unset depot path environment variable
unsetenv(depot_envvar);

// let it be set explicitly and check
update_depot_path( julia_project_path, julia_project_path );
EXPECT_STREQ( getenv(depot_envvar), julia_project_path );

// unset depot path environment variable
unsetenv(depot_envvar);

// let it be set to default location and check
update_depot_path( julia_project_path, NULL );
std::string expected_depot_path( julia_project_path );
expected_depot_path.append("/");
expected_depot_path.append( default_depot_path );
EXPECT_STREQ( getenv(depot_envvar), expected_depot_path.c_str() );

// unset depot path environment variable
unsetenv(depot_envvar);

// be evil: use probably non-existing project path
const char * garbage_path = "/no/where";
EXPECT_DEATH( update_depot_path( garbage_path, NULL ),
"could not resolve depot path");

// unset depot path environment variable
unsetenv(depot_envvar);

// be evil: use too long project path
const char * garbage = "this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long"
"this_string_is_just_way_toooooooooooooooooooo_long";
EXPECT_DEATH( update_depot_path( garbage, NULL ),
"buffer size not sufficient for depot path construction");
}
Loading

0 comments on commit f6f6143

Please sign in to comment.