./testall # Launch all tests
./testall --help # revise how it goes if you forgot
./testall --tests=-all # run no test at all (yeah, that's useless)
-./testall --dump-only # Display all existing test suite
-./testall --tests=-all,+dict # Only launch the tests from the dict testsuite
+./testall --dump-only # Display all existing test suites
+./testall --tests=-all,+dict # Only launch the tests from the dict test suite
./testall --tests=-all,+foo:bar # run only the bar test from the foo suite.
\endverbatim
\section inside_tests_add_units Adding unit tests
If you want to test a specific function or set of functions, you need
-a unit test. Edit
-<project/directory>/tools/cmake/UnitTesting.cmake to add your
-source file to the TEST_CFILES list, and add the corresponding unit
-file to the TEST_UNITS list. For example, if your file is toto.c,
-your unit file will be toto_unit.c. The full path to your file must be
-provided, but the unit file will always be in src/ directly.
-
-If you want to create unit tests in the file src/xbt/toto.c, your
-changes should look similar to:
+a unit test. Edit the file tools/cmake/UnitTesting.cmake to
+add your source file to the FILES_CONTAINING_UNITTESTS list. For
+example, if you want to create unit tests in the file src/xbt/plouf.c,
+your changes should look like that:
\verbatim
--- a/tools/cmake/UnitTesting.cmake
+++ b/tools/cmake/UnitTesting.cmake
-@@ -11,6 +11,7 @@ set(TEST_CFILES
+@@ -11,6 +11,7 @@ set(FILES_CONTAINING_UNITTESTS
src/xbt/xbt_strbuff.c
src/xbt/xbt_sha.c
src/xbt/config.c
-+ src/xbt/toto.c
- )
- set(TEST_UNITS
- ${CMAKE_CURRENT_BINARY_DIR}/src/cunit_unit.c
-@@ -22,6 +23,7 @@ set(TEST_UNITS
- ${CMAKE_CURRENT_BINARY_DIR}/src/xbt_strbuff_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/xbt_sha_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/config_unit.c
-+ ${CMAKE_CURRENT_BINARY_DIR}/src/toto_unit.c
-
- ${CMAKE_CURRENT_BINARY_DIR}/src/simgrid_units_main.c
++ src/xbt/plouf.c
)
+
+ if(HAVE_MC)
\endverbatim
Then, you want to actually add your tests in the source file. All the
intermediate steps. The messages will be shown only if the
corresponding test fails.
-Here is a recaping example, inspired from the dynar implementation.
+Here is a recaping example, inspired from src/xbt/dynar.h (see that
+file for details).
@code
/* The rest of your module implementation */
-# To add a new tested file, simply add the original file in
-# TEST_CFILES and generated file in TEST_UNITS. The rest is automatic.
+# This file is in charge of the unit testing in SimGrid.
+# See http://simgrid.gforge.inria.fr/simgrid/3.13/doc/inside_tests.html#inside_tests_add_units
-set(TEST_CFILES
+# To register a file containing unit tests, simply add it to
+# FILES_CONTAINING_UNITTESTS and have a pleasant day.
+
+set(FILES_CONTAINING_UNITTESTS
src/xbt/cunit.c
src/xbt/ex.c
src/xbt/dynar.c
src/xbt/xbt_str.c
src/xbt/xbt_strbuff.c
src/xbt/config.c
- )
-set(TEST_UNITS
- ${CMAKE_CURRENT_BINARY_DIR}/src/cunit_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/ex_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/dynar_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/dict_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/swag_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/xbt_str_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/xbt_strbuff_unit.c
- ${CMAKE_CURRENT_BINARY_DIR}/src/config_unit.c
-
- ${CMAKE_CURRENT_BINARY_DIR}/src/simgrid_units_main.c
- )
+)
if(HAVE_MC)
- set(TEST_CFILES ${TEST_CFILES}
+ set(FILES_CONTAINING_UNITTESTS ${FILES_CONTAINING_UNITTESTS}
src/mc/PageStore.cpp
src/mc/mc_snapshot.cpp
- )
- set(TEST_UNITS ${TEST_UNITS}
- ${CMAKE_CURRENT_BINARY_DIR}/src/PageStore_unit.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/src/mc_snapshot_unit.cpp
- )
+ )
endif()
-ADD_CUSTOM_COMMAND(
- OUTPUT ${TEST_UNITS}
-
- DEPENDS ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl
- ${TEST_CFILES}
-
- COMMAND ${CMAKE_COMMAND} -E remove -f ${TEST_UNITS}
+#### Nothing to change below this line to add a new tested file
+################################################################
- COMMAND chmod +x ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl
+foreach(file ${FILES_CONTAINING_UNITTESTS})
+ get_filename_component(basename ${file} NAME_WE)
+ set(EXTRACTED_TEST_SOURCE_FILES ${EXTRACTED_TEST_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/src/${basename}_unit.c)
+endforeach()
+
+set(EXTRACTED_TEST_SOURCE_FILES ${EXTRACTED_TEST_SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/src/simgrid_units_main.c)
- COMMAND ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl --root=src/ --outdir=${CMAKE_CURRENT_BINARY_DIR}/src/ ${TEST_CFILES}
-
- WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
+set_source_files_properties(${EXTRACTED_TEST_SOURCE_FILES} PROPERTIES GENERATED true)
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${EXTRACTED_TEST_SOURCE_FILES}
+ DEPENDS ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl ${FILES_CONTAINING_UNITTESTS}
COMMENT "Generating *_units files for testall..."
- )
-
-### Ensure the build of testall
-set_source_files_properties(${TEST_UNITS} PROPERTIES GENERATED true)
+ WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}
+ COMMAND ${CMAKE_COMMAND} -E remove -f ${EXTRACTED_TEST_SOURCE_FILES}
+ COMMAND chmod +x ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl
+ COMMAND ${CMAKE_HOME_DIRECTORY}/tools/sg_unit_extractor.pl --root=src/ --outdir=${CMAKE_CURRENT_BINARY_DIR}/src/ ${FILES_CONTAINING_UNITTESTS}
+)
-add_executable (testall ${TEST_UNITS})
+add_executable (testall ${EXTRACTED_TEST_SOURCE_FILES})
target_link_libraries(testall simgrid)