Have psa_sim_serialise.pl generate psa_sim_serialize_reset()

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
diff --git a/tests/psa-client-server/psasim/src/psa_sim_serialise.c b/tests/psa-client-server/psasim/src/psa_sim_serialise.c
index e326637..f51133c 100644
--- a/tests/psa-client-server/psasim/src/psa_sim_serialise.c
+++ b/tests/psa-client-server/psasim/src/psa_sim_serialise.c
@@ -711,4 +711,6 @@
 {
     memset(hash_operation_handles, 0, sizeof(hash_operation_handles));
     memset(hash_operations, 0, sizeof(hash_operations));
+    memset(aead_operation_handles, 0, sizeof(aead_operation_handles));
+    memset(aead_operations, 0, sizeof(aead_operations));
 }
diff --git a/tests/psa-client-server/psasim/src/psa_sim_serialise.h b/tests/psa-client-server/psasim/src/psa_sim_serialise.h
index 7217595..537730c 100644
--- a/tests/psa-client-server/psasim/src/psa_sim_serialise.h
+++ b/tests/psa-client-server/psasim/src/psa_sim_serialise.h
@@ -54,6 +54,10 @@
  * don't contain pointers.
  */
 
+/** Reset all operation slots.
+ *
+ * Should be called when all clients have disconnected.
+ */
 void psa_sim_serialize_reset(void);
 
 /** Return how much buffer space is needed by \c psasim_serialise_begin().
diff --git a/tests/psa-client-server/psasim/src/psa_sim_serialise.pl b/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
index e09bb81..bbd946f 100755
--- a/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
+++ b/tests/psa-client-server/psasim/src/psa_sim_serialise.pl
@@ -105,6 +105,7 @@
         }
     }
 
+    print define_server_serialize_reset(@types);
 } else {
     die("internal error - shouldn't happen");
 }
@@ -329,6 +330,12 @@
  * don't contain pointers.
  */
 
+/** Reset all operation slots.
+ *
+ * Should be called when all clients have disconnected.
+ */
+void psa_sim_serialize_reset(void);
+
 /** Return how much buffer space is needed by \c psasim_serialise_begin().
  *
  * \return                   The number of bytes needed in the buffer for
@@ -907,6 +914,33 @@
 EOF
 }
 
+# Return the code for psa_sim_serialize_reset()
+sub define_server_serialize_reset
+{
+    my @types = @_;
+
+    my $code = <<EOF;
+
+void psa_sim_serialize_reset(void)
+{
+EOF
+
+    for my $type (@types) {
+        next unless $type =~ /^psa_(\w+_operation)_t$/;
+
+        my $what = $1;  # e.g. "hash_operation"
+
+        $code .= <<EOF;
+    memset(${what}_handles, 0, sizeof(${what}_handles));
+    memset(${what}s, 0, sizeof(${what}s));
+EOF
+    }
+
+    $code .= <<EOF;
+}
+EOF
+}
+
 # Horrible way to align first, second and third lines of function signature to
 # appease uncrustify (these are the 2nd-4th lines of code, indices 1, 2 and 3)
 #