[aravis] tests: add a simple test program that test heartbeat robustness.
- From: Emmanuel Pacaud <emmanuel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [aravis] tests: add a simple test program that test heartbeat robustness.
- Date: Thu, 9 Feb 2012 10:43:07 +0000 (UTC)
commit 9edbce2c24effd5b2d35e8d3821bbf933ef721a1
Author: Luca Barbato <lu_zero gentoo org>
Date: Thu Feb 9 11:42:40 2012 +0100
tests: add a simple test program that test heartbeat robustness.
tests/.gitignore | 1 +
tests/Makefile.am | 5 +-
tests/arvheartbeattest.c | 151 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 156 insertions(+), 1 deletions(-)
---
diff --git a/tests/.gitignore b/tests/.gitignore
index f88817c..120d415 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -8,3 +8,4 @@ arv-genicam-test
arv-evaluator-test
arv-zip-test
arv-camera-test
+arv-heartbeat-test
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a55ca90..a2dc157 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -6,7 +6,7 @@ test_progs_ldadd = \
$(top_builddir)/src/libaravis- ARAVIS_API_VERSION@.la \
$(ARAVIS_LIBS)
-noinst_PROGRAMS = arv-test arv-genicam-test arv-evaluator-test arv-zip-test arv-camera-test
+noinst_PROGRAMS = arv-test arv-genicam-test arv-evaluator-test arv-zip-test arv-camera-test arv-heartbeat-test
arv_test_SOURCES = arvtest.c
arv_test_LDADD = $(test_progs_ldadd)
@@ -23,6 +23,9 @@ arv_zip_test_LDADD = $(test_progs_ldadd)
arv_camera_test_SOURCES = arvcameratest.c
arv_camera_test_LDADD = $(test_progs_ldadd)
+arv_heartbeat_test_SOURCES = arvheartbeattest.c
+arv_heartbeat_test_LDADD = $(test_progs_ldadd)
+
TEST_PROGS += evaluator buffer fake genicam cpp
noinst_PROGRAMS += $(TEST_PROGS)
diff --git a/tests/arvheartbeattest.c b/tests/arvheartbeattest.c
new file mode 100644
index 0000000..c84fbab
--- /dev/null
+++ b/tests/arvheartbeattest.c
@@ -0,0 +1,151 @@
+#include <arv.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static gboolean cancel = FALSE;
+
+static void
+set_cancel (int signal)
+{
+ cancel = TRUE;
+}
+
+static char *arv_option_camera_name = NULL;
+static char *arv_option_feature_name = "Gain";
+static int arv_option_min = 0;
+static int arv_option_max = 10;
+static char *arv_option_debug_domains = "device";
+
+static const GOptionEntry arv_option_entries[] =
+{
+ {
+ "name", 'n', 0, G_OPTION_ARG_STRING,
+ &arv_option_camera_name, "Camera name", NULL
+ },
+ {
+ "feature", 'f', 0, G_OPTION_ARG_STRING,
+ &arv_option_feature_name, "Feature name", NULL
+ },
+ {
+ "max", 'a', 0, G_OPTION_ARG_INT,
+ &arv_option_max, "Max", NULL
+ },
+ {
+ "min", 'i', 0, G_OPTION_ARG_INT,
+ &arv_option_min, "Min", NULL
+ },
+ {
+ "debug", 'd', 0, G_OPTION_ARG_STRING,
+ &arv_option_debug_domains, "Debug domains", NULL
+ },
+ { NULL }
+};
+
+int main(int argc, char *argv[])
+{
+ ArvDevice *device;
+ ArvStream *stream;
+ ArvCamera *camera;
+ ArvGcNode *feature;
+ guint64 n_completed_buffers;
+ guint64 n_failures;
+ guint64 n_underruns;
+ GOptionContext *context;
+ GError *error = NULL;
+ void (*old_sigint_handler)(int);
+ int i, payload;
+
+ g_thread_init (NULL);
+ g_type_init ();
+
+ context = g_option_context_new (NULL);
+ g_option_context_set_summary (context, "Test of heartbeat robustness while continuously changing a feature.");
+ g_option_context_add_main_entries (context, arv_option_entries, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ g_option_context_free (context);
+ g_print ("Option parsing failed: %s\n", error->message);
+ g_error_free (error);
+ return EXIT_FAILURE;
+ }
+
+ g_option_context_free (context);
+
+ arv_debug_enable (arv_option_debug_domains);
+
+ camera = arv_camera_new (arv_option_camera_name);
+ if (!ARV_IS_CAMERA (camera)) {
+ printf ("Device not found\n");
+ return EXIT_FAILURE;
+ }
+
+ device = arv_camera_get_device (camera);
+
+ stream = arv_camera_create_stream (camera, NULL, NULL);
+ if (!ARV_IS_STREAM (stream)) {
+ printf ("Invalid device\n");
+ } else {
+ payload = arv_camera_get_payload (camera);
+
+ if (ARV_IS_GV_STREAM (stream)) {
+ g_object_set (stream,
+ //"socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_AUTO,
+ "socket-buffer", ARV_GV_STREAM_SOCKET_BUFFER_FIXED,
+ "socket-buffer-size", payload*6,
+ "packet-timeout", 1000 * 1000,
+ "frame-retention", 100 * 1000,
+ "packet-resend", ARV_GV_STREAM_PACKET_RESEND_ALWAYS,
+ NULL);
+ }
+
+ for (i = 0; i < 100; i++)
+ arv_stream_push_buffer(stream, arv_buffer_new(payload, NULL));
+
+ arv_camera_set_acquisition_mode(camera, ARV_ACQUISITION_MODE_CONTINUOUS);
+
+ feature = arv_device_get_feature (device, arv_option_feature_name);
+
+ arv_camera_start_acquisition (camera);
+
+ old_sigint_handler = signal (SIGINT, set_cancel);
+
+ while (!cancel) {
+ ArvBuffer *buffer = arv_stream_timed_pop_buffer(stream, 2000000);
+ if (buffer) {
+ usleep(10);
+ arv_stream_push_buffer (stream, buffer);
+ }
+
+ if (!(++i%5)) {
+ char *value;
+
+ if ((i/100) % 2 == 0)
+ value = g_strdup_printf ("%d", arv_option_min);
+ else
+ value = g_strdup_printf ("%d", arv_option_max);
+
+ fprintf (stderr, "Setting %s from %s to %s\n",
+ arv_option_feature_name,
+ arv_gc_node_get_value_as_string (feature),
+ value);
+ arv_gc_node_set_value_from_string (feature, value);
+
+ g_free (value);
+ }
+ }
+
+ signal (SIGINT, old_sigint_handler);
+
+ arv_stream_get_statistics (stream, &n_completed_buffers, &n_failures, &n_underruns);
+
+ g_printf ("\nCompleted buffers = %Lu\n", (unsigned long long) n_completed_buffers);
+ g_printf ("Failures = %Lu\n", (unsigned long long) n_failures);
+ g_printf ("Underruns = %Lu\n", (unsigned long long) n_underruns);
+
+ arv_camera_stop_acquisition (camera);
+ }
+
+ g_object_unref (camera);
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]