aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-30 11:21:31 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-30 11:21:31 +0000
commitb15aee9f1925cbf8755ad427a0bf4aa7e66a321f (patch)
tree293e1a085d336d3b40c3d9e9e5f799e0571fbf28 /src/testing
parenteab4b6722aa4204502f193fb965d9a5193857354 (diff)
downloadgnunet-b15aee9f1925cbf8755ad427a0bf4aa7e66a321f.tar.gz
gnunet-b15aee9f1925cbf8755ad427a0bf4aa7e66a321f.zip
-GNUNET_TESTING_service_run
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing_new.c75
1 files changed, 73 insertions, 2 deletions
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index 3d0d944c4..4f9494bea 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -36,6 +36,9 @@
36#define LOG(kind,...) \ 36#define LOG(kind,...) \
37 GNUNET_log_from (kind, "gnunettestingnew", __VA_ARGS__) 37 GNUNET_log_from (kind, "gnunettestingnew", __VA_ARGS__)
38 38
39#define TIME_REL_SEC(sec) \
40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec)
41
39/** 42/**
40 * AI_NUMERICSERV not defined in windows. A hack to keep on going. 43 * AI_NUMERICSERV not defined in windows. A hack to keep on going.
41 */ 44 */
@@ -792,6 +795,53 @@ GNUNET_TESTING_peer_run (const char *tmppath,
792} 795}
793 796
794 797
798/**
799 * Structure for holding service data
800 */
801struct ServiceContext
802{
803 /**
804 * The service's main process
805 */
806 struct GNUNET_OS_Process *main_process;
807
808 /**
809 * Callback to signal service startup
810 */
811 GNUNET_TESTING_TestMain tm;
812
813 /**
814 * Closure for the above callback
815 */
816 void *tm_cls;
817};
818
819
820/**
821 * Scheduler callback to stop service upon call to GNUNET_SCHEDULER_shutdown
822 *
823 * @param cls the ServiceContext
824 * @param tc the TaskContext
825 */
826static void
827stop_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
828{
829 GNUNET_break (0);
830}
831
832
833/**
834 * Scheduler callback to stop service upon call to GNUNET_SCHEDULER_shutdown
835 *
836 * @param cls the ServiceContext
837 * @param tc the TaskContext
838 */
839static void
840check_service_status (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
841{
842 GNUNET_break (0);
843}
844
795 845
796/** 846/**
797 * Start a single service (no ARM, except of course if the given 847 * Start a single service (no ARM, except of course if the given
@@ -819,8 +869,29 @@ GNUNET_TESTING_service_run (const char *tmppath,
819 GNUNET_TESTING_TestMain tm, 869 GNUNET_TESTING_TestMain tm,
820 void *tm_cls) 870 void *tm_cls)
821{ 871{
822 GNUNET_break (0); 872 struct ServiceContext *sc;
823 return 1; 873 char uval[128];
874
875 GNUNET_assert (NULL != service_name);
876 GNUNET_snprintf (uval, sizeof (uval), "gnunet-service-%s", service_name);
877 sc = GNUNET_malloc (sizeof (struct ServiceContext));
878 if (NULL == cfgfilename)
879 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval);
880 else
881 sc->main_process = GNUNET_OS_start_process (GNUNET_NO, NULL, NULL, uval,
882 "-c", cfgfilename);
883 if (NULL == sc->main_process)
884 {
885 LOG (GNUNET_ERROR_TYPE_DEBUG, "Failed to start process %s\n", service_name);
886 GNUNET_free (sc);
887 return 1;
888 }
889 sc->tm = tm;
890 sc->tm_cls = tm_cls;
891 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
892 &stop_service, sc);
893 GNUNET_SCHEDULER_add_delayed (TIME_REL_SEC(3), &check_service_status, sc);
894 return 0;
824} 895}
825 896
826 897