GstCheck.Harness¶
Fields¶
Name |
Type |
Access |
Description |
---|---|---|---|
element |
r/w |
the element inside the harness |
|
sink_harness |
r/w |
the sink (output) harness (if any) |
|
sinkpad |
r/w |
the internal harness sink pad |
|
src_harness |
r/w |
the source (input) harness (if any) |
|
srcpad |
r/w |
the internal harness source pad |
Methods¶
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 aGst.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 harnessedGst.Element
src and sinkGst.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 theGst.Caps
of the harnessGst.Pads
, using functions likeGstCheck.Harness.set_src_caps
() orGstCheck.Harness.set_sink_caps_str
(), you can test how theGst.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
andGst.Events
on to the srcpad, using functions likeGstCheck.Harness.push
() andGstCheck.Harness.push_event
(), and then pull them out to examine them withGstCheck.Harness.pull
() andGstCheck.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 theGstCheck.TestClock
. Operating theGstCheck.TestClock
can be very challenging, butGstCheck.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 likeGstCheck.Harness.crank_single_clock_wait
().GstCheck.Harness
also supports sub-harnesses, as a way of generating and validating data. A sub-harness is anotherGstCheck.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 convenientGstCheck.Harness.add_src
() orGstCheck.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)[source]¶
- Parameters:
- Return type:
Stop the running
GstCheck.HarnessThread
MT safe.
New in version 1.6.
- add_element_sink_pad(sinkpad)[source]¶
-
Links the specified
Gst.Pad
the GstHarness srcpad.MT safe.
New in version 1.6.
- add_element_src_pad(srcpad)[source]¶
-
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)[source]¶
- Parameters:
element_name (
str
) – astr
with aGst.ElementFactory
namepad_name (
str
) – astr
with the name of the pad to attach the probe tomask (
Gst.PadProbeType
) – aGst.PadProbeType
(seeGst.Pad.add_probe
)callback (
Gst.PadProbeCallback
) – aGst.PadProbeCallback
(seeGst.Pad.add_probe
)user_data (
object
orNone
) – aobject
(seeGst.Pad.add_probe
)
A convenience function to allows you to call
Gst.Pad.add_probe
on aGst.Pad
of aGst.Element
that are residing inside theGstCheck.Harness
, by using normalGst.Pad.add_probe
syntaxMT safe.
New in version 1.6.
- add_propose_allocation_meta(api, params)[source]¶
- Parameters:
api (
GObject.GType
) – a metadata APIparams (
Gst.Structure
orNone
) – API specific 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)[source]¶
- Parameters:
sink_element_name (
str
) – astr
with the name of aGst.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)[source]¶
- Parameters:
sink_harness (
GstCheck.Harness
) – aGstCheck.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 harnessedGst.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)[source]¶
- Parameters:
launchline (
str
) – astr
with the name of aGst.Element
Similar to
GstCheck.Harness.add_sink
, this allows you to specify a launch-line instead of just an element name. SeeGstCheck.Harness.add_src_parse
for details.MT safe.
New in version 1.6.
- add_src(src_element_name, has_clock_wait)[source]¶
- Parameters:
src_element_name (
str
) – astr
with the name of aGst.Element
has_clock_wait (
bool
) – abool
specifying if theGst.Element
uses gst_clock_wait_id internally.
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)[source]¶
- Parameters:
src_harness (
GstCheck.Harness
) – aGstCheck.Harness
to be added as a src-harness.has_clock_wait (
bool
) – abool
specifying if theGst.Element
uses gst_clock_wait_id internally.
A src-harness is a great way of providing the
GstCheck.Harness
with data. By adding a src-typeGst.Element
, it is then easy to use functions likeGstCheck.Harness.push_from_src
orGstCheck.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)[source]¶
- Parameters:
has_clock_wait (
bool
) – abool
specifying if theGst.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 oneGst.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()[source]¶
-
The number of
Gst.Buffers
currently in theGstCheck.Harness
sinkpadGLib.AsyncQueue
MT safe.
New in version 1.6.
- buffers_received()[source]¶
-
The total number of
Gst.Buffers
that has arrived on theGstCheck.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)[source]¶
- Parameters:
waits (
int
) – aint
describing the number of #GstClockIDs to crank- Returns:
a gboolean
True
if the “crank” was successful,False
if not.- Return type:
Similar to
GstCheck.Harness.crank_single_clock_wait
(), this is the function to use if your harnessed element(s) are using more then oneGst.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()[source]¶
-
A “crank” consists of three steps: 1: Wait for a #GstClockID to be registered with the
GstCheck.TestClock
. 2: Advance theGstCheck.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)[source]¶
- Parameters:
size (
int
) – a #gsize specifying the size of the buffer- Returns:
a
Gst.Buffer
of size size- Return type:
Allocates a buffer using a
Gst.BufferPool
if present, or else using the configuredGst.Allocator
andGst.AllocationParams
MT safe.
New in version 1.6.
- dump_to_file(filename)[source]¶
-
Allows you to dump the
Gst.Buffers
theGstCheck.Harness
sinkpadGLib.AsyncQueue
to a file.MT safe.
New in version 1.6.
- events_in_queue()[source]¶
-
The number of
Gst.Events
currently in theGstCheck.Harness
sinkpadGLib.AsyncQueue
MT safe.
New in version 1.6.
- events_received()[source]¶
-
The total number of
Gst.Events
that has arrived on theGstCheck.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)[source]¶
- Parameters:
element_name (
str
) – astr
with aGst.ElementFactory
name- Returns:
a
Gst.Element
orNone
if not found- Return type:
Gst.Element
orNone
Most useful in conjunction with gst_harness_new_parse, this will scan the
Gst.Elements
inside theGstCheck.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()[source]¶
- Returns:
- allocator:
the
Gst.Allocator
used- params:
the
Gst.AllocationParams
of allocator
- Return type:
(allocator:
Gst.Allocator
orNone
, 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()[source]¶
- Returns:
a #GstClockTime with the timestamp or
Gst.CLOCK_TIME_NONE
if noGst.Buffer
has been pushed on theGstCheck.Harness
srcpad- Return type:
Get the timestamp of the last
Gst.Buffer
pushed on theGstCheck.Harness
srcpad, typically withGstCheck.Harness.push
orGstCheck.Harness.push_from_src
.MT safe.
New in version 1.6.
- get_testclock()[source]¶
- Returns:
a
GstCheck.TestClock
, orNone
if the testclock is not present.- Return type:
Get the
GstCheck.TestClock
. Useful if specific operations on the testclock is needed.MT safe.
New in version 1.6.
- play()[source]¶
This will set the harnessed
Gst.Element
toGst.State.PLAYING
.Gst.Elements
without a sink-Gst.Pad
and with theGst.ElementFlags.SOURCE
flag set is considered a srcGst.Element
Non-srcGst.Elements
(like sinks and filters) are automatically set to playing by theGstCheck.Harness
, but srcGst.Elements
are not to avoid them starting to produce buffers. Hence, for srcGst.Element
you must callGstCheck.Harness.play
() explicitly.MT safe.
New in version 1.6.
- pull()[source]¶
- Returns:
a
Gst.Buffer
orNone
if timed out.- Return type:
Gst.Buffer
orNone
Pulls a
Gst.Buffer
from theGLib.AsyncQueue
on theGstCheck.Harness
sinkpad. The pull will timeout in 60 seconds. This is the standard way of getting a buffer from a harnessedGst.Element
.MT safe.
New in version 1.6.
- pull_event()[source]¶
-
Pulls an
Gst.Event
from theGLib.AsyncQueue
on theGstCheck.Harness
sinkpad. Timeouts after 60 seconds similar toGstCheck.Harness.pull
.MT safe.
New in version 1.6.
- pull_until_eos()[source]¶
- Returns:
True
on success,False
on timeout.- buf:
A
Gst.Buffer
, orNone
if EOS or timeout occures first.
- Return type:
(
bool
, buf:Gst.Buffer
orNone
)
Pulls a
Gst.Buffer
from theGLib.AsyncQueue
on theGstCheck.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()[source]¶
-
Pulls an
Gst.Event
from theGLib.AsyncQueue
on theGstCheck.Harness
srcpad. Timeouts after 60 seconds similar toGstCheck.Harness.pull
.MT safe.
New in version 1.6.
- push(buffer)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
to push- Returns:
a
Gst.FlowReturn
with the result from the push- Return type:
Pushes a
Gst.Buffer
on theGstCheck.Harness
srcpad. The standard way of interacting with an harnessed element.MT safe.
New in version 1.6.
- push_and_pull(buffer)[source]¶
- Parameters:
buffer (
Gst.Buffer
) – aGst.Buffer
to push- Returns:
a
Gst.Buffer
orNone
if timed out.- Return type:
Gst.Buffer
orNone
Basically a
GstCheck.Harness.push
and aGstCheck.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)[source]¶
- Parameters:
- Returns:
a
bool
with the result from the push- Return type:
Pushes an
Gst.Event
on theGstCheck.Harness
srcpad.MT safe.
New in version 1.6.
- push_from_src()[source]¶
- Returns:
a
Gst.FlowReturn
with the result of the push- Return type:
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 aGst.Buffer
from the src-GstCheck.Harness
(see:GstCheck.Harness.pull
) 4: Push the sameGst.Buffer
into the main-GstCheck.Harness
(see:GstCheck.Harness.push
)MT safe.
New in version 1.6.
- push_to_sink()[source]¶
- Returns:
a
Gst.FlowReturn
with the result of the push- Return type:
Transfer one
Gst.Buffer
from the main-GstCheck.Harness
to the sink-GstCheck.Harness
. SeeGstCheck.Harness.push_from_src
for details.MT safe.
New in version 1.6.
- push_upstream_event(event)[source]¶
- Parameters:
- Returns:
a
bool
with the result from the push- Return type:
Pushes an
Gst.Event
on theGstCheck.Harness
sinkpad.MT safe.
New in version 1.6.
- query_latency()[source]¶
- Returns:
a #GstClockTime with min latency
- Return type:
Get the min latency reported by any harnessed
Gst.Element
.MT safe.
New in version 1.6.
- set_blocking_push_mode()[source]¶
Setting this will make the harness block in the chain-function, and then release when
GstCheck.Harness.pull
() orGstCheck.Harness.try_pull
() is called. Can be useful when wanting to control a src-element that is not implementingGst.Clock.id_wait
() so it can’t be controlled by theGstCheck.TestClock
, since it otherwise would produce buffers as fast as possible.MT safe.
New in version 1.6.
- set_caps(in_, out)[source]¶
- Parameters:
Sets the GstHarness srcpad and sinkpad caps.
MT safe.
New in version 1.6.
- set_caps_str(in_, out)[source]¶
- Parameters:
Sets the GstHarness srcpad and sinkpad caps using strings.
MT safe.
New in version 1.6.
- set_drop_buffers(drop_buffers)[source]¶
-
When set to
True
, instead of placing the buffers arriving from the harnessedGst.Element
inside the sinkpadsGLib.AsyncQueue
, they are instead unreffed.MT safe.
New in version 1.6.
- set_forwarding(forwarding)[source]¶
-
As a convenience, a src-harness will forward
Gst.EventType.STREAM_START
,Gst.EventType.CAPS
andGst.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 theGst.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)[source]¶
-
Sets the liveness reported by
GstCheck.Harness
when receiving a latency-query. The default isTrue
.New in version 1.20.
- set_propose_allocator(allocator, params)[source]¶
- Parameters:
allocator (
Gst.Allocator
orNone
) – aGst.Allocator
params (
Gst.AllocationParams
orNone
) – aGst.AllocationParams
Sets the allocator and params to propose when receiving an allocation query.
MT safe.
New in version 1.6.
- set_sink_caps_str(str)[source]¶
-
Sets the GstHarness sinkpad caps using a string.
MT safe.
New in version 1.6.
- set_src_caps(caps)[source]¶
-
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)[source]¶
-
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)[source]¶
- Parameters:
time (
int
) – a #GstClockTime to advance the clock to- Returns:
- Return type:
Advance the
GstCheck.TestClock
to a specific time.MT safe.
New in version 1.6.
- set_upstream_latency(latency)[source]¶
- Parameters:
latency (
int
) – a #GstClockTime specifying the latency
Sets the min latency reported by
GstCheck.Harness
when receiving a latency-queryNew in version 1.6.
- sink_push_many(pushes)[source]¶
- Parameters:
pushes (
int
) – aint
with the number of calls toGstCheck.Harness.push_to_sink
- Returns:
a
Gst.FlowReturn
with the result of the push- Return type:
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)[source]¶
- Parameters:
cranks (
int
) – aint
with the number of calls toGstCheck.Harness.crank_single_clock_wait
pushes (
int
) – aint
with the number of calls toGstCheck.Harness.push
- Returns:
a
Gst.FlowReturn
with the result of the push- Return type:
Transfer data from the src-
GstCheck.Harness
to the main-GstCheck.Harness
. Similar toGstCheck.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()[source]¶
-
Similar to what gst_harness_src_push does with
Gst.Buffers
, this transfers aGst.Event
from the src-GstCheck.Harness
to the main-GstCheck.Harness
. Note that someGst.Events
are being transferred automagically. Look at sink_forward_pad for details.MT safe.
New in version 1.6.
- take_all_data()[source]¶
- Returns:
a pointer to the data, newly allocated. Free with
GLib.free
() when no longer needed.- Return type:
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()[source]¶
- Returns:
the data as a buffer. Unref with gst_buffer_unref() when no longer needed.
- Return type:
Pulls all pending data from the harness and returns it as a single buffer.
New in version 1.14.
- teardown()[source]¶
Tears down a GstHarness, freeing all resources allocated using it.
MT safe.
New in version 1.6.
- try_pull()[source]¶
- Returns:
a
Gst.Buffer
orNone
if no buffers are present in theGLib.AsyncQueue
- Return type:
Gst.Buffer
orNone
Pulls a
Gst.Buffer
from theGLib.AsyncQueue
on theGstCheck.Harness
sinkpad. UnlikeGstCheck.Harness.pull
this will not wait for any buffers if not any are present, and returnNone
straight away.MT safe.
New in version 1.6.
- try_pull_event()[source]¶
- Returns:
a
Gst.Event
orNone
if no buffers are present in theGLib.AsyncQueue
- Return type:
Pulls an
Gst.Event
from theGLib.AsyncQueue
on theGstCheck.Harness
sinkpad. SeeGstCheck.Harness.try_pull
for details.MT safe.
New in version 1.6.
- try_pull_upstream_event()[source]¶
- Returns:
a
Gst.Event
orNone
if no buffers are present in theGLib.AsyncQueue
- Return type:
Pulls an
Gst.Event
from theGLib.AsyncQueue
on theGstCheck.Harness
srcpad. SeeGstCheck.Harness.try_pull
for details.MT safe.
New in version 1.6.
- upstream_events_in_queue()[source]¶
-
The number of
Gst.Events
currently in theGstCheck.Harness
srcpadGLib.AsyncQueue
MT safe.
New in version 1.6.
- upstream_events_received()[source]¶
-
The total number of
Gst.Events
that has arrived on theGstCheck.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()[source]¶
Sets the system
Gst.Clock
on the GstHarnessGst.Element
MT safe.
New in version 1.6.
- use_testclock()[source]¶
Sets the
GstCheck.TestClock
on theGstCheck.Harness
Gst.Element
MT safe.
New in version 1.6.
- wait_for_clock_id_waits(waits, timeout)[source]¶
- Parameters:
waits (
int
) – aint
describing the numbers of #GstClockID registered with theGstCheck.TestClock
timeout (
int
) – aint
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:
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.