diff mbox series

[v4,15/19] test: tee: test TEE uclass

Message ID 20180925144023.24555-16-jens.wiklander@linaro.org
State New
Headers show
Series AVB using OP-TEE | expand

Commit Message

Jens Wiklander Sept. 25, 2018, 2:40 p.m. UTC
Tests the TEE uclass with a sandbox tee driver.

Reviewed-by: Simon Glass <sjg@chromium.org>

Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>

---
 test/dm/Makefile |  1 +
 test/dm/tee.c    | 98 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 test/dm/tee.c

-- 
2.17.1

Comments

Tom Rini Oct. 8, 2018, 1:41 a.m. UTC | #1
On Tue, Sep 25, 2018 at 04:40:19PM +0200, Jens Wiklander wrote:

> Tests the TEE uclass with a sandbox tee driver.

> 

> Reviewed-by: Simon Glass <sjg@chromium.org>

> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>


Applied to u-boot/master, thanks!

-- 
Tom
diff mbox series

Patch

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 67c1fe6d0142..b1eedf4a6ee2 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -46,4 +46,5 @@  obj-$(CONFIG_SPMI) += spmi.o
 obj-$(CONFIG_WDT) += wdt.o
 obj-$(CONFIG_AXI) += axi.o
 obj-$(CONFIG_MISC) += misc.o
+obj-$(CONFIG_TEE) += tee.o
 endif
diff --git a/test/dm/tee.c b/test/dm/tee.c
new file mode 100644
index 000000000000..ab1c7da9d2d3
--- /dev/null
+++ b/test/dm/tee.c
@@ -0,0 +1,98 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2018 Linaro Limited
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/test.h>
+#include <sandboxtee.h>
+#include <tee.h>
+#include <test/ut.h>
+#include <tee/optee_ta_avb.h>
+
+static int open_session(struct udevice *dev, u32 *session)
+{
+	struct tee_open_session_arg arg;
+	const struct tee_optee_ta_uuid uuid = TA_AVB_UUID;
+	int rc;
+
+	memset(&arg, 0, sizeof(arg));
+	tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
+	rc = tee_open_session(dev, &arg, 0, NULL);
+	if (rc)
+		return rc;
+	if (arg.ret)
+		return -EIO;
+	*session = arg.session;
+
+	return 0;
+}
+
+static int invoke_func(struct udevice *dev, u32 session)
+{
+	struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT };
+	struct tee_invoke_arg arg;
+
+	memset(&arg, 0, sizeof(arg));
+	arg.session = session;
+	arg.func = TA_AVB_CMD_READ_LOCK_STATE;
+
+	if (tee_invoke_func(dev, &arg, 1, &param) || arg.ret)
+		return -1;
+
+	return 0;
+}
+
+static int match(struct tee_version_data *vers, const void *data)
+{
+	return vers->gen_caps & TEE_GEN_CAP_GP;
+}
+
+static int dm_test_tee(struct unit_test_state *uts)
+{
+	struct tee_version_data vers;
+	struct udevice *dev;
+	struct sandbox_tee_state *state;
+	u32 session;
+	int rc;
+	u8 data[128];
+	struct tee_shm *reg_shm;
+	struct tee_shm *alloc_shm;
+
+	dev = tee_find_device(NULL, match, NULL, &vers);
+	ut_assert(dev);
+	state = dev_get_priv(dev);
+	ut_assert(!state->session);
+
+	rc = open_session(dev, &session);
+	ut_assert(!rc);
+	ut_assert(session == state->session);
+
+	rc = invoke_func(dev, session);
+	ut_assert(!rc);
+
+	rc = tee_close_session(dev, session);
+	ut_assert(!rc);
+	ut_assert(!state->session);
+
+	ut_assert(!state->num_shms);
+	rc = tee_shm_register(dev, data, sizeof(data), 0, &reg_shm);
+	ut_assert(!rc);
+	ut_assert(state->num_shms == 1);
+
+	rc = tee_shm_alloc(dev, 256, 0, &alloc_shm);
+	ut_assert(!rc);
+	ut_assert(state->num_shms == 2);
+
+	ut_assert(tee_shm_is_registered(reg_shm, dev));
+	ut_assert(tee_shm_is_registered(alloc_shm, dev));
+
+	tee_shm_free(reg_shm);
+	tee_shm_free(alloc_shm);
+	ut_assert(!state->num_shms);
+
+	return 0;
+}
+
+DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT);