Skip to content

Commit

Permalink
Update integration test, hide behind cmake flag
Browse files Browse the repository at this point in the history
Signed-off-by: Evan Flynn <[email protected]>
  • Loading branch information
flynneva committed Jan 26, 2025
1 parent b8af9df commit dc68016
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 44 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ if(BUILD_TESTING)
test/test_pixel_formats.cpp)
target_link_libraries(test_pixel_formats
${PROJECT_NAME})
# TODO(flynneva): rewrite this test in another PR
# Integration tests
# ament_add_gtest(test_usb_cam_lib
# test/test_usb_cam_lib.cpp)
# target_link_libraries(test_usb_cam_lib
# ${PROJECT_NAME})
if(INTEGRATION_TESTS)
ament_add_gtest(test_usb_cam_lib
test/test_usb_cam_lib.cpp)
target_link_libraries(test_usb_cam_lib
${PROJECT_NAME})
endif()
endif()

install(
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,25 @@ Unfortunately `rviz2` and `show_image.py` do not support visualizing the compres
ros2 run image_transport republish compressed raw --ros-args --remap in/compressed:=image_raw/compressed --remap out:=image_raw/uncompressed
```

## Address and leak sanitizing
## Testing

To run the basic unit tests for this repository:

```shell
colcon build --packages-select usb_cam
colcon test --pacakges-select usb_cam
```

### Integration tests

To run integration tests for this repository:

```shell
colcon build --packages-select usb_cam --cmake-args -DINTEGRATION_TESTS=1
colcon test --pacakges-select usb_cam
```

### Address and leak sanitizing

Incorporated into the `CMakelists.txt` file to assist with memory leak and address sanitizing
is a flag to add these compile commands to the targets.
Expand Down
47 changes: 21 additions & 26 deletions include/usb_cam/usb_cam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,27 @@ typedef struct

typedef struct
{
std::string camera_name; // can be anything
std::string device_name; // usually /dev/video0 or something similiar
std::string frame_id;
std::string io_method_name;
std::string camera_info_url;
// these parameters all have to be a combination supported by the device
// Use
// v4l2-ctl --device=0 --list-formats-ext
// to discover them,
// or guvcview
std::string pixel_format_name;
std::string av_device_format;
int image_width;
int image_height;
int framerate;
int brightness;
int contrast;
int saturation;
int sharpness;
int gain;
int white_balance;
int exposure;
int focus;
bool auto_white_balance;
bool autoexposure;
bool autofocus;
std::string camera_name = "usb_cam"; // can be anything
std::string device_name = "/dev/video0"; // usually /dev/video0 or something similiar
std::string frame_id = "camera";
std::string io_method_name = "mmap";
std::string camera_info_url = "package://usb_cam/config/camera_info.yaml";
std::string pixel_format_name = "yuyv2rgb";
std::string av_device_format = "YUV422P";
int image_width = 600;
int image_height = 400;
int framerate = 30.0;
int brightness = -1;
int contrast = -1;
int saturation = -1;
int sharpness = -1;
int gain = -1;
int white_balance = -1;
int exposure = -1;
int focus = -1;
bool auto_white_balance = true;
bool autoexposure = true;
bool autofocus = false;
} parameters_t;

typedef struct
Expand Down
19 changes: 8 additions & 11 deletions test/test_usb_cam_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,19 @@
TEST(test_usb_cam_lib, test_usb_cam_class) {
usb_cam::UsbCam test_usb_cam;

usb_cam::parameters_t parameters;
test_usb_cam.configure(parameters, usb_cam::utils::IO_METHOD_MMAP);

test_usb_cam.start();

auto supported_fmts = test_usb_cam.get_supported_formats();

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

// TODO(flynneva): rework these tests in another MR
{
// test_usb_cam.configure(
// "/dev/video0",
// usb_cam::utils::IO_METHOD_MMAP,
// "yuyv2rgb", 640, 480, 30);
// test_usb_cam.start();
// TODO(flynneva): uncomment once /dev/video0 can be simulated in CI
// EXPECT_TRUE(test_usb_cam.is_capturing());
// test_usb_cam.shutdown();
}
// TODO(flynneva): uncomment once /dev/video0 can be simulated in CI
EXPECT_TRUE(test_usb_cam.is_capturing());
test_usb_cam.shutdown();
}

0 comments on commit dc68016

Please sign in to comment.