Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
gtest as test suite

CI to auto detect all tests + use ninja
  • Loading branch information
Foo committed Feb 5, 2024
1 parent 512dfe2 commit 2e95113
Show file tree
Hide file tree
Showing 234 changed files with 8,696 additions and 8,388 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/runTests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Unit Tests

on:
Expand All @@ -17,38 +16,41 @@ jobs:
include:
- name: ubuntu-gcc
os: ubuntu-latest
compiler_opt: "-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -G \"Unix Makefiles\""
compiler_opt: "-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++"
build_system: '-G Ninja'
- name: ubuntu-clang
os: ubuntu-latest
compiler_opt: "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -G \"Unix Makefiles\""
compiler_opt: "-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++"
build_system: '-G Ninja'
- name: windows-VS
os: windows-latest
compiler_opt: ""
build_system: ""

runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/[email protected]
- name: Checkout submodules
run: git submodule update --init --recursive
- name: show HEAD
run: git rev-parse HEAD
- name: Install openMp
if: matrix.name == 'ubuntu-clang'
run: sudo apt-get update; sudo apt-get install -y libomp5 libomp-dev
- name: Install Ninja
if: matrix.build_system == '-G Ninja'
uses: seanmiddleditch/gha-setup-ninja@master
- name: CMake configure
run: cmake -B./build -DCMAKE_INSTALL_PREFIX:STRING=./artifacts/ -DBUILD_MT_RRT_SAMPLES=ON -DBUILD_MT_RRT_TESTS=ON -DENABLE_MT_RRT_TESTS_LOGGING=ON -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_BUILD_TYPE:STRING=Release ${{ matrix.compiler_opt }}
run: cmake -B./build -DCMAKE_INSTALL_PREFIX:STRING=./artifacts/ -D BUILD_MT_RRT_SAMPLES=ON -DBUILD_MT_RRT_TESTS=ON -DCMAKE_CONFIGURATION_TYPES="Release" -DCMAKE_BUILD_TYPE:STRING=Release ${{ matrix.build_system }} ${{ matrix.compiler_opt }}
- name: Build
run: cmake --build ./build --config Release
- name: Install
run: cmake --install ./build --config Release
- name: carpet tests
run: ./artifacts/bin/MT-RRT-carpet-tests
- name: trivial problem tests
run: ./artifacts/bin/MT-RRT-sample-TrivialProblem-lib-tests
- name: core tests
run: ./artifacts/bin/MT-RRT-core-tests
- name: multi threaded planners tests
run: ./artifacts/bin/MT-RRT-multi-threaded-tests
- name: planar robots problem tests
run: ./artifacts/bin/MT-RRT-sample-PlanarRobotsProblem-lib-tests
- name: navigation problem tests
run: ./artifacts/bin/MT-RRT-sample-NavigationProblem-lib-tests
- name: Tests-show
run: python script/RunTests.py --folder ./artifacts/bin --list
- name: Tests
run: python script/RunTests.py --folder ./artifacts/bin
- uses: actions/upload-artifact@v2
with:
path: artifacts
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ build
.vscode
log-*
.vs
TODO
__pycache__
*.pyc
39 changes: 20 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,30 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MakeTest.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/MakeLibrary.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchJSONlib.cmake)

project(MT-RRT)

option(LIB_OPT "Compile shared libraries (ON) or static (OFF)" OFF)
set(MT_RRT_SCRIPTS ${CMAKE_CURRENT_SOURCE_DIR}/script)

option(BUILD_MT_RRT_TESTS "Build MT-RRT tests" OFF)
if(BUILD_MT_RRT_TESTS)
message("fetching catch2")
include(FetchContent)
FetchContent_Declare(
catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG 4ff8b27bb6bed4b8b309e56cd269b4f1fbc24e89
)
FetchContent_MakeAvailable(catch2)

option(ENABLE_MT_RRT_TESTS_LOGGING "Enable log generations when running tests" ON)
include(${MT_RRT_SCRIPTS}/Fetch.cmake)
include(${MT_RRT_SCRIPTS}/Terraform.cmake)

if(DEFINED PYTHON_EXECUTABLE)
# indeed, this env var is defined by the setup.py script
# if here the package is being built in order to generate a wheel
set(PYTHON_CMD ${PYTHON_EXECUTABLE})
else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
find_package(PythonLibs 3 REQUIRED)
set(PYTHON_CMD "${Python3_EXECUTABLE}")
endif()
set(COMMON_KIT_PATH ${CMAKE_SOURCE_DIR}/script)

option(LIB_OPT "Compile shared libraries (ON) or static (OFF)" OFF)

option(BUILD_MT_RRT_TESTS "Build MT-RRT tests" OFF)
option(BUILD_MT_RRT_SAMPLES "Build MT-RRT samples" ON)

add_subdirectory(src)
add_subdirectory(samples)
add_subdirectory(extern)

Terraform(src)
Terraform(problems)
12 changes: 0 additions & 12 deletions cmake/FetchJSONlib.cmake

This file was deleted.

34 changes: 0 additions & 34 deletions cmake/MakeLibrary.cmake

This file was deleted.

24 changes: 0 additions & 24 deletions cmake/MakeTest.cmake

This file was deleted.

17 changes: 17 additions & 0 deletions extern/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
include(FetchContent)

if(BUILD_MT_RRT_TESTS)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
if (WIN32)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
endif (WIN32)
FetchContent_MakeAvailable(googletest)
endif()

if(BUILD_MT_RRT_TESTS OR BUILD_MT_RRT_SAMPLES)
Fetch(https://github.com/nlohmann/json.git v3.10.5 json_lib)
endif()
1 change: 1 addition & 0 deletions problems/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CMakeLists.txt
File renamed without changes.
File renamed without changes.
76 changes: 76 additions & 0 deletions problems/misc/header/Geometry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Author: Andrea Casalino
* Created: 16.02.2021
*
* report any bug to [email protected].
**/

#pragma once

#include <MT-RRT/Limited.h>
#include <MT-RRT/View.h>

#ifdef _WIN32
#include <corecrt_math_defines.h>
#endif
#include <math.h>

#include <array>
#include <optional>
#include <variant>

namespace mt_rrt::geom {
static constexpr float PI = static_cast<float>(M_PI);
static constexpr float PI_HALF = static_cast<float>(M_PI_2);

float to_rad(float angle);

float to_grad(float angle);

// important!!! b is assumed to have the same size of a,
// but no check is done inside this function
float distance(const View &a, const View &b);

// important!!! b is assumed to have the same size of a,
// but no check is done inside this function
float dot(const View &a, const View &b);

struct Point {
Point() : Point{0, 0} {}
Point(float x, float y);
Point(const View &v);

Point(const Point &o) : Point{o.data_[0], o.data_[1]} {}
Point &operator=(const Point &o);

Point(Point &&o);
Point &operator=(Point &&o);

const float *data() const { return data_; }

View asView() const { return View{data_, 2}; }

std::vector<float> asVec() const {
return std::vector<float>{data_[0], data_[1]};
}

private:
std::optional<std::array<float, 2>> container_;
const float *data_;
};

float distance(const Point &a, const Point &b);

float dot(const Point &a, const Point &b);

Point sum(const Point &subject, const Point &to_add,
const std::optional<float> &to_add_scale = std::nullopt);

Point diff(const Point &subject, const Point &to_remove,
const std::optional<float> &to_remove_scale = std::nullopt);

float curve_length(const std::vector<std::vector<float>> &sequence);

float curve_similarity(const std::vector<std::vector<float>> &a,
const std::vector<std::vector<float>> &b);
} // namespace mt_rrt::geom
66 changes: 66 additions & 0 deletions problems/misc/header/LogResult.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Author: Andrea Casalino
* Created: 16.02.2021
*
* report any bug to [email protected].
**/

#pragma once

#include <MT-RRT/Extender.h>
#include <MT-RRT/Node.h>
#include <MT-RRT/Planner.h>

#include <Logger.h>
#include <MiscConversions.h>

namespace mt_rrt {
template <typename ObstacleT> struct ObstacleTrait {};

template <> struct ObstacleTrait<geom::Box> {
static std::string typeStr() { return "Box"; }
};

template <> struct ObstacleTrait<geom::Segment> {
static std::string typeStr() { return "Segment"; }
};

template <> struct ObstacleTrait<geom::Sphere> {
static std::string typeStr() { return "Sphere"; }
};

class LogResult {
public:
LogResult();

const auto &get() const { return content; }

nlohmann::json &addToScene(const std::string &key) { return scene[key]; }

template <typename ObstacleT> void addObstacle(const ObstacleT &subject) {
auto &added = obstacles.emplace_back();
to_json(added, subject);
added["type"] = ObstacleTrait<ObstacleT>::typeStr();
}

void addTree(const TreeHandler &tree);

void addSolution(const std::vector<std::vector<float>> &sequence);
void addSolution(const Solution &solution);

void addPlannerSolution(const PlannerSolution &sol) {
for (const auto &tree : sol.trees) {
addTree(*tree);
}
auto &added = solutions.emplace_back();
added["sequence"] = sol.solution;
}

private:
nlohmann::json content;
nlohmann::json &scene = content["scene"];
nlohmann::json &obstacles = scene["obstacles"];
nlohmann::json &trees = content["trees"];
nlohmann::json &solutions = content["solutions"];
};
} // namespace mt_rrt
35 changes: 35 additions & 0 deletions problems/misc/header/Logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Author: Andrea Casalino
* Created: 16.02.2021
*
* report any bug to [email protected].
**/

#pragma once

#include <nlohmann/json.hpp>

#include <filesystem>
#include <unordered_map>
#include <unordered_set>

namespace mt_rrt {
class Logger {
public:
static Logger &get();

void add(const std::string &tag, const std::string &title,
const nlohmann::json &content);

static const auto &logRoot() { return LOG_FOLDER; }

private:
// clean up the log folder when building a new singleton
Logger();

static inline const std::filesystem::path LOG_FOLDER =
std::filesystem::path{MT_RRT_LOG_FOLDER};

std::unordered_map<std::string, std::unordered_set<std::string>> results;
};
} // namespace mt_rrt
Loading

0 comments on commit 2e95113

Please sign in to comment.