gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated (6a8c520 -> feec78d)


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (6a8c520 -> feec78d)
Date: Wed, 20 Jun 2018 22:20:54 +0200

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

marcello pushed a change to branch master
in repository exchange.

    from 6a8c520  fix leaks.
     new 61fecfc  Put lookup logic for meta-commands.
     new 1d83e01  batch CMD skeleton + include defs.
     new 3a30377  Meta-CMD-aware instruction pointer.
     new d568464  Batch CMD needs to memcpy CMDs in its internal status.
     new feec78d  Implementing #5306.

The 5 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/exchange-lib/Makefile.am                       |   4 +-
 src/exchange-lib/testing_api_cmd_batch.c           | 178 +++++++++++++++++++++
 src/exchange-lib/testing_api_cmd_deposit.c         |   3 +-
 src/exchange-lib/testing_api_loop.c                |  61 ++++++-
 ...ng_api_trait_json.c => testing_api_trait_cmd.c} |  48 +++---
 src/include/taler_testing_lib.h                    |  60 +++++++
 6 files changed, 324 insertions(+), 30 deletions(-)
 create mode 100644 src/exchange-lib/testing_api_cmd_batch.c
 copy src/exchange-lib/{testing_api_trait_json.c => testing_api_trait_cmd.c} 
(54%)

diff --git a/src/exchange-lib/Makefile.am b/src/exchange-lib/Makefile.am
index 57c9350..f2bfae4 100644
--- a/src/exchange-lib/Makefile.am
+++ b/src/exchange-lib/Makefile.am
@@ -54,6 +54,7 @@ libtalertesting_la_SOURCES = \
   testing_api_cmd_payback.c \
   testing_api_cmd_signal.c \
   testing_api_cmd_check_keys.c \
+  testing_api_cmd_batch.c \
   testing_api_helpers.c \
   testing_api_loop.c \
   testing_api_traits.c \
@@ -69,7 +70,8 @@ libtalertesting_la_SOURCES = \
   testing_api_trait_string.c \
   testing_api_trait_key_peer.c \
   testing_api_trait_wtid.c \
-  testing_api_trait_amount.c
+  testing_api_trait_amount.c \
+  testing_api_trait_cmd.c
 libtalertesting_la_LIBADD = \
   $(top_builddir)/src/wire/libtalerwire.la \
   $(top_builddir)/src/json/libtalerjson.la \
diff --git a/src/exchange-lib/testing_api_cmd_batch.c 
b/src/exchange-lib/testing_api_cmd_batch.c
new file mode 100644
index 0000000..3912762
--- /dev/null
+++ b/src/exchange-lib/testing_api_cmd_batch.c
@@ -0,0 +1,178 @@
+/*
+  This file is part of TALER
+  Copyright (C) 2014-2018 Taler Systems SA
+
+  TALER 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.
+
+  TALER 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 TALER; see the file COPYING.  If not, see
+  <http://www.gnu.org/licenses/>
+*/
+/**
+ * @file exchange/testing_api_cmd_batch.c
+ * @brief Implement batch-execution of CMDs.
+ * @author Marcello Stanisci
+ */
+#include "platform.h"
+#include "taler_json_lib.h"
+#include <gnunet/gnunet_curl_lib.h>
+#include "exchange_api_handle.h"
+#include "taler_testing_lib.h"
+
+
+/**
+ * State for a "batch" CMD.
+ */
+struct BatchState
+{
+  /* CMDs batch.  */
+  struct TALER_TESTING_Command *batch;
+
+  /* Internal comand pointer.  */
+  int batch_ip;
+};
+
+
+/**
+ * Run the command.
+ *
+ * @param cls closure.
+ * @param cmd the command being executed.
+ * @param is the interpreter state.
+ */
+static void
+batch_run (void *cls,
+           const struct TALER_TESTING_Command *cmd,
+           struct TALER_TESTING_Interpreter *is)
+{
+  struct BatchState *bs = cls;
+
+  bs->batch_ip++;
+
+  TALER_LOG_DEBUG ("Running batched command: %s\n",
+                   bs->batch[bs->batch_ip].label);
+
+  /* hit end command, leap to next top-level command.  */
+  if (NULL == bs->batch[bs->batch_ip].label)
+  {
+    TALER_LOG_INFO ("Exiting from batch: %s\n",
+                    cmd->label);
+    TALER_TESTING_interpreter_next (is);
+    return;
+  }
+
+  bs->batch[bs->batch_ip].run (bs->batch[bs->batch_ip].cls,
+                               &bs->batch[bs->batch_ip],
+                               is);
+}
+
+
+/**
+ * Cleanup the state from a "reserve status" CMD, and possibly
+ * cancel a pending operation thereof.
+ *
+ * @param cls closure.
+ * @param cmd the command which is being cleaned up.
+ */
+static void
+batch_cleanup (void *cls,
+               const struct TALER_TESTING_Command *cmd)
+{
+  struct BatchState *bs = cls;
+
+  for (unsigned int i=0;
+       NULL != bs->batch[i].label;
+       i++)
+    bs->batch[i].cleanup (bs->batch[i].cls,
+                          &bs->batch[i]);
+  GNUNET_free_non_null (bs->batch);
+}
+
+
+/**
+ * Offer internal data from a "batch" CMD, to other commands.
+ *
+ * @param cls closure.
+ * @param ret[out] result.
+ * @param trait name of the trait.
+ * @param index index number of the object to offer.
+ *
+ * @return #GNUNET_OK on success.
+ */
+static int
+batch_traits (void *cls,
+              void **ret,
+              const char *trait,
+              unsigned int index)
+{
+  #define CURRENT_CMD_INDEX 0
+  #define BATCH_INDEX 1
+
+  struct BatchState *bs = cls;
+
+  struct TALER_TESTING_Trait traits[] = {
+    TALER_TESTING_make_trait_cmd
+      (CURRENT_CMD_INDEX, &bs->batch[bs->batch_ip]),
+    TALER_TESTING_make_trait_cmd
+      (BATCH_INDEX, bs->batch),
+    TALER_TESTING_trait_end ()
+  };
+
+  /* Always return current command.  */
+  return TALER_TESTING_get_trait (traits,
+                                  ret,
+                                  trait,
+                                  index);
+}
+
+/**
+ * Create a "batch" command.  Such command takes a
+ * end_CMD-terminated array of CMDs and executed them.
+ * Once it hits the end CMD, it passes the control
+ * to the next top-level CMD, regardless of it being
+ * another batch or ordinary CMD.
+ *
+ * @param label the command label.
+ * @param batch array of CMDs to execute.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_batch (const char *label,
+                         struct TALER_TESTING_Command *batch)
+{
+  struct TALER_TESTING_Command cmd;
+  struct BatchState *bs;
+  unsigned int i;
+
+  cmd.meta = GNUNET_YES;
+  bs = GNUNET_new (struct BatchState);
+  bs->batch_ip = -1;
+
+  /* Get number of commands.  */
+  for (i=0;NULL != batch[i].label;i++)
+    /* noop */
+    ;
+
+  bs->batch = GNUNET_new_array (i + 1,
+                                struct TALER_TESTING_Command);
+  memcpy (bs->batch,
+          batch,
+          sizeof (struct TALER_TESTING_Command) * i);
+
+  cmd.cls = bs;
+  cmd.label = label;
+  cmd.run = &batch_run;
+  cmd.cleanup = &batch_cleanup;
+  cmd.traits = &batch_traits;
+
+  return cmd;
+}
diff --git a/src/exchange-lib/testing_api_cmd_deposit.c 
b/src/exchange-lib/testing_api_cmd_deposit.c
index 9756d0b..e8bcf02 100644
--- a/src/exchange-lib/testing_api_cmd_deposit.c
+++ b/src/exchange-lib/testing_api_cmd_deposit.c
@@ -370,7 +370,8 @@ deposit_traits (void *cls,
   struct TALER_TESTING_Trait traits[] = {
     TALER_TESTING_make_trait_coin_priv (0, coin_spent_priv),
     TALER_TESTING_make_trait_wire_details (0, ds->wire_details),
-    TALER_TESTING_make_trait_contract_terms (0, ds->contract_terms),
+    TALER_TESTING_make_trait_contract_terms
+      (0, ds->contract_terms),
     TALER_TESTING_make_trait_peer_key
       (0, &ds->merchant_priv.eddsa_priv),
     TALER_TESTING_trait_end ()
diff --git a/src/exchange-lib/testing_api_loop.c 
b/src/exchange-lib/testing_api_loop.c
index 7efadb3..ac68859 100644
--- a/src/exchange-lib/testing_api_loop.c
+++ b/src/exchange-lib/testing_api_loop.c
@@ -57,11 +57,37 @@ TALER_TESTING_interpreter_lookup_command
                 "Attempt to lookup command for empty label\n");
     return NULL;
   }
-  for (unsigned int i=0;NULL != (cmd = &is->commands[i])->label;i++)
+  for (unsigned int i=0;
+       NULL != (cmd = &is->commands[i])->label;
+       i++)
+  {
+    /* Give precedence to top-level commands.  */
     if ( (NULL != cmd->label) &&
          (0 == strcmp (cmd->label,
                        label)) )
       return cmd;
+
+    if (GNUNET_YES == cmd->meta)
+    {
+      #define BATCH_INDEX 1
+      struct TALER_TESTING_Command *batch;
+
+      /* NEED BATCH HERE FROM TRAIT.  */
+      GNUNET_assert
+        (GNUNET_OK == TALER_TESTING_get_trait_cmd
+          (cmd, BATCH_INDEX, &batch));
+
+      for (unsigned int i=0;
+           NULL != (cmd = &batch[i])->label;
+           i++) 
+      {
+        if ( (NULL != cmd->label) &&
+            (0 == strcmp (cmd->label,
+                          label)) )
+          return cmd;
+      }
+    }
+  }
   GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
               "Command not found: %s\n",
               label);
@@ -142,12 +168,28 @@ interpreter_run (void *cls);
  * Current command is done, run the next one.
  */
 void
-TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *i)
+TALER_TESTING_interpreter_next (struct TALER_TESTING_Interpreter *is)
 {
-  if (GNUNET_SYSERR == i->result)
+  struct TALER_TESTING_Command *cmd = &is->commands[is->ip];
+
+  if (GNUNET_SYSERR == is->result)
     return; /* ignore, we already failed! */
-  i->ip++;
-  i->task = GNUNET_SCHEDULER_add_now (&interpreter_run, i);
+
+  if (GNUNET_YES == cmd->meta)
+  {
+    #define CURRENT_BATCH_SUBCMD_INDEX 0
+    struct TALER_TESTING_Command *sub_cmd;
+
+    GNUNET_assert (GNUNET_OK == TALER_TESTING_get_trait_cmd
+      (cmd, CURRENT_BATCH_SUBCMD_INDEX, &sub_cmd));
+      
+      if (NULL == sub_cmd->label)
+        is->ip++;
+  }
+  else
+    is->ip++;
+
+  is->task = GNUNET_SCHEDULER_add_now (&interpreter_run, is);
 }
 
 
@@ -312,6 +354,15 @@ maint_child_death (void *cls)
   struct GNUNET_OS_Process **processp;
   char c[16];
 
+  if (GNUNET_YES == cmd->meta)
+  {
+    struct TALER_TESTING_Command *batch_cmd;
+    GNUNET_assert
+      (GNUNET_OK == TALER_TESTING_get_trait_cmd
+        (cmd, 0, &batch_cmd)); /* bad? */
+    cmd = batch_cmd;
+  }
+
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Got SIGCHLD for `%s'.\n",
               cmd->label);
diff --git a/src/exchange-lib/testing_api_trait_json.c 
b/src/exchange-lib/testing_api_trait_cmd.c
similarity index 54%
copy from src/exchange-lib/testing_api_trait_json.c
copy to src/exchange-lib/testing_api_trait_cmd.c
index 675be6c..9f7c8d5 100644
--- a/src/exchange-lib/testing_api_trait_json.c
+++ b/src/exchange-lib/testing_api_trait_cmd.c
@@ -18,8 +18,8 @@
 */
 
 /**
- * @file exchange-lib/testing_api_trait_json.c
- * @brief offers JSON traits.
+ * @file exchange-lib/testing_api_trait_cmd.c
+ * @brief offers CMDs as traits.
  * @author Marcello Stanisci
  */
 #include "platform.h"
@@ -29,52 +29,54 @@
 #include "taler_signatures.h"
 #include "taler_testing_lib.h"
 
-#define TALER_TESTING_TRAIT_WIRE_DETAILS "wire-details"
+#define TALER_TESTING_TRAIT_CMD "cmd"
 
 /**
- * Obtain wire details from @a cmd.
+ * Obtain a command from @a cmd.
  *
- * @param cmd command to extract the wire details from.
- * @param index index number associate with the wire details
- *        on offer; usually zero, as one command sticks to
- *        one bank account.
- * @param wire_details[out] where to write the wire details.
+ * @param cmd command to extract the command from.
+ * @param index always zero.  Commands offering this
+ *        kind of traits do not need this index.  For
+ *        example, a "meta" CMD returns always the
+ *        CMD currently being executed.
+ * @param cmd_[out] where to write the wire details.
  *
  * @return #GNUNET_OK on success.
  */
 int
-TALER_TESTING_get_trait_wire_details
+TALER_TESTING_get_trait_cmd
   (const struct TALER_TESTING_Command *cmd,
    unsigned int index,
-   const json_t **wire_details)
+   struct TALER_TESTING_Command **_cmd)
 {
   return cmd->traits (cmd->cls,
-                      (void **) wire_details,
-                      TALER_TESTING_TRAIT_WIRE_DETAILS,
+                      (void **) _cmd,
+                      TALER_TESTING_TRAIT_CMD,
                       index);
 }
 
 /**
- * Offer wire details in a trait.
+ * Offer a command in a trait.
  *
- * @param index index number associate with the wire details
- *        on offer; usually zero, as one command sticks to
- *        one bank account.
- * @param wire_details wire details to offer.
+ * @param index always zero.  Commands offering this
+ *        kind of traits do not need this index.  For
+ *        example, a "meta" CMD returns always the
+ *        CMD currently being executed.
+ * @param cmd wire details to offer.
  *
  * @return the trait.
  */
 struct TALER_TESTING_Trait
-TALER_TESTING_make_trait_wire_details
+TALER_TESTING_make_trait_cmd
   (unsigned int index,
-   const json_t *wire_details)
+   const struct TALER_TESTING_Command *cmd)
 {
   struct TALER_TESTING_Trait ret = {
     .index = index,
-    .trait_name = TALER_TESTING_TRAIT_WIRE_DETAILS,
-    .ptr = (const json_t *) wire_details
+    .trait_name = TALER_TESTING_TRAIT_CMD,
+    .ptr = (const struct TALER_TESTING_Command *) cmd
   };
   return ret;
 }
 
-/* end of testing_api_trait_json.c */
+/* end of testing_api_trait_cmd.c */
diff --git a/src/include/taler_testing_lib.h b/src/include/taler_testing_lib.h
index 428bcb7..b63bd8c 100644
--- a/src/include/taler_testing_lib.h
+++ b/src/include/taler_testing_lib.h
@@ -300,6 +300,15 @@ struct TALER_TESTING_Command
             const char *trait,
             unsigned int index);
 
+
+  /**
+   * Has GNUNET_YES if the command is a "meta" one.  Meta
+   * commands are those that takes arrays of commands and
+   * execute them.  Are used to group testing commands in
+   * order to improve readability of test cases.
+   */
+  unsigned int meta;
+
 };
 
 /**
@@ -1106,6 +1115,23 @@ TALER_TESTING_cmd_check_keys
    unsigned int num_denom_keys,
    struct TALER_EXCHANGE_Handle *exchange);
 
+/**
+ * Create a "batch" command.  Such command takes a
+ * end_CMD-terminated array of CMDs and executed them.
+ * Once it hits the end CMD, it passes the control
+ * to the next top-level CMD, regardless of it being
+ * another batch or ordinary CMD.
+ *
+ * @param label the command label.
+ * @param batch array of CMDs to execute.
+ *
+ * @return the command.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_batch (const char *label,
+                         struct TALER_TESTING_Command *batch);
+
+
 /* *** Generic trait logic for implementing traits ********* */
 
 /**
@@ -1797,4 +1823,38 @@ TALER_TESTING_get_trait_rejected
    unsigned int index,
    const char **rejected_reference);
 
+
+/**
+ * Offer a command in a trait.
+ *
+ * @param index always zero.  Commands offering this
+ *        kind of traits do not need this index.  For
+ *        example, a "meta" CMD returns always the
+ *        CMD currently being executed.
+ * @param cmd wire details to offer.
+ *
+ * @return the trait.
+ */
+struct TALER_TESTING_Trait
+TALER_TESTING_make_trait_cmd
+  (unsigned int index,
+   const struct TALER_TESTING_Command *cmd);
+
+/**
+ * Obtain a command from @a cmd.
+ *
+ * @param cmd command to extract the command from.
+ * @param index always zero.  Commands offering this
+ *        kind of traits do not need this index.  For
+ *        example, a "meta" CMD returns always the
+ *        CMD currently being executed.
+ * @param cmd_[out] where to write the wire details.
+ *
+ * @return #GNUNET_OK on success.
+ */
+int
+TALER_TESTING_get_trait_cmd
+  (const struct TALER_TESTING_Command *cmd,
+   unsigned int index,
+   struct TALER_TESTING_Command **_cmd);
 #endif

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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