Skip to content

Commit aded5d0

Browse files
authored
Merge pull request #212 from tritonuas/fix/unit_tests_handler_macro
Fix unit tests using GCS Handler Macro
2 parents dc5bf79 + 0dce15a commit aded5d0

File tree

9 files changed

+49
-81
lines changed

9 files changed

+49
-81
lines changed

CMakeLists.txt

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,11 @@ add_subdirectory(src)
118118
# =============================
119119

120120
# =============================
121-
# Integration tests
121+
# Tests
122122

123-
add_subdirectory(tests/integration)
124-
125-
# cuda_check
126-
add_executable(cuda_check ${SOURCES} tests/integration/cuda_check.cpp)
127-
target_add_torch(cuda_check)
128-
target_add_json(cuda_check)
129-
target_add_httplib(cuda_check)
130-
target_add_mavsdk(cuda_check)
131-
target_add_matplot(cuda_check)
132-
target_add_protobuf(cuda_check)
133-
target_add_opencv(cuda_check)
134-
target_add_loguru(cuda_check)
135-
# for some reason calling target_add_imagemagick here conflicts with, so we are including/linking without the function call
136-
# target_add_imagemagick(cuda_check)
137-
target_include_directories(cuda_check PRIVATE ${ImageMagick_INCLUDE_DIRS})
138-
target_link_libraries(cuda_check PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})
139-
140-
# =============================
141-
142-
# =============================
143-
# Unit tests
144-
add_subdirectory(tests/unit)
145123
add_subdirectory(${DEPS_DIRECTORY}/google-test)
124+
add_subdirectory(tests)
125+
146126
# =============================
147127

148128
# =============================

tests/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# so everything in unit and integration tests can include header files in this directory
2+
include_directories(util)
3+
4+
add_compile_definitions(CONFIG_DIRECTORY="${PROJECT_SOURCE_DIR}/configs")
5+
6+
add_subdirectory(integration)
7+
8+
add_subdirectory(unit)

tests/integration/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,18 @@ target_add_matplot(camera_mock)
283283
target_add_loguru(camera_mock)
284284
target_include_directories(camera_mock PRIVATE ${ImageMagick_INCLUDE_DIRS})
285285
target_link_libraries(camera_mock PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})
286+
287+
# cuda_check
288+
add_executable(cuda_check ${SOURCES} cuda_check.cpp)
289+
target_add_torch(cuda_check)
290+
target_add_json(cuda_check)
291+
target_add_httplib(cuda_check)
292+
target_add_mavsdk(cuda_check)
293+
target_add_matplot(cuda_check)
294+
target_add_protobuf(cuda_check)
295+
target_add_opencv(cuda_check)
296+
target_add_loguru(cuda_check)
297+
# for some reason calling target_add_imagemagick here conflicts with, so we are including/linking without the function call
298+
# target_add_imagemagick(cuda_check)
299+
target_include_directories(cuda_check PRIVATE ${ImageMagick_INCLUDE_DIRS})
300+
target_link_libraries(cuda_check PRIVATE -Wl,--copy-dt-needed-entries ${ImageMagick_LIBRARIES})

tests/integration/airdrop_approach.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
#include "utilities/datatypes.hpp"
2121
#include "utilities/http.hpp"
2222

23-
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
24-
int argc = 2; \
25-
char path1[] = "bin/obcpp"; \
26-
char path2[] = "../configs/dev-config.json"; \
27-
char *paths[] = {path1, path2}; \
28-
char **paths_ptr = paths; \
29-
std::shared_ptr<MissionState> STATE = std::make_shared<MissionState>(OBCConfig(argc, paths_ptr)); \
30-
httplib::Request REQ; \
31-
httplib::Response RESP
23+
#include "handler_params.hpp"
3224

3325
const static char* mission_json_2024 = R"(
3426
{

tests/integration/coverage_pathing.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,8 @@
2020
#include "utilities/datatypes.hpp"
2121
#include "utilities/http.hpp"
2222

23-
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
24-
int argc = 2; \
25-
char path1[] = "bin/obcpp"; \
26-
char path2[] = "../configs/dev-config.json"; \
27-
char *paths[] = {path1, path2}; \
28-
char **paths_ptr = paths; \
29-
std::shared_ptr<MissionState> STATE = \
30-
std::make_shared<MissionState>(OBCConfig(argc, paths_ptr)); \
31-
httplib::Request REQ; \
32-
httplib::Response RESP
23+
#include "handler_params.hpp"
24+
3325

3426
const static char *mission_json_2020 = R"(
3527
{

tests/integration/coverage_pathing_2.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,7 @@
2020
#include "utilities/datatypes.hpp"
2121
#include "utilities/http.hpp"
2222

23-
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
24-
int argc = 2; \
25-
char path1[] = "bin/obcpp"; \
26-
char path2[] = "../configs/dev-config.json"; \
27-
char* paths[] = {path1, path2}; \
28-
char** paths_ptr = paths; \
29-
std::shared_ptr<MissionState> STATE = \
30-
std::make_shared<MissionState>(OBCConfig(argc, paths_ptr)); \
31-
httplib::Request REQ; \
32-
httplib::Response RESP
23+
#include "handler_params.hpp"
3324

3425
const static char* mission_json_2024 = R"(
3526
{

tests/integration/path_planning.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,7 @@
2020
#include "utilities/datatypes.hpp"
2121
#include "utilities/http.hpp"
2222

23-
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
24-
int argc = 2; \
25-
char path1[] = "bin/obcpp"; \
26-
char path2[] = "../configs/dev-config.json"; \
27-
char *paths[] = {path1, path2}; \
28-
char **paths_ptr = paths; \
29-
std::shared_ptr<MissionState> STATE = std::make_shared<MissionState>(OBCConfig(argc, paths_ptr)); \
30-
httplib::Request REQ; \
31-
httplib::Response RESP
23+
#include "handler_params.hpp"
3224

3325
const static char* mission_json_2020 = R"(
3426
{

tests/unit/gcs_server_test.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,7 @@
2020
#include "ticks/mav_upload.hpp"
2121
#include "ticks/tick.hpp"
2222

23-
// TODO: figure out why it is seg faulting when running these unit tests and fix it...
24-
// I think it's something to do with DECLARE_HANDLER_PARAMS not being up to
25-
// date with updated command line arguments, but after trying to fix that it was
26-
// stil seg faulting and I want a green checkmark...
27-
28-
/*
29-
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
30-
int argc = 2; \
31-
char path1[] = "bin/obcpp"; \
32-
char path2[] = "../configs"; \
33-
char path3[] = "dev"; \
34-
char path4[] = "stickbug"; \
35-
char path5[] = "sitl"; \
36-
char *paths[] = {path1, path2, path3, path4, path5}; \
37-
char **paths_ptr = paths; \
38-
std::shared_ptr<MissionState> STATE = std::make_shared<MissionState>(OBCConfig(argc, paths_ptr)); \
39-
httplib::Request REQ; \
40-
httplib::Response RESP
23+
#include "handler_params.hpp"
4124

4225
// Might have to change this later on if we preload
4326
// mission from file
@@ -214,5 +197,4 @@ TEST(GCSServerTest, SetupStateTransitions) {
214197

215198
// todo: figure out way to mock the mav connection
216199
// so we can validate the path and mock mission upload
217-
}
218-
*/
200+
}

tests/util/handler_params.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TESTS_HELPERS_HPP_
2+
#define TESTS_HELPERS_HPP_
3+
4+
#define DECLARE_HANDLER_PARAMS(STATE, REQ, RESP) \
5+
int argc = 5; \
6+
char argv0[] = "bin/obcpp"; \
7+
char argv1[] = CONFIG_DIRECTORY; \
8+
char argv2[] = "dev"; \
9+
char argv3[] = "stickbug"; \
10+
char argv4[] = "sitl"; \
11+
char *argv[] = {argv0, argv1, argv2, argv3, argv4, nullptr }; \
12+
std::shared_ptr<MissionState> STATE = std::make_shared<MissionState>(OBCConfig(argc, argv)); \
13+
httplib::Request REQ; \
14+
httplib::Response RESP
15+
16+
#endif // TESTS_HELPERS_HPP_

0 commit comments

Comments
 (0)