Skip to content

Commit

Permalink
Merge branch 'feature/add-process-tests' into dev-0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
maumonteroj committed Jun 24, 2019
2 parents e63de5e + 3a2ff4e commit 8179d4c
Show file tree
Hide file tree
Showing 7 changed files with 2,928 additions and 28 deletions.
130 changes: 102 additions & 28 deletions tests/check/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,46 +1,120 @@
include $(top_srcdir)/common/check.mak

CHECK_REGISTRY = $(top_builddir)/tests/check/test-registry.reg
TEST_FILES_DIRECTORY = $(top_srcdir)/tests/files

REGISTRY_ENVIRONMENT = \
GST_REGISTRY_1_0=$(CHECK_REGISTRY)
REGISTRY_ENVIRONMENT = \
GST_REGISTRY=$(CHECK_REGISTRY)

AM_TESTS_ENVIRONMENT += \
$(REGISTRY_ENVIRONMENT) \
GST_PLUGIN_SYSTEM_PATH_1_0= \
GST_PLUGIN_PATH_1_0=$(top_builddir)/gst:$(top_builddir)/ext:$(top_builddir)/sys:$(GSTPB_PLUGINS_DIR):$(GST_PLUGINS_DIR) \
GST_PLUGIN_LOADING_WHITELIST="gstreamer@$(GST_PLUGINS_DIR):gst-plugins-base@$(GSTPB_PLUGINS_DIR):gst-inference@$(top_builddir)" \
GST_STATE_IGNORE_ELEMENTS= \
GSETTINGS_BACKEND="memory"
AM_TESTS_ENVIRONMENT = \
CK_DEFAULT_TIMEOUT=120 \
$(REGISTRY_ENVIRONMENT) \
GST_PLUGIN_SYSTEM_PATH_1_0= \
GST_PLUGIN_PATH_1_0=$(top_builddir)/gst:$(GST_PLUGINS_DIR) \
GST_PLUGIN_LOADING_WHITELIST="gstreamer:gst-plugins-good:gst-plugins-base:gst-plugins-bad:gst-plugins-ugly:libnice:gst-libav:gst-inference@$(top_builddir)"

# the core dumps of some machines have PIDs appended
CLEANFILES = core.* test-registry.*
# the core dumps of some machines have PIDs appended, test registry and
# profiling data
CLEANFILES = core core.* test-registry.* *.gcno *.gcda

SUPPRESSIONS = $(top_srcdir)/common/gst.supp

clean-local: clean-local-check

#if USE_PLUGIN_EXAMPLE
#check_example = \
# elements/example \
# elements/example
#else
#check_example =
#endif
$(CHECK_REGISTRY):
$(AM_TESTS_ENVIRONMENT)

check_PROGRAMS =
check_PROGRAMS = \
process/test_gst_pixel_to_float_function \
process/test_gst_subtract_mean_function \
process/test_gst_normalize_function \
process/test_gst_fill_classification_meta_function

VALGRIND_TO_FIX =
# failing tests
noinst_PROGRAMS =

TESTS = $(check_PROGRAMS)

AM_CFLAGS = $(GST_OBJ_CFLAGS) $(GST_CHECK_CFLAGS) $(CHECK_CFLAGS) \
$(GST_OPTION_CFLAGS) $(GST_CFLAGS) -DGST_TEST_FILES_PATH="\"$(TEST_FILES_DIRECTORY)\"" \
-DGST_CHECK_TEST_ENVIRONMENT_BEACON="\"GST_PLUGIN_LOADING_WHITELIST\"" \
-UG_DISABLE_ASSERT -UG_DISABLE_CAST_CHECKS $(PTHREAD_CFLAGS)
LDADD = $(GST_OBJ_LIBS) $(GST_CHECK_LIBS) $(CHECK_LIBS)
noinst_HEADERS =

AM_CFLAGS = \
$(GST_CFLAGS) \
$(GST_CHECK_FLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_PLUGINS_GOOD_CFLAGS) \
-I$(top_srcdir)/gst-libs/

LDADD = \
$(top_builddir)/gst-libs/gst/r2inference/libgstinference-1.0.la \
$(top_builddir)/gst-libs/gst/opencv/libgstinferenceoverlay-1.0.la \
$(GST_LIBS) \
$(GST_PLUGINS_BASE_LIBS) \
-lgstvideo-1.0 \
$(GST_PLUGINS_GOOD_LIBS) \
$(GST_CHECK_LIBS)

# valgrind testing
VALGRIND_TESTS_DISABLE = \
# these just need valgrind fixing, period
VALGRIND_TO_FIX =

VALGRIND_IGNORE =

# these need fixing because the threads cause segfaults under valgrind
TESTS_THREADED =

VALGRIND_TESTS_DISABLE = \
$(TESTS_THREADED) \
$(VALGRIND_IGNORE) \
$(VALGRIND_TO_FIX)

SUPPRESSIONS = $(top_srcdir)/common/gst.supp
# indexers does not get tested yet
COVERAGE_DIRS = gst-libs/gst/r2inference \
gst-libs/gst/opencv

COVERAGE_FILES = $(foreach dir,$(COVERAGE_DIRS),$(wildcard $(top_builddir)/$(dir)/*.gcov))
COVERAGE_FILES_REL = $(subst $(top_builddir)/,,$(COVERAGE_FILES))
COVERAGE_OUT_FILES = $(foreach dir,$(COVERAGE_DIRS),$(wildcard $(top_builddir)/$(dir)/*.gcov.out))
COVERAGE_OUT_FILES_REL = $(subst $(top_builddir)/,,$(COVERAGE_OUT_FILES))

debug:
echo $(GST_PLUGINS_DIR)
echo $(COVERAGE_FILES)
echo $(COVERAGE_FILES_REL)

.PHONY: coverage
if GST_GCOV_ENABLED
# we rebuild a registry and do gst-inspect so that all the get/set codepaths
# are also covered
coverage:
for file in `find $(top_builddir) -name '*.gcda'`; do rm $$file; done
-rm $(CHECK_REGISTRY)
echo "Inspecting all elements"
for e in `$(GST_INSPECT) | head -n -2 | cut -d: -f2`; do $(GST_INSPECT) $$e > /dev/null 2>&1; done
make check
make coverage-report
else
coverage:
echo "You need to configure with --enable-gcov to get coverage data"
exit 1
endif

coverage-report:
rm -r coverage
for dir in $(COVERAGE_DIRS); do \
mkdir -p coverage/$$dir; \
make -C $(top_builddir)/$$dir gcov; \
done
for dir in $(COVERAGE_DIRS); do \
files="`ls $(top_builddir)/$$dir/*.gcov.out 2> /dev/null`"; \
if test ! -z "$$files"; then \
perl $(top_srcdir)/common/coverage/coverage-report.pl \
$(top_builddir)/$$dir/*.gcov.out > \
coverage/$$dir/index.xml; \
xsltproc $(top_srcdir)/common/coverage/coverage-report.xsl \
coverage/$$dir/index.xml > coverage/$$dir/index.html; \
fi; \
done
for file in $(COVERAGE_FILES_REL); do \
echo Generating coverage/$$file.html; \
perl $(top_srcdir)/common/coverage/coverage-report-entry.pl \
$(top_builddir)/$$file > coverage/$$file.html; \
done
135 changes: 135 additions & 0 deletions tests/check/process/preprocess_functions_utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
* GStreamer
* Copyright (C) 2019 RidgeRun
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/

#include "preprocess_functions_utils.h"

void
gst_check_output_pixels (GstVideoFrame * outframe, gfloat expected_value_red,
gfloat expected_value_green, gfloat expected_value_blue, gint first_index,
gint last_index, gint model_channels)
{
gfloat out_value;
gint frame_width;
gint frame_height;

frame_width = GST_VIDEO_FRAME_WIDTH (outframe);
frame_height = GST_VIDEO_FRAME_HEIGHT (outframe);

fail_if (outframe == NULL);
fail_if (frame_width == 0);
fail_if (frame_height == 0);

for (gint i = 0; i < frame_height; ++i) {
for (gint j = 0; j < frame_width; ++j) {
out_value =
((gfloat *) outframe->data[0])[(i * frame_width +
j) * model_channels + first_index];
if (out_value != expected_value_red)
GST_LOG ("Value in index: %d is different to expected value red",
(i * frame_width + j) * model_channels + first_index);
fail_if (out_value != expected_value_red);

out_value =
((gfloat *) outframe->data[0])[(i * frame_width +
j) * model_channels + 1];
if (out_value != expected_value_green)
GST_LOG ("Value in index: %d is different to expected value green",
(i * frame_width + j) * model_channels + first_index);
fail_if (out_value != expected_value_green);

out_value =
((gfloat *) outframe->data[0])[(i * frame_width +
j) * model_channels + last_index];
if (out_value != expected_value_blue)
GST_LOG ("Value in index: %d is different to expected value blue",
(i * frame_width + j) * model_channels + first_index);
fail_if (out_value != expected_value_blue);
}
}
}

void
gst_create_test_frames (GstVideoFrame * inframe, GstVideoFrame * outframe,
guchar value_red, guchar value_green, guchar value_blue, gint buffer_size,
gint width, gint height, gint offset, GstVideoFormat format)
{
gboolean ret = FALSE;
GstAllocationParams params;
GstMapFlags flags;
guint pixel_stride;
guint channels;
gint frame_width;
gint frame_height;

GstVideoInfo *info = gst_video_info_new ();
GstBuffer *buffer = gst_buffer_new ();
GstBuffer *buffer_out = gst_buffer_new ();

fail_if (inframe == NULL);
fail_if (outframe == NULL);

gst_video_info_init (info);
gst_video_info_set_format (info, format, width, height);

fail_if (info == NULL);

/* Allocate an output buffer for the pre-processed data */
gst_allocation_params_init (&params);
buffer =
gst_buffer_new_allocate (NULL, buffer_size * sizeof (guchar), &params);
buffer_out =
gst_buffer_new_allocate (NULL, buffer_size * sizeof (float), &params);

fail_if (buffer == NULL);
fail_if (buffer_out == NULL);

flags = (GstMapFlags) (GST_MAP_WRITE | GST_VIDEO_FRAME_MAP_FLAG_NO_REF);

ret = gst_video_frame_map (inframe, info, buffer, flags);

fail_if (ret == FALSE);

ret = gst_video_frame_map (outframe, info, buffer_out, flags);

fail_if (ret == FALSE);

channels = GST_VIDEO_FRAME_COMP_PSTRIDE (inframe, 0);
pixel_stride = GST_VIDEO_FRAME_COMP_STRIDE (inframe, 0) / channels;
frame_width = GST_VIDEO_FRAME_WIDTH (inframe);
frame_height = GST_VIDEO_FRAME_HEIGHT (inframe);

fail_if (frame_width == 0);
fail_if (frame_height == 0);

for (gint i = 0; i < frame_height; ++i) {
for (gint j = 0; j < frame_width; ++j) {
((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 0 +
offset] = value_red;
((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 1 +
offset] = value_green;
((guchar *) inframe->data[0])[(i * pixel_stride + j) * channels + 2 +
offset] = value_blue;
}
}
gst_video_info_free (info);
gst_video_frame_unmap (inframe);
gst_video_frame_unmap (outframe);
}
39 changes: 39 additions & 0 deletions tests/check/process/preprocess_functions_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* GStreamer
* Copyright (C) 2019 RidgeRun
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifndef __PREPROCESS_FUNCTIONS_UTILS_H__
#define __PREPROCESS_FUNCTIONS_UTILS_H__

#include <gst/video/video.h>

G_BEGIN_DECLS

void gst_create_test_frames (GstVideoFrame * inframe,
GstVideoFrame * outframe, guchar value_red, guchar value_green, guchar value_blue, gint buffer_size, gint width,
gint height, gint offset, GstVideoFormat format);

void gst_check_output_pixels (GstVideoFrame * outframe,
gfloat expected_value_red, gfloat expected_value_green,
gfloat expected_value_blue, gint first_index, gint last_index,
gint model_channels);

G_END_DECLS

#endif
Loading

0 comments on commit 8179d4c

Please sign in to comment.