1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2018 Linaro Limited
11 #include <sandboxtee.h>
14 #include <tee/optee_ta_avb.h>
16 static int open_session(struct udevice *dev, u32 *session)
18 struct tee_open_session_arg arg;
19 const struct tee_optee_ta_uuid uuid = TA_AVB_UUID;
22 memset(&arg, 0, sizeof(arg));
23 tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
24 rc = tee_open_session(dev, &arg, 0, NULL);
29 *session = arg.session;
34 static int invoke_func(struct udevice *dev, u32 session)
36 struct tee_param param = { .attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT };
37 struct tee_invoke_arg arg;
39 memset(&arg, 0, sizeof(arg));
40 arg.session = session;
41 arg.func = TA_AVB_CMD_READ_LOCK_STATE;
43 if (tee_invoke_func(dev, &arg, 1, ¶m) || arg.ret)
49 static int match(struct tee_version_data *vers, const void *data)
51 return vers->gen_caps & TEE_GEN_CAP_GP;
54 struct test_tee_vars {
55 struct tee_shm *reg_shm;
56 struct tee_shm *alloc_shm;
59 static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars)
61 struct tee_version_data vers;
63 struct sandbox_tee_state *state;
68 dev = tee_find_device(NULL, match, NULL, &vers);
70 state = dev_get_priv(dev);
71 ut_assert(!state->session);
73 rc = open_session(dev, &session);
75 ut_assert(session == state->session);
77 rc = invoke_func(dev, session);
80 rc = tee_close_session(dev, session);
82 ut_assert(!state->session);
84 ut_assert(!state->num_shms);
85 rc = tee_shm_register(dev, data, sizeof(data), 0, &vars->reg_shm);
87 ut_assert(state->num_shms == 1);
89 rc = tee_shm_alloc(dev, 256, 0, &vars->alloc_shm);
91 ut_assert(state->num_shms == 2);
93 ut_assert(tee_shm_is_registered(vars->reg_shm, dev));
94 ut_assert(tee_shm_is_registered(vars->alloc_shm, dev));
96 tee_shm_free(vars->reg_shm);
98 tee_shm_free(vars->alloc_shm);
99 vars->alloc_shm = NULL;
100 ut_assert(!state->num_shms);
105 static int dm_test_tee(struct unit_test_state *uts)
107 struct test_tee_vars vars = { NULL, NULL };
108 int rc = test_tee(uts, &vars);
110 /* In case test_tee() asserts these may still remain allocated */
111 tee_shm_free(vars.reg_shm);
112 tee_shm_free(vars.alloc_shm);
117 DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT);