Skip to content

Update boost utf lecture #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions 05_testing_and_ci/boost_testing_exercise.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Boost.Test and CTest in Action: SideMade Exercise

In this exercise, you extend and automate the unit tests of the [SideMade code](https://github.com/Simulation-Software-Engineering/testing-boost-exercise-wt2223), on which we worked during the lecture.
In this exercise, you extend and automate the unit tests of the [SideMade code](https://github.com/Simulation-Software-Engineering/testing-boost-exercise-wt2425), on which we worked during the lecture.

Deadline: **Thursday, February 9th, 2023, 09:00**
Deadline: **Thursday, February 5, 2025, 09:00**

## Preparation and Submission


- Import the [testing boost exercise repository](https://github.com/Simulation-Software-Engineering/testing-boost-exercise-wt2223) in your own account/namespace on GitHub and name it `testing-boost-exercise` again. **Note**: We cannot work with forks here because GitHub Actions may not work in pull requests without explicit approval of the owner of the target repository
- Import the [testing boost exercise repository](https://github.com/Simulation-Software-Engineering/testing-boost-exercise-wt2425) in your own account/namespace on GitHub and name it `testing-boost-exercise` again. **Note**: We cannot work with forks here because GitHub Actions may not work in pull requests without explicit approval of the owner of the target repository
- Create a new branch `extend-tests` from `main` and work in this branch.
- To submit, open a PR from `extend-tests` to `main` in your own repository. Then paste a link to this PR in a new issue in the original repository. Use `[GITLAB-USERNAME] Boost test exercise` as title of the issue.

Expand All @@ -25,12 +24,13 @@ Deadline: **Thursday, February 9th, 2023, 09:00**
- Test: Check whether all tests run successfully.
- Add a corresponding [GitHub workflow status badge](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/adding-a-workflow-status-badge) to the `README.md`.

## Optional Task
## Optional Tasks

- Extend the automation with a [build matrix](https://docs.github.com/en/actions/using-jobs/using-a-build-matrix-for-your-jobs). Test whether your code builds in Debug and in Release mode, and with the gcc and the clang compiler. Make use of CMake variables to modify these parameters.
- Implement more tests.

## Hints and Remarks

- When importing a project on GitHub, it could be that by default actions are disabled. You can enable them via `Settings -> Actions -> General -> Allow all actions`.
- Be careful: the style job should not format the code, but rather report whether the code was formatted correctly or not. There are different ways how to do this. You could use the option `--dry-run`, but then you still need to interpret warnings as errors with `-Werror`. Or you could format inplace (`-i`) and use `git diff`.
- Try to use the build from the build job for the tests in the test job by uploading and downloading the build as an artifact. Problem is that this way file permissions are not preserved. You can work around this problem, by archiving. See [the official workaround](https://github.com/actions/upload-artifact#maintaining-file-permissions-and-case-sensitive-files).
- Try to use the build from the build job for the tests in the test job by uploading and downloading the build as an artifact. Previously, there was an issue with file permissions, where archiving was [a known workaround](https://github.com/actions/upload-artifact/tree/v3.2.1?tab=readme-ov-file#maintaining-file-permissions-and-case-sensitive-files). This should no longer be a problem.
4 changes: 2 additions & 2 deletions 05_testing_and_ci/boost_testing_intro_slides.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ slideOptions:
- Powerful unit test framework
- Sometimes called (the) **Unit Test Framework** (UTF) or **Boost.Test**
- Valid on all slides: `namespace utf = boost::unit_test;`
- [List of contributors and maintainers](https://www.boost.org/doc/libs/1_81_0/libs/test/doc/html/boost_test/acknowledgements.html)
- [List of contributors and maintainers](https://www.boost.org/doc/libs/1_87_0/libs/test/doc/html/boost_test/acknowledgements.html)

---

Expand Down Expand Up @@ -190,4 +190,4 @@ Which behavior do you then expect and why?

## Further Reading

- [Documentation of Boost Unit Test Framework](https://www.boost.org/doc/libs/1_78_0/libs/test/doc/html/index.html)
- [Documentation of Boost Unit Test Framework](https://www.boost.org/doc/libs/1_87_0/libs/test/doc/html/index.html)
18 changes: 11 additions & 7 deletions 05_testing_and_ci/boost_testing_precice_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Look around preCICE in the terminal + text editor.
- Imports `testing/Testing.hpp`, there we handle UTF imports
- Test suite for `math` namespace and test suite per file (here `math/differences.hpp`)
- `BOOST_CHECK` actually not recommended to use. Is used internally by `BOOST_TEST`.
- Powerful macro `PRECICE_TEST(1_rank)`; here it means that this test is run on one MPI rank
- Tests are normally run on 4 MPI ranks to test parallel implementation and to mimic different coupled solvers
- Powerful macro `PRECICE_TEST()` to setup test context (resources, singletons, not data)

## Unit vs. Integration Tests

- Clear separation in preCICE: integration tests only directly use API of preCICE.
- They are located in `tests` folder.
- Look at `tests/serial/initialize-data/Explicit.cpp`
- Explain `PRECICE_TEST` and how it is used
- Look at `tests/serial/initialize-data/Explicit.cpp`:
- Explain `PRECICE_TEST_SETUP` and how it is used: test is run on two MPI ranks living in seperate MPI communicators.
- Information can be accessed via `context`.
- More information: [blog post on bssw.io on multiphysics testing](https://bssw.io/blog_posts/overcoming-complexity-in-testing-multiphysics-coupling-software)

## White-Box Testing
Expand All @@ -34,18 +34,22 @@ Look around preCICE in the terminal + text editor.
- Has public and private members. We want to check the private members in tests.
- Does not `friend` every test, but only `WaveformFixture`
- `src/testing/WaveformFixture.hpp` has functions to access private members
- This fixture is used in many tests in `src/time/tests/WaveformTests`
- This fixture is used in many tests in `src/time/tests/WaveformTests` (but not handed over to test like normal UTF fixtures)

## Test Matrices

- Look at `tests/serial/mapping-nearest-projection/QuadMappingDiagonalNearestProjectionEdgesTallKite.cpp`:
- Define test matrix with data sets: `boost::unit_test::data::make`

## Test Context
## Boost Test Context

- Look at `src/mapping/tests/NearestProjectionMappingTest.cpp`:
- `BOOST_TEST_CONTEXT` outputs context information on failure

## CMake

- Look at `cmake/CTestConfig.cmake`: More things tested than only UTF
- Look at `cmake/CTestConfig.cmake`: Complicated, but more things tested than only UTF (search for `add_test`)

## CTest in Parallel

- Build preCICE and run tests via `ctest -j 16`, runs tests in parallel, automatic feature of CTest
3 changes: 3 additions & 0 deletions 05_testing_and_ci/boost_testing_sidemade_demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ Repository: [testing boost exercise – demo-start branch](https://github.com/Si
find_package(Boost 1.71 REQUIRED unit_test_framework)
file(GLOB_RECURSE TEST_FILES CONFIGURE_DEPENDS tests/*.cpp)
add_executable(testsidemade "${TEST_FILES}")
set_property(target testsidemade PROPERTY CXX_STANDARD 11)
target_link_libraries(testsidemade PRIVATE Boost::unit_test_framework)
add_test(NAME "MatrixSolverTests" COMMAND ${CMAKE_CURRENT_BINARY_DIR}/testsidemade)
```

- `add_test` can work with anything that returns an exit code. Does not have to be a fancy testing framework.

- Reconfigure CMake, build, run via ...
- `./testsidemade`
- `./testsidemade --list_content`
Expand Down
3 changes: 1 addition & 2 deletions timetable.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@

## 13.2 – Wed, January 29, 2025

- **15** min.: Lecture evaluation
- **75** min.: [Boost.Test and CTest in Action: SideMade Exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/05_testing_and_ci/boost_testing_exercise.md)
- **90** min.: [Boost.Test and CTest in Action: SideMade Exercise](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/05_testing_and_ci/boost_testing_exercise.md)

## 14.1 – Wed, February 5, 2025

Expand Down
Loading