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.Harnessis meant to make writing unit test for GStreamer much easier. It can be thought of as a way of treating aGst.Elementas a black box, deterministically feeding it data, and controlling what data it outputs.The basic structure of
GstCheck.Harnessis two “floating”Gst.Padsthat connect to the harnessedGst.Elementsrc and sinkGst.Padslike so:__________________________ _____ | _____ _____ | _____ | | | | | | | | | | | src |--+-| sink| Element | src |-+--| sink| |_____| | |_____| |_____| | |_____| |__________________________|With this, you can now simulate any environment the
Gst.Elementmight find itself in. By specifying theGst.Capsof the harnessGst.Pads, using functions likeGstCheck.Harness.set_src_caps() orGstCheck.Harness.set_sink_caps_str(), you can test how theGst.Elementinteracts with different caps sets.Your harnessed
Gst.Elementcan 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.BuffersandGst.Eventson 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.Harnessis its integration with theGstCheck.TestClock. Operating theGstCheck.TestClockcan be very challenging, butGstCheck.Harnesssimplifies 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.Harnessalso supports sub-harnesses, as a way of generating and validating data. A sub-harness is anotherGstCheck.Harnessthat 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.HarnessThreadMT safe.
New in version 1.6.
- add_element_sink_pad(sinkpad)[source]¶
-
Links the specified
Gst.Padthe GstHarness srcpad.MT safe.
New in version 1.6.
- add_element_src_pad(srcpad)[source]¶
-
Links the specified
Gst.Padthe 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) – astrwith aGst.ElementFactorynamepad_name (
str) – astrwith 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 (
objectorNone) – aobject(seeGst.Pad.add_probe)
A convenience function to allows you to call
Gst.Pad.add_probeon aGst.Padof aGst.Elementthat are residing inside theGstCheck.Harness, by using normalGst.Pad.add_probesyntaxMT safe.
New in version 1.6.
- add_propose_allocation_meta(api, params)[source]¶
- Parameters:
api (
GObject.GType) – a metadata APIparams (
Gst.StructureorNone) – 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) – astrwith 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.Harnessto be added as a sink-harness.
Similar to
GstCheck.Harness.add_src, this allows you to send the data coming out of your harnessedGst.Elementto 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) – astrwith 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_parsefor details.MT safe.
New in version 1.6.
- add_src(src_element_name, has_clock_wait)[source]¶
- Parameters:
src_element_name (
str) – astrwith the name of aGst.Elementhas_clock_wait (
bool) – aboolspecifying if theGst.Elementuses 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.Harnessto be added as a src-harness.has_clock_wait (
bool) – aboolspecifying if theGst.Elementuses gst_clock_wait_id internally.
A src-harness is a great way of providing the
GstCheck.Harnesswith data. By adding a src-typeGst.Element, it is then easy to use functions likeGstCheck.Harness.push_from_srcorGstCheck.Harness.src_crank_and_push_manyto 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) – aboolspecifying if theGst.Elementuses 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.Elementacting 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.Bufferscurrently in theGstCheck.HarnesssinkpadGLib.AsyncQueueMT safe.
New in version 1.6.
- buffers_received()[source]¶
-
The total number of
Gst.Buffersthat has arrived on theGstCheck.Harnesssinkpad. 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) – aintdescribing the number of #GstClockIDs to crank- Returns:
a gboolean
Trueif the “crank” was successful,Falseif 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.TestClockto 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.Bufferof size size- Return type:
Allocates a buffer using a
Gst.BufferPoolif present, or else using the configuredGst.AllocatorandGst.AllocationParamsMT safe.
New in version 1.6.
- dump_to_file(filename)[source]¶
-
Allows you to dump the
Gst.BufferstheGstCheck.HarnesssinkpadGLib.AsyncQueueto a file.MT safe.
New in version 1.6.
- events_in_queue()[source]¶
-
The number of
Gst.Eventscurrently in theGstCheck.HarnesssinkpadGLib.AsyncQueueMT safe.
New in version 1.6.
- events_received()[source]¶
-
The total number of
Gst.Eventsthat has arrived on theGstCheck.Harnesssinkpad 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) – astrwith aGst.ElementFactoryname- Returns:
a
Gst.ElementorNoneif not found- Return type:
Gst.ElementorNone
Most useful in conjunction with gst_harness_new_parse, this will scan the
Gst.Elementsinside 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.Allocatorused- params:
the
Gst.AllocationParamsof allocator
- Return type:
(allocator:
Gst.AllocatororNone, 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_NONEif noGst.Bufferhas been pushed on theGstCheck.Harnesssrcpad- Return type:
Get the timestamp of the last
Gst.Bufferpushed on theGstCheck.Harnesssrcpad, typically withGstCheck.Harness.pushorGstCheck.Harness.push_from_src.MT safe.
New in version 1.6.
- get_testclock()[source]¶
- Returns:
a
GstCheck.TestClock, orNoneif 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.ElementtoGst.State.PLAYING.Gst.Elementswithout a sink-Gst.Padand with theGst.ElementFlags.SOURCEflag set is considered a srcGst.ElementNon-srcGst.Elements(like sinks and filters) are automatically set to playing by theGstCheck.Harness, but srcGst.Elementsare not to avoid them starting to produce buffers. Hence, for srcGst.Elementyou must callGstCheck.Harness.play() explicitly.MT safe.
New in version 1.6.
- pull()[source]¶
- Returns:
a
Gst.BufferorNoneif timed out.- Return type:
Gst.BufferorNone
Pulls a
Gst.Bufferfrom theGLib.AsyncQueueon theGstCheck.Harnesssinkpad. 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.Eventfrom theGLib.AsyncQueueon theGstCheck.Harnesssinkpad. Timeouts after 60 seconds similar toGstCheck.Harness.pull.MT safe.
New in version 1.6.
- pull_until_eos()[source]¶
- Returns:
Trueon success,Falseon timeout.- buf:
A
Gst.Buffer, orNoneif EOS or timeout occures first.
- Return type:
(
bool, buf:Gst.BufferorNone)
Pulls a
Gst.Bufferfrom theGLib.AsyncQueueon theGstCheck.Harnesssinkpad. 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.Eventfrom theGLib.AsyncQueueon theGstCheck.Harnesssrcpad. Timeouts after 60 seconds similar toGstCheck.Harness.pull.MT safe.
New in version 1.6.
- push(buffer)[source]¶
- Parameters:
buffer (
Gst.Buffer) – aGst.Bufferto push- Returns:
a
Gst.FlowReturnwith the result from the push- Return type:
Pushes a
Gst.Bufferon theGstCheck.Harnesssrcpad. 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.Bufferto push- Returns:
a
Gst.BufferorNoneif timed out.- Return type:
Gst.BufferorNone
Basically a
GstCheck.Harness.pushand aGstCheck.Harness.pullin 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
boolwith the result from the push- Return type:
Pushes an
Gst.Eventon theGstCheck.Harnesssrcpad.MT safe.
New in version 1.6.
- push_from_src()[source]¶
- Returns:
a
Gst.FlowReturnwith the result of the push- Return type:
Transfer data from the src-
GstCheck.Harnessto 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.Bufferfrom the src-GstCheck.Harness(see:GstCheck.Harness.pull) 4: Push the sameGst.Bufferinto the main-GstCheck.Harness(see:GstCheck.Harness.push)MT safe.
New in version 1.6.
- push_to_sink()[source]¶
- Returns:
a
Gst.FlowReturnwith the result of the push- Return type:
Transfer one
Gst.Bufferfrom the main-GstCheck.Harnessto the sink-GstCheck.Harness. SeeGstCheck.Harness.push_from_srcfor details.MT safe.
New in version 1.6.
- push_upstream_event(event)[source]¶
- Parameters:
- Returns:
a
boolwith the result from the push- Return type:
Pushes an
Gst.Eventon theGstCheck.Harnesssinkpad.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.Elementinside 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.CAPSandGst.EventType.SEGMENTto 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.Harnesswhen receiving a latency-query. The default isTrue.New in version 1.20.
- set_propose_allocator(allocator, params)[source]¶
- Parameters:
allocator (
Gst.AllocatororNone) – aGst.Allocatorparams (
Gst.AllocationParamsorNone) – 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.TestClockto 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.Harnesswhen receiving a latency-queryNew in version 1.6.
- sink_push_many(pushes)[source]¶
- Parameters:
pushes (
int) – aintwith the number of calls toGstCheck.Harness.push_to_sink- Returns:
a
Gst.FlowReturnwith the result of the push- Return type:
Convenience that calls
GstCheck.Harness.push_to_sinkpushes 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) – aintwith the number of calls toGstCheck.Harness.crank_single_clock_waitpushes (
int) – aintwith the number of calls toGstCheck.Harness.push
- Returns:
a
Gst.FlowReturnwith the result of the push- Return type:
Transfer data from the src-
GstCheck.Harnessto 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.Eventfrom the src-GstCheck.Harnessto the main-GstCheck.Harness. Note that someGst.Eventsare 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.BufferorNoneif no buffers are present in theGLib.AsyncQueue- Return type:
Gst.BufferorNone
Pulls a
Gst.Bufferfrom theGLib.AsyncQueueon theGstCheck.Harnesssinkpad. UnlikeGstCheck.Harness.pullthis will not wait for any buffers if not any are present, and returnNonestraight away.MT safe.
New in version 1.6.
- try_pull_event()[source]¶
- Returns:
a
Gst.EventorNoneif no buffers are present in theGLib.AsyncQueue- Return type:
Pulls an
Gst.Eventfrom theGLib.AsyncQueueon theGstCheck.Harnesssinkpad. SeeGstCheck.Harness.try_pullfor details.MT safe.
New in version 1.6.
- try_pull_upstream_event()[source]¶
- Returns:
a
Gst.EventorNoneif no buffers are present in theGLib.AsyncQueue- Return type:
Pulls an
Gst.Eventfrom theGLib.AsyncQueueon theGstCheck.Harnesssrcpad. SeeGstCheck.Harness.try_pullfor details.MT safe.
New in version 1.6.
- upstream_events_in_queue()[source]¶
-
The number of
Gst.Eventscurrently in theGstCheck.HarnesssrcpadGLib.AsyncQueueMT safe.
New in version 1.6.
- upstream_events_received()[source]¶
-
The total number of
Gst.Eventsthat has arrived on theGstCheck.Harnesssrcpad 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.Clockon the GstHarnessGst.ElementMT safe.
New in version 1.6.
- use_testclock()[source]¶
Sets the
GstCheck.TestClockon theGstCheck.HarnessGst.ElementMT safe.
New in version 1.6.
- wait_for_clock_id_waits(waits, timeout)[source]¶
- Parameters:
waits (
int) – aintdescribing the numbers of #GstClockID registered with theGstCheck.TestClocktimeout (
int) – aintdescribing how many seconds to wait for waits to be true
- Returns:
a gboolean
Trueif the waits have been registered,Falseif 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.