Skip to content

Commit dc68016

Browse files
committed
Update integration test, hide behind cmake flag
Signed-off-by: Evan Flynn <[email protected]>
1 parent b8af9df commit dc68016

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ if(BUILD_TESTING)
8686
test/test_pixel_formats.cpp)
8787
target_link_libraries(test_pixel_formats
8888
${PROJECT_NAME})
89-
# TODO(flynneva): rewrite this test in another PR
90-
# Integration tests
91-
# ament_add_gtest(test_usb_cam_lib
92-
# test/test_usb_cam_lib.cpp)
93-
# target_link_libraries(test_usb_cam_lib
94-
# ${PROJECT_NAME})
89+
if(INTEGRATION_TESTS)
90+
ament_add_gtest(test_usb_cam_lib
91+
test/test_usb_cam_lib.cpp)
92+
target_link_libraries(test_usb_cam_lib
93+
${PROJECT_NAME})
94+
endif()
9595
endif()
9696

9797
install(

README.md

+19-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,25 @@ Unfortunately `rviz2` and `show_image.py` do not support visualizing the compres
154154
ros2 run image_transport republish compressed raw --ros-args --remap in/compressed:=image_raw/compressed --remap out:=image_raw/uncompressed
155155
```
156156

157-
## Address and leak sanitizing
157+
## Testing
158+
159+
To run the basic unit tests for this repository:
160+
161+
```shell
162+
colcon build --packages-select usb_cam
163+
colcon test --pacakges-select usb_cam
164+
```
165+
166+
### Integration tests
167+
168+
To run integration tests for this repository:
169+
170+
```shell
171+
colcon build --packages-select usb_cam --cmake-args -DINTEGRATION_TESTS=1
172+
colcon test --pacakges-select usb_cam
173+
```
174+
175+
### Address and leak sanitizing
158176

159177
Incorporated into the `CMakelists.txt` file to assist with memory leak and address sanitizing
160178
is a flag to add these compile commands to the targets.

include/usb_cam/usb_cam.hpp

+21-26
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,27 @@ typedef struct
104104

105105
typedef struct
106106
{
107-
std::string camera_name; // can be anything
108-
std::string device_name; // usually /dev/video0 or something similiar
109-
std::string frame_id;
110-
std::string io_method_name;
111-
std::string camera_info_url;
112-
// these parameters all have to be a combination supported by the device
113-
// Use
114-
// v4l2-ctl --device=0 --list-formats-ext
115-
// to discover them,
116-
// or guvcview
117-
std::string pixel_format_name;
118-
std::string av_device_format;
119-
int image_width;
120-
int image_height;
121-
int framerate;
122-
int brightness;
123-
int contrast;
124-
int saturation;
125-
int sharpness;
126-
int gain;
127-
int white_balance;
128-
int exposure;
129-
int focus;
130-
bool auto_white_balance;
131-
bool autoexposure;
132-
bool autofocus;
107+
std::string camera_name = "usb_cam"; // can be anything
108+
std::string device_name = "/dev/video0"; // usually /dev/video0 or something similiar
109+
std::string frame_id = "camera";
110+
std::string io_method_name = "mmap";
111+
std::string camera_info_url = "package://usb_cam/config/camera_info.yaml";
112+
std::string pixel_format_name = "yuyv2rgb";
113+
std::string av_device_format = "YUV422P";
114+
int image_width = 600;
115+
int image_height = 400;
116+
int framerate = 30.0;
117+
int brightness = -1;
118+
int contrast = -1;
119+
int saturation = -1;
120+
int sharpness = -1;
121+
int gain = -1;
122+
int white_balance = -1;
123+
int exposure = -1;
124+
int focus = -1;
125+
bool auto_white_balance = true;
126+
bool autoexposure = true;
127+
bool autofocus = false;
133128
} parameters_t;
134129

135130
typedef struct

test/test_usb_cam_lib.cpp

+8-11
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,19 @@
3838
TEST(test_usb_cam_lib, test_usb_cam_class) {
3939
usb_cam::UsbCam test_usb_cam;
4040

41+
usb_cam::parameters_t parameters;
42+
test_usb_cam.configure(parameters, usb_cam::utils::IO_METHOD_MMAP);
43+
44+
test_usb_cam.start();
45+
4146
auto supported_fmts = test_usb_cam.get_supported_formats();
4247

4348
// TODO(flynneva): iterate over availble formats with test_usb_cam obj
4449
for (auto fmt : supported_fmts) {
4550
std::cerr << "format: " << fmt.format.type << std::endl;
4651
}
4752

48-
// TODO(flynneva): rework these tests in another MR
49-
{
50-
// test_usb_cam.configure(
51-
// "/dev/video0",
52-
// usb_cam::utils::IO_METHOD_MMAP,
53-
// "yuyv2rgb", 640, 480, 30);
54-
// test_usb_cam.start();
55-
// TODO(flynneva): uncomment once /dev/video0 can be simulated in CI
56-
// EXPECT_TRUE(test_usb_cam.is_capturing());
57-
// test_usb_cam.shutdown();
58-
}
53+
// TODO(flynneva): uncomment once /dev/video0 can be simulated in CI
54+
EXPECT_TRUE(test_usb_cam.is_capturing());
55+
test_usb_cam.shutdown();
5956
}

0 commit comments

Comments
 (0)