Tests should release the RX buffer when they are done.

Add a TEAR_DOWN to all test suites which use the RX buffer to check
that it has been released by the time each test finishes.

Bug: 146208457
Change-Id: Ic3b14fe7acee4ceaeef948dade39d87f6b2e0861
diff --git a/test/vmapi/arch/aarch64/gicv3/timer_secondary.c b/test/vmapi/arch/aarch64/gicv3/timer_secondary.c
index 0637dce..1e5c107 100644
--- a/test/vmapi/arch/aarch64/gicv3/timer_secondary.c
+++ b/test/vmapi/arch/aarch64/gicv3/timer_secondary.c
@@ -23,6 +23,7 @@
 
 #include "gicv3.h"
 #include "test/hftest.h"
+#include "test/vmapi/spci.h"
 
 SET_UP(timer_secondary)
 {
@@ -38,6 +39,11 @@
 	arch_irq_enable();
 }
 
+TEAR_DOWN(timer_secondary)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 static void timer_busywait_secondary()
 {
 	const char message[] = "loop 0099999";
diff --git a/test/vmapi/primary_with_secondaries/interrupts.c b/test/vmapi/primary_with_secondaries/interrupts.c
index 5aaf830..dce89ab 100644
--- a/test/vmapi/primary_with_secondaries/interrupts.c
+++ b/test/vmapi/primary_with_secondaries/interrupts.c
@@ -24,6 +24,11 @@
 #include "test/hftest.h"
 #include "test/vmapi/spci.h"
 
+TEAR_DOWN(interrupts)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 /**
  * Send a message to the interruptible VM, which will interrupt itself to send a
  * response back.
diff --git a/test/vmapi/primary_with_secondaries/mailbox.c b/test/vmapi/primary_with_secondaries/mailbox.c
index 8e2e67c..b96c595 100644
--- a/test/vmapi/primary_with_secondaries/mailbox.c
+++ b/test/vmapi/primary_with_secondaries/mailbox.c
@@ -63,6 +63,11 @@
 	}
 }
 
+TEAR_DOWN(mailbox)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 /**
  * Clearing an empty mailbox is an error.
  */
@@ -307,6 +312,7 @@
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
 	EXPECT_EQ(spci_msg_send_size(run_res), sizeof(message));
 	EXPECT_EQ(memcmp(mb.recv, message, sizeof(message)), 0);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 }
 
 /**
@@ -341,6 +347,7 @@
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
 	EXPECT_EQ(spci_msg_send_size(run_res), sizeof(message));
 	EXPECT_EQ(memcmp(mb.recv, message, sizeof(message)), 0);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Run VM again so that it clears its mailbox. */
 	run_res = spci_run(SERVICE_VM1, 0);
diff --git a/test/vmapi/primary_with_secondaries/memory_sharing.c b/test/vmapi/primary_with_secondaries/memory_sharing.c
index 44b5c92..08a8f25 100644
--- a/test/vmapi/primary_with_secondaries/memory_sharing.c
+++ b/test/vmapi/primary_with_secondaries/memory_sharing.c
@@ -186,6 +186,11 @@
 	}
 }
 
+TEAR_DOWN(memory_sharing)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 /**
  * Sharing memory concurrently gives both VMs access to the memory so it can be
  * used for communication.
@@ -498,6 +503,7 @@
 	/* Observe the service doesn't fault when accessing the memory. */
 	run_res = spci_run(SERVICE_VM1, 0);
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 }
 
 /**
@@ -896,6 +902,7 @@
 	/* Let the memory be sent from VM1 to PRIMARY (returned). */
 	run_res = spci_run(SERVICE_VM1, 0);
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Check we have access again. */
 	ptr[0] = 'f';
@@ -1042,6 +1049,7 @@
 	/* Receive and return memory from VM1. */
 	run_res = spci_run(SERVICE_VM1, 0);
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Use VM1 to fail to donate memory from the primary to VM2. */
 	run_res = spci_run(SERVICE_VM1, 0);
@@ -1136,6 +1144,7 @@
 	/* Receive and return memory from VM1. */
 	run_res = spci_run(SERVICE_VM1, 0);
 	EXPECT_EQ(run_res.func, SPCI_MSG_SEND_32);
+	EXPECT_EQ(spci_rx_release().func, SPCI_SUCCESS_32);
 
 	/* Try to lend memory from primary in VM1. */
 	run_res = spci_run(SERVICE_VM1, 0);
diff --git a/test/vmapi/primary_with_secondaries/run_race.c b/test/vmapi/primary_with_secondaries/run_race.c
index 6f7c459..c31fa3c 100644
--- a/test/vmapi/primary_with_secondaries/run_race.c
+++ b/test/vmapi/primary_with_secondaries/run_race.c
@@ -73,6 +73,11 @@
 	run_loop((struct mailbox_buffers *)arg);
 }
 
+TEAR_DOWN(vcpu_state)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 /**
  * This test tries to run the same secondary vCPU from two different physical
  * CPUs concurrently. The vCPU checks that the state is ok while it bounces
diff --git a/test/vmapi/primary_with_secondaries/smp.c b/test/vmapi/primary_with_secondaries/smp.c
index ea1fc00..d76b5f0 100644
--- a/test/vmapi/primary_with_secondaries/smp.c
+++ b/test/vmapi/primary_with_secondaries/smp.c
@@ -24,6 +24,11 @@
 #include "test/hftest.h"
 #include "test/vmapi/spci.h"
 
+TEAR_DOWN(smp)
+{
+	EXPECT_SPCI_ERROR(spci_rx_release(), SPCI_DENIED);
+}
+
 /**
  * Run a service that starts a second vCPU, and check that both the first and
  * second vCPU send messages to us.