Skip to content

Commit

Permalink
Repair unit tests and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sirknightj committed Jan 24, 2025
1 parent 1ba1872 commit 9adc3e4
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 21 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/kvssink.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: kvssink checks

on:
push:
branches:
- develop
- master
pull_request:
branches:
- develop
- master

jobs:
unit-tests:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
id-token: write
contents: read
strategy:
matrix:
include:
- os: Ubuntu 22.04
image: public.ecr.aws/ubuntu/ubuntu:22.04_stable
- os: Ubuntu 20.04
image: public.ecr.aws/ubuntu/ubuntu:20.04_stable
fail-fast: false

name: kvssink unit tests on ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y automake build-essential cmake git \
gstreamer1.0-plugins-base-apps gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly \
gstreamer1.0-tools \
libcurl4-openssl-dev libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev liblog4cplus-dev \
libssl-dev pkg-config gtest
- name: Setup build directory
run: |
mkdir -p build
cd build
- name: Build kvssink unit tests
working-directory: ./build
run: |
cmake .. -DBUILD_GSTREAMER_PLUGIN=ON -DBUILD_TEST=ON -DCMAKE_BUILD_TYPE=Debug -DALIGNED_MEMORY_MODEL=ON
make -j$(nproc)
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }}
aws-region: ${{ secrets.AWS_REGION }}
role-duration-seconds: 10800

- name: Run the unit tests
working-directory: ./build
run: |
./tst/gstkvsplugintest
76 changes: 55 additions & 21 deletions tst/gstreamer/gstkvstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,58 @@ static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
));
static char const *accessKey;
static char const *secretKey;
static char const *sessionToken;

static GstElement *
setup_kinesisvideoproducersink(void)
{
GstElement *kinesisvideoproducersink;
GST_DEBUG ("Setup kinesisvideoproducersink");
GST_DEBUG("Setup kinesisvideoproducersink");
kinesisvideoproducersink = gst_check_setup_element ("kvssink");
fail_unless(kinesisvideoproducersink != nullptr, "Failed to create kvssink element (is GST_PLUGIN_PATH set?)");

g_object_set(G_OBJECT (kinesisvideoproducersink),
"access-key", accessKey,
"secret-key", secretKey,
"session-token", sessionToken,
NULL);

GstPad *sinkpad = gst_element_request_pad_simple(kinesisvideoproducersink, "video_0");
fail_unless(sinkpad != nullptr, "Failed to request video pad");
gst_object_unref(sinkpad);

return kinesisvideoproducersink;
}

static void
cleanup_kinesisvideoproducersink(GstElement * kinesisvideoproducersink)
{
GstPad *sinkpad = gst_element_get_static_pad(kinesisvideoproducersink, "video_0");
if (sinkpad) {
gst_element_release_request_pad(kinesisvideoproducersink, sinkpad);
gst_object_unref(sinkpad);
}

gst_check_teardown_src_pad (kinesisvideoproducersink);
gst_check_teardown_element (kinesisvideoproducersink);
}

GST_START_TEST(kvsproducersinktestplay)
GST_START_TEST(kvsproducersinktestplayandstop)
{
GstElement *pElement =
setup_kinesisvideoproducersink();
fail_unless_equals_int(gst_element_set_state(pElement, GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC);
cleanup_kinesisvideoproducersink(pElement);
GstElement *pElement = setup_kinesisvideoproducersink();

}
GST_END_TEST;
// Set up source pad
GstPad *srcpad = gst_check_setup_src_pad_by_name(pElement, &srctemplate, "video_0");
fail_unless(srcpad != nullptr, "Failed to setup source pad");
gst_pad_set_active(srcpad, TRUE);

GST_START_TEST(kvsproducersinktestpause)
{
GstElement *pElement =
setup_kinesisvideoproducersink();
fail_unless_equals_int(gst_element_set_state(pElement, GST_STATE_PAUSED), GST_STATE_CHANGE_ASYNC);
cleanup_kinesisvideoproducersink(pElement);
// Set to PLAYING state (NULL -> PLAYING)
fail_unless_equals_int(GST_STATE_CHANGE_SUCCESS, gst_element_set_state(pElement, GST_STATE_PLAYING));

// Set back to NULL state (PLAYING -> NULL)
fail_unless_equals_int(GST_STATE_CHANGE_SUCCESS, gst_element_set_state(pElement, GST_STATE_NULL));

gst_pad_set_active(srcpad, FALSE);
cleanup_kinesisvideoproducersink(pElement);
}
GST_END_TEST;

Expand All @@ -60,7 +73,7 @@ GST_START_TEST(kvsproducersinktestplaytopausetoplay)
setup_kinesisvideoproducersink();
GstPad *srcpad;

srcpad = gst_check_setup_src_pad_by_name (pElement, &srctemplate, "sink");
srcpad = gst_check_setup_src_pad_by_name (pElement, &srctemplate, "video_0");

gst_pad_set_active (srcpad, TRUE);

Expand Down Expand Up @@ -206,7 +219,7 @@ GST_START_TEST(check_playing_to_paused_and_back_to_playing)
setup_kinesisvideoproducersink();
GstPad *srcpad;

srcpad = gst_check_setup_src_pad_by_name (pElement, &srctemplate, "sink");
srcpad = gst_check_setup_src_pad_by_name (pElement, &srctemplate, "video_0");

gst_pad_set_active (srcpad, TRUE);

Expand All @@ -221,16 +234,37 @@ GST_START_TEST(check_playing_to_paused_and_back_to_playing)
}
GST_END_TEST;

GST_START_TEST(test_check_credentials)
{
ck_abort_msg("Required environment variables (ACCESS_KEY and/or SECRET_KEY) are not set");
}
GST_END_TEST;

//Verify all State change events and direct state set events.

Suite *gst_kinesisvideoproducer_suite(void) {
Suite *s = suite_create("GstKinesisVideoSinkPlugin");
TCase *tc = tcase_create("AllStateChangeTests");
accessKey = getenv(ACCESS_KEY_ENV_VAR);
secretKey = getenv(SECRET_KEY_ENV_VAR);

tcase_add_test(tc, kvsproducersinktestplay);
tcase_add_test(tc, kvsproducersinktestpause);
accessKey = GETENV(ACCESS_KEY_ENV_VAR);
secretKey = GETENV(SECRET_KEY_ENV_VAR);
sessionToken = GETENV(SESSION_TOKEN_ENV_VAR);

accessKey = accessKey ? accessKey : "";
secretKey = secretKey ? secretKey : "";
sessionToken = sessionToken ? sessionToken : "";

// Check if required environment variables are set
if (accessKey[0] == '\0' || secretKey[0] == '\0') {
TCase *tc_env = tcase_create("Credentials check");
tcase_add_test_raise_signal(tc_env, test_check_credentials, SIGABRT);
suite_add_tcase(s, tc_env);

// Return the suite with only this failing test
return s;
}

tcase_add_test(tc, kvsproducersinktestplayandstop);
tcase_add_test(tc, kvsproducersinktestplaytopausetoplay);
tcase_add_test(tc, kvsproducersinkteststop);
tcase_add_test(tc, check_properties_are_passed_correctly);
Expand Down

0 comments on commit 9adc3e4

Please sign in to comment.