Skip to content

Commit

Permalink
[Infra] Reorganize all files
Browse files Browse the repository at this point in the history
- Employ new directory structure
- Move some stuff around

Topic: directory-reorg
Relative:
Reviewers:
  • Loading branch information
sahil-kale committed Oct 9, 2023
1 parent fce54ea commit c7ca508
Show file tree
Hide file tree
Showing 39 changed files with 72 additions and 176 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
*.out
*.app

build/
build/

# Bazel files
bazel-*
97 changes: 63 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,34 +1,63 @@
cmake_minimum_required(VERSION 3.8)

set(This MAINS)
set(BINARY ${CMAKE_PROJECT_NAME})

project(${This} C CXX)

set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_GMOCK ON)

# enable Werror
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")

enable_testing()

# add the googletest subdirectory, located in the lib folder tree that is one level above this one
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest)

# set the HEADERS as everything in the inc folder, as well as test *.hpp files
file(GLOB HEADERS "inc/*.hpp")

# set the SOURCES as everything in the src folder
file(GLOB SOURCES "src/*.cpp")

# add_executable(${BINARY}_run ${SOURCES})
add_library(${This} STATIC ${SOURCES} ${HEADERS})

add_subdirectory(test)

# To find the tests, this is rquired
include_directories(inc)
include_directories(src)
cmake_minimum_required(VERSION 3.14)

set(This tests)

set(BINARY ${CMAKE_PROJECT_NAME})

project(${This} C CXX)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_C_STANDARD 99)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(BUILD_GMOCK ON)

#enable Werror, Wextra, Wall, pedantic, and pedantic-errors
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wextra -Wall")

# enable testing
enable_testing()

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libs/googletest ${CMAKE_CURRENT_BINARY_DIR}/googletest)

# Glob recurse the headers inside hal/
file(GLOB_RECURSE HAL_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/hal/*.hpp)

# Glob recurse the headers inside hwbridge/
file(GLOB_RECURSE HWBRIDGE_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/hwbridge/*.hpp)

# Glob recurse the headers inside control_loop/
file(GLOB_RECURSE CONTROL_LOOP_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/control_loop/*.hpp)
# Glob recurse the sources inside control_loop/
file(GLOB_RECURSE CONTROL_LOOP_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/control_loop/*.cpp)

# Glob recurse the headers inside utils/
file(GLOB_RECURSE UTILS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/util/*.hpp)
# Glob recurse the sources inside utils/
file(GLOB_RECURSE UTILS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/util/*.cpp)

# Add a compiler definition -DUNITTEST to the compiler
add_definitions(-DUNIT_TEST)

# Glob recurse the headers inside test/
file(GLOB_RECURSE TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/test/*.hpp)
# Glob recurse the sources inside test/
file(GLOB_RECURSE TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp)

# Include the headers in the above paths and also do so recursively as there is a hierarchy
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hal)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hwbridge/3phase)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hwbridge/h_bridge)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/control_loop)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/control_loop/brushed)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/control_loop/bldc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/control_loop/stepper)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/util/pid)

# Mocks
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test/mocks)

# Add an executable with the above sources
add_executable(${This} ${CONTROL_LOOP_SOURCES} ${UTILS_SOURCES} ${TEST_SOURCES})

# Link the executable with the GoogleTest libraries
target_link_libraries(${This} PUBLIC gtest gtest_main gmock)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include <math.h>

#include "param_service.hpp"

namespace control_loop {

Brushless6StepControlLoop::Brushless6StepControlLoopState Brushless6StepControlLoop::get_desired_state(utime_t current_time_us,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Brushless6StepControlLoop : public ControlLoop {
CommutationSignal u;
CommutationSignal v;
CommutationSignal w;
};
} phase_commutation_signals;
} commutation_step_t;

static constexpr uint8_t num_commutation_steps = 6;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "brushed_control_loop.hpp"

#include "param_service.hpp"

namespace control_loop {

BrushedControlLoop::BrushedControlLoop() {}
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "stepper_control_loop.hpp"

#include "math.h"
#include "param_service.hpp"

namespace control_loop {

Expand Down
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.
7 changes: 0 additions & 7 deletions inc/example.hpp

This file was deleted.

92 changes: 0 additions & 92 deletions inc/param_service.hpp

This file was deleted.

5 changes: 4 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

set -exo pipefail

# make a build directory if it doesn't exist
mkdir -p build

# Change to the build directory
cd build

Expand All @@ -25,5 +28,5 @@ then
else
# If no argument is specified, build and run the tests
cmake .. -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles"
make all && ./test/tests
make all && ./tests
fi
5 changes: 0 additions & 5 deletions src/example.cpp

This file was deleted.

23 changes: 0 additions & 23 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +0,0 @@
cmake_minimum_required(VERSION 3.8)

set(This tests)

# set the test sources to everything in this folder that is cpp
file(GLOB SOURCES "*.cpp")
# add the main project sources in ../src to the test sources
file(GLOB MAIN_SOURCES "../src/*.cpp")

# include the headers from the main project, which is located at "../inc/"
include_directories(../inc)
include_directories((../test/))

add_test(
NAME ${This}
COMMAND ${This}
)

# add compiler definition for UNIT_TEST
add_definitions(-DUNIT_TEST)

add_executable(${This} ${SOURCES} ${MAIN_SOURCES})
target_link_libraries(${This} PUBLIC gtest_main gtest gmock)
1 change: 0 additions & 1 deletion test/brushed_control_loop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "brushed_control_loop.hpp"

#include "gmock/gmock.h"
#include "param_service.hpp"

namespace control_loop {

Expand Down
1 change: 0 additions & 1 deletion test/brushless_6step_control_loop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "mock_bridge_3phase.hpp"
#include "mock_hal_adc.hpp"
#include "mock_hal_clock.hpp"
#include "param_service.hpp"

namespace control_loop {
using namespace ::testing;
Expand Down
1 change: 0 additions & 1 deletion test/brushless_foc_control_loop_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "mock_hal_adc.hpp"
#include "mock_hal_clock.hpp"
#include "mock_hal_timer.hpp"
#include "param_service.hpp"

namespace control_loop {
using namespace ::testing;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions test/test.cpp

This file was deleted.

File renamed without changes.
File renamed without changes.

0 comments on commit c7ca508

Please sign in to comment.