Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@ on:
workflow_run:
workflows: ["Build Latest"]
types: [completed]
push:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small fix here for integration test triggers

branches:
- '*'
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
branches:
- '*'
paths-ignore:
- 'README.md'
- 'docs/**'

permissions:
contents: read
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Unit Tests

on:
push:
branches:
- '*'
paths-ignore:
- 'README.md'
- 'docs/**'
pull_request:
branches:
- '*'
paths-ignore:
- 'README.md'
- 'docs/**'

jobs:
unit-test:
name: Unit Tests
runs-on: buildjet-2vcpu-ubuntu-2204-arm
strategy:
matrix:
include:
- container: ghcr.io/viam-modules/csi-camera/viam-cpp-base-jetson:0.0.6
TARGET: jetson

container:
image: ${{ matrix.container }}
options: --platform linux/arm64

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set environment variables
run: |
echo "TARGET=${{ matrix.TARGET }}" >> $GITHUB_ENV
echo "META_PATH=${{ matrix.META_PATH }}" >> $GITHUB_ENV

- name: Install module dependencies
run: make dep

- name: Build viam-csi binary
run: make build

- name: Run unit tests
run: |
export VIAM_CSI_DEVICE=${{ matrix.TARGET }}
export VIAM_CSI_TEST_MODE=1
ctest --test-dir build --rerun-failed --output-on-failure -VV
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ etc/appimage-build
**/.DS_Store
gha-creds-*.json
.vscode
*Testing
*squashfs-root*
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ install(TARGETS ${PROJECT_NAME} DESTINATION usr/local/bin)


# Test executable
add_executable(${PROJECT_NAME}_test test/test_csi_camera.cpp)
add_executable(${PROJECT_NAME}_test tests/unit/test_csi_camera.cpp)

target_link_libraries(${PROJECT_NAME}_test
${GSTREAMER_LIBRARIES}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ dep:
apt-get update && \
if [ "$(TARGET)" = "jetson" ]; then \
apt-get -y install libgtest-dev && \
apt-get install -y gstreamer1.0-tools && \
apt-get install -y gstreamer1.0-tools gstreamer1.0-plugins-good && \
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need this to run test piepline on Ubuntu

apt-get install -y libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libgstreamer-plugins-good1.0-dev \
Expand Down
4 changes: 0 additions & 4 deletions test/test_jetson_pipeline.sh

This file was deleted.

4 changes: 0 additions & 4 deletions test/test_pi_pipeline.sh

This file was deleted.

28 changes: 19 additions & 9 deletions test/test_csi_camera.cpp → tests/unit/test_csi_camera.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
#include <gtest/gtest.h>
#include <cstdlib>
#include <viam/sdk/common/instance.hpp>
#include <viam/sdk/common/proto_convert.hpp>
#include <viam/sdk/components/camera.hpp>

#include "../constraints.h"
#include "../csi_camera.cpp"
#include "../utils.cpp"
#include "../../constraints.h"
#include "../../csi_camera.cpp"
#include "../../utils.cpp"

using namespace viam::sdk;

// One-time runtime bootstrap to initialize Viam SDK Instance and GStreamer
static void ensure_runtime() {
static bool inited = false;
if (inited)
return;
static Instance inst;
gst_init(nullptr, nullptr);
inited = true;
}

// Test that the camera can be created with default values

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a follow up, it would be great to be able to inject pictures and make sure to receive them.

TEST(CSICamera, CreateDefault) {
gst_init(nullptr, nullptr);
ensure_runtime();

ProtoStruct attrs = std::unordered_map<std::string, ProtoValue>();

Expand All @@ -26,7 +38,7 @@ TEST(CSICamera, CreateDefault) {

// Test that the camera can be created with custom values
TEST(CSICamera, CreateCustom) {
gst_init(nullptr, nullptr);
ensure_runtime();

ProtoStruct attrs = std::unordered_map<std::string, ProtoValue>();
attrs.insert(std::make_pair("width_px", ProtoValue(640)));
Expand Down Expand Up @@ -59,8 +71,6 @@ TEST(CSICamera, StartStopPipeline) {

camera.stop_pipeline();

pipeline = camera.get_pipeline();
appsink = camera.get_appsink();
EXPECT_EQ(GST_STATE(pipeline), GST_STATE_NULL);
EXPECT_EQ(GST_STATE(appsink), GST_STATE_NULL);
EXPECT_EQ(camera.get_pipeline(), nullptr);
EXPECT_EQ(camera.get_appsink(), nullptr);
}