gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated (674607475 -> ec694204b)


From: gnunet
Subject: [gnunet] branch master updated (674607475 -> ec694204b)
Date: Sun, 19 May 2024 21:01:18 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository gnunet.

    from 674607475 fix barrier finishing
     new df0829d38 -fix looping
     new ec694204b fix jumps

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/gnunet_testing_lib.h         |  10 ++-
 src/lib/testing/Makefile.am              |   1 +
 src/lib/testing/test_testing_api.c       |  46 ++++++++++++
 src/lib/testing/testing_api_cmd_exec.c   |  38 ++++++++--
 src/lib/testing/testing_api_cmd_signal.c | 120 +++++++++++++++++++++++++++++++
 src/lib/testing/testing_api_cmd_stat.c   |  10 +--
 src/lib/testing/testing_api_loop.c       |  63 ++++++++++------
 7 files changed, 251 insertions(+), 37 deletions(-)
 create mode 100644 src/lib/testing/testing_api_cmd_signal.c

diff --git a/src/include/gnunet_testing_lib.h b/src/include/gnunet_testing_lib.h
index 72359e962..815ac14cf 100644
--- a/src/include/gnunet_testing_lib.h
+++ b/src/include/gnunet_testing_lib.h
@@ -692,11 +692,15 @@ GNUNET_TESTING_cmd_exec_va (
 
 /**
  * Make the instruction pointer point to @a target_label
- * only if @a counter is greater than zero.
+ * only if @a counter is greater than zero.  Note that
+ * the command that will be executed next in this case
+ * is the one AFTER @a target_label, as the command we
+ * jump to is skipped by the advancing IP after the
+ * rewind.
  *
  * @param label command label
  * @param target_label label of the new instruction pointer's destination 
after the jump;
- *                     must be before the current instruction
+ *                     must be before the current instruction (and the command 
at the @a target_label itself will not be run, but the one afterwards)
  * @param counter counts how many times the rewinding is to happen.
  */
 struct GNUNET_TESTING_Command
@@ -948,7 +952,7 @@ GNUNET_TESTING_get_trait (
  * @param op operation to perform
  * @param prefix prefix to pass to @e op
  */
-#define GNUNET_TESTING_SIMPLE_TRAITS(op,prefix)             \
+#define GNUNET_TESTING_SIMPLE_TRAITS(op,prefix)                  \
         op (prefix, process, struct GNUNET_OS_Process *)         \
         op (prefix, cmd, const struct GNUNET_TESTING_Command)    \
         op (prefix, batch_cmds, struct GNUNET_TESTING_Command *)
diff --git a/src/lib/testing/Makefile.am b/src/lib/testing/Makefile.am
index f47ecd17a..7acdf709d 100644
--- a/src/lib/testing/Makefile.am
+++ b/src/lib/testing/Makefile.am
@@ -33,6 +33,7 @@ libgnunettesting_la_SOURCES = \
   testing_api_cmd_get_topo.c \
   testing_api_cmd_netjail_start.c \
   testing_api_cmd_netjail_start_cmds_helper.c \
+  testing_api_cmd_signal.c \
   testing_api_cmd_stat.c \
   testing_api_cmds.c \
   testing_api_loop.c testing_api_loop.h \
diff --git a/src/lib/testing/test_testing_api.c 
b/src/lib/testing/test_testing_api.c
index edc09231c..edf8187ec 100644
--- a/src/lib/testing/test_testing_api.c
+++ b/src/lib/testing/test_testing_api.c
@@ -35,11 +35,28 @@ main (int argc,
     { .prefix = NULL }
   };
   struct GNUNET_TESTING_Command batch[] = {
+    GNUNET_TESTING_cmd_exec_va ("batch-echo-once",
+                                GNUNET_OS_PROCESS_EXITED,
+                                0,
+                                "echo",
+                                "-n",
+                                "LI",
+                                NULL),
+    GNUNET_TESTING_cmd_exec_va ("batch-echo",
+                                GNUNET_OS_PROCESS_EXITED,
+                                0,
+                                "echo",
+                                "-n",
+                                "LA",
+                                NULL),
     GNUNET_TESTING_cmd_end ()
   };
   struct GNUNET_TESTING_Command commands[] = {
     GNUNET_TESTING_cmd_batch ("batch",
                               batch),
+    GNUNET_TESTING_cmd_rewind_ip ("rewind",
+                                  "batch-echo-once",
+                                  2),
     GNUNET_TESTING_cmd_barrier_create ("barrier",
                                        1),
     GNUNET_TESTING_cmd_barrier_reached ("barrier-reached",
@@ -62,6 +79,35 @@ main (int argc,
                                GNUNET_TIME_UNIT_SECONDS),
     GNUNET_TESTING_cmd_stat ("stat",
                              timers),
+    GNUNET_TESTING_cmd_exec_va ("sleep",
+                                GNUNET_OS_PROCESS_EXITED,
+                                0,
+                                "sleep",
+                                "0.01",
+                                NULL),
+    GNUNET_TESTING_cmd_make_unblocking (
+      GNUNET_TESTING_cmd_exec_va ("sleep",
+                                  GNUNET_OS_PROCESS_SIGNALED,
+                                  SIGKILL,
+                                  "sleep",
+                                  "5",
+                                  NULL)),
+    GNUNET_TESTING_cmd_signal ("kill-sleep",
+                               "sleep",
+                               SIGKILL),
+    GNUNET_TESTING_cmd_finish ("wait-sleep",
+                               "sleep",
+                               GNUNET_TIME_UNIT_SECONDS),
+    GNUNET_TESTING_cmd_exec_va ("echo",
+                                GNUNET_OS_PROCESS_EXITED,
+                                0,
+                                "echo",
+                                "-n",
+                                "LA",
+                                NULL),
+    GNUNET_TESTING_cmd_rewind_ip ("rewind",
+                                  "wait-sleep",
+                                  4),
     GNUNET_TESTING_cmd_end ()
   };
 
diff --git a/src/lib/testing/testing_api_cmd_exec.c 
b/src/lib/testing/testing_api_cmd_exec.c
index 9e03e7c17..3a931e220 100644
--- a/src/lib/testing/testing_api_cmd_exec.c
+++ b/src/lib/testing/testing_api_cmd_exec.c
@@ -115,20 +115,21 @@ child_completed_callback (void *cls,
 {
   struct BashScriptState *bss = cls;
 
+  bss->cwh = NULL;
   GNUNET_OS_process_destroy (bss->start_proc);
   bss->start_proc = NULL;
-  bss->cwh = NULL;
   if ( (bss->expected_type != type) ||
        (bss->expected_exit_code != exit_code) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Child failed with error %lu!\n",
-                exit_code);
+                "Child failed with error %lu (wanted %lu) %d/%d!\n",
+                exit_code,
+                bss->expected_exit_code,
+                type,
+                bss->expected_type);
     GNUNET_TESTING_async_fail (&bss->ac);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Child succeeded!\n");
   GNUNET_TESTING_async_finish (&bss->ac);
 }
 
@@ -144,6 +145,7 @@ exec_bash_script_run (void *cls,
 {
   struct BashScriptState *bss = cls;
 
+  GNUNET_assert (NULL == bss->cwh);
   bss->start_proc
     = GNUNET_OS_start_process_vap (
         GNUNET_OS_INHERIT_STD_ERR,
@@ -159,6 +161,28 @@ exec_bash_script_run (void *cls,
 }
 
 
+/**
+ * This function prepares an array with traits.
+ */
+static enum GNUNET_GenericReturnValue
+traits (void *cls,
+        const void **ret,
+        const char *trait,
+        unsigned int index)
+{
+  struct BashScriptState *bss = cls;
+  struct GNUNET_TESTING_Trait traits[] = {
+    GNUNET_TESTING_make_trait_process (&bss->start_proc),
+    GNUNET_TESTING_trait_end ()
+  };
+
+  return GNUNET_TESTING_get_trait (traits,
+                                   ret,
+                                   trait,
+                                   index);
+}
+
+
 const struct GNUNET_TESTING_Command
 GNUNET_TESTING_cmd_exec (
   const char *label,
@@ -184,7 +208,7 @@ GNUNET_TESTING_cmd_exec (
     label,
     &exec_bash_script_run,
     &exec_bash_script_cleanup,
-    NULL,
+    &traits,
     &bss->ac);
 }
 
@@ -225,6 +249,6 @@ GNUNET_TESTING_cmd_exec_va (
     label,
     &exec_bash_script_run,
     &exec_bash_script_cleanup,
-    NULL,
+    &traits,
     &bss->ac);
 }
diff --git a/src/lib/testing/testing_api_cmd_signal.c 
b/src/lib/testing/testing_api_cmd_signal.c
new file mode 100644
index 000000000..adbcda946
--- /dev/null
+++ b/src/lib/testing/testing_api_cmd_signal.c
@@ -0,0 +1,120 @@
+/*
+  This file is part of GNUNET
+  (C) 2018 GNUnet e.V.
+
+  GNUNET is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as
+  published by the Free Software Foundation; either version 3, or
+  (at your option) any later version.
+
+  GNUNET is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public
+  License along with GNUNET; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file testing/testing_api_cmd_signal.c
+ * @brief command(s) to send signals to processes.
+ * @author Marcello Stanisci
+ */
+#include "platform.h"
+#include "gnunet_testing_lib.h"
+
+
+/**
+ * State for a "signal" CMD.
+ */
+struct SignalState
+{
+  /**
+   * Label of the process to send the signal to.
+   */
+  const char *process_label;
+
+  /**
+   * The signal to send to the process.
+   */
+  int signal;
+};
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command to execute.
+ * @param is the interpreter state.
+ */
+static void
+signal_run (void *cls,
+            struct GNUNET_TESTING_Interpreter *is)
+{
+  struct SignalState *ss = cls;
+  const struct GNUNET_TESTING_Command *pcmd;
+  struct GNUNET_OS_Process **process;
+
+  pcmd
+    = GNUNET_TESTING_interpreter_lookup_command (is,
+                                                 ss->process_label);
+  if (NULL == pcmd)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                "Did not find command `%s'\n",
+                ss->process_label);
+    GNUNET_TESTING_FAIL (is);
+  }
+  if (GNUNET_OK !=
+      GNUNET_TESTING_get_trait_process (pcmd,
+                                        &process))
+    GNUNET_TESTING_FAIL (is);
+  GNUNET_break (0 ==
+                GNUNET_OS_process_kill (*process,
+                                        ss->signal));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Signaling '%d'..\n",
+              ss->signal);
+}
+
+
+/**
+ * Cleanup the state from a "signal" CMD.
+ *
+ * @param cls closure.
+ */
+static void
+signal_cleanup (void *cls)
+{
+  struct SignalState *ss = cls;
+
+  GNUNET_free (ss);
+}
+
+
+/**
+ * Create a "signal" CMD.
+ *
+ * @param label command label.
+ * @param process handle to the process to signal.
+ * @param signal signal to send.
+ * @return the command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_signal (
+  const char *label,
+  const char *process_label,
+  int signal)
+{
+  struct SignalState *ss;
+
+  ss = GNUNET_new (struct SignalState);
+  ss->process_label = process_label;
+  ss->signal = signal;
+  return GNUNET_TESTING_command_new (ss,
+                                     label,
+                                     &signal_run,
+                                     &signal_cleanup,
+                                     NULL);
+}
diff --git a/src/lib/testing/testing_api_cmd_stat.c 
b/src/lib/testing/testing_api_cmd_stat.c
index d429dda43..f751a01d0 100644
--- a/src/lib/testing/testing_api_cmd_stat.c
+++ b/src/lib/testing/testing_api_cmd_stat.c
@@ -115,10 +115,10 @@ do_stat (void *cls,
       return;
     }
     for (unsigned int j = 0;
-         NULL != bcmd[j]->run;
+         NULL != (*bcmd)[j].run;
          j++)
       do_stat (timings,
-               bcmd[j]);
+               &(*bcmd)[j]);
     return;
   }
   stat_cmd (timings,
@@ -140,9 +140,9 @@ stat_run (void *cls,
   struct GNUNET_TESTING_Timer *timings = cls;
 
   GNUNET_TESTING_interpreter_commands_iterate (is,
-                          true,
-                          &do_stat,
-                          timings);
+                                               true,
+                                               &do_stat,
+                                               timings);
 }
 
 
diff --git a/src/lib/testing/testing_api_loop.c 
b/src/lib/testing/testing_api_loop.c
index 220f4a38e..7317dc115 100644
--- a/src/lib/testing/testing_api_loop.c
+++ b/src/lib/testing/testing_api_loop.c
@@ -411,6 +411,7 @@ GNUNET_TESTING_interpreter_run_cmd_ (
   {
     cmd->ac->is = is;
     cmd->ac->finished = GNUNET_NO;
+    cmd->ac->next_called = false;
   }
   cmd->run (cmd->cls,
             is);
@@ -839,8 +840,8 @@ seek_batch (struct GNUNET_TESTING_Interpreter *is,
   unsigned int new_ip;
   struct GNUNET_TESTING_Command **batch;
   const struct GNUNET_TESTING_Command *current;
-  struct GNUNET_TESTING_Command *icmd;
-  struct GNUNET_TESTING_Command *match;
+  const struct GNUNET_TESTING_Command *icmd;
+  bool found = false;
 
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_TESTING_get_trait_cmd (cmd,
@@ -848,32 +849,34 @@ seek_batch (struct GNUNET_TESTING_Interpreter *is,
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_TESTING_get_trait_batch_cmds (cmd,
                                                       &batch));
-  match = NULL;
   for (new_ip = 0;
-       NULL != (icmd = batch[new_ip]);
+       NULL != (icmd = &((*batch)[new_ip]))->run;
        new_ip++)
   {
     if (current == target)
       current = NULL;
     if (icmd == target)
     {
-      match = icmd;
+      found = true;
       break;
     }
     if (GNUNET_TESTING_cmd_is_batch_ (icmd))
     {
-      int ret = seek_batch (is,
-                            icmd,
-                            target);
+      enum GNUNET_GenericReturnValue ret
+        = seek_batch (is,
+                      icmd,
+                      target);
       if (GNUNET_SYSERR == ret)
         return GNUNET_SYSERR; /* failure! */
       if (GNUNET_OK == ret)
       {
-        match = icmd;
+        found = true;
         break;
       }
     }
   }
+  if (! found)
+    return GNUNET_NO; /* not found */
   if (NULL == current)
   {
     /* refuse to jump forward */
@@ -881,8 +884,6 @@ seek_batch (struct GNUNET_TESTING_Interpreter *is,
     GNUNET_TESTING_interpreter_fail (is);
     return GNUNET_SYSERR;
   }
-  if (NULL == match)
-    return GNUNET_NO; /* not found */
   GNUNET_TESTING_cmd_batch_set_current_ (cmd,
                                          new_ip);
   return GNUNET_OK;
@@ -902,7 +903,9 @@ rewind_ip_run (void *cls,
 {
   struct RewindIpState *ris = cls;
   const struct GNUNET_TESTING_Command *target;
+  const struct GNUNET_TESTING_Command *icmd;
   unsigned int new_ip;
+  bool found = false;
 
   if (0 == ris->counter)
     return;
@@ -917,25 +920,41 @@ rewind_ip_run (void *cls,
   }
   ris->counter--;
   for (new_ip = 0;
-       NULL != is->commands[new_ip].run;
+       NULL != (icmd = &is->commands[new_ip])->run;
        new_ip++)
   {
-    const struct GNUNET_TESTING_Command *cmd
-      = &is->commands[new_ip];
-
-    if (cmd == target)
+    if (icmd == target)
+    {
+      found = true;
       break;
-    if (GNUNET_TESTING_cmd_is_batch_ (cmd))
+    }
+    if (GNUNET_TESTING_cmd_is_batch_ (icmd))
     {
-      int ret = seek_batch (is,
-                            cmd,
-                            target);
+      enum GNUNET_GenericReturnValue ret
+        = seek_batch (is,
+                      icmd,
+                      target);
       if (GNUNET_SYSERR == ret)
-        return;   /* failure! */
+      {
+        /* failure! */
+        GNUNET_break (0);
+        GNUNET_TESTING_interpreter_fail (is);
+        return;
+      }
       if (GNUNET_OK == ret)
+      {
+        /* counter subtraction below for batch */
+        found = true;
         break;
+      }
     }
   }
+  if (! found)
+  {
+    GNUNET_break (0);
+    GNUNET_TESTING_interpreter_fail (is);
+    return;
+  }
   if (new_ip > (unsigned int) is->ip)
   {
     /* refuse to jump forward */
@@ -943,7 +962,7 @@ rewind_ip_run (void *cls,
     GNUNET_TESTING_interpreter_fail (is);
     return;
   }
-  is->ip = new_ip - 1; /* -1 because the next function will advance by one */
+  is->ip = new_ip;
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]