add post-installation test (answer issue #2361)#2362
Conversation
Address issue #2361 by adding a post-installation test goal (`post_install_tests`). This works by: - generating a top-level CMakeLists.txt file with hardcoded paths reflecting the installation directories and installing it in a directory with documentation - installing two simple CMakeLists.txt files meant as t8code use examples; the two are located in respective sub-directories, both containing the same sample t8code program (the first tutorial program actually) - ensuring that the top-level CMakeLists.txt file is be usable from anywhere without further configuration, and uses the two CMakeLists.txt files to build two executables and run them (via the `tests` target) - having a `post_install_tests` target, to build the above two programs in the temporary `post_install_tests_dir` directory for test purposes - assuming the `post_install_tests` target to only work after `install` - keeping the test to be basic - the goal is to have detection of the t8code library to work, as well as build and execution of the two test programs Current shortcomings: - test limited to Linux - not documented anywhere ( ideal would be in this files' tree, but current t8code practice uses t8code.wiki, which is separate ) - it may assume that the two MPI-enabled executables can be ran straight-ahead - installation happens in a documentation directory, but to be enabled, this feature relies on T8CODE_BUILD_TUTORIALS, not T8CODE_BUILD_DOCUMENTATION p.s.: Since this is my first contribution to t8code, I'm including my authorization to treat this contribution under the "FreeBSD License" and I'm signing (at least) this commit with my usual GPG key.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2362 +/- ##
=======================================
Coverage 82.30% 82.30%
=======================================
Files 125 125
Lines 20559 20559
=======================================
Hits 16922 16922
Misses 3637 3637 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
sandro-elsweijer
left a comment
There was a problem hiding this comment.
Thanks for the contribution, this is a good and useful addition to our testing pipeline, especially for testing the validity of the installed packages.
For merging, we’ll need it a bit more aligned with our coding guidelines: clearer structure (one responsibility per folder), more descriptive naming instead of single-letter identifiers, and a more CMake-native approach instead of shell/system-specific assumptions. Also, hardcoding should really be avoided unless there’s no reasonable alternative.
With those adjustments, this looks ready to go.
| cmake_minimum_required(VERSION 3.22.0) | ||
| project(t8test DESCRIPTION "t8code test program (requires CMAKE_PREFIX_PATH to point to T8CODE's package files are)" LANGUAGES CXX) | ||
| find_package(T8CODE) | ||
| add_executable(test_a test.cxx) |
There was a problem hiding this comment.
Can you please avoid using single letter file names, variable names, etc.?
| endif() | ||
| find_path(SC_INCLUDE_DIR sc.h REQUIRED) | ||
| find_path(T8CODE_INCLUDE_DIR t8.h REQUIRED) | ||
| add_executable(test_b test.cxx) |
There was a problem hiding this comment.
It'd be good to have the directories under doc/cmake_examples easily enumerable via globbing from elsewhere -- i.e. with no need to know their identifier in other places. The current scheme was "single letter". I could introduce a prefix (e.g. example_mini and example_midi); that would be an epsilon more informative (not worth the cognitive effort IMO) but would be introducing redundancy (which I'm striving to reduce). Would you still prefer that way (say example_mini and example_midi) ?
There was a problem hiding this comment.
What about post_installation_check_1 and post_installation_check_2?
There is nothing against using enumerations of any sort, but test_b and test.cxx are not really descriptive and it could mean anything.
| endif( T8CODE_EXPORT_COMPILE_COMMANDS ) | ||
|
|
||
| install( TARGETS ${ADD_T8_TUTORIAL_NAME} RUNTIME ) | ||
| install( FILES ${ADD_T8_TUTORIAL_SOURCES} DESTINATION ${CMAKE_INSTALL_DOCDIR}/tutorials/general/ ) |
There was a problem hiding this comment.
Can you please add a new configuration argument to do this and place this in its own cmake file inside the test folder? We want to keep all directories true to their purpose and the tutorial folder is just for tutorials. Same for the documentation folder.
There was a problem hiding this comment.
Why are you suggesting a new configuration variable? test/CMakeLists.txt depends on T8CODE_BUILD_TESTS, which is an already existing configuration variable.
There was a problem hiding this comment.
I think he meant that it should not be installed in ${ADD_T8_TUTORIAL_SOURCES}.
There was a problem hiding this comment.
No, I meant that this is a post installation test and that it does not have anything to do with the tutorials. Yes, it uses a tutorial source file as test subject, but as a user i would not expect a post installation test in the tutorial folder. I would expect this to be in the test folder.
Also, I would not expect this post installation test to be dependent on the T8CODE_BUILD_TUTORIALS option since, as i already explained, it is a test.
| # notice that in the following, we install files from doc/ and tutorials/ together: | ||
| file(GLOB T8CODE_CMAKE_EXAMPLES RELATIVE "${PROJECT_SOURCE_DIR}/doc/cmake_examples/" "${PROJECT_SOURCE_DIR}/doc/cmake_examples/?") # for each single-character directory; notice there's no explicit listing here | ||
| configure_file( ${PROJECT_SOURCE_DIR}/doc/cmake_examples/CMakeLists.txt.in ${CMAKE_BINARY_DIR}/doc/cmake_examples/CMakeLists.txt @ONLY) | ||
| install(FILES ${CMAKE_BINARY_DIR}/doc/cmake_examples/CMakeLists.txt DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/ RENAME CMakeLists.txt) # reminder that we may want to name this differently (yet, no necessity for .in) | ||
| foreach(_dir IN LISTS T8CODE_CMAKE_EXAMPLES) | ||
| install(DIRECTORY ${PROJECT_SOURCE_DIR}/doc/cmake_examples/${_dir} DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/) # notice we take directories from doc... | ||
| install(FILES ${PROJECT_SOURCE_DIR}/tutorials/general/t8_step0_helloworld.cxx DESTINATION ${CMAKE_INSTALL_DOCDIR}/cmake_examples/${_dir}/ RENAME test.cxx) #... and add the same sample tutorial program as a test | ||
| endforeach() |
There was a problem hiding this comment.
You can happily re-use the tutorial files as test source code, but the actual testing should stay outside the tutorial folder
There was a problem hiding this comment.
I don't understand your comment. Testing happens anyway in a post_install_tests_dir directory.
There was a problem hiding this comment.
I meant, that the main purpose of this whole PR is to introduce a software test. Therefore, everything should be located in the test folder. The PR is not meant as documentation and also not as a tutorial. Yes, users could look at this to inspire them, but the main purpose is still that this is a software test.
| if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) # post-install tests currently limited to our main development OS | ||
| add_custom_target(post_install_tests # notice that add_test() would not be appropriate for this test | ||
| COMMAND rm -fR post_install_tests_dir # we perform the test out of this cmake tree | ||
| COMMAND mkdir post_install_tests_dir | ||
| COMMAND cd post_install_tests_dir && cmake ${CMAKE_INSTALL_PREFIX}/share/doc/T8CODE/cmake_examples/ && make VERBOSE=1 && make VERBOSE=1 tests | ||
| COMMAND rm -fR post_install_tests_dir | ||
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | ||
| VERBATIM | ||
| COMMENT "Post-install tests' target. It creates, uses, and deletes temporary directory 'post_install_tests_dir'. It assumes running under Linux." | ||
| ) | ||
| endif() |
There was a problem hiding this comment.
I tried to translate this to cmake commands as good as possible. This way cmake peserves the used generator, build type, etc. and it is also OS agnostic.
The BINARY_DIR could be extracted from the (PROJECT_BINARY_DIR)[PROJECT_BINARY_DIR] cmake variable and passed to the test in the CMakeLists calling this build script.
| if ( CMAKE_SYSTEM_NAME MATCHES "Linux" ) # post-install tests currently limited to our main development OS | |
| add_custom_target(post_install_tests # notice that add_test() would not be appropriate for this test | |
| COMMAND rm -fR post_install_tests_dir # we perform the test out of this cmake tree | |
| COMMAND mkdir post_install_tests_dir | |
| COMMAND cd post_install_tests_dir && cmake ${CMAKE_INSTALL_PREFIX}/share/doc/T8CODE/cmake_examples/ && make VERBOSE=1 && make VERBOSE=1 tests | |
| COMMAND rm -fR post_install_tests_dir | |
| WORKING_DIRECTORY ${PROJECT_BINARY_DIR} | |
| VERBATIM | |
| COMMENT "Post-install tests' target. It creates, uses, and deletes temporary directory 'post_install_tests_dir'. It assumes running under Linux." | |
| ) | |
| endif() | |
| # Remove any previous build directory. | |
| file(REMOVE_RECURSE "${BINARY_DIR}/post_install_tests") | |
| file(MAKE_DIRECTORY "${BINARY_DIR}") | |
| set(EXAMPLE_DIR | |
| "${INSTALL_PREFIX}/path_to_dir" | |
| ) | |
| # Run configure step | |
| execute_process( | |
| COMMAND | |
| ${CMAKE_COMMAND} | |
| -S "${EXAMPLE_DIR}" | |
| -B "${BINARY_DIR/post_install_tests}" | |
| RESULT_VARIABLE result | |
| ) | |
| if(NOT result EQUAL 0) | |
| message(FATAL_ERROR "Failed to configure installed example.") | |
| endif() | |
| # Run build step | |
| execute_process( | |
| COMMAND | |
| ${CMAKE_COMMAND} | |
| --build "${BINARY_DIR/post_install_tests}" | |
| RESULT_VARIABLE result | |
| ) | |
| if(NOT result EQUAL 0) | |
| message(FATAL_ERROR "Failed to build installed example.") | |
| endif() | |
| # Run tests | |
| execute_process( | |
| COMMAND | |
| ${CMAKE_COMMAND} | |
| --build "${BINARY_DIR/post_install_tests}" | |
| --target tests | |
| RESULT_VARIABLE result | |
| ) | |
| if(NOT result EQUAL 0) | |
| message(FATAL_ERROR "Installed example tests failed.") | |
| endif() | |
| file(REMOVE_RECURSE "${BINARY_DIR/post_install_tests}") |
There was a problem hiding this comment.
You removed the post_install_tests target along the way. We want to have that.
There was a problem hiding this comment.
Ah sorry, I added it back
Closes #2363
Address issue #2361 by adding a post-installation test goal (
post_install_tests).This works by:
teststarget)post_install_teststarget, to build the above two programs in the temporarypost_install_tests_dirdirectory for test purposespost_install_teststarget to only work afterinstallCurrent shortcomings:
p.s.: Since this is my first contribution to t8code, I'm including my
authorization to treat this contribution under the "FreeBSD License"
and I'm signing (at least) this commit with my usual GPG key.
Describe your changes here:
All these boxes must be checked by the AUTHOR before requesting review:
Documentation:,Bugfix:,Feature:,Improvement:orOther:.All these boxes must be checked by the REVIEWERS before merging the pull request:
As a reviewer please read through all the code lines and make sure that the code is fully understood, bug free, well-documented and well-structured.
General
Tests
If the Pull request introduces code that is not covered by the github action (for example coupling with a new library):
Scripts and Wiki
scripts/internal/find_all_source_files.shto check the indentation of these files.License
doc/(or already has one).