A unit-testing framework to do the exercises


  • We’ll be using the unit-testing framework as a black-box to verify the correctness of your code in hands-on sessions.
    • You only need to change one file per activity; Mostly
  • Exercises are provided as test units for convenient interaction with the code (compile-run-debug cycles).
  • Clone this repo and run Alltest using your local OpenFOAM installation to make sure everything works as expected.

The following diagram depicts the general workflow of solving the exercises proposed during the hands-on sessions:

%%{init: {'theme':'dark'}}%% flowchart TD subgraph one[<b>foamUT repo</b>] subgraph dum1[ ] A("Alltest") G("Catch2") F[Compile and test<br>everything in tests<br>on cases] H("tests") I("cases") E[Unit-tests backend] end end subgraph two[<b>Exercises repo</b>] subgraph dum2[ ] B("exercises/*C") J("exercises/Make") C[This is the files you modify] D[Make dir. for your<br> OpenFOAM fork] end end B ==> |Symlink/Copy into tests| H C -.- B D -.- J G -.- E A -.- F A --> G F -.-> H F -.-> I classDef Title fill:none,stroke:none; class dum1,dum2 Title classDef graphDate fill-opacity:0.15,color:#E1B028 classDef date fill-opacity:0.85,color:#FFFFFF,fill:#1d0e4e class one,two graphDate class A,B,G,H,I,J date

In short, the Alltest script runs all unit tests found in tests directory on all OpenFOAM cases found in cases directory. So, to run your own tests:

# Clone the repos
cd /tmp
git clone https://github.com/FoamScience/foamUT foamUT
git clone <Exercise-repo-URL> Ex01
# Replace sample tests with the exercise code
cd foamUT
rm -rf tests/exampleTests
ln -s $PWD/../Ex01/exercises $PWD/tests/ex01
# Compile and run tests
./Alltest
Important notes about using foamUT
  • If you want to see FATAL ERRORS (As if running a regular solver), put Foam::FatalError.dontThrowExceptions(); at the start of the test case.
  • Your code is supposed to work (all tests pass) both in serial and in parallel.
  • The unit tests are timed-out in Alltest (change timeOut if it’s too quick for you).
  • The unit tests run in /dev/shm by default; you can change this in Alltest
  • All cases run on 4 processors but tests may run on specific processors only.

If your machine has less than 4 CPUs, you need to enable MPI oversubscribing; otherwise your parallel tests will fail (This is useful for example if you’re using Github codespaces or running CI jobs on Github machines which only have 2 CPUs):

sed -i 's/mpirun/mpirun --oversubscribe/g' Alltest

At this point, only one task remains:

  1. Register to the Workshop’s event
  2. Set up a Text Editor or an IDE for OpenFOAM development.
  3. Have a working OpenFOAM installation.
  4. Clone our unit-testing framework and make sure it works for you.
  5. Solve a demo exercise so you get familiarized with the typical workflow during the hands-on sessions (You’ll need no knowledge from the workshop for this).