[farsight2/master] Start/stop the stund in test fixtures
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:26:44 PST 2008
---
tests/check/transmitter/generic.c | 37 +++++++++++++++++++++++++++++++++++++
tests/check/transmitter/generic.h | 5 +++++
tests/check/transmitter/nice.c | 18 ++----------------
tests/check/transmitter/rawudp.c | 18 ++----------------
4 files changed, 46 insertions(+), 32 deletions(-)
diff --git a/tests/check/transmitter/generic.c b/tests/check/transmitter/generic.c
index 3f86404..9029204 100644
--- a/tests/check/transmitter/generic.c
+++ b/tests/check/transmitter/generic.c
@@ -26,6 +26,9 @@
#include <gst/farsight/fs-transmitter.h>
#include <gst/farsight/fs-stream-transmitter.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
#include "check-threadsafe.h"
#include "generic.h"
@@ -204,3 +207,37 @@ test_transmitter_creation (gchar *transmitter_name)
gst_object_unref (pipeline);
}
+
+
+GPid stund_pid = 0;
+
+void
+setup_stund (void)
+{
+ GError *error = NULL;
+ gchar *argv[] = {"stund", NULL};
+
+ stund_pid = 0;
+
+ if (!g_spawn_async (NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL, &stund_pid, &error))
+ {
+ g_debug ("Could not spawn stund, skipping stun testing: %s",
+ error->message);
+ g_clear_error (&error);
+ return;
+ }
+}
+
+void
+teardown_stund (void)
+{
+ if (!stund_pid)
+ return;
+
+ kill (stund_pid, SIGTERM);
+ waitpid (stund_pid, NULL, 0);
+ g_spawn_close_pid (stund_pid);
+ stund_pid = 0;
+}
diff --git a/tests/check/transmitter/generic.h b/tests/check/transmitter/generic.h
index 51bc142..be0612a 100644
--- a/tests/check/transmitter/generic.h
+++ b/tests/check/transmitter/generic.h
@@ -38,5 +38,10 @@ gboolean bus_error_callback (GstBus *bus, GstMessage *message,
void test_transmitter_creation (gchar *transmitter_name);
+extern GPid stund_pid;
+
+void setup_stund (void);
+void teardown_stund (void);
+
#endif /* __GENERIC_H__ */
diff --git a/tests/check/transmitter/nice.c b/tests/check/transmitter/nice.c
index c7f1df8..0d5cdad 100644
--- a/tests/check/transmitter/nice.c
+++ b/tests/check/transmitter/nice.c
@@ -535,21 +535,10 @@ GST_END_TEST;
GST_START_TEST (test_nicetransmitter_stund)
{
- GError *error = NULL;
- gint myout, myin;
- GPid pid;
- gchar *argv[] = {"stund", NULL};
GParameter params[2];
- if (!g_spawn_async_with_pipes (NULL, argv, NULL,
- G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &myin, &myout, NULL,
- &error))
- {
- g_debug ("Could not spawn stund, skipping stun testing: %s",
- error->message);
- g_clear_error (&error);
+ if (stund_pid <= 0)
return;
- }
memset (params, 0, sizeof (GParameter) * 2);
@@ -562,10 +551,6 @@ GST_START_TEST (test_nicetransmitter_stund)
g_value_set_uint (¶ms[1].value, 3478);
run_nice_transmitter_test (2, params, 0);
-
- close (myout);
- close (myin);
- g_spawn_close_pid (pid);
}
GST_END_TEST;
@@ -758,6 +743,7 @@ nicetransmitter_suite (void)
if (g_getenv ("STUND"))
{
tc_chain = tcase_create ("nicetransmitter-stund");
+ tcase_add_checked_fixture (tc_chain, setup_stund, teardown_stund);
tcase_add_test (tc_chain, test_nicetransmitter_stund);
suite_add_tcase (s, tc_chain);
}
diff --git a/tests/check/transmitter/rawudp.c b/tests/check/transmitter/rawudp.c
index 7135acb..20823a5 100644
--- a/tests/check/transmitter/rawudp.c
+++ b/tests/check/transmitter/rawudp.c
@@ -435,20 +435,9 @@ GST_END_TEST;
GST_START_TEST (test_rawudptransmitter_run_stund)
{
GParameter params[3];
- GError *error = NULL;
- gint myout, myin;
- GPid pid;
- gchar *argv[] = {"stund", NULL};
- if (!g_spawn_async_with_pipes (NULL, argv, NULL,
- G_SPAWN_SEARCH_PATH, NULL, NULL, &pid, &myin, &myout, NULL,
- &error))
- {
- g_debug ("Could not spawn stund, skipping stun testing: %s",
- error->message);
- g_clear_error (&error);
+ if (stund_pid <= 0)
return;
- }
memset (params, 0, sizeof (GParameter) * 3);
@@ -465,10 +454,6 @@ GST_START_TEST (test_rawudptransmitter_run_stund)
g_value_set_uint (¶ms[2].value, 5);
run_rawudp_transmitter_test (3, params, FLAG_HAS_STUN);
-
- close (myout);
- close (myin);
- g_spawn_close_pid (pid);
}
GST_END_TEST;
@@ -698,6 +683,7 @@ rawudptransmitter_suite (void)
{
tc_chain = tcase_create ("rawudptransmitter-stund");
tcase_set_timeout (tc_chain, 15);
+ tcase_add_checked_fixture (tc_chain, setup_stund, teardown_stund);
tcase_add_test (tc_chain, test_rawudptransmitter_run_stund);
suite_add_tcase (s, tc_chain);
}
--
1.5.6.5
More information about the farsight-commits
mailing list