diff --git a/.github/workflows/catkin_build.yml b/.github/workflows/catkin_build.yml deleted file mode 100644 index f31e2c8..0000000 --- a/.github/workflows/catkin_build.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: 'ROS Noetic: Build and Test' - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - name: Build and Test - runs-on: ubuntu-latest - container: ros:noetic-ros-base-focal - steps: - - uses: actions/checkout@v4 - - - name: Install System Deps on Noetic - run: | - apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 - apt update && apt install -y python3-wstool python3-catkin-tools git libtool - - - name: Build - env: - DEBIAN_FRONTEND: noninteractiv - shell: bash - run: | - apt update - mkdir -p $HOME/catkin_ws/src; - cd $HOME/catkin_ws - catkin init - catkin config --extend "/opt/ros/noetic" - catkin config --merge-devel - catkin config --cmake-args -DCMAKE_BUILD_TYPE=RelWithDebInfo - cd $HOME/catkin_ws/src - ln -s $GITHUB_WORKSPACE - - # Dependencies - git clone https://github.com/catkin/catkin_simple.git - git clone https://github.com/ethz-asl/glog_catkin.git - git clone https://github.com/ethz-asl/eigen_catkin.git - # Build - catkin build catkin_simple glog_catkin eigen_catkin - catkin build spatial_hash - - - name: Test - shell: bash - run: | - cd $HOME/catkin_ws - catkin test spatial_hash --test-target test \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..6fedb18 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,49 @@ +--- +name: 'Spatial Hash: Build and Test' +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Dependencies + run: sudo apt-get update && sudo apt install pipx + - name: Lint + run: pipx install pre-commit && cd ${{github.workspace}} && pre-commit run --all-files + cmake: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Dependencies + run: sudo apt-get update && sudo apt install libgtest-dev libeigen3-dev libgoogle-glog-dev + - name: Configure + run: cmake -B ${{github.workspace}}/build -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release + - name: Build + run: cmake --build ${{github.workspace}}/build --config Release + - name: Test + working-directory: ${{github.workspace}}/build + run: ctest -C Release + ros2: + runs-on: ubuntu-latest + container: ros:jazzy-ros-base + steps: + - uses: actions/checkout@v4 + with: {path: src/spatial_hash} + - name: Dependencies + run: | + sudo apt-get update + rosdep update --rosdistro jazzy && rosdep install --rosdistro jazzy --from-paths src --ignore-src -r -y + - name: Build + shell: bash + run: | + source /opt/ros/jazzy/setup.bash + colcon build --cmake-args --no-warn-unused-cli -DCMAKE_BUILD_TYPE=Release + - name: Test + shell: bash + run: |- + source /opt/ros/jazzy/setup.bash + colcon test diff --git a/CMakeLists.txt b/CMakeLists.txt index f21fb2c..597c43c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,6 @@ set(CMAKE_CXX_EXTENSIONS OFF) add_compile_options(-Wall -Wextra) -option(SPATIAL_HASH_BUILD_TESTS "Build tests" ON) - find_package(Eigen3 REQUIRED) find_package(PkgConfig REQUIRED) pkg_check_modules(glog REQUIRED IMPORTED_TARGET libglog) @@ -26,8 +24,8 @@ target_include_directories( ) target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen PkgConfig::glog) -if(SPATIAL_HASH_BUILD_TESTS) - find_package(GTest REQUIRED) +include(CTest) +if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() diff --git a/README.md b/README.md index 52f278e..65c860d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -![Build and Test](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/catkin_build.yml/badge.svg) +[![Spatial Hash: Build and Test](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/ci.yaml/badge.svg)](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/ci.yaml) # Spatial Hash A minimal library for spatial data structures based on voxel-block-hashing. @@ -35,7 +35,7 @@ It was developed by [Lukas Schmid](https://schmluk.github.io/) at the [MIT-SPARK cd build cmake .. make -j - + # optionally install this package sudo make install ``` diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7cc169d..2850715 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,19 +1,4 @@ -if(NOT TARGET gtest) - include(FetchContent) - FetchContent_Declare( - googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.13.0 - ) - - FetchContent_GetProperties(googletest) - if(NOT googletest_POPULATED) - FetchContent_Populate(googletest) - endif() - - set(BUILD_SHARED_LIBS_THIS ${BUILD_SHARED_LIBS}) - set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "") - add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL) - set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_THIS} CACHE BOOL "") -endif() +find_package(GTest REQUIRED) include(GoogleTest) enable_testing() @@ -33,7 +18,3 @@ add_executable( target_include_directories(utest_${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(utest_${PROJECT_NAME} PRIVATE ${PROJECT_NAME} GTest::gtest_main) gtest_add_tests(TARGET utest_${PROJECT_NAME}) - -install(TARGETS utest_${PROJECT_NAME} -RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME} -) diff --git a/tests/utest_hash.cpp b/tests/utest_hash.cpp index cfc27a8..6a0ceb8 100644 --- a/tests/utest_hash.cpp +++ b/tests/utest_hash.cpp @@ -39,11 +39,10 @@ namespace spatial_hash { -template -IndexType randomIndex(const Type range) { - return IndexType(static_cast(rand() % (2 * range) - range), - static_cast(rand() % (2 * range) - range), - static_cast(rand() % (2 * range) - range)); +template +IndexType randomIndex(const Type range, Generator& gen) { + std::uniform_int_distribution distribution(-range, range); + return IndexType(distribution(gen), distribution(gen), distribution(gen)); } // Compute the badness of a hash map. The lower the better the hash. 0 is optimal @@ -85,13 +84,15 @@ TEST(Hash, HashMapAccess) { // NOTE(lschmid): Takes a few seconds to compute and onlyu relevant if hash is updated (see if it // gets better or worse, might need more thorough test cases though.) TEST(Hash, DISABLED_HashMapCollisions) { + std::random_device rd; + std::mt19937 gen(rd()); + IndexHashMap map; int range = 1290; - srand(42); // Within range. for (size_t i = 0; i < 100000; ++i) { - map[randomIndex(range)] = i; + map[randomIndex(range, gen)] = i; } double badness = computeMapBadness(map); EXPECT_NEAR(badness, 0.002408, 1e-6); @@ -100,7 +101,7 @@ TEST(Hash, DISABLED_HashMapCollisions) { range = 10000; map.clear(); for (size_t i = 0; i < 100000; ++i) { - map[randomIndex(range)] = i; + map[randomIndex(range, gen)] = i; } badness = computeMapBadness(map); EXPECT_NEAR(badness, 0.0, 1e-6);