Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the timer regression test to an example
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 13 Feb 2005 23:04:34 +0000 (23:04 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Sun, 13 Feb 2005 23:04:34 +0000 (23:04 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@1009 48e7efb5-ca39-0410-a469-dd3cf9ba447f

examples/gras/timer/.cvsignore [new file with mode: 0644]
examples/gras/timer/Makefile.am [new file with mode: 0644]
examples/gras/timer/test_rl.in [new file with mode: 0755]
examples/gras/timer/test_sg.in [new file with mode: 0755]
examples/gras/timer/timer.c [new file with mode: 0644]
examples/gras/timer/timer_deployment.xml [new file with mode: 0644]

diff --git a/examples/gras/timer/.cvsignore b/examples/gras/timer/.cvsignore
new file mode 100644 (file)
index 0000000..d95616c
--- /dev/null
@@ -0,0 +1,4 @@
+.deps .libs Makefile Makefile.in _*.c timer_client timer_simulator
+test_sg
+test_rl
+timer.Makefile.am
diff --git a/examples/gras/timer/Makefile.am b/examples/gras/timer/Makefile.am
new file mode 100644 (file)
index 0000000..d909385
--- /dev/null
@@ -0,0 +1,25 @@
+INCLUDES= -I$(top_srcdir)/include
+AM_CFLAGS=-g
+NAME=timer
+PROCESSES= client
+
+TESTS= test_rl test_sg
+EXTRA_DIST=$(NAME)_deployment.xml $(TESTS)
+
+# AUTOMAKE variable definition
+noinst_PROGRAMS=timer_client timer_simulator
+
+timer_simulator_SOURCES=       _timer_simulator.c timer.c
+timer_simulator_LDADD= $(top_builddir)/src/libsimgrid.la
+
+timer_client_SOURCES=  _timer_client.c timer.c
+timer_client_LDADD=    $(top_builddir)/src/libgras.la
+
+# cleanup temps
+MAINTAINERCLEANFILES = _$(NAME)_simulator.c _$(NAME)_client.c _$(NAME)_server.c 
+
+# generate temps
+
+$(foreach proc, $(PROCESSES), _$(NAME)_$(proc).c) _$(NAME)_simulator.c: $(srcdir)/$(NAME)_deployment.xml $(top_srcdir)/tools/gras/gras_stub_generator
+       $(top_srcdir)/tools/gras/gras_stub_generator $(NAME) $(NAME)_deployment.xml >/dev/null
+
diff --git a/examples/gras/timer/test_rl.in b/examples/gras/timer/test_rl.in
new file mode 100755 (executable)
index 0000000..18dbc80
--- /dev/null
@@ -0,0 +1,8 @@
+#! @BASH@ -e
+if [ x@EXEEXT@ = x ] ; then 
+  wine=
+else
+  wine=wine
+fi
+    
+exec $wine ./timer_client@EXEEXT@ 
diff --git a/examples/gras/timer/test_sg.in b/examples/gras/timer/test_sg.in
new file mode 100755 (executable)
index 0000000..72a7403
--- /dev/null
@@ -0,0 +1,5 @@
+#! @BASH@
+if test -x ./timer_simulator ; then
+  exec ./timer_simulator @top_srcdir@/examples/msg/small_platform.xml @srcdir@/timer_deployment.xml
+fi
+exit 77
diff --git a/examples/gras/timer/timer.c b/examples/gras/timer/timer.c
new file mode 100644 (file)
index 0000000..45cd18b
--- /dev/null
@@ -0,0 +1,87 @@
+/* $Id$ */
+
+/* timer: repetitive and delayed actions                                    */
+
+/* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+int client(int argc,char *argv[]); /* Placed here to not bother doxygen inclusion */
+
+#include "gras.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
+
+#define REPEAT_INTERVAL 1.0
+#define DELAY_INTERVAL 2.0
+#define LOOP_COUNT 5
+
+typedef struct {
+   int still_to_do;
+} my_globals;
+
+static void repetitive_action(void) {
+   my_globals *globals=(my_globals*)gras_userdata_get();
+   
+   /* Stop if nothing to do yet */
+   if (globals->still_to_do <= 0) {
+     INFO1("[%.0f] Repetitive_action has nothing to do yet",gras_os_time());
+     return;
+   }
+   
+   if (globals->still_to_do == 1) {
+      /* Unregister myself if I'm done */
+      gras_timer_cancel_repeat(REPEAT_INTERVAL,repetitive_action);
+   }
+
+   INFO2("[%.0f] repetitive_action decrementing globals->still_to_do. New value: %d",gras_os_time(),
+        globals->still_to_do-1);
+   
+   globals->still_to_do--; /* should be the last line of the action since value=0 stops the program */
+} /* end_of_repetitive_action */
+
+static void delayed_action(void) {
+   my_globals *globals=(my_globals*)gras_userdata_get();
+   
+   INFO2("[%.0f] delayed_action setting globals->still_to_do to %d",
+        gras_os_time(),LOOP_COUNT);
+
+   globals->still_to_do = LOOP_COUNT;
+} /* end_of_delayed_action */
+
+int client(int argc,char *argv[]) {
+  xbt_error_t errcode;
+  int cpt;
+  my_globals *globals;
+
+  gras_init(&argc,argv,NULL);
+  globals=gras_userdata_new(my_globals);
+  globals->still_to_do = -1;
+
+  INFO2("[%.0f] Programming the repetitive_action with a frequency of %f sec", gras_os_time(), REPEAT_INTERVAL);
+  gras_timer_repeat(REPEAT_INTERVAL,repetitive_action);
+   
+  INFO2("[%.0f] Programming the delayed_action for after %f sec", gras_os_time(), DELAY_INTERVAL);
+  gras_timer_delay(REPEAT_INTERVAL,delayed_action);
+
+  INFO1("[%.0f] Have a rest", gras_os_time());  
+  gras_os_sleep(DELAY_INTERVAL / 2.0, 0);
+   
+  INFO1("[%.0f] Canceling the delayed_action.",gras_os_time());
+  gras_timer_cancel_delay(REPEAT_INTERVAL,delayed_action);
+
+  INFO2("[%.0f] Re-programming the delayed_action for after %f sec", gras_os_time(),DELAY_INTERVAL);
+  gras_timer_delay(REPEAT_INTERVAL,delayed_action);
+
+  while (globals->still_to_do == -1 ||  /* Before delayed action runs */
+        globals->still_to_do > 0 /* after delayed_action, and not enough repetitive_action */) {
+
+     DEBUG2("[%.0f] Prepare to handle messages for 5 sec (still_to_do=%d)",
+           gras_os_time(), globals->still_to_do);
+     gras_msg_handle(5.0);
+  }
+  gras_exit();
+  return 0;
+} /* end_of_client */
+
diff --git a/examples/gras/timer/timer_deployment.xml b/examples/gras/timer/timer_deployment.xml
new file mode 100644 (file)
index 0000000..35a1458
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version='1.0'?>
+<!DOCTYPE platform_description SYSTEM "surfxml.dtd">
+<platform_description>
+  <process host="Fafard" function="client"></process>
+</platform_description>