Skip to content

Commit

Permalink
reorganize test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
aperijake committed Jul 30, 2024
1 parent 3240dd0 commit a19f4c6
Show file tree
Hide file tree
Showing 41 changed files with 308 additions and 247 deletions.
435 changes: 228 additions & 207 deletions .github/workflows/ci-cd-pipeline.yaml

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions cmake/performance_testing.cmake
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
############# PERFORMANCE TESTING #############
file(GLOB PERFORMANCE_TEST_SOURCES "test/*PerformanceTest.cpp")
list(APPEND PERFORMANCE_TEST_SOURCES "test/UnitTestUtils.cpp")
list(FILTER TEST_SOURCES EXCLUDE REGEX "test/unit_tests.cpp")
file(GLOB PERFORMANCE_TEST_SOURCES "test/performance_tests/gtests/*.cpp")
list(APPEND PERFORMANCE_TEST_SOURCES "test/unit_tests/UnitTestUtils.cpp")

# Add an executable for the unit tests
add_executable(performance_tests
test/performance_tests.cpp # Test runner file
${PERFORMANCE_TEST_SOURCES}
)
target_include_directories(performance_tests PRIVATE
"${CMAKE_SOURCE_DIR}/include/"
"${CMAKE_SOURCE_DIR}/test/"
"${CMAKE_SOURCE_DIR}/test/unit_tests/"
"${CMAKE_SOURCE_DIR}/test/performance_tests/gtests/"
${MPI_INCLUDE_PATH}
)
target_link_libraries(performance_tests
aperimech
GTest::gtest_main
)
gtest_discover_tests(performance_tests TIMEOUT 3600 DISCOVERY_TIMEOUT 600)
gtest_discover_tests(performance_tests TIMEOUT 3600 DISCOVERY_TIMEOUT 600)
43 changes: 34 additions & 9 deletions cmake/testing.cmake
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
############# TESTING #############
enable_testing()
include(GoogleTest)
file(GLOB TEST_SOURCES "test/*.cpp")
list(FILTER TEST_SOURCES EXCLUDE REGEX ".*PerformanceTest.cpp$")
list(FILTER TEST_SOURCES EXCLUDE REGEX "test/performance_tests.cpp")
file(GLOB TEST_SOURCES "test/unit_tests/*.cpp")

# Add an executable for the unit tests
add_executable(unit_tests
test/unit_tests.cpp # Test runner file
${TEST_SOURCES}
)
target_include_directories(unit_tests PRIVATE
"${CMAKE_SOURCE_DIR}/include/"
"${CMAKE_SOURCE_DIR}/test/"
"${CMAKE_SOURCE_DIR}/test/unit_tests/"
${MPI_INCLUDE_PATH}
)
target_link_libraries(unit_tests
Expand All @@ -21,17 +18,45 @@ target_link_libraries(unit_tests
)
gtest_discover_tests(unit_tests TIMEOUT 3600 DISCOVERY_TIMEOUT 600)

# Add a custom target to run all the unit tests, both the googletests in unit_tests and testbook tests in the python notebooks (e.g. material_tests)
add_custom_target(run_all_unit_tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/run_all_unit_tests.sh
#--------------------------------------------------
# Add a custom target to run all the unit tests
add_custom_target(run_unit_tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/run_unit_tests.sh
DEPENDS unit_tests
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
#--------------------------------------------------

#--------------------------------------------------
# Add a custom target to run all the material tests, the testbook tests in the python notebooks (e.g. material_tests)
add_custom_target(run_material_tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/run_material_tests.sh
DEPENDS material_driver
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

# Create a symbolic link to the material_test directory in the build directory so that the run_all_unit_tests script can find it
add_custom_target(create_material_tests_symlink ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_SOURCE_DIR}/test/material_tests ${CMAKE_CURRENT_BINARY_DIR}/material_tests
COMMENT "Creating symlink to material_tests directory"
)
add_dependencies(run_all_unit_tests create_material_tests_symlink)
add_dependencies(run_material_tests create_material_tests_symlink)
#--------------------------------------------------

#--------------------------------------------------
# Add a custom target to run all the utils module tests
add_custom_target(run_utils_modules_tests
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test/run_utils_modules_tests.sh
DEPENDS aperi-mech
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

# Create a symbolic link to the utils directory in the build directory so that the run_all_unit_tests script can find it
add_custom_target(create_utils_symlink ALL
COMMAND ${CMAKE_COMMAND} -E create_symlink
${CMAKE_SOURCE_DIR}/test/utils ${CMAKE_CURRENT_BINARY_DIR}/utils
COMMENT "Creating symlink to utils directory"
)
add_dependencies(run_utils_modules_tests create_utils_symlink)
#--------------------------------------------------
File renamed without changes.
File renamed without changes.
25 changes: 1 addition & 24 deletions test/run_all_unit_tests.sh → test/run_material_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi

# Check if material_tests/python_test_driver.py exists
if [[ ! -f ./material_tests/python_test_driver.py ]]; then
echo "python_test_driver.py not found. Please run this script from the build directory."
echo "material_tests/python_test_driver.py not found. Please run this script from the build directory."
exit 1
fi

Expand All @@ -21,25 +21,13 @@ if [[ ! -f ./material_driver ]]; then
exit 1
fi

# Check if unit_tests exists
if [[ ! -f ./unit_tests ]]; then
echo "unit_tests executable not found. Please build the project first."
echo "This should be run from the build directory using the command: make run_all_tests"
exit 1
fi

# Check if pytest is installed
if ! command -v pytest &> /dev/null; then
echo "pytest is not installed. Please install pytest per the README instructions and be sure to activate the correct conda environment (e.g. conda activate aperi-mech) before running the tests."
exit 1
fi
# -----------------------------------------------------------------------------

# Run C++ Google Tests
echo "Running C++ Google Tests..."
./unit_tests
gtest_status=$?

# Run Python tests with pytest
echo "Running Python tests with pytest..."
# Set JUPYTER_PLATFORM_DIRS environment variable to use platformdirs, supressing warnings
Expand All @@ -49,14 +37,3 @@ mkdir -p ./material_tests_temp_files
# Full path to the temporary directory
temp_dir=$(realpath ./material_tests_temp_files)
pytest ./material_tests/python_test_driver.py --material_driver="./material_driver" --path_to_notebooks="./material_tests" --temp_dir="${temp_dir}"
pytest_status=$?

# Check if any tests failed
if [[ ${gtest_status} -ne 0 ]] || [[ ${pytest_status} -ne 0 ]]; then
echo "Some tests failed."
echo "Remember to load the correct conda environment (e.g. conda activate aperi-mech) before running the tests."
exit 1
else
echo "All tests passed."
exit 0
fi
17 changes: 17 additions & 0 deletions test/run_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# -----------------------------------------------------------------------------
# Check for required files and folders

# Check if unit_tests exists
if [[ ! -f ./unit_tests ]]; then
echo "unit_tests executable not found. Please build the project first."
echo "This should be run from the build directory using the command: make run_all_tests"
exit 1
fi

# -----------------------------------------------------------------------------

# Run C++ Google Tests
echo "Running C++ Google Tests..."
./unit_tests
22 changes: 22 additions & 0 deletions test/run_utils_modules_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# -----------------------------------------------------------------------------
# Check for required files and folders

# Check if utils exists
if [[ ! -d ./utils ]]; then
echo "utils directory not found. Please run this script from the build directory."
exit 1
fi

# Check if utils/unit_test_all_modules.py exists
if [[ ! -f ./utils/unit_test_all_modules.py ]]; then
echo "utils/unit_test_all_modules.py not found. Please run this script from the build directory."
exit 1
fi

# -----------------------------------------------------------------------------

# Run unit tests for all modules
echo "Running unit tests for all utils modules..."
python3 ./utils/unit_test_all_modules.py
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/utils/regression_test/test_regression_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUpClass(cls) -> None:
if cls.aperi_mech is None:
error_msg = "aperi-mech not found at: " + cls.aperi_mech
error_msg += "\nPlease make sure the environment is set up correctly:"
error_msg += "\n - Make sure 'aperi-mech' is in the PATH. e.g. 'which aperi-mech' to check. If not, add it to the PATH: 'export PATH=\$PATH:/path/to/aperi-mech'"
error_msg += r"\n - Make sure 'aperi-mech' is in the PATH. e.g. 'which aperi-mech' to check. If not, add it to the PATH: 'export PATH=\$PATH:/path/to/aperi-mech'"
raise FileNotFoundError(error_msg)

# Get the current directory
Expand Down

0 comments on commit a19f4c6

Please sign in to comment.