regression: add case 1017

Adds regression case 1017 to test coalesced memref parameters.

Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
diff --git a/host/xtest/regression_1000.c b/host/xtest/regression_1000.c
index 0fa9d66..ee0cc41 100644
--- a/host/xtest/regression_1000.c
+++ b/host/xtest/regression_1000.c
@@ -59,6 +59,7 @@
 #endif
 static void xtest_tee_test_1015(ADBG_Case_t *Case_p);
 static void xtest_tee_test_1016(ADBG_Case_t *Case_p);
+static void xtest_tee_test_1017(ADBG_Case_t *Case_p);
 
 ADBG_CASE_DEFINE(regression, 1001, xtest_tee_test_1001, "Core self tests");
 ADBG_CASE_DEFINE(regression, 1002, xtest_tee_test_1002, "PTA parameters");
@@ -88,6 +89,8 @@
 		"FS hash-tree corner cases");
 ADBG_CASE_DEFINE(regression, 1016, xtest_tee_test_1016,
 		"Test TA to TA transfers (in/out/inout memrefs on the stack)");
+ADBG_CASE_DEFINE(regression, 1017, xtest_tee_test_1017,
+		"Test coalescing memrefs");
 
 struct xtest_crypto_session {
 	ADBG_Case_t *c;
@@ -1319,3 +1322,58 @@
 
 	TEEC_CloseSession(&session);
 }
+
+static void xtest_tee_test_1017(ADBG_Case_t *c)
+{
+	TEEC_Session session = { 0 };
+	TEEC_Operation op = TEEC_OPERATION_INITIALIZER;
+	uint32_t ret_orig;
+	TEEC_SharedMemory shm;
+	size_t page_size = 4096;
+
+	memset(&shm, 0, sizeof(shm));
+	shm.size = 8 * page_size;
+	shm.flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
+	if (!ADBG_EXPECT_TEEC_SUCCESS(c,
+		TEEC_AllocateSharedMemory(&xtest_teec_ctx, &shm)))
+		return;
+
+	if (!ADBG_EXPECT_TEEC_SUCCESS(c,
+		xtest_teec_open_session(&session, &os_test_ta_uuid, NULL,
+		                        &ret_orig)))
+		goto out;
+
+	op.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT,
+					 TEEC_MEMREF_PARTIAL_INPUT,
+					 TEEC_MEMREF_PARTIAL_OUTPUT,
+					 TEEC_MEMREF_PARTIAL_OUTPUT);
+
+	/*
+	 * The first two memrefs are supposed to be combined into in
+	 * region and the last two memrefs should have one region each
+	 * when the parameters are mapped for the TA.
+	 */
+	op.params[0].memref.parent = &shm;
+	op.params[0].memref.size = page_size;
+	op.params[0].memref.offset = 0;
+
+	op.params[1].memref.parent = &shm;
+	op.params[1].memref.size = page_size;
+	op.params[1].memref.offset = page_size;
+
+	op.params[2].memref.parent = &shm;
+	op.params[2].memref.size = page_size;
+	op.params[2].memref.offset = 4 * page_size;
+
+	op.params[3].memref.parent = &shm;
+	op.params[3].memref.size = 2 * page_size;
+	op.params[3].memref.offset = 6 * page_size;
+
+	(void)ADBG_EXPECT_TEEC_SUCCESS(c,
+		TEEC_InvokeCommand(&session, TA_OS_TEST_CMD_PARAMS, &op,
+				   &ret_orig));
+
+	TEEC_CloseSession(&session);
+out:
+	TEEC_ReleaseSharedMemory(&shm);
+}