gstcheck.harness
Module for [Harness] class
Types 1
#GstHarness is meant to make writing unit test for GStreamer much easier. It can be thought of as a way of treating a #GstElement as a black box, deterministically feeding it data, and controlling what data it outputs.
The basic structure of #GstHarness is two "floating" #GstPads that connect to the harnessed #GstElement src and sink #GstPads like so:
__________________________
_____ | _____ _____ | _____
| | | | | | | | | |
| src |--+-| sink| Element | src |-+--| sink|
|_____| | |_____| |_____| | |_____|
|__________________________|With this, you can now simulate any environment the #GstElement might find itself in. By specifying the #GstCaps of the harness #GstPads, using functions like [gstcheck.harness.Harness.setSrcCaps] or [gstcheck.harness.Harness.setSinkCapsStr], you can test how the #GstElement interacts with different caps sets.
Your harnessed #GstElement can of course also be a bin, and using [gstcheck.harness.Harness.newParse] supporting standard gst-launch syntax, you can easily test a whole pipeline instead of just one element.
You can then go on to push #GstBuffers and #GstEvents on to the srcpad, using functions like [gstcheck.harness.Harness.push] and [gstcheck.harness.Harness.pushEvent], and then pull them out to examine them with [gstcheck.harness.Harness.pull] and [gstcheck.harness.Harness.pullEvent].
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 #GstHarness is its integration with the #GstTestClock. Operating the #GstTestClock can be very challenging, but #GstHarness 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.Harness.crankSingleClockWait].
#GstHarness also supports sub-harnesses, as a way of generating and validating data. A sub-harness is another #GstHarness that is managed by the "parent" harness, and can either be created by using the standard gst_harness_new type functions directly on the (GstHarness *)->src_harness, or using the much more convenient [gstcheck.harness.Harness.addSrc] or [gstcheck.harness.Harness.addSinkParse]. 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);GstHarness _cInstancevoid * _cPtr()void element(gst.element.Element propval) @propertySet `element` field. Params: propval = the element inside the harnessvoid srcpad(gst.pad.Pad propval) @propertySet `srcpad` field. Params: propval = the internal harness source padvoid sinkpad(gst.pad.Pad propval) @propertySet `sinkpad` field. Params: propval = the internal harness sink padgstcheck.harness.Harness srcHarness() @propertyGet `srcHarness` field. Returns: the source (input) harness (if any)gstcheck.harness.Harness sinkHarness() @propertyGet `sinkHarness` field. Returns: the sink (output) harness (if any)void addElementSinkPad(gst.pad.Pad sinkpad)Links the specified #GstPad the GstHarness srcpad.void addElementSrcPad(gst.pad.Pad srcpad)Links the specified #GstPad 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 re...void addProbe(string elementName, string padName, gst.types.PadProbeType mask, gst.types.PadProbeCallback callback)A convenience function to allows you to call gstpadaddprobe on a #GstPad of a #GstElement that are residing inside the #GstHarness, by using normal gstpadaddprobe syntaxvoid addProposeAllocationMeta(gobject.types.GType api, gst.structure.Structure params = null)Add api with params as one of the supported metadata API to propose when receiving an allocation query.void addSink(string sinkElementName)Similar to gstharnessaddsinkharness, this is a convenience to directly create a sink-harness using the sinkelementname name specified.void addSinkHarness(gstcheck.harness.Harness sinkHarness)Similar to gstharnessaddsrc, this allows you to send the data coming out of your harnessed #GstElement to a sink-element, allowing to test different responses the element output might create in sin...void addSinkParse(string launchline)Similar to gstharnessaddsink, this allows you to specify a launch-line instead of just an element name. See gstharnessaddsrc_parse for details.void addSrc(string srcElementName, bool hasClockWait)Similar to gstharnessaddsrcharness, this is a convenience to directly create a src-harness using the srcelementname name specified.void addSrcHarness(gstcheck.harness.Harness srcHarness, bool hasClockWait)A src-harness is a great way of providing the #GstHarness with data. By adding a src-type #GstElement, it is then easy to use functions like gstharnesspushfromsrc or gstharnesssrccrankandpushmany t...void addSrcParse(string launchline, bool hasClockWait)Similar to gstharnessadd_src, this allows you to specify a launch-line, which can be useful for both having more then one #GstElement acting as your src (Like a src producing raw buffers, and then ...uint buffersInQueue()The number of #GstBuffers currently in the #GstHarness sinkpad #GAsyncQueueuint buffersReceived()The total number of #GstBuffers that has arrived on the #GstHarness sinkpad. This number includes buffers that have been dropped as well as buffers that have already been pulled out.bool crankMultipleClockWaits(uint waits)Similar to [gstcheck.harness.Harness.crankSingleClockWait], this is the function to use if your harnessed element(s) are using more then one gstclockid_wait. Failing to do so can (and will) make it...bool crankSingleClockWait()A "crank" consists of three steps: 1: Wait for a #GstClockID to be registered with the #GstTestClock. 2: Advance the #GstTestClock to the time the #GstClockID is waiting for. 3: Release the #GstClo...gst.buffer.Buffer createBuffer(size_t size)Allocates a buffer using a #GstBufferPool if present, or else using the configured #GstAllocator and #GstAllocationParamsvoid dumpToFile(string filename)Allows you to dump the #GstBuffers the #GstHarness sinkpad #GAsyncQueue to a file.uint eventsInQueue()The number of #GstEvents currently in the #GstHarness sinkpad #GAsyncQueueuint eventsReceived()The total number of #GstEvents that has arrived on the #GstHarness sinkpad This number includes events handled by the harness as well as events that have already been pulled out.gst.element.Element findElement(string elementName)Most useful in conjunction with gstharnessnewparse, this will scan the #GstElements inside the #GstHarness, and check if any of them matches elementname. Typical usecase being that you need to acce...void getAllocator(out gst.allocator.Allocator allocator, out gst.allocation_params.AllocationParams params)Gets the allocator and its params that has been decided to use after an allocation query.gst.types.ClockTime getLastPushedTimestamp()Get the timestamp of the last #GstBuffer pushed on the #GstHarness srcpad, typically with gstharnesspush or gstharnesspushfromsrc.gstcheck.test_clock.TestClock getTestclock()Get the #GstTestClock. Useful if specific operations on the testclock is needed.void play()This will set the harnessed #GstElement to [gst.types.State.Playing]. #GstElements without a sink-#GstPad and with the [gst.types.ElementFlags.Source] flag set is considered a src #GstElement Non-s...gst.buffer.Buffer pull()Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. The pull will timeout in 60 seconds. This is the standard way of getting a buffer from a harnessed #GstElement.gst.event.Event pullEvent()Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness sinkpad. Timeouts after 60 seconds similar to gstharnesspull.bool pullUntilEos(out gst.buffer.Buffer buf)Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. The pull will block until an EOS event is received, or timeout in 60 seconds. MT safe.gst.event.Event pullUpstreamEvent()Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness srcpad. Timeouts after 60 seconds similar to gstharnesspull.gst.types.FlowReturn push(gst.buffer.Buffer buffer)Pushes a #GstBuffer on the #GstHarness srcpad. The standard way of interacting with an harnessed element.gst.buffer.Buffer pushAndPull(gst.buffer.Buffer buffer)Basically a gstharnesspush and a gstharnesspull 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.bool pushEvent(gst.event.Event event)Pushes an #GstEvent on the #GstHarness srcpad.gst.types.FlowReturn pushFromSrc()Transfer data from the src-#GstHarness to the main-#GstHarness. It consists of 4 steps: 1: Make sure the src is started. (see: gstharnessplay) 2: Crank the clock (see: gstharnesscranksingleclockwai...gst.types.FlowReturn pushToSink()Transfer one #GstBuffer from the main-#GstHarness to the sink-#GstHarness. See gstharnesspushfromsrc for details.bool pushUpstreamEvent(gst.event.Event event)Pushes an #GstEvent on the #GstHarness sinkpad.gst.types.ClockTime queryLatency()Get the min latency reported by any harnessed #GstElement.void setBlockingPushMode()Setting this will make the harness block in the chain-function, and then release when [gstcheck.harness.Harness.pull] or [gstcheck.harness.Harness.tryPull] is called. Can be useful when wanting to ...void setCaps(gst.caps.Caps in_, gst.caps.Caps out_)Sets the GstHarness srcpad and sinkpad caps.void setCapsStr(string in_, string out_)Sets the GstHarness srcpad and sinkpad caps using strings.void setDropBuffers(bool dropBuffers)When set to true, instead of placing the buffers arriving from the harnessed #GstElement inside the sinkpads #GAsyncQueue, they are instead unreffed.void setForwarding(bool forwarding)As a convenience, a src-harness will forward [gst.types.EventType.StreamStart], [gst.types.EventType.Caps] and [gst.types.EventType.Segment] to the main-harness if forwarding is enabled, and forwar...void setLive(bool isLive)Sets the liveness reported by #GstHarness when receiving a latency-query. The default is true.void setProposeAllocator(gst.allocator.Allocator allocator, gst.allocation_params.AllocationParams params)Sets the allocator and params to propose when receiving an allocation query.void setSinkCaps(gst.caps.Caps caps)Sets the GstHarness sinkpad caps.void setSinkCapsStr(string str)Sets the GstHarness sinkpad caps using a string.void setSrcCaps(gst.caps.Caps caps)Sets the GstHarness srcpad caps. This must be done before any buffers can legally be pushed from the harness to the element.void setSrcCapsStr(string str)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.bool setTime(gst.types.ClockTime time)Advance the #GstTestClock to a specific time.void setUpstreamLatency(gst.types.ClockTime latency)Sets the min latency reported by #GstHarness when receiving a latency-querygst.types.FlowReturn sinkPushMany(int pushes)Convenience that calls gstharnesspushtosink pushes number of times. Will abort the pushing if any one push fails.gst.types.FlowReturn srcCrankAndPushMany(int cranks, int pushes)Transfer data from the src-#GstHarness to the main-#GstHarness. Similar to gstharnesspushfromsrc, this variant allows you to specify how many cranks and how many pushes to perform. This can be usef...bool srcPushEvent()Similar to what gstharnesssrcpush does with #GstBuffers, this transfers a #GstEvent from the src-#GstHarness to the main-#GstHarness. Note that some #GstEvents are being transferred automagically. ...gst.buffer.Buffer takeAllDataAsBuffer()Pulls all pending data from the harness and returns it as a single buffer. Returns: the data as a buffer. Unref with gstbufferunref() when no longer needed.glib.bytes.Bytes takeAllData()Pulls all pending data from the harness and returns it as a single #GBytes. Returns: a pointer to the data, newly allocated. Free with [glib.global.gfree] when no longer needed.void teardown()Tears down a GstHarness, freeing all resources allocated using it.gst.buffer.Buffer tryPull()Pulls a #GstBuffer from the #GAsyncQueue on the #GstHarness sinkpad. Unlike gstharnesspull this will not wait for any buffers if not any are present, and return null straight away.gst.event.Event tryPullEvent()Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness sinkpad. See gstharnesstry_pull for details.gst.event.Event tryPullUpstreamEvent()Pulls an #GstEvent from the #GAsyncQueue on the #GstHarness srcpad. See gstharnesstry_pull for details.uint upstreamEventsInQueue()The number of #GstEvents currently in the #GstHarness srcpad #GAsyncQueueuint upstreamEventsReceived()The total number of #GstEvents that has arrived on the #GstHarness srcpad This number includes events handled by the harness as well as events that have already been pulled out.void useSystemclock()Sets the system #GstClock on the GstHarness #GstElementvoid useTestclock()Sets the #GstTestClock on the #GstHarness #GstElementbool waitForClockIdWaits(uint waits, uint timeout)Waits for timeout seconds until waits number of #GstClockID waits is registered with the #GstTestClock. Useful for writing deterministic tests, where you want to make sure that an expected number o...uint stressThreadStop(gstcheck.types.HarnessThread t)Stop the running #GstHarnessThread