GstCheck.Harness

Fields

Name

Type

Access

Description

element

Gst.Element

r/w

the element inside the harness

sink_harness

GstCheck.Harness

r/w

the sink (output) harness (if any)

sinkpad

Gst.Pad

r/w

the internal harness sink pad

src_harness

GstCheck.Harness

r/w

the source (input) harness (if any)

srcpad

Gst.Pad

r/w

the internal harness source pad

Methods

class

stress_thread_stop (t)

add_element_sink_pad (sinkpad)

add_element_src_pad (srcpad)

add_probe (element_name, pad_name, mask, callback, *user_data)

add_propose_allocation_meta (api, params)

add_sink (sink_element_name)

add_sink_harness (sink_harness)

add_sink_parse (launchline)

add_src (src_element_name, has_clock_wait)

add_src_harness (src_harness, has_clock_wait)

add_src_parse (launchline, has_clock_wait)

buffers_in_queue ()

buffers_received ()

crank_multiple_clock_waits (waits)

crank_single_clock_wait ()

create_buffer (size)

dump_to_file (filename)

events_in_queue ()

events_received ()

find_element (element_name)

get_allocator ()

get_last_pushed_timestamp ()

get_testclock ()

play ()

pull ()

pull_event ()

pull_until_eos ()

pull_upstream_event ()

push (buffer)

push_and_pull (buffer)

push_event (event)

push_from_src ()

push_to_sink ()

push_upstream_event (event)

query_latency ()

set_blocking_push_mode ()

set_caps (in_, out)

set_caps_str (in_, out)

set_drop_buffers (drop_buffers)

set_forwarding (forwarding)

set_live (is_live)

set_propose_allocator (allocator, params)

set_sink_caps (caps)

set_sink_caps_str (str)

set_src_caps (caps)

set_src_caps_str (str)

set_time (time)

set_upstream_latency (latency)

sink_push_many (pushes)

src_crank_and_push_many (cranks, pushes)

src_push_event ()

take_all_data ()

take_all_data_as_buffer ()

teardown ()

try_pull ()

try_pull_event ()

try_pull_upstream_event ()

upstream_events_in_queue ()

upstream_events_received ()

use_systemclock ()

use_testclock ()

wait_for_clock_id_waits (waits, timeout)

Details

class GstCheck.Harness

GstCheck.Harness is meant to make writing unit test for GStreamer much easier. It can be thought of as a way of treating a Gst.Element as a black box, deterministically feeding it data, and controlling what data it outputs.

The basic structure of GstCheck.Harness is two “floating” Gst.Pads that connect to the harnessed Gst.Element src and sink Gst.Pads like so:

__________________________
 _____   |  _____            _____  |   _____
|     |  | |     |          |     | |  |     |
| src |--+-| sink|  Element | src |-+--| sink|
|_____|  | |_____|          |_____| |  |_____|
         |__________________________|

With this, you can now simulate any environment the Gst.Element might find itself in. By specifying the Gst.Caps of the harness Gst.Pads, using functions like GstCheck.Harness.set_src_caps() or GstCheck.Harness.set_sink_caps_str(), you can test how the Gst.Element interacts with different caps sets.

Your harnessed Gst.Element can of course also be a bin, and using gst_harness_new_parse() supporting standard gst-launch syntax, you can easily test a whole pipeline instead of just one element.

You can then go on to push Gst.Buffers and Gst.Events on to the srcpad, using functions like GstCheck.Harness.push() and GstCheck.Harness.push_event(), and then pull them out to examine them with GstCheck.Harness.pull() and GstCheck.Harness.pull_event().

A simple buffer-in buffer-out example
#include <gst/gst.h>
#include <gst/check/gstharness.h>
GstHarness *h;
GstBuffer *in_buf;
GstBuffer *out_buf;

// attach the harness to the src and sink pad of GstQueue
h = gst_harness_new ("queue");

// we must specify a caps before pushing buffers
gst_harness_set_src_caps_str (h, "mycaps");

// create a buffer of size 42
in_buf = gst_harness_create_buffer (h, 42);

// push the buffer into the queue
gst_harness_push (h, in_buf);

// pull the buffer from the queue
out_buf = gst_harness_pull (h);

// validate the buffer in is the same as buffer out
fail_unless (in_buf == out_buf);

// cleanup
gst_buffer_unref (out_buf);
gst_harness_teardown (h);

Another main feature of the GstCheck.Harness is its integration with the GstCheck.TestClock. Operating the GstCheck.TestClock can be very challenging, but GstCheck.Harness simplifies some of the most desired actions a lot, like wanting to manually advance the clock while at the same time releasing a #GstClockID that is waiting, with functions like GstCheck.Harness.crank_single_clock_wait().

GstCheck.Harness also supports sub-harnesses, as a way of generating and validating data. A sub-harness is another GstCheck.Harness that is managed by the “parent” harness, and can either be created by using the standard gst_harness_new type functions directly on the (GstCheck.Harness *)->src_harness, or using the much more convenient GstCheck.Harness.add_src() or GstCheck.Harness.add_sink_parse(). If you have a decoder-element you want to test, (like vp8dec) it can be very useful to add a src-harness with both a src-element (videotestsrc) and an encoder (vp8enc) to feed the decoder data with different configurations, by simply doing:

GstHarness * h = gst_harness_new ("vp8dec");
gst_harness_add_src_parse (h, "videotestsrc is-live=1 ! vp8enc", TRUE);

and then feeding it data with:

gst_harness_push_from_src (h);

New in version 1.6.

classmethod stress_thread_stop(t)
Parameters:

t (GstCheck.HarnessThread) – a GstCheck.HarnessThread

Return type:

int

Stop the running GstCheck.HarnessThread

MT safe.

New in version 1.6.

add_element_sink_pad(sinkpad)
Parameters:

sinkpad (Gst.Pad) – a Gst.Pad to link to the harness srcpad

Links the specified Gst.Pad the GstHarness srcpad.

MT safe.

New in version 1.6.

add_element_src_pad(srcpad)
Parameters:

srcpad (Gst.Pad) – a Gst.Pad to link to the harness sinkpad

Links the specified Gst.Pad the GstHarness sinkpad. This can be useful if perhaps the srcpad did not exist at the time of creating the harness, like a demuxer that provides a sometimes-pad after receiving data.

MT safe.

New in version 1.6.

add_probe(element_name, pad_name, mask, callback, *user_data)
Parameters:

A convenience function to allows you to call Gst.Pad.add_probe on a Gst.Pad of a Gst.Element that are residing inside the GstCheck.Harness, by using normal Gst.Pad.add_probe syntax

MT safe.

New in version 1.6.

add_propose_allocation_meta(api, params)
Parameters:

Add api with params as one of the supported metadata API to propose when receiving an allocation query.

MT safe.

New in version 1.16.

add_sink(sink_element_name)
Parameters:

sink_element_name (str) – a str with the name of a Gst.Element

Similar to GstCheck.Harness.add_sink_harness, this is a convenience to directly create a sink-harness using the sink_element_name name specified.

MT safe.

New in version 1.6.

add_sink_harness(sink_harness)
Parameters:

sink_harness (GstCheck.Harness) – a GstCheck.Harness to be added as a sink-harness.

Similar to GstCheck.Harness.add_src, this allows you to send the data coming out of your harnessed Gst.Element to a sink-element, allowing to test different responses the element output might create in sink elements. An example might be an existing sink providing some analytical data on the input it receives that can be useful to your testing. If the goal is to test a sink-element itself, this is better achieved using gst_harness_new directly on the sink.

If a sink-harness already exists it will be replaced.

MT safe.

New in version 1.6.

add_sink_parse(launchline)
Parameters:

launchline (str) – a str with the name of a Gst.Element

Similar to GstCheck.Harness.add_sink, this allows you to specify a launch-line instead of just an element name. See GstCheck.Harness.add_src_parse for details.

MT safe.

New in version 1.6.

add_src(src_element_name, has_clock_wait)
Parameters:

Similar to GstCheck.Harness.add_src_harness, this is a convenience to directly create a src-harness using the src_element_name name specified.

MT safe.

New in version 1.6.

add_src_harness(src_harness, has_clock_wait)
Parameters:

A src-harness is a great way of providing the GstCheck.Harness with data. By adding a src-type Gst.Element, it is then easy to use functions like GstCheck.Harness.push_from_src or GstCheck.Harness.src_crank_and_push_many to provide your harnessed element with input. The has_clock_wait variable is a great way to control you src-element with, in that you can have it produce a buffer for you by simply cranking the clock, and not have it spin out of control producing buffers as fast as possible.

If a src-harness already exists it will be replaced.

MT safe.

New in version 1.6.

add_src_parse(launchline, has_clock_wait)
Parameters:
  • launchline (str) – a str describing a gst-launch type line

  • has_clock_wait (bool) – a bool specifying if the Gst.Element uses gst_clock_wait_id internally.

Similar to GstCheck.Harness.add_src, this allows you to specify a launch-line, which can be useful for both having more then one Gst.Element acting as your src (Like a src producing raw buffers, and then an encoder, providing encoded data), but also by allowing you to set properties like “is-live” directly on the elements.

MT safe.

New in version 1.6.

buffers_in_queue()
Returns:

a int number of buffers in the queue

Return type:

int

The number of Gst.Buffers currently in the GstCheck.Harness sinkpad GLib.AsyncQueue

MT safe.

New in version 1.6.

buffers_received()
Returns:

a int number of buffers received

Return type:

int

The total number of Gst.Buffers that has arrived on the GstCheck.Harness sinkpad. This number includes buffers that have been dropped as well as buffers that have already been pulled out.

MT safe.

New in version 1.6.

crank_multiple_clock_waits(waits)
Parameters:

waits (int) – a int describing the number of #GstClockIDs to crank

Returns:

a gboolean True if the “crank” was successful, False if not.

Return type:

bool

Similar to GstCheck.Harness.crank_single_clock_wait(), this is the function to use if your harnessed element(s) are using more then one Gst.Clock.id_wait. Failing to do so can (and will) make it racy which #GstClockID you actually are releasing, where as this function will process all the waits at the same time, ensuring that one thread can’t register another wait before both are released.

MT safe.

New in version 1.6.

crank_single_clock_wait()
Returns:

a gboolean True if the “crank” was successful, False if not.

Return type:

bool

A “crank” consists of three steps: 1: Wait for a #GstClockID to be registered with the GstCheck.TestClock. 2: Advance the GstCheck.TestClock to the time the #GstClockID is waiting for. 3: Release the #GstClockID wait. Together, this provides an easy way to not have to think about the details around clocks and time, but still being able to write deterministic tests that are dependent on this. A “crank” can be though of as the notion of manually driving the clock forward to its next logical step.

MT safe.

New in version 1.6.

create_buffer(size)
Parameters:

size (int) – a #gsize specifying the size of the buffer

Returns:

a Gst.Buffer of size size

Return type:

Gst.Buffer

Allocates a buffer using a Gst.BufferPool if present, or else using the configured Gst.Allocator and Gst.AllocationParams

MT safe.

New in version 1.6.

dump_to_file(filename)
Parameters:

filename (str) – a str with a the name of a file

Allows you to dump the Gst.Buffers the GstCheck.Harness sinkpad GLib.AsyncQueue to a file.

MT safe.

New in version 1.6.

events_in_queue()
Returns:

a int number of events in the queue

Return type:

int

The number of Gst.Events currently in the GstCheck.Harness sinkpad GLib.AsyncQueue

MT safe.

New in version 1.6.

events_received()
Returns:

a int number of events received

Return type:

int

The total number of Gst.Events that has arrived on the GstCheck.Harness sinkpad This number includes events handled by the harness as well as events that have already been pulled out.

MT safe.

New in version 1.6.

find_element(element_name)
Parameters:

element_name (str) – a str with a Gst.ElementFactory name

Returns:

a Gst.Element or None if not found

Return type:

Gst.Element or None

Most useful in conjunction with gst_harness_new_parse, this will scan the Gst.Elements inside the GstCheck.Harness, and check if any of them matches element_name. Typical usecase being that you need to access one of the harnessed elements for properties and/or signals.

MT safe.

New in version 1.6.

get_allocator()
Returns:

allocator:

the Gst.Allocator used

params:

the Gst.AllocationParams of allocator

Return type:

(allocator: Gst.Allocator or None, params: Gst.AllocationParams)

Gets the allocator and its params that has been decided to use after an allocation query.

MT safe.

New in version 1.6.

get_last_pushed_timestamp()
Returns:

a #GstClockTime with the timestamp or Gst.CLOCK_TIME_NONE if no Gst.Buffer has been pushed on the GstCheck.Harness srcpad

Return type:

int

Get the timestamp of the last Gst.Buffer pushed on the GstCheck.Harness srcpad, typically with GstCheck.Harness.push or GstCheck.Harness.push_from_src.

MT safe.

New in version 1.6.

get_testclock()
Returns:

a GstCheck.TestClock, or None if the testclock is not present.

Return type:

GstCheck.TestClock or None

Get the GstCheck.TestClock. Useful if specific operations on the testclock is needed.

MT safe.

New in version 1.6.

play()

This will set the harnessed Gst.Element to Gst.State.PLAYING. Gst.Elements without a sink-Gst.Pad and with the Gst.ElementFlags.SOURCE flag set is considered a src Gst.Element Non-src Gst.Elements (like sinks and filters) are automatically set to playing by the GstCheck.Harness, but src Gst.Elements are not to avoid them starting to produce buffers. Hence, for src Gst.Element you must call GstCheck.Harness.play() explicitly.

MT safe.

New in version 1.6.

pull()
Returns:

a Gst.Buffer or None if timed out.

Return type:

Gst.Buffer or None

Pulls a Gst.Buffer from the GLib.AsyncQueue on the GstCheck.Harness sinkpad. The pull will timeout in 60 seconds. This is the standard way of getting a buffer from a harnessed Gst.Element.

MT safe.

New in version 1.6.

pull_event()
Returns:

a Gst.Event or None if timed out.

Return type:

Gst.Event or None

Pulls an Gst.Event from the GLib.AsyncQueue on the GstCheck.Harness sinkpad. Timeouts after 60 seconds similar to GstCheck.Harness.pull.

MT safe.

New in version 1.6.

pull_until_eos()
Returns:

True on success, False on timeout.

buf:

A Gst.Buffer, or None if EOS or timeout occures first.

Return type:

(bool, buf: Gst.Buffer or None)

Pulls a Gst.Buffer from the GLib.AsyncQueue on the GstCheck.Harness sinkpad. The pull will block until an EOS event is received, or timeout in 60 seconds. MT safe.

New in version 1.18.

pull_upstream_event()
Returns:

a Gst.Event or None if timed out.

Return type:

Gst.Event or None

Pulls an Gst.Event from the GLib.AsyncQueue on the GstCheck.Harness srcpad. Timeouts after 60 seconds similar to GstCheck.Harness.pull.

MT safe.

New in version 1.6.

push(buffer)
Parameters:

buffer (Gst.Buffer) – a Gst.Buffer to push

Returns:

a Gst.FlowReturn with the result from the push

Return type:

Gst.FlowReturn

Pushes a Gst.Buffer on the GstCheck.Harness srcpad. The standard way of interacting with an harnessed element.

MT safe.

New in version 1.6.

push_and_pull(buffer)
Parameters:

buffer (Gst.Buffer) – a Gst.Buffer to push

Returns:

a Gst.Buffer or None if timed out.

Return type:

Gst.Buffer or None

Basically a GstCheck.Harness.push and a GstCheck.Harness.pull in one line. Reflects the fact that you often want to do exactly this in your test: Push one buffer in, and inspect the outcome.

MT safe.

New in version 1.6.

push_event(event)
Parameters:

event (Gst.Event) – a Gst.Event to push

Returns:

a bool with the result from the push

Return type:

bool

Pushes an Gst.Event on the GstCheck.Harness srcpad.

MT safe.

New in version 1.6.

push_from_src()
Returns:

a Gst.FlowReturn with the result of the push

Return type:

Gst.FlowReturn

Transfer data from the src-GstCheck.Harness to the main-GstCheck.Harness. It consists of 4 steps: 1: Make sure the src is started. (see: GstCheck.Harness.play) 2: Crank the clock (see: GstCheck.Harness.crank_single_clock_wait) 3: Pull a Gst.Buffer from the src-GstCheck.Harness (see: GstCheck.Harness.pull) 4: Push the same Gst.Buffer into the main-GstCheck.Harness (see: GstCheck.Harness.push)

MT safe.

New in version 1.6.

push_to_sink()
Returns:

a Gst.FlowReturn with the result of the push

Return type:

Gst.FlowReturn

Transfer one Gst.Buffer from the main-GstCheck.Harness to the sink-GstCheck.Harness. See GstCheck.Harness.push_from_src for details.

MT safe.

New in version 1.6.

push_upstream_event(event)
Parameters:

event (Gst.Event) – a Gst.Event to push

Returns:

a bool with the result from the push

Return type:

bool

Pushes an Gst.Event on the GstCheck.Harness sinkpad.

MT safe.

New in version 1.6.

query_latency()
Returns:

a #GstClockTime with min latency

Return type:

int

Get the min latency reported by any harnessed Gst.Element.

MT safe.

New in version 1.6.

set_blocking_push_mode()

Setting this will make the harness block in the chain-function, and then release when GstCheck.Harness.pull() or GstCheck.Harness.try_pull() is called. Can be useful when wanting to control a src-element that is not implementing Gst.Clock.id_wait() so it can’t be controlled by the GstCheck.TestClock, since it otherwise would produce buffers as fast as possible.

MT safe.

New in version 1.6.

set_caps(in_, out)
Parameters:

Sets the GstHarness srcpad and sinkpad caps.

MT safe.

New in version 1.6.

set_caps_str(in_, out)
Parameters:
  • in (str) – a gchar describing a Gst.Caps to set on the harness srcpad

  • out (str) – a gchar describing a Gst.Caps to set on the harness sinkpad

Sets the GstHarness srcpad and sinkpad caps using strings.

MT safe.

New in version 1.6.

set_drop_buffers(drop_buffers)
Parameters:

drop_buffers (bool) – a bool specifying to drop outgoing buffers or not

When set to True, instead of placing the buffers arriving from the harnessed Gst.Element inside the sinkpads GLib.AsyncQueue, they are instead unreffed.

MT safe.

New in version 1.6.

set_forwarding(forwarding)
Parameters:

forwarding (bool) – a bool to enable/disable forwarding

As a convenience, a src-harness will forward Gst.EventType.STREAM_START, Gst.EventType.CAPS and Gst.EventType.SEGMENT to the main-harness if forwarding is enabled, and forward any sticky-events from the main-harness to the sink-harness. It will also forward the Gst.QueryType.ALLOCATION.

If forwarding is disabled, the user will have to either manually push these events from the src-harness using GstCheck.Harness.src_push_event(), or create and push them manually. While this will allow full control and inspection of these events, for the most cases having forwarding enabled will be sufficient when writing a test where the src-harness’ main function is providing data for the main-harness.

Forwarding is enabled by default.

MT safe.

New in version 1.6.

set_live(is_live)
Parameters:

is_live (bool) – True for live, False for non-live

Sets the liveness reported by GstCheck.Harness when receiving a latency-query. The default is True.

New in version 1.20.

set_propose_allocator(allocator, params)
Parameters:

Sets the allocator and params to propose when receiving an allocation query.

MT safe.

New in version 1.6.

set_sink_caps(caps)
Parameters:

caps (Gst.Caps) – a Gst.Caps to set on the harness sinkpad

Sets the GstHarness sinkpad caps.

MT safe.

New in version 1.6.

set_sink_caps_str(str)
Parameters:

str (str) – a gchar describing a Gst.Caps to set on the harness sinkpad

Sets the GstHarness sinkpad caps using a string.

MT safe.

New in version 1.6.

set_src_caps(caps)
Parameters:

caps (Gst.Caps) – a Gst.Caps to set on the harness srcpad

Sets the GstHarness srcpad caps. This must be done before any buffers can legally be pushed from the harness to the element.

MT safe.

New in version 1.6.

set_src_caps_str(str)
Parameters:

str (str) – a gchar describing a Gst.Caps to set on the harness srcpad

Sets the GstHarness srcpad caps using a string. This must be done before any buffers can legally be pushed from the harness to the element.

MT safe.

New in version 1.6.

set_time(time)
Parameters:

time (int) – a #GstClockTime to advance the clock to

Returns:

a gboolean True if the time could be set. False if not.

Return type:

bool

Advance the GstCheck.TestClock to a specific time.

MT safe.

New in version 1.6.

set_upstream_latency(latency)
Parameters:

latency (int) – a #GstClockTime specifying the latency

Sets the min latency reported by GstCheck.Harness when receiving a latency-query

New in version 1.6.

sink_push_many(pushes)
Parameters:

pushes (int) – a int with the number of calls to GstCheck.Harness.push_to_sink

Returns:

a Gst.FlowReturn with the result of the push

Return type:

Gst.FlowReturn

Convenience that calls GstCheck.Harness.push_to_sink pushes number of times. Will abort the pushing if any one push fails.

MT safe.

New in version 1.6.

src_crank_and_push_many(cranks, pushes)
Parameters:
Returns:

a Gst.FlowReturn with the result of the push

Return type:

Gst.FlowReturn

Transfer data from the src-GstCheck.Harness to the main-GstCheck.Harness. Similar to GstCheck.Harness.push_from_src, this variant allows you to specify how many cranks and how many pushes to perform. This can be useful for both moving a lot of data at the same time, as well as cases when one crank does not equal one buffer to push and v.v.

MT safe.

New in version 1.6.

src_push_event()
Returns:

a bool with the result of the push

Return type:

bool

Similar to what gst_harness_src_push does with Gst.Buffers, this transfers a Gst.Event from the src-GstCheck.Harness to the main-GstCheck.Harness. Note that some Gst.Events are being transferred automagically. Look at sink_forward_pad for details.

MT safe.

New in version 1.6.

take_all_data()
Returns:

a pointer to the data, newly allocated. Free with GLib.free() when no longer needed.

Return type:

GLib.Bytes

Pulls all pending data from the harness and returns it as a single GLib.Bytes.

New in version 1.14.

take_all_data_as_buffer()
Returns:

the data as a buffer. Unref with gst_buffer_unref() when no longer needed.

Return type:

Gst.Buffer

Pulls all pending data from the harness and returns it as a single buffer.

New in version 1.14.

teardown()

Tears down a GstHarness, freeing all resources allocated using it.

MT safe.

New in version 1.6.

try_pull()
Returns:

a Gst.Buffer or None if no buffers are present in the GLib.AsyncQueue

Return type:

Gst.Buffer or None

Pulls a Gst.Buffer from the GLib.AsyncQueue on the GstCheck.Harness sinkpad. Unlike GstCheck.Harness.pull this will not wait for any buffers if not any are present, and return None straight away.

MT safe.

New in version 1.6.

try_pull_event()
Returns:

a Gst.Event or None if no buffers are present in the GLib.AsyncQueue

Return type:

Gst.Event or None

Pulls an Gst.Event from the GLib.AsyncQueue on the GstCheck.Harness sinkpad. See GstCheck.Harness.try_pull for details.

MT safe.

New in version 1.6.

try_pull_upstream_event()
Returns:

a Gst.Event or None if no buffers are present in the GLib.AsyncQueue

Return type:

Gst.Event or None

Pulls an Gst.Event from the GLib.AsyncQueue on the GstCheck.Harness srcpad. See GstCheck.Harness.try_pull for details.

MT safe.

New in version 1.6.

upstream_events_in_queue()
Returns:

a int number of events in the queue

Return type:

int

The number of Gst.Events currently in the GstCheck.Harness srcpad GLib.AsyncQueue

MT safe.

New in version 1.6.

upstream_events_received()
Returns:

a int number of events received

Return type:

int

The total number of Gst.Events that has arrived on the GstCheck.Harness srcpad This number includes events handled by the harness as well as events that have already been pulled out.

MT safe.

New in version 1.6.

use_systemclock()

Sets the system Gst.Clock on the GstHarness Gst.Element

MT safe.

New in version 1.6.

use_testclock()

Sets the GstCheck.TestClock on the GstCheck.Harness Gst.Element

MT safe.

New in version 1.6.

wait_for_clock_id_waits(waits, timeout)
Parameters:
  • waits (int) – a int describing the numbers of #GstClockID registered with the GstCheck.TestClock

  • timeout (int) – a int describing how many seconds to wait for waits to be true

Returns:

a gboolean True if the waits have been registered, False if not. (Could be that it timed out waiting or that more waits than waits was found)

Return type:

bool

Waits for timeout seconds until waits number of #GstClockID waits is registered with the GstCheck.TestClock. Useful for writing deterministic tests, where you want to make sure that an expected number of waits have been reached.

MT safe.

New in version 1.6.