Unverified Commit d173ea4a authored by Axel Kohlmeyer's avatar Axel Kohlmeyer Committed by GitHub
Browse files

Merge pull request #2114 from akohlmey/more-unittest-changes

More updates and corrections for unit tests
parents c34501c1 2a4bd9ef
Loading
Loading
Loading
Loading
+24 −3
Original line number Diff line number Diff line
@@ -15,14 +15,35 @@ if(ENABLE_COVERAGE)
            gen_coverage_xml
            COMMAND ${GCOVR_BINARY} -s -x -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o coverage.xml
            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
            COMMENT "Generating XML Coverage Report..."
            COMMENT "Generating XML coverage report..."
        )

        set(COVERAGE_HTML_DIR ${CMAKE_BINARY_DIR}/coverage_html)

        add_custom_target(coverage_html_folder
            COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_HTML_DIR})

        add_custom_target(
            gen_coverage_html
            COMMAND ${GCOVR_BINARY} -s  --html --html-details -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o coverage.html
            COMMAND ${GCOVR_BINARY} -s  --html --html-details -r ${ABSOLUTE_LAMMPS_SOURCE_DIR} --object-directory=${CMAKE_BINARY_DIR} -o ${COVERAGE_HTML_DIR}/index.html
            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
            COMMENT "Generating HTML Coverage Report..."
            COMMENT "Generating HTML coverage report..."
        )
        add_dependencies(gen_coverage_html coverage_html_folder)

        add_custom_target(clean_coverage_html
            ${CMAKE_COMMAND} -E remove_directory ${COVERAGE_HTML_DIR}
            COMMENT "Deleting HTML coverage report..."
        )

        add_custom_target(reset_coverage
            ${CMAKE_COMMAND} -E remove -f */*.gcda */*/*.gcda */*/*/*.gcda
                              */*/*/*/*.gcda */*/*/*/*/*.gcda */*/*/*/*/*/*.gcda
                              */*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*.gcda
                              */*/*/*/*/*/*/*/*/*.gcda */*/*/*/*/*/*/*/*/*/*.gcda
            WORKIND_DIRECTORY ${CMAKE_BINARY_DIR}
            COMMENT "Deleting coverage data files..."
        )
        add_dependencies(reset_coverage clean_coverage_html)
    endif()
endif()
+47 −8
Original line number Diff line number Diff line
@@ -244,22 +244,35 @@ and working.
     of mis-compiled code (or undesired large of precision due to
     reordering of operations).

------------
Collect and visualize code coverage metrics
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can also collect code coverage metrics while running the tests by
enabling coverage support during building.
You can also collect code coverage metrics while running LAMMPS or the
tests by enabling code coverage support during the CMake configuration:

.. code-block:: bash

   -D ENABLE_COVERAGE=value  # enable coverage measurements, value = no (default) or yes
   -D ENABLE_COVERAGE=on  # enable coverage measurements (off by default)

This will also add the following targets to generate coverage reports
after running the LAMMPS executable or the unit tests:
This will instrument all object files to write information about which
lines of code were accessed during execution in files next to the
corresponding object files.  These can be post-processed to visually
show the degree of coverage and which code paths are accessed and which
are not taken.  When working on unit tests (see above), this can be
extremely helpful to determine which parts of the code are not executed
and thus what kind of tests are still missing. The coverage data is
cumulative, i.e. new data is added with each new run.

Enabling code coverage will also add the following build targets to
generate coverage reports after running the LAMMPS executable or the
unit tests:

.. code-block:: bash

   make gen_coverage_html   # generate coverage report in HTML format
   make gen_coverage_xml    # generate coverage report in XML format
   make clean_coverage_html # delete folder with HTML format coverage report
   make reset_coverage      # delete all collected coverage data and HTML output

These reports require `GCOVR <https://gcovr.com/>`_ to be installed. The easiest way
to do this to install it via pip:
@@ -267,3 +280,29 @@ to do this to install it via pip:
.. code-block:: bash

   pip install git+https://github.com/gcovr/gcovr.git

After post-processing with ``gen_coverage_html`` the results are in
a folder ``coverage_html`` and can be viewed with a web browser.
The images below illustrate how the data is presented.

.. list-table::

      * - .. figure:: JPG/coverage-overview-top.png
             :target: JPG/coverage-overview-top.png

          Top of the overview page

        - .. figure:: JPG/coverage-overview-manybody.png
             :target: JPG/coverage-overview-manybody.png

          Styles with good coverage

        - .. figure:: JPG/coverage-file-top.png
             :target: JPG/coverage-file-top.png

          Top of individual source page

        - .. figure:: JPG/coverage-file-branches.png
             :target: JPG/coverage-file-branches.png

          Source page with branches
+153 KiB
Loading image diff...
+110 KiB
Loading image diff...
+302 KiB
Loading image diff...
Loading