Skip to content

Commit

Permalink
Move index tests to separate executable (#240)
Browse files Browse the repository at this point in the history
* move index tests to separate executable

* add index ci
  • Loading branch information
alifahrri committed Jul 31, 2023
1 parent d481a76 commit bde587b
Show file tree
Hide file tree
Showing 45 changed files with 169 additions and 48 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ jobs:
./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/utl/array/numeric-tests-utl-array'
./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/utl/utl/numeric-tests-utl'
dockcross-clang-index:
name: ${{ matrix.name }}-index
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- name: linux-x64-clang
steps:
- uses: actions/checkout@v2
- name: setup dockcross
run: docker run --rm dockcross/${{ matrix.name }} > ./dockcross-${{ matrix.name }}; chmod +x ./dockcross-${{ matrix.name }}
- uses: actions/cache@v2
id: cache
with:
path: ./build/${{ matrix.name }}
key: ${{ github.job }}-${{ matrix.name }}-${{ hashFiles('./**') }}
- name: setup doctest
run: bash scripts/download_doctest_header.sh -d include/
- name: build
run: ./dockcross-${{ matrix.name }} bash -c 'mkdir -p build/${{ matrix.name }} && cd build/${{ matrix.name }}/ && cmake -DCMAKE_TOOLCHAIN_FILE=${PWD}/../../cmake/toolchains/clang-werror.cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_INDEX_TESTS=ON ../.. && make -j2 VERBOSE=1 numeric-tests-index-doctest'
- name: run tests
run: |
./dockcross-${{ matrix.name }} bash -c 'build/${{ matrix.name }}/tests/index/numeric-tests-index-doctest'
dockcross-clang-generic-ndarray:
name: ${{ matrix.name }}-generic-ndarray
runs-on: ubuntu-20.04
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/gcc-9.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ jobs:
build/tests/utl/array/numeric-tests-utl-array
build/tests/utl/utl/numeric-tests-utl
gcc-9-index:
name: gcc-9-index
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up GCC
uses: egor-tensin/setup-gcc@v1
with:
version: 9
platform: x64
- name: setup doctest
run: bash scripts/download_doctest_header.sh -d include/
- build:
run: mkdir -p build/ && cd build/ && cmake -DNMTOOLS_TEST_ALL=OFF -DNMTOOLS_BUILD_INDEX_TESTS=ON .. && make -j2 VERBOSE=1 numeric-tests-index-doctest
- name: run tests
run: |
build/tests/index/numeric-tests-index-doctest
gcc-9-constexpr-eval:
name: gcc-9-constexpr-eval
runs-on: ubuntu-20.04
Expand Down
5 changes: 5 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ if (NMTOOLS_BUILD_SIMDE_TESTS)
add_subdirectory(simde)
endif (NMTOOLS_BUILD_SIMDE_TESTS)

option(NMTOOLS_BUILD_INDEX_TESTS "build index test programs" OFF)
if (NMTOOLS_BUILD_INDEX_TESTS)
add_subdirectory(index)
endif (NMTOOLS_BUILD_INDEX_TESTS)

option(NMTOOLS_BUILD_OPENCL_TESTS "build opencl test programs" OFF)
if (NMTOOLS_BUILD_OPENCL_TESTS)
add_subdirectory(opencl)
Expand Down
48 changes: 0 additions & 48 deletions tests/array/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ endif ()
add_definitions(-DNMTOOLS_TESTING_DOCTEST_DISABLE_BENCH)

option(NMTOOLS_TEST_ALL "test all modules" ON)
option(NMTOOLS_TEST_ARRAY_INDEX "test array index modules" OFF)
option(NMTOOLS_TEST_ARRAY_UTILITY "test array utility modules" OFF)
option(NMTOOLS_TEST_UTILS "test utils modules" OFF)
option(NMTOOLS_TEST_NDARRAY "test ndarray modules" OFF)
Expand All @@ -51,7 +50,6 @@ option(NMTOOLS_TEST_FUNCTIONAL "test functional module" OFF)
option(NMTOOLS_TEST_MISC "test other modules" OFF)

if (NMTOOLS_TEST_ALL)
SET(NMTOOLS_TEST_ARRAY_INDEX ON CACHE BOOL "test array index modules" FORCE)
SET(NMTOOLS_TEST_ARRAY_UTILITY ON CACHE BOOL "test array utility modules" FORCE)
SET(NMTOOLS_TEST_UTILS ON CACHE BOOL "test utils modules" FORCE)
SET(NMTOOLS_TEST_NDARRAY ON CACHE BOOL "test ndarray modules" FORCE)
Expand All @@ -65,50 +63,6 @@ if (NMTOOLS_TEST_ALL)
SET(NMTOOLS_TEST_MISC ON CACHE BOOL "test other modules" FORCE)
endif (NMTOOLS_TEST_ALL)

set(ARRAY_INDEX_TEST_SOURCES
index/argsort.cpp
index/array_slice.cpp
index/broadcast_shape.cpp
index/broadcast_to.cpp
index/choose.cpp
index/compress.cpp
index/compute_indices.cpp
index/compute_offset.cpp
index/compute_strides.cpp
index/concatenate.cpp
index/conv.cpp
index/expand_dims.cpp
index/filter.cpp
index/free_axes.cpp
index/gather.cpp
index/insert_index.cpp
index/logical_not.cpp
index/matmul.cpp
index/moveaxis.cpp
index/ndenumerate.cpp
index/ndindex.cpp
index/nonzero.cpp
index/normalize_axis.cpp
index/outer.cpp
index/pad.cpp
index/pooling.cpp
index/remove_dims.cpp
index/remove_single_dims.cpp
index/repeat.cpp
index/reshape.cpp
index/reverse.cpp
index/scatter.cpp
index/shape_concatenate.cpp
index/shape_tile.cpp
index/slice.cpp
index/take.cpp
index/take_along_axis.cpp
index/tile.cpp
)
if (NOT NMTOOLS_TEST_ARRAY_INDEX)
set(ARRAY_INDEX_TEST_SOURCES "")
endif ()

set(UTILS_TEST_SOURCES
utils/isequal.cpp
utils/isclose.cpp
Expand Down Expand Up @@ -540,8 +494,6 @@ if (NOT NMTOOLS_TEST_FUNCTIONAL)
endif()

add_executable(${PROJECT_NAME}-doctest tests.cpp
## array detail
${ARRAY_INDEX_TEST_SOURCES}
## utility function
${UTILS_TEST_SOURCES}
## array utility
Expand Down
110 changes: 110 additions & 0 deletions tests/index/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
cmake_minimum_required(VERSION 3.10.2)
project(numeric-tests-index)

# TODO: cleanup
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
find_package(nmtools REQUIRED CONFIG)
set(${NMTOOLS_INCLUDE_DIR} ${nmtools_INCLUDE_DIRS})
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake)
endif()

# TODO: cleanup
include(nmtools)

# TODO: cleanup
# handle emscripten
if(CMAKE_CXX_COMPILER MATCHES "/em\\+\\+(-[a-zA-Z0-9.])?$")
set (EMSCRIPTEN)
endif()
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
set (ARM)
endif()

# optionally use boost (esp. for type_id)
find_package(Boost)
if (Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
endif()

enable_testing()

# TODO: remove, trye to detect constexpr math from stdlib
## defer static check to runtime for clang
## since constexpr math not supported
if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR EMSCRIPTEN OR ANDROID OR MSYS)
add_definitions(-DDEFER_STATIC_CHECK)
endif ()

## disable benchmarks
add_definitions(-DNMTOOLS_TESTING_DOCTEST_DISABLE_BENCH)

option(NMTOOLS_INDEX_TEST_ALL "test all index modules" ON)

if (NMTOOLS_INDEX_TEST_ALL)
set(ARRAY_INDEX_TEST_SOURCES
src/argsort.cpp
src/array_slice.cpp
src/broadcast_shape.cpp
src/broadcast_to.cpp
src/choose.cpp
src/compress.cpp
src/compute_indices.cpp
src/compute_offset.cpp
src/compute_strides.cpp
src/concatenate.cpp
src/conv.cpp
src/expand_dims.cpp
src/filter.cpp
src/free_axes.cpp
src/gather.cpp
src/insert_index.cpp
src/logical_not.cpp
src/matmul.cpp
src/moveaxis.cpp
src/ndenumerate.cpp
src/ndindex.cpp
src/nonzero.cpp
src/normalize_axis.cpp
src/outer.cpp
src/pad.cpp
src/pooling.cpp
src/remove_dims.cpp
src/remove_single_dims.cpp
src/repeat.cpp
src/reshape.cpp
src/reverse.cpp
src/scatter.cpp
src/shape_concatenate.cpp
src/shape_tile.cpp
src/slice.cpp
src/take.cpp
src/take_along_axis.cpp
src/tile.cpp
)
endif (NMTOOLS_INDEX_TEST_ALL)

add_executable(${PROJECT_NAME}-doctest tests.cpp
${ARRAY_INDEX_TEST_SOURCES}
)

target_compile_features(${PROJECT_NAME}-doctest PRIVATE cxx_std_17)
if (doctest_FOUND)
target_link_libraries(${PROJECT_NAME}-doctest PRIVATE doctest::doctest)
endif()

option(NMTOOLS_ENABLE_TEST_BENCHMARKS "build benchmark programs" OFF)
if (NMTOOLS_ENABLE_TEST_BENCHMARKS)
add_definitions(-DNMTOOLS_TESTING_ENABLE_BENCHMARKS)
add_library(nanobench nanobench.cpp)
target_link_libraries(${PROJECT_NAME}-doctest PRIVATE nanobench)
endif()

target_compile_features(${PROJECT_NAME}-doctest PRIVATE cxx_std_17)
target_include_directories(
${PROJECT_NAME}-doctest PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include
)

if (NMTOOLS_CODE_COVERAGE)
target_link_libraries(${PROJECT_NAME}-doctest PUBLIC coverage_config)
endif (NMTOOLS_CODE_COVERAGE)
6 changes: 6 additions & 0 deletions tests/index/nanobench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define ANKERL_NANOBENCH_IMPLEMENT
#if __has_include("nanobench/nanobench.h")
#include "nanobench/nanobench.h"
#else
#include "nanobench.h"
#endif
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.
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.
6 changes: 6 additions & 0 deletions tests/index/tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#if __has_include("doctest/doctest.h")
#include "doctest/doctest.h"
#else
#include "doctest.h"
#endif

0 comments on commit bde587b

Please sign in to comment.