Skip to content

Commit

Permalink
Add CTest testsuite
Browse files Browse the repository at this point in the history
  • Loading branch information
tbeu committed Oct 26, 2024
1 parent 2c0f829 commit ce8e58c
Show file tree
Hide file tree
Showing 25 changed files with 779 additions and 563 deletions.
51 changes: 12 additions & 39 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 5
submodules: recursive
- name: Setup python environment
uses: actions/setup-python@v5
with:
Expand All @@ -59,13 +60,13 @@ jobs:
echo "/Users/runner/Library/Python/${{ matrix.python-version }}/bin" >> $GITHUB_PATH
fi
if [ "${{ matrix.compiler }}" == "msvc" ]; then
cmake -S . -B build -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
cmake -S . -B build -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DBUILD_TESTING=ON
elif [ "${{ matrix.compiler }}" == "mingw" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_ENABLE_CPPCHECK=ON -G "MinGW Makefiles"
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DBUILD_TESTING=ON -DMATIO_ENABLE_CPPCHECK=ON -G "MinGW Makefiles"
elif [ "${{ matrix.compiler }}" == "gcc" ]; then
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DMATIO_ENABLE_CPPCHECK=ON
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DBUILD_TESTING=ON -DMATIO_ENABLE_CPPCHECK=ON
else
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF
cmake -S . -B build -DCMAKE_BUILD_TYPE=${{ matrix.configuration }} -DMATIO_USE_CONAN=ON -DMATIO_SHARED=OFF -DBUILD_TESTING=ON
fi
- name: Build with ${{ matrix.compiler }}
run: |
Expand All @@ -75,19 +76,7 @@ jobs:
cmake --build build -- -j8
fi
- name: Test
run: |
if [ "${{ matrix.compiler }}" == "msvc" ]; then
MATDUMP="./build/Release/matdump.exe"
else
MATDUMP="./build/bin/matdump"
fi
for file in ./share/*.mat; do
"$MATDUMP" -d "$file" d
"$MATDUMP" -v "$file"
"$MATDUMP" -v -f whos "$file"
done
"$MATDUMP" -v -H
"$MATDUMP" -V
run: ctest --no-tests=error --test-dir build --build-config ${{ matrix.configuration }}

build-openbsd:
name: openbsd-clang
Expand All @@ -97,6 +86,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 5
submodules: recursive
- name: Test with clang
uses: vmactions/openbsd-vm@v1
with:
Expand All @@ -107,17 +97,9 @@ jobs:
pkg_add cmake
run: |
set -e
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF -DBUILD_TESTING=ON
cmake --build build -- -j8
./build/test_snprintf
./build/test_mat -H
./build/test_mat -L
./build/test_mat -V
./build/matdump -v -H
./build/matdump -V
./build/matdump -d ./share/test_file.mat structure
./build/matdump -v ./share/test_file.mat
./build/matdump -v -f whos ./share/test_file.mat
ctest --no-tests=error --test-dir build --build-config Release
build-solaris:
name: solaris-gcc
Expand All @@ -127,6 +109,7 @@ jobs:
uses: actions/checkout@v4
with:
fetch-depth: 5
submodules: recursive
- name: Test with gcc
uses: vmactions/solaris-vm@v1
with:
Expand All @@ -139,17 +122,9 @@ jobs:
run: |
set -e
mkdir build
cmake -S . -Bbuild -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DMATIO_SHARED=OFF -DMATIO_MAT73=OFF -DBUILD_TESTING=ON
cmake --build build -- -j8
./build/test_snprintf
./build/test_mat -H
./build/test_mat -L
./build/test_mat -V
./build/matdump -v -H
./build/matdump -V
./build/matdump -d ./share/test_file.mat structure
./build/matdump -v ./share/test_file.mat
./build/matdump -v -f whos ./share/test_file.mat
ctest --no-tests=error --test-dir build --build-config Release
build-cygwin:
name: windows-cygwin
Expand Down Expand Up @@ -177,8 +152,6 @@ jobs:
export PATH=/usr/bin:$PATH
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -G Ninja
shell: C:\cygwin\bin\bash.exe -eo pipefail -o igncr '{0}'
env:
CYGWIN_NOWINPATH: 1
- name: Build with gcc
run: |
export PATH=/usr/bin:$PATH
Expand Down
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ FakesAssemblies/
# Python virtual environment
#
.venv

#
# CMake related files

build
out
CMakeLists.txt.user
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
7 changes: 6 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,14 @@ Table of Contents
2.3.3. CMake build system
The CMake build system is supported as an alternative build system,
which usually consists of three steps for configuration, build and
installation, for example,
installation. By default, the CMake project is also configured for
testing with CTest. For example,

$ tar zxf matio-X.Y.Z.tar.gz
$ cd matio-X.Y.Z
$ cmake .
$ cmake --build .
$ ctest --test-dir .
$ cmake --install .

The following matio specific options for building with CMake are
Expand Down Expand Up @@ -197,6 +200,8 @@ Table of Contents
* 'MATIO_WITH_ZLIB:BOOL=ON'
This option enables CMake to check for availability of the
zlib library (see section 2.1.1 for information about zlib).
* 'MATIO_BUILD_TESTING:BOOL=ON'
This option enables the matio testsuite for CTest.
* 'MATIO_ENABLE_CPPCHECK:BOOL=OFF'
This option enables CMake >= 3.10 to perform static analysis
with Cppcheck.
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ This option sets the default MAT file version (4,5,7.3) that will be used when w
This option specifies a suffix to apply to library directories when installing and looking for dependent libraries (i.e. HDF5 and zlib). For example, some multi-arch Linux distributions install 64-bit libraries into lib64 and 32-bit libraries into lib.

#### 2.2.3 CMake build system
The CMake build system is supported as an alternative build system, which usually consists of three steps for configuration, build and installation, for example,
The CMake build system is supported as an alternative build system, which usually consists of three steps for configuration, build and installation. By default, the CMake project is also configured for testing with CTest. For example,
```console
git clone git://git.code.sf.net/p/matio/matio
cd matio
git submodule update --init # for datasets used in unit tests
cmake .
cmake --build .
ctest --test-dir .
cmake --install .
```
The following matio specific options for building with CMake are available.
Expand All @@ -137,6 +139,8 @@ This option builds the matio library as shared object (i.e., a dynamic link libr
This option enables CMake to check for availability of the HDF5 library (see section [2.1.2](#212-hdf5) for information about HDF5).
* `MATIO_WITH_ZLIB:BOOL=ON`
This option enables CMake to check for availability of the zlib library (see section [2.1.1](#211-zlib) for information about zlib).
* `MATIO_BUILD_TESTING:BOOL=ON`
This option enables the matio testsuite for CTest.
* `MATIO_ENABLE_CPPCHECK:BOOL=OFF`
This option enables CMake ≥ 3.10 to perform static analysis with Cppcheck.

Expand Down
8 changes: 8 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ endif()
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.10")
option(MATIO_ENABLE_CPPCHECK "Enable static analysis with Cppcheck." OFF)
endif()

# Option to enable matio testsuite
option(MATIO_BUILD_TESTING "Build matio testing" ON)

set(BUILD_TESTING OFF)
if (MATIO_BUILD_TESTING)
set(BUILD_TESTING ON)
endif()
64 changes: 48 additions & 16 deletions cmake/test.cmake
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
add_executable(test_mat ${PROJECT_SOURCE_DIR}/test/test_mat.c)
target_link_libraries(test_mat matio)
if(NOT HAVE_GETOPT)
target_link_libraries(test_mat getopt)
endif()
if(MATIO_BUILD_TESTING)
add_executable(test_mat "${PROJECT_SOURCE_DIR}/test/test_mat.c")
target_link_libraries(test_mat matio)
if(NOT HAVE_GETOPT)
target_link_libraries(test_mat getopt)
endif()

if(NOT HAVE_SNPRINTF OR UNIX)
add_executable(test_snprintf
"${PROJECT_SOURCE_DIR}/test/test_snprintf.c"
"${PROJECT_SOURCE_DIR}/snprintf/snprintf.c"
)
if(HAVE_LIBM)
target_link_libraries(test_snprintf m)
endif()
target_include_directories(test_snprintf PUBLIC
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_BINARY_DIR}/src"
)
endif()

find_package(Python3 QUIET COMPONENTS Interpreter)
if(Python3_Interpreter_FOUND)
set(MATIO_CTESTS_DIR ${PROJECT_BINARY_DIR}/tests)
set(MATIO_TESTING_DIR ${MATIO_CTESTS_DIR}/temporary)
execute_process(
COMMAND "${Python3_EXECUTABLE}" "${PROJECT_SOURCE_DIR}/test/convert_at_to_ctest.py" "${MATIO_CTESTS_DIR}"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/test"
)

enable_testing()

add_test(NAME create_temp_dir
COMMAND ${CMAKE_COMMAND} -E make_directory ${MATIO_TESTING_DIR})
set_tests_properties(create_temp_dir PROPERTIES FIXTURES_SETUP TEMPDIR)

file(GLOB CMAKE_TEST_FILES "${MATIO_CTESTS_DIR}/*.cmake")
foreach(test_file ${CMAKE_TEST_FILES})
include(${test_file})
endforeach()

if(NOT HAVE_SNPRINTF OR UNIX)
add_executable(test_snprintf
${PROJECT_SOURCE_DIR}/test/test_snprintf.c
${PROJECT_SOURCE_DIR}/snprintf/snprintf.c
)
if(HAVE_LIBM)
target_link_libraries(test_snprintf m)
add_test(NAME remove_temp_dir
COMMAND ${CMAKE_COMMAND} -E remove_directory ${MATIO_TESTING_DIR})
set_tests_properties(remove_temp_dir PROPERTIES FIXTURES_CLEANUP TEMPDIR)
else()
message(WARNING
" Python3 not found."
" Set MATIO_BUILD_TESTING to OFF to silence this warning."
)
endif()
target_include_directories(test_snprintf PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src
)
endif()
2 changes: 1 addition & 1 deletion test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ CHECK_ENVIRONMENT = GREP=$(GREP) MAT73=$(MAT73) MATLABEXE=$(MATLABEXE) \
LIBTOOL="$(top_builddir)/libtool"

EXTRA_DIST = $(TESTSUITE_AT) $(TESTSUITE) $(srcdir)/package.m4 \
$(TEST_DATAFILES)
$(TEST_DATAFILES) $(srcdir)/convert_at_to_ctest.py

if NEED_GETOPT
GETOPT_CFLAGS = -I$(top_builddir)/getopt
Expand Down
Loading

0 comments on commit ce8e58c

Please sign in to comment.